diff --git a/src/entity/Entity.php b/src/entity/Entity.php index 78bbceef..dfe80ab2 100644 --- a/src/entity/Entity.php +++ b/src/entity/Entity.php @@ -895,8 +895,8 @@ class Entity extends Position } } - /* - * METADATA VALUES(EXPEREMENTAL) + /** + * METADATA VALUES * ***************** * Types: Get input type of * 0 -> Byte @@ -917,7 +917,6 @@ class Entity extends Position * DATA FLAGS IDS * 0 - fire * 1 - crouching - * 2 - riding - no idea why doesnt it work * 4 - inAction(ex.: using a bow) */ public function getMetadata() diff --git a/src/entity/ai/tasks/TaskBase.php b/src/entity/ai/tasks/TaskBase.php index 9c0e4ffd..56eaf4fb 100644 --- a/src/entity/ai/tasks/TaskBase.php +++ b/src/entity/ai/tasks/TaskBase.php @@ -4,6 +4,8 @@ abstract class TaskBase { public $isStarted = false, $selfCounter = 0; + public function __construct(){} + /** * Executed when entity starts task. It is recommended to set counter here. * @param EntityAI $ai diff --git a/src/entity/ai/tasks/TaskDestroyServerPerformance.php b/src/entity/ai/tasks/TaskDestroyServerPerformance.php new file mode 100644 index 00000000..790f42ac --- /dev/null +++ b/src/entity/ai/tasks/TaskDestroyServerPerformance.php @@ -0,0 +1,89 @@ +server = ServerAPI::request(); + } + + public function onStart(EntityAI $ai) + { + $this->selfCounter = 1; + } + + 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()) || (Utils::distance_noroot($this->target, $ai->entity) > 256) || $this->target->level->getName() != $ai->entity->level->getName()){ + $this->reset(); + return; + } + if(Utils::distance_noroot($this->target, $ai->entity) > 100){ + $ai->mobController->moveTo($this->target->x, floor($ai->entity->y), $this->target->z); + }else{ + //TODO move away + } + $ai->mobController->lookOn($this->target); + + if(--$this->attackTime <= 0){ + $this->rangedAttack($ai->entity, $this->target); + $this->attackTime = 60; + } + } + + /** + * + * @param Entity $selfEntity + * @param Entity $target + */ + public function rangedAttack($selfEntity, $target){ + $d = [ + "x" => $selfEntity->x, + "y" => $selfEntity->y + 1.6, + "z" => $selfEntity->z, + "yaw" => $selfEntity->yaw, + "pitch" => $selfEntity->pitch + ]; + /** + * @var Arrow $arrow + */ + $arrow = $this->server->api->entity->add($selfEntity->level, ENTITY_OBJECT, OBJECT_ARROW, $d); + $arrow->shotByEntity = true; + $arrow->shooterEID = $selfEntity->eid; + $posY = ($target->y + $target->getEyeHeight() - 0.1); + $diffX = $target->x - $selfEntity->x; + $diffY = ($target->boundingBox->minY + ($target->height / 3)) - $posY; + $diffZ = $target->z - $selfEntity->z; + $v12 = sqrt($diffX * $diffX + $diffZ * $diffZ); + if($v12 >= 1.0e-7){ + $yaw = ((atan2($diffZ, $diffX) * 180) / M_PI) - 90; + $pitch = -((atan2($diffY, $v12) * 180) / M_PI); + $v16 = $diffX / $v12; + $v18 = $diffZ / $v12; + $arrow->x = $selfEntity->x + $v16; + $arrow->y = $posY; + $arrow->z = $selfEntity->z + $v18; + $arrow->yaw = $yaw; + $arrow->pitch = $pitch; + $arrow->updateAABB(); + $v20 = $v12 * 0.2; + $arrow->shoot($diffX, $diffY + $v20, $diffZ, 1.6, 12); + $this->server->api->entity->spawnToAll($arrow); + } + } + + public function canBeExecuted(EntityAI $ai) + { + $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; + return true; + } + + return false; + } +} + diff --git a/src/entity/monster/Skeleton.php b/src/entity/monster/Skeleton.php index 70d52c9f..bc5f3338 100644 --- a/src/entity/monster/Skeleton.php +++ b/src/entity/monster/Skeleton.php @@ -7,6 +7,7 @@ class Skeleton extends Monster{ $this->setHealth(isset($this->data["Health"]) ? $this->data["Health"] : 10, "generic"); $this->setName("Skeleton"); $this->ai->removeTask("TaskAttackPlayer"); + $this->ai->addTask(new TaskDestroyServerPerformance()); $this->setSpeed(0.25); $this->update(); } @@ -16,6 +17,7 @@ class Skeleton extends Monster{ } public function updateBurning(){ + return false; if($this->fire > 0 or !$this->level->isDay()){ return false; }