mirror of
https://github.com/oldminecraftcommunity/NostalgiaCore.git
synced 2026-11-20 11:39:43 +00:00
fixed tasklookaround
This commit is contained in:
parent
b7f9d3f1c5
commit
3d1dba6b86
14 changed files with 58 additions and 24 deletions
|
|
@ -115,9 +115,14 @@ abstract class Living extends Entity implements Pathfindable{
|
|||
|
||||
public function updateEntityMovement(){
|
||||
if(!$this->dead && Entity::$allowedAI && $this->idleTime <= 0) {
|
||||
$this->ai->updateTasks();
|
||||
//$this->ai->updateTasks();
|
||||
}
|
||||
|
||||
//if($this->onGround){
|
||||
// if(!$this->hasPath() && $this->pathFinder instanceof ITileNavigator){
|
||||
// $this->path = $this->pathFinder->navigate(new PathTileXYZ($this->x, $this->y, $this->z, $this->level), new PathTileXYZ($this->x + mt_rand(-10, 10), $this->y + mt_rand(-1, 1), $this->z + mt_rand(-10, 10), $this->level), 10);
|
||||
// }
|
||||
// $this->pathFollower->followPath();
|
||||
//}
|
||||
$this->ai->mobController->movementTick();
|
||||
$this->ai->mobController->rotateTick();
|
||||
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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());
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -14,6 +14,7 @@ class Chicken extends Animal{
|
|||
$this->ai->addTask(new TaskRandomWalk(0.25));
|
||||
$this->ai->addTask(new TaskLookAtPlayer(6));
|
||||
$this->ai->addTask(new TaskPanic(0.375));
|
||||
$this->ai->addTask(new TaskLookAround());
|
||||
}
|
||||
public function isFood($id){
|
||||
return $id === PUMPKIN_SEEDS || $id === MELON_SEEDS || $id === BEETROOT_SEEDS || $id === WHEAT_SEEDS;
|
||||
|
|
|
|||
|
|
@ -10,6 +10,9 @@ class Cow extends Animal{
|
|||
$this->ai->addTask(new TaskRandomWalk(0.2));
|
||||
$this->ai->addTask(new TaskLookAtPlayer(6));
|
||||
$this->ai->addTask(new TaskPanic(0.375));
|
||||
$this->ai->addTask(new TaskLookAround());
|
||||
|
||||
//$this->ai->addTask(new TaskSwimming());
|
||||
}
|
||||
|
||||
public function isFood($id){
|
||||
|
|
|
|||
|
|
@ -13,7 +13,7 @@ class Pig extends Animal implements Rideable{
|
|||
$this->ai->addTask(new TaskRandomWalk(0.25));
|
||||
$this->ai->addTask(new TaskLookAtPlayer(6));
|
||||
$this->ai->addTask(new TaskPanic(0.375));
|
||||
|
||||
$this->ai->addTask(new TaskLookAround());
|
||||
}
|
||||
/**
|
||||
* @return boolean
|
||||
|
|
|
|||
|
|
@ -17,7 +17,7 @@ class Sheep extends Animal{
|
|||
$this->ai->addTask(new TaskLookAtPlayer(6));
|
||||
$this->ai->addTask(new TaskPanic(0.375));
|
||||
$this->ai->addTask(new TaskEatTileGoal());
|
||||
|
||||
$this->ai->addTask(new TaskLookAround());
|
||||
}
|
||||
|
||||
public function createSaveData(){
|
||||
|
|
|
|||
|
|
@ -13,6 +13,7 @@ class Creeper extends Monster{
|
|||
$this->timeUntilExplode = $this->isIgnited() ? self::EXPL_TIME : 0;
|
||||
|
||||
$this->ai->addTask(new TaskRandomWalk(0.25));
|
||||
$this->ai->addTask(new TaskLookAround());
|
||||
}
|
||||
|
||||
public function getAttackDamage(){
|
||||
|
|
|
|||
|
|
@ -7,6 +7,9 @@ class PigZombie extends Monster{
|
|||
$this->setHealth(isset($this->data["Health"]) ? $this->data["Health"] : 12, "generic");
|
||||
$this->setName("Pigman");
|
||||
$this->setSpeed(0.25);
|
||||
|
||||
$this->ai->addTask(new TaskLookAround());
|
||||
$this->ai->addTask(new TaskRandomWalk(0.25));
|
||||
}
|
||||
public function getAttackDamage(){
|
||||
return 5;
|
||||
|
|
|
|||
|
|
@ -10,6 +10,7 @@ class Skeleton extends Monster{
|
|||
//$this->ai->addTask(new TaskDestroyServerPerformance());
|
||||
|
||||
$this->ai->addTask(new TaskRandomWalk(0.25));
|
||||
$this->ai->addTask(new TaskLookAround());
|
||||
}
|
||||
|
||||
public function getAttackDamage(){
|
||||
|
|
|
|||
|
|
@ -8,6 +8,7 @@ class Spider extends Monster{
|
|||
$this->setName("Spider");
|
||||
$this->setSpeed(0.3);
|
||||
$this->ai->addTask(new TaskRandomWalk(0.25)); //TODO this mob doesnt use newAI -> speed is not correct
|
||||
$this->ai->addTask(new TaskLookAround()); //TODO this mob doesnt use newAI
|
||||
}
|
||||
|
||||
public function getDrops(){
|
||||
|
|
|
|||
|
|
@ -9,6 +9,7 @@ class Zombie extends Monster{
|
|||
$this->setSpeed(0.23);
|
||||
|
||||
$this->ai->addTask(new TaskRandomWalk(0.25));
|
||||
$this->ai->addTask(new TaskLookAround());
|
||||
}
|
||||
|
||||
public function getArmorValue(){
|
||||
|
|
|
|||
|
|
@ -188,7 +188,16 @@ class AxisAlignedBB{
|
|||
public function intersectsWith(AxisAlignedBB $bb){
|
||||
return $bb->maxX > $this->minX and $bb->minX < $this->maxX && $bb->maxZ > $this->minZ and $bb->minZ < $this->maxZ && $bb->maxY > $this->minY and $bb->minY < $this->maxY;
|
||||
}
|
||||
|
||||
public function isXYZInsideNS($x, $y, $z){
|
||||
if($x < $this->minX or $x > $this->maxX){
|
||||
return false;
|
||||
}
|
||||
if($y < $this->minY or $y > $this->maxY){
|
||||
return false;
|
||||
}
|
||||
|
||||
return $z > $this->minZ and $z < $this->maxZ;
|
||||
}
|
||||
public function isXYZInside($x, $y, $z){
|
||||
if($x <= $this->minX or $x >= $this->maxX){
|
||||
return false;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue