mirror of
https://github.com/oldminecraftcommunity/NostalgiaCore.git
synced 2026-11-20 19:49:44 +00:00
entity ai classes, pigs should look around
This commit is contained in:
parent
6f603fcbe9
commit
8d454e5ec9
12 changed files with 206 additions and 38 deletions
46
src/entity/ai/EntityAI.php
Normal file
46
src/entity/ai/EntityAI.php
Normal file
|
|
@ -0,0 +1,46 @@
|
|||
<?php
|
||||
|
||||
class EntityAI
|
||||
{
|
||||
/**
|
||||
* @var Living
|
||||
*/
|
||||
public $entity;
|
||||
|
||||
/**
|
||||
* @var TaskBase[]
|
||||
*/
|
||||
protected $tasks;
|
||||
|
||||
public $lastTask;
|
||||
|
||||
public function __construct($entity){
|
||||
$this->entity = $entity;
|
||||
$this->tasks = [];
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a task for entity
|
||||
* @param TaskBase $task
|
||||
*/
|
||||
public function addTask(TaskBase $task){
|
||||
console("[DEBUG] Adding new task...",true, true, 2);
|
||||
$this->tasks[] = $task;
|
||||
}
|
||||
|
||||
public function updateTasks(){
|
||||
foreach($this->tasks as $t){
|
||||
if($t->wasExecuted($this)){
|
||||
$t->onUpdate($this);
|
||||
continue;
|
||||
}
|
||||
if($t->shouldBeExecuted($this)){
|
||||
$t->onStart($this);
|
||||
$t->onUpdate($this);
|
||||
$this->lastTask = $this;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue