changed pathfinder(hopefully one last time)

This commit is contained in:
GameHerobrine 2022-12-26 02:16:24 +03:00
parent 8c12e0de26
commit e11c40f645
28 changed files with 401 additions and 416 deletions

View file

@ -6,10 +6,13 @@ move methods
abstract class Creature extends Living{
const CLASS_TYPE = ENTITY_MOB;
public $pathFinder, $path = null, $currentIndex = 0, $currentNode;
public $inPanic;
public function __construct(Level $level, $eid, $class, $type = 0, $data = []){
$this->inPanic = false; //force for now
$this->pathFinder = new TileNavigator(new MCBlockedProvider(), new MCDiagonalProvider(), new Pythagoras3D(), new ManhattanHeuristic3D());
parent::__construct($level, $eid, $class, $type, $data);
$this->setHealth(isset($this->data["Health"]) ? $this->data["Health"] : 1, "generic");
//$this->setName((isset($mobs[$this->type]) ? $mobs[$this->type]:$this->type));
@ -18,11 +21,24 @@ abstract class Creature extends Living{
$this->ai->addTask(new TaskRandomWalk());
$this->ai->addTask(new TaskLookAtPlayer());
}
}
public function update(){
/*if($this->path === null && $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(-7, 7), $this->y, $this->z + mt_rand(-7, 7), $this->level));
}
if(is_array($this->path) && count($this->path) <= 0 || $this->currentIndex >= count($this->path)){
$this->path = null;
$this->currentIndex = 0;
$this->currentNode = false;
}elseif($this->currentNode == false || $this->ai->mobController->moveTo($this->currentNode->x, $this->currentNode->y, $this->currentNode->z) === false){
console("this");
$this->currentNode = $this->path[$this->currentIndex++];
}*/
/*if($this->path === false || count($this->path) <= 0){
$this->path = $this->pathFinder->findPath(MinecraftNode::fromArray([$this->x, $this->y, $this->z]), new MinecraftNode($this->x + mt_rand(-7, 7), $this->y, $this->z + mt_rand(-7, 7)));
}
$state = $this->pathNavigator->followPath($this->path);
if($state === PathNavigator::PATH_COMPLETED){