mirror of
https://github.com/oldminecraftcommunity/NostalgiaCore.git
synced 2026-11-21 12:09:43 +00:00
changed pathfinder(hopefully one last time)
This commit is contained in:
parent
8c12e0de26
commit
e11c40f645
28 changed files with 401 additions and 416 deletions
|
|
@ -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){
|
||||
|
|
|
|||
|
|
@ -1,14 +1,10 @@
|
|||
<?php
|
||||
|
||||
abstract class Living extends Entity implements Damageable{
|
||||
public $pathFinder, $pathFound, $path, $pathNavigator, $target, $ai;
|
||||
public $target, $ai;
|
||||
public function __construct(Level $level, $eid, $class, $type = 0, $data = array()){
|
||||
$this->pathFinder = new AStar($this);
|
||||
$this->pathFound = false;
|
||||
$this->target = false;
|
||||
$this->path = null;
|
||||
$this->ai = new EntityAI($this);
|
||||
$this->pathNavigator = new PathNavigator($this);
|
||||
parent::__construct($level, $eid, $class, $type, $data);
|
||||
$this->canBeAttacked = true;
|
||||
$this->hasGravity = true;
|
||||
|
|
|
|||
|
|
@ -12,9 +12,10 @@ class MobController
|
|||
}
|
||||
|
||||
public function moveNonInstant($x, $y, $z){
|
||||
if($x === $this->entity->x && $y === $this->entity->y && $z === $this->entity->z){
|
||||
if($x == 0 && $y == 0 && $z == 0){
|
||||
return false; //failed
|
||||
}
|
||||
|
||||
$ox = ($x > 0 ? 1 : ($x < 0 ? -1 : 0));
|
||||
$oy = ($y > 0 ? 1 : ($y < 0 ? -1 : 0));
|
||||
$oz = ($z > 0 ? 1 : ($z < 0 ? -1 : 0));
|
||||
|
|
@ -27,6 +28,10 @@ class MobController
|
|||
return true;
|
||||
}
|
||||
|
||||
public function moveTo($x, $y, $z){
|
||||
return $this->moveNonInstant($x - floor($this->entity->x), $y - floor($this->entity->y), $z - floor($this->entity->z));
|
||||
}
|
||||
|
||||
public function faceEntity(Vector3 $v){
|
||||
$d = $v->subtract($this->entity)->normalize();
|
||||
$dx = $d->x;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue