diff --git a/src/entity/ai/EntityAI.php b/src/entity/ai/EntityAI.php index b9e9929f..5bdea803 100644 --- a/src/entity/ai/EntityAI.php +++ b/src/entity/ai/EntityAI.php @@ -32,6 +32,15 @@ class EntityAI console("[DEBUG] Adding new task...",true, true, 2); $this->tasks[$task->__toString()] = $task; } + + public function removeTask($name){ + if(isset($this->tasks[$name])){ + unset($this->tasks[$name]); + return true; + } + return false; + } + /** * * @param mixed $id classname diff --git a/src/entity/ai/tasks/TaskAttackPlayer.php b/src/entity/ai/tasks/TaskAttackPlayer.php index a91d1083..8dd91a75 100644 --- a/src/entity/ai/tasks/TaskAttackPlayer.php +++ b/src/entity/ai/tasks/TaskAttackPlayer.php @@ -11,14 +11,17 @@ class TaskAttackPlayer extends TaskTempt } public function onUpdate(EntityAI $ai) { - if(!($this->target instanceof Entity) && ($ai->entity instanceof Spider && $ai->entity->level->isDay()) || ($this->target instanceof Entity && !$this->target->isPlayer()) || $this->target->distanceSquared($ai->entity) > 100 || $this->target->level->getName() != $ai->entity->level->getName()){ + if(!($this->target instanceof Entity) || ($ai->entity instanceof Spider && $ai->entity->level->isDay()) || ($this->target instanceof Entity && !$this->target->isPlayer()) || (Utils::distance_noroot($this->target, $ai->entity) > 256) || $this->target->level->getName() != $ai->entity->level->getName()){ $this->reset(); return; } $ai->mobController->moveTo($this->target->x, floor($ai->entity->y), $this->target->z); $ai->mobController->lookOn($this->target); - if($ai->entity->boundingBox->intersectsWith($this->target->boundingBox) && $this->attackTime <= 0){ + $mult = $ai->entity instanceof Spider ? 1 : 2; + $radius = ($ai->entity->width * $mult)*($ai->entity->width * $mult); + console(Utils::distance_noroot($this->target, $ai->entity)); + if(Utils::distance_noroot($this->target, $ai->entity) <= $radius && $this->attackTime <= 0){ $ai->entity->attackEntity($this->target); $this->attackTime = 20; } @@ -27,7 +30,7 @@ class TaskAttackPlayer extends TaskTempt } public function canBeExecuted(EntityAI $ai) { - $target = $this->findTarget($ai->entity, 10); + $target = $this->findTarget($ai->entity, 16); if(($ai->entity instanceof Spider && !$ai->entity->level->isDay()) || $target instanceof Entity && $target->class === ENTITY_PLAYER && $target->isPlayer()){ $this->target = $target; //TODO get rid of it $ai->entity->target = $target; diff --git a/src/entity/ai/tasks/TaskTempt.php b/src/entity/ai/tasks/TaskTempt.php index e2589436..78172ad9 100644 --- a/src/entity/ai/tasks/TaskTempt.php +++ b/src/entity/ai/tasks/TaskTempt.php @@ -18,7 +18,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()) || $this->target->level->getName() != $ai->entity->level->getName()){ + if(!($this->target instanceof Entity) || ($this->target instanceof Entity && !$this->target->isPlayer()) || (Utils::distance_noroot($this->target, $ai->entity) > 100) || !$ai->entity->isFood($this->target->player->getHeldItem()->getID()) || $this->target->level->getName() != $ai->entity->level->getName()){ $this->reset(); return; } diff --git a/src/entity/monster/Skeleton.php b/src/entity/monster/Skeleton.php index 443dc438..70d52c9f 100644 --- a/src/entity/monster/Skeleton.php +++ b/src/entity/monster/Skeleton.php @@ -6,6 +6,7 @@ class Skeleton extends Monster{ parent::__construct($level, $eid, $class, $type, $data); $this->setHealth(isset($this->data["Health"]) ? $this->data["Health"] : 10, "generic"); $this->setName("Skeleton"); + $this->ai->removeTask("TaskAttackPlayer"); $this->setSpeed(0.25); $this->update(); }