mirror of
https://github.com/oldminecraftcommunity/NostalgiaCore.git
synced 2026-11-21 12:09:43 +00:00
ai changes
This commit is contained in:
parent
4835c15747
commit
5a3aeecd93
9 changed files with 196 additions and 98 deletions
|
|
@ -2,49 +2,50 @@
|
|||
|
||||
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 && ($this->x != 0 || $this->z != 0);
|
||||
}
|
||||
private $x, $z, $setupLook = false;
|
||||
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 = floor(5 * Utils::distance($ai->entity, $this->newPos));
|
||||
$this->looking = true;
|
||||
if($this->x = 0 && $this->z = 0){
|
||||
$this->reset();
|
||||
console("rip task");
|
||||
return false;
|
||||
}
|
||||
$this->selfCounter = floor(5 * Utils::distance($ai->entity, $ai->entity->add($this->x, 0, $this->z)));
|
||||
$this->setupLook = false;
|
||||
}
|
||||
|
||||
public function onEnd(EntityAI $ai)
|
||||
{
|
||||
$this->x = $this->z = 0;
|
||||
$ai->entity->idleTime = mt_rand(20, 120);
|
||||
}
|
||||
|
||||
public function onUpdate(EntityAI $ai)
|
||||
{
|
||||
if($ai->entity->moveTime <= 1){
|
||||
$ai->entity->idleTime = mt_rand(10,40);
|
||||
$this->x = 0;
|
||||
$this->z = 0;
|
||||
$this->looking = false;
|
||||
if($ai->entity instanceof Creeper && $ai->entity->isIgnited()) {
|
||||
return false; //TODO Better way: block movement
|
||||
}
|
||||
$ai->entity->moveEntityWithOffset(($this->x > 0 ? 1 : ($this->x < 0 ? -1 : 0)), 0, ($this->z > 0 ? 1 : ($this->z < 0 ? -1 : 0)));
|
||||
if($this->looking){
|
||||
$this->testLook($ai, $ai->entity->speedX, $ai->entity->speedZ);
|
||||
--$this->selfCounter;
|
||||
$ai->mobController->moveNonInstant($this->x, 0, $this->z);
|
||||
if(!$this->setupLook){
|
||||
$ai->mobController->lookAt($ai->entity->speedX, 0, $ai->entity->speedZ);
|
||||
$ai->entity->headYaw = $ai->entity->yaw;
|
||||
$this->looking = false;
|
||||
$ai->entity->idleTime = 10;
|
||||
$this->setupLook = true;
|
||||
return;
|
||||
}
|
||||
|
||||
}
|
||||
public function updateLook($ai){
|
||||
$ai->entity->server->query("UPDATE entities SET pitch = ".$ai->entity->pitch.", yaw = ".$ai->entity->yaw." WHERE EID = ".$ai->entity->eid.";");
|
||||
}
|
||||
public function testLook($ai, $vX, $vZ){
|
||||
$ai->entity->yaw = -atan2($vX, $vZ) * 180 / M_PI;
|
||||
//nopitch $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.";");
|
||||
|
||||
public function canBeExecuted(EntityAI $ai)
|
||||
{
|
||||
if($ai->entity instanceof Creeper && $ai->entity->isIgnited()) {
|
||||
return false;
|
||||
}
|
||||
return !$ai->getTask("TaskLookAround")->isStarted;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue