small changes to entity ai(again =/)

This commit is contained in:
GameHerobrine 2022-11-11 20:13:08 +03:00
parent c29d8dab9d
commit 978447cdbb
9 changed files with 44 additions and 41 deletions

View file

@ -2,10 +2,10 @@
class TaskLookAround extends TaskBase
{
private $finYaw = 0;
private $rotation = 0;
public function shouldBeExecuted(EntityAI $ai)
{
return !$ai->entity->isMoving() && $ai->entity->lookTime <= 0 && mt_rand(0,30) == 1 && $ai->entity->idleTime <= 0;
return !$ai->entity->isMoving() && $ai->entity->lookTime <= 0 && Utils::randomFloat() < 0.02 && $ai->entity->idleTime <= 0;
}
public function wasExecuted(EntityAI $ai){
@ -14,8 +14,8 @@ class TaskLookAround extends TaskBase
}
public function onStart(EntityAI $ai){
$ai->entity->lookTime = 120;
$this->finYaw = $ai->entity->yaw;
$ai->entity->lookTime = 20 + mt_rand(0, 20);
$this->rotation = mt_rand(-180,180);
}
public function onUpdate(EntityAI $ai)
@ -26,21 +26,13 @@ class TaskLookAround extends TaskBase
if($ai->entity->lookTime === 1){
$ai->entity->idleTime = mt_rand(10, 40);
}
if(Utils::in_range($ai->entity->lookTime, 45, 60) || Utils::in_range($ai->entity->lookTime, 0, 15)){
$ai->entity->yaw -= 3;
}
if(Utils::in_range($ai->entity->lookTime, 15, 45)){
$ai->entity->yaw += 3;
}
$v = Utils::getSign($this->rotation) * 10;
$ai->entity->yaw += $v;
$pk = new RotateHeadPacket();
$pk->eid = $ai->entity->eid;
$pk->yaw = $ai->entity->yaw;
$ai->entity->server->api->player->broadcastPacket($ai->entity->level->players, $pk);
}
public function testLook($pos){
$this->rotation -= $v;
}
}