skeletons are peaceful and will not attack player, entity will seaatch 16 block radius to find attackable player

This commit is contained in:
GameHerobrine 2023-01-25 19:27:27 +03:00
parent ed30995f9d
commit 395e35ad5d
4 changed files with 17 additions and 4 deletions

View file

@ -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

View file

@ -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;

View file

@ -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;
}

View file

@ -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();
}