fixed tasklookaround

This commit is contained in:
GameHerobrine 2024-01-12 05:54:19 +03:00
parent b7f9d3f1c5
commit 3d1dba6b86
14 changed files with 58 additions and 24 deletions

View file

@ -49,7 +49,13 @@ class MobController
public function isRotationCompleted(){
return $this->finalHeadYaw === $this->entity->headYaw;
}
public function setMovingTarget($x, $y, $z, $speed){
$this->moveToX = $x;
$this->moveToY = $y;
$this->moveToZ = $z;
$this->speed = $speed;
$this->updateMove = true;
}
public function setMovingOffset($x, $y, $z, $speed){
$this->moveToX = $this->entity->x + ($x);
$this->moveToY = $this->entity->y + ($y);

View file

@ -13,13 +13,18 @@ class PathFollower{
public function followPath(){
if(!isset($this->entity) || !($this->entity instanceof Living)) return;
if(!$this->entity->hasPath()) return;
if($this->entity->path != null && (is_array($this->entity->path) && count($this->entity->path) <= 0 || $this->entity->currentIndex >= count($this->entity->path))){
$this->entity->path = null;
$this->entity->currentIndex = 0;
$this->entity->currentNode = false;
}elseif($this->entity->path != null && ($this->entity->currentNode == false || $this->entity->boundingBox->isXYZInside($this->entity->currentNode->x, $this->entity->currentNode->y, $this->entity->currentNode->z) || $this->entity->ai->mobController->moveTo($this->entity->currentNode->x, $this->entity->currentNode->y, $this->entity->currentNode->z) === false)){
$this->entity->currentNode = $this->entity->path[$this->entity->currentIndex++];
if($this->entity->currentNode == null){
$this->entity->currentNode = $this->entity->path[$this->entity->currentIndex];
}
$this->entity->ai->mobController->setMovingTarget($this->entity->currentNode->x, $this->entity->currentNode->y, $this->entity->currentNode->z, 0.25);
console($this->entity->currentNode.":".$this->entity->boundingBox);
if($this->entity->boundingBox->isXYZInsideNS($this->entity->currentNode->x, $this->entity->currentNode->y, $this->entity->currentNode->z)){
++$this->entity->currentIndex;
console("next");
$this->entity->currentNode = null;
}
}

View file

@ -2,31 +2,29 @@
class TaskLookAround extends TaskBase
{
private $rotation;
public $lookOffsetX, $lookOffsetZ;
public function onStart(EntityAI $ai)
{
$this->selfCounter = 1;
$this->rotation = mt_rand(-120, 120);
$this->selfCounter = 20 + lcg_value();
$v = (M_PI * 2) * lcg_value();
$this->lookOffsetX = cos($v);
$this->lookOffsetZ = sin($v);
}
public function onEnd(EntityAI $ai)
{
$ai->entity->idleTime = mt_rand(20, 40);
//$ai->entity->idleTime = mt_rand(20, 40);
}
public function canBeExecuted(EntityAI $ai)
{
return !$ai->entity->inPanic && !$ai->entity->isMoving() && lcg_value() < 0.02 && !$ai->isStarted("TaskLookAtPlayer") && !$ai->isStarted("TaskMate") && !$ai->isStarted("TaskTempt") && !$ai->entity->hasPath(); /*Vanilla value*/
}
public function onUpdate(EntityAI $ai)
{
if($this->rotation === 0){
$this->selfCounter = 0;
}
$v = min(Utils::getSign($this->rotation) * 10, $this->rotation);
$ai->entity->headYaw += $v;
$this->rotation -= $v;
--$this->selfCounter;
$ai->mobController->setLookPosition($ai->entity->x + $this->lookOffsetX, $ai->entity->y + $ai->entity->getEyeHeight(), $ai->entity->z + $this->lookOffsetZ, 10, $ai->entity->getVerticalFaceSpeed());
}
}