changes to skeleton ai, theoretical performance increase with huge amount of mobs and players

This commit is contained in:
GameHerobrine 2024-04-12 06:06:59 +03:00
parent c9da91378d
commit da28b3b0ff
9 changed files with 89 additions and 96 deletions

View file

@ -4,17 +4,32 @@ abstract class Creature extends Living{
const CLASS_TYPE = ENTITY_MOB;
public $inPanic;
public $closestPlayerEID = false;
public $closestPlayerDist = INF;
public function __construct(Level $level, $eid, $class, $type = 0, $data = []){
$this->inPanic = false; //force for now
parent::__construct($level, $eid, $class, $type, $data);
$this->setHealth(isset($this->data["Health"]) ? $this->data["Health"] : 1, "generic");
$this->enableAutojump = true;
//$this->setName((isset($mobs[$this->type]) ? $mobs[$this->type]:$this->type));
//$this->ai->addTask(new TaskLookAround());
//$this->ai->addTask(new TaskRandomWalk());
//$this->ai->addTask(new TaskLookAtPlayer());
//$this->ai->addTask(new TaskSwimming());
$this->searchForClosestPlayers = true;
}
public function handlePrePlayerSearcher(){
parent::handlePrePlayerSearcher();
if($this->closestPlayerEID !== false && !isset($this->level->entityList[$this->closestPlayerEID])){
$this->closestPlayerEID = false;
$this->closestPlayerDist = INF;
}
}
public function handlePlayerSearcher(Player $player, $dist){
parent::handlePlayerSearcher($player, $dist);
if($this->closestPlayerDist >= $dist){
$this->closestPlayerEID = $player->entity->eid;
$this->closestPlayerDist = $dist;
}
}
public function createSaveData(){