ai changes

This commit is contained in:
GameHerobrine 2022-12-26 08:15:13 +03:00
parent 11b1a09599
commit 0f72601891
9 changed files with 52 additions and 29 deletions

View file

@ -0,0 +1,24 @@
<?php
class PathFollower{
/**
* @var Living
*/
public $entity;
public function __construct(Living $entity){
$this->entity = $entity;
}
public function followPath(){
if($this->entity->path != null && (is_array($this->entity->path) && count($this->entity->path) <= 0 || $this->entity->currentIndex >= count($this->entity->path))){
$this->entity->path = null;
$this->entity->currentIndex = 0;
$this->entity->currentNode = false;
}elseif($this->entity->path != null && ($this->entity->currentNode == false || $this->entity->ai->mobController->moveTo($this->entity->currentNode->x, $this->entity->currentNode->y, $this->entity->currentNode->z) === false)){
$this->entity->currentNode = $this->entity->path[$this->entity->currentIndex++];
}
}
}

View file

@ -16,7 +16,7 @@ class TaskLookAround extends TaskBase
public function canBeExecuted(EntityAI $ai)
{
return !$ai->entity->isMoving() && Utils::randomFloat() < 0.02 && !$ai->isStarted("TaskLookAtPlayer") && !$ai->isStarted("TaskTempt"); /*Vanilla value*/
return !$ai->entity->isMoving() && Utils::randomFloat() < 0.02 && !$ai->isStarted("TaskLookAtPlayer") && !$ai->isStarted("TaskTempt") && !$ai->entity->hasPath(); /*Vanilla value*/
}
public function onUpdate(EntityAI $ai)

View file

@ -6,7 +6,7 @@ class TaskLookAtPlayer extends TaskBase{
public $target = false;
private $state, $yaw, $pitch;
public function canBeExecuted(EntityAI $ai){
return Utils::randomFloat() < 0.02 && !$ai->entity->isMoving() && !$ai->isStarted("TaskLookAround") && !$ai->isStarted("TaskTempt");
return Utils::randomFloat() < 0.02 && !$ai->entity->isMoving() && !$ai->isStarted("TaskLookAround") && !$ai->isStarted("TaskTempt") && !$ai->entity->hasPath();
}
protected function findTarget($e, $r){
@ -42,7 +42,7 @@ class TaskLookAtPlayer extends TaskBase{
}
public function onUpdate(EntityAI $ai){
if(!($this->target instanceof Entity) || Utils::distance($ai->entity, $this->target) > 6){ //TODO max distance for different mobs
if(!($this->target instanceof Entity) || Utils::distance($ai->entity, $this->target) > 6 || $this->target->level->getName() != $ai->entity->level->getName()){ //TODO max distance for different mobs
$this->reset();
return;
}

View file

@ -21,7 +21,7 @@ class TaskRandomWalk extends TaskBase
public function onUpdate(EntityAI $ai)
{
if($ai->entity instanceof Creeper && $ai->entity->isIgnited()) {
if($ai->entity instanceof Creeper && $ai->entity->isIgnited() || $ai->isStarted("TaskTempt")) {
return false; //TODO Better way: block movement
}
--$this->selfCounter;
@ -30,7 +30,7 @@ class TaskRandomWalk extends TaskBase
public function canBeExecuted(EntityAI $ai)
{
if($ai->entity instanceof Creeper && $ai->entity->isIgnited()) {
if($ai->entity instanceof Creeper && $ai->entity->isIgnited() || $ai->entity->hasPath() || $ai->isStarted("TaskTempt")) {
return false;
}
return !$ai->isStarted("TaskLookAround") && !$ai->isStarted("TaskLookAtPlayer") && mt_rand(0, 120) == 0;

View file

@ -17,7 +17,7 @@ class TaskTempt extends TaskBase
public function onUpdate(EntityAI $ai)
{
if($this->target instanceof Entity && $this->target->isPlayer() && $this->target->distanceSquared($ai->entity) > 100 || !$ai->entity->isFood($this->target->player->getHeldItem()->getID())){
if(($this->target instanceof Entity && !$this->target->isPlayer()) || $this->target->distanceSquared($ai->entity) > 100 || !$ai->entity->isFood($this->target->player->getHeldItem()->getID()) || $this->target->level->getName() != $ai->entity->level->getName()){
$this->reset();
return;
}
@ -31,7 +31,7 @@ class TaskTempt extends TaskBase
public function canBeExecuted(EntityAI $ai)
{
if(!($ai->entity instanceof Breedable)){
if(!($ai->entity instanceof Breedable)){ //TODO Work with path
return false;
}
$target = $this->findTarget($ai->entity, 10);