mirror of
https://github.com/oldminecraftcommunity/NostalgiaCore.git
synced 2026-11-21 20:19:44 +00:00
fixed more tasks
This commit is contained in:
parent
bcf7ef7c79
commit
2636aa985d
15 changed files with 64 additions and 20 deletions
|
|
@ -26,6 +26,9 @@ class MobController
|
|||
public $moveToX, $moveToY, $moveToZ;
|
||||
public $speed;
|
||||
public $updateMove = false;
|
||||
|
||||
public $lookX, $lookY, $lookZ;
|
||||
public $deltaLookYaw, $deltaLookPitch;
|
||||
public $isLooking = false;
|
||||
|
||||
|
||||
|
|
@ -132,7 +135,17 @@ class MobController
|
|||
$this->entity->pitch = 0;
|
||||
if($this->isLooking){
|
||||
$this->isLooking = false;
|
||||
//TODO
|
||||
|
||||
$diffX = $this->lookX - $this->entity->x;
|
||||
$diffY = $this->lookY - ($this->entity->y + $this->entity->getEyeHeight());
|
||||
$diffZ = $this->lookZ - $this->entity->z;
|
||||
$distance = sqrt($diffX*$diffX + $diffZ*$diffZ);
|
||||
|
||||
$v9 = (atan2($diffZ, $diffX)*180 / M_PI) - 90;
|
||||
$v10 = -(atan2($diffY, $distance)*180 / M_PI);
|
||||
|
||||
$this->entity->pitch = self::limitAngle($this->entity->pitch, $v10, $this->deltaLookPitch);
|
||||
$this->entity->headYaw = self::limitAngle($this->entity->headYaw, $v9, $this->deltaLookYaw);
|
||||
}else{
|
||||
$this->entity->headYaw = self::limitAngle($this->entity->headYaw, $this->entity->renderYawOffset, 10);
|
||||
}
|
||||
|
|
@ -160,8 +173,13 @@ class MobController
|
|||
//$this->entity->headYaw = Utils::wrapAngleTo360($this->entity->headYaw + $w180min);
|
||||
}
|
||||
|
||||
public function moveTo($x, $y, $z, $camera = true){
|
||||
//TODO fix return $this->moveNonInstant($x - floor($this->entity->x), $y - floor($this->entity->y), $z - floor($this->entity->z), $camera);
|
||||
public function setLookPosition($posX, $posY, $posZ, $lookYaw, $lookPitch){
|
||||
$this->lookX = $posX;
|
||||
$this->lookY = $posY;
|
||||
$this->lookZ = $posZ;
|
||||
$this->deltaLookYaw = $lookYaw;
|
||||
$this->deltaLookPitch = $lookPitch;
|
||||
$this->isLooking = true;
|
||||
}
|
||||
|
||||
public function faceEntity($x, $y, $z){
|
||||
|
|
|
|||
|
|
@ -2,7 +2,11 @@
|
|||
|
||||
class TaskLookAtPlayer extends TaskBase{
|
||||
public $target = false;
|
||||
private $state, $yaw, $pitch;
|
||||
public $distance;
|
||||
public function __construct($distance){
|
||||
$this->distance = $distance;
|
||||
}
|
||||
|
||||
public function canBeExecuted(EntityAI $ai){
|
||||
return !$ai->entity->inPanic && lcg_value() < 0.02 && !$ai->entity->isMovingHorizontally() && !$ai->isStarted("TaskMate") && !$ai->isStarted("TaskLookAround") && !$ai->isStarted("TaskTempt") && !$ai->isStarted("TaskPanic") && !$ai->entity->hasPath();
|
||||
}
|
||||
|
|
@ -37,14 +41,13 @@ class TaskLookAtPlayer extends TaskBase{
|
|||
}
|
||||
|
||||
public function onStart(EntityAI $ai){
|
||||
$this->target = $this->findTarget($ai->entity, 6); //TODO max distance for different mobs
|
||||
$this->target = $this->findTarget($ai->entity, $this->distance);
|
||||
if(!($this->target instanceof Entity) || !$this->target->isPlayer()){
|
||||
$this->reset();
|
||||
$this->onEnd($ai);
|
||||
return;
|
||||
}
|
||||
$this->yaw = $ai->entity->yaw;
|
||||
$this->pitch = $ai->entity->pitch;
|
||||
|
||||
$this->selfCounter = mt_rand(20, 60);
|
||||
}
|
||||
|
||||
|
|
@ -54,6 +57,7 @@ class TaskLookAtPlayer extends TaskBase{
|
|||
$this->onEnd($ai);
|
||||
return;
|
||||
}
|
||||
$ai->mobController->setLookPosition($this->target->x, $this->target->y + $this->target->getEyeHeight(), $this->target->z, 10, $ai->entity->getVerticalFaceSpeed());
|
||||
$ai->mobController->lookOn($this->target);
|
||||
$this->selfCounter--;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3,6 +3,12 @@
|
|||
class TaskPanic extends TaskBase
|
||||
{
|
||||
protected $randX = 2, $randZ = 2;
|
||||
|
||||
public $moveSpeed;
|
||||
public function __construct($moveSpeed){
|
||||
$this->moveSpeed = $moveSpeed;
|
||||
}
|
||||
|
||||
public function onStart(EntityAI $ai)
|
||||
{
|
||||
$this->selfCounter = 60;
|
||||
|
|
@ -16,8 +22,8 @@ class TaskPanic extends TaskBase
|
|||
}
|
||||
|
||||
public function regenerateRandXZ(){
|
||||
$this->randX = (mt_rand(0, 1) ? -1 : 1) * 2;
|
||||
$this->randZ = (mt_rand(0, 1) ? -1 : 1) * 2;
|
||||
$this->randX = (mt_rand(0, 1) ? -1 : 1);
|
||||
$this->randZ = (mt_rand(0, 1) ? -1 : 1);
|
||||
}
|
||||
|
||||
public function reset(){
|
||||
|
|
@ -28,7 +34,7 @@ class TaskPanic extends TaskBase
|
|||
{
|
||||
--$this->selfCounter;
|
||||
if($this->selfCounter % 20 === 0) $this->regenerateRandXZ();
|
||||
//TODO fix $ai->mobController->moveNonInstant($this->randX, 0, $this->randZ);
|
||||
$ai->mobController->setMovingOffset($this->randX, 0, $this->randZ, $this->moveSpeed);
|
||||
}
|
||||
|
||||
public function canBeExecuted(EntityAI $ai)
|
||||
|
|
|
|||
|
|
@ -37,11 +37,10 @@ class TaskRandomWalk extends TaskBase
|
|||
|
||||
public function canBeExecuted(EntityAI $ai)
|
||||
{
|
||||
return true;
|
||||
//if(($ai->entity instanceof Creeper && $ai->entity->isIgnited()) || $ai->entity->hasPath() || $ai->isStarted("TaskTempt") ||$ai->isStarted("TaskAttackPlayer")) {
|
||||
// return false;
|
||||
//} // i really need mutexBits
|
||||
//return !$ai->entity->inPanic && !$ai->isStarted("TaskMate") && !$ai->isStarted("TaskEatTileGoal") && !$ai->isStarted("TaskLookAround") && !$ai->isStarted("TaskLookAtPlayer") && mt_rand(0, 120) == 0;
|
||||
if(($ai->entity instanceof Creeper && $ai->entity->isIgnited()) || $ai->entity->hasPath() || $ai->isStarted("TaskTempt") ||$ai->isStarted("TaskAttackPlayer")) {
|
||||
return false;
|
||||
} // i really need mutexBits
|
||||
return !$ai->entity->inPanic && !$ai->isStarted("TaskMate") && !$ai->isStarted("TaskEatTileGoal") && !$ai->isStarted("TaskLookAround") && !$ai->isStarted("TaskLookAtPlayer") && mt_rand(0, 120) == 0;
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue