mirror of
https://github.com/oldminecraftcommunity/NostalgiaCore.git
synced 2026-11-21 12:09:43 +00:00
fixed bug with flying detection, added panic task
This commit is contained in:
parent
7c47c852e2
commit
d7561ed1ba
10 changed files with 70 additions and 17 deletions
|
|
@ -1,32 +1,38 @@
|
|||
<?php
|
||||
|
||||
class TaskLookAtPlayer extends TaskBase{
|
||||
const S_LOOK = 0x1;
|
||||
const S_STOPLOOK = 0x2;
|
||||
public $target = false;
|
||||
private $state, $yaw, $pitch;
|
||||
public function canBeExecuted(EntityAI $ai){
|
||||
return Utils::randomFloat() < 0.02 && !$ai->entity->isMovingHorizontally() && !$ai->isStarted("TaskLookAround") && !$ai->isStarted("TaskTempt") && !$ai->entity->hasPath();
|
||||
return !$ai->entity->inPanic && Utils::randomFloat() < 0.02 && !$ai->entity->isMovingHorizontally() && !$ai->isStarted("TaskLookAround") && !$ai->isStarted("TaskTempt") && !$ai->entity->hasPath();
|
||||
}
|
||||
|
||||
protected function findTarget($e, $r){
|
||||
$svd = null;
|
||||
$svdDist = -1;
|
||||
foreach($e->server->api->entity->getRadius($e, $r, ENTITY_PLAYER) as $p){
|
||||
foreach($e->level->players as $p){
|
||||
$p = $p->entity;
|
||||
if(Utils::distance_noroot($e, $p) > $r*$r){
|
||||
continue;
|
||||
}
|
||||
if($svdDist === -1){
|
||||
$svdDist = Utils::manh_distance($e, $p);
|
||||
$svdDist = Utils::distance_noroot($e, $p);
|
||||
$svd = $p;
|
||||
continue;
|
||||
}
|
||||
if($svd != null && $svdDist === 0){
|
||||
$svd = $p;
|
||||
}
|
||||
|
||||
if(($cd = Utils::manh_distance($e, $p)) < $svdDist){
|
||||
if(($cd = Utils::distance_noroot($e, $p)) < $svdDist){
|
||||
$svdDist = $cd;
|
||||
$svd = $p;
|
||||
}
|
||||
}
|
||||
|
||||
if($svd == null){
|
||||
return null;
|
||||
}
|
||||
|
||||
return $svd;
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue