rewrite of interact system, bugfixes, ai tweaks

This commit is contained in:
GameHerobrine 2022-11-01 00:55:49 +03:00
parent f5222be9d2
commit ac1a1b2449
62 changed files with 649 additions and 491 deletions

View file

@ -5,19 +5,22 @@ class TaskRandomWalk extends TaskBase
private $x, $z, $delay = 10, $newPos, $looking = false;
public function shouldBeExecuted(EntityAI $ai)
{
if($ai->entity instanceof Creeper && $ai->entity->isIgnited()){
return false;
}
return !$ai->entity->pathFound && $ai->entity->moveTime <= 0 && $ai->entity->lookTime <= 0 && $ai->entity->idleTime <= 0 && !($ai->entity->target instanceof Entity) && mt_rand(0,3) == 1;
}
public function wasExecuted(EntityAI $ai)
{
return $ai->entity->moveTime > 0;
return $ai->entity->moveTime > 0 && ($this->x != 0 || $this->z != 0);
}
public function onStart(EntityAI $ai)
{
$this->x = mt_rand(-7, 7);
$this->z = mt_rand(-7, 7);
$this->newPos = $ai->entity->add($this->x, 0, $this->z);
$ai->entity->moveTime = 15 * Utils::distance($ai->entity, $this->newPos);
$ai->entity->moveTime = floor(5 * Utils::distance($ai->entity, $this->newPos));
}
public function onUpdate(EntityAI $ai)
@ -36,12 +39,12 @@ class TaskRandomWalk extends TaskBase
}
}
if($ai->entity->moveTime <= 1){
$ai->entity->idleTime = mt_rand(10,100);
$ai->entity->idleTime = mt_rand(10,40);
$this->x = 0;
$this->z = 0;
$this->looking = false;
}
if(!$ai->entity->isMoving()){
$ai->entity->addVelocity(($this->x > 0 ? 0.1 : ($this->x < 0 ? -0.1 : 0)), 0, ($this->z > 0 ? 0.1 : ($this->z < 0 ? -0.1 : 0)));
}
$ai->entity->moveEntityWithOffset(($this->x > 0 ? 1 : ($this->x < 0 ? -1 : 0)), 0, ($this->z > 0 ? 1 : ($this->z < 0 ? -1 : 0)));
}
public function updateLook($ai){
$ai->entity->server->query("UPDATE entities SET pitch = ".$ai->entity->pitch.", yaw = ".$ai->entity->yaw." WHERE EID = ".$ai->entity->eid.";");
@ -50,9 +53,8 @@ class TaskRandomWalk extends TaskBase
$x = $this->newPos->x - $ai->entity->x;
$y = $this->newPos->y - $ai->entity->y;
$z = $this->newPos->z - $ai->entity->z;
$ai->entity->yaw = -atan2($vX, $vZ) * 180 / M_PI;
$ai->entity->yaw = -atan2($x, $z) * 180 / M_PI;
$ai->entity->pitch = $y == 0 ? 0 : rad2deg(-atan2($y, sqrt(pow($x, 2) + pow($z, 2))));
$ai->entity->server->query("UPDATE entities SET pitch = ".$ai->entity->pitch.", yaw = ".$ai->entity->yaw." WHERE EID = ".$ai->entity->eid.";");
}
}
}