mirror of
https://github.com/oldminecraftcommunity/NostalgiaCore.git
synced 2026-11-21 03:59:43 +00:00
ai changes
This commit is contained in:
parent
4835c15747
commit
5a3aeecd93
9 changed files with 196 additions and 98 deletions
|
|
@ -2,6 +2,10 @@
|
|||
|
||||
class EntityAI
|
||||
{
|
||||
/**
|
||||
* @var MobController
|
||||
*/
|
||||
public $mobController;
|
||||
/**
|
||||
* @var Living
|
||||
*/
|
||||
|
|
@ -17,6 +21,7 @@ class EntityAI
|
|||
public function __construct($entity){
|
||||
$this->entity = $entity;
|
||||
$this->tasks = [];
|
||||
$this->mobController = new MobController($entity);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -25,22 +30,36 @@ class EntityAI
|
|||
*/
|
||||
public function addTask(TaskBase $task){
|
||||
console("[DEBUG] Adding new task...",true, true, 2);
|
||||
$this->tasks[] = $task;
|
||||
$this->tasks[$task->__toString()] = $task;
|
||||
}
|
||||
/**
|
||||
*
|
||||
* @param mixed $id classname
|
||||
* @return TaskBase | false
|
||||
*/
|
||||
public function getTask($id){
|
||||
return $this->tasks[$id] ?: false; //i never saw this operator before
|
||||
}
|
||||
|
||||
public function updateTasks(){
|
||||
foreach($this->tasks as $t){
|
||||
if($t->wasExecuted($this)){
|
||||
$t->onUpdate($this);
|
||||
continue;
|
||||
}
|
||||
if($t->shouldBeExecuted($this)){
|
||||
if(!$t->isStarted && $t->canBeExecuted($this)){
|
||||
$t->isStarted = true;
|
||||
$t->onStart($this);
|
||||
}
|
||||
if($t->isStarted){
|
||||
$t->onUpdate($this);
|
||||
$this->lastTask = $this;
|
||||
if($t->selfCounter <= 0){
|
||||
$t->isStarted = false;
|
||||
$t->onEnd($this);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function __destruct(){
|
||||
unset($this->entity);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue