mirror of
https://github.com/oldminecraftcommunity/NostalgiaCore.git
synced 2026-11-21 12:09:43 +00:00
project uses tabs instead of spaces(as in CONTRIBUTING.md)
This commit is contained in:
parent
f00318b6ed
commit
62571f26cd
115 changed files with 2291 additions and 2364 deletions
|
|
@ -2,46 +2,46 @@
|
|||
|
||||
abstract class TaskBase
|
||||
{
|
||||
public $isStarted = false, $selfCounter = 0;
|
||||
|
||||
/**
|
||||
* Executed when entity starts task. It is recommended to set counter here.
|
||||
* @param EntityAI $ai
|
||||
*/
|
||||
abstract function onStart(EntityAI $ai);
|
||||
|
||||
/**
|
||||
* Every tick until counter will be not equal to 0. It is recommended to update value of counter here.
|
||||
* @param EntityAI $ai
|
||||
*/
|
||||
abstract function onUpdate(EntityAI $ai);
|
||||
|
||||
/**
|
||||
* On task end.
|
||||
* @param EntityAI $ai
|
||||
*/
|
||||
abstract function onEnd(EntityAI $ai);
|
||||
|
||||
/**
|
||||
* Can start the task
|
||||
* @param EntityAI $ai
|
||||
*/
|
||||
abstract function canBeExecuted(EntityAI $ai);
|
||||
|
||||
/**
|
||||
* @return number ticks
|
||||
*/
|
||||
function getIdleTimeAfterEnd(){
|
||||
return 0;
|
||||
}
|
||||
|
||||
function reset(){
|
||||
$this->isStarted = false;
|
||||
$this->selfCounter = 0;
|
||||
}
|
||||
|
||||
final function __toString(){
|
||||
return get_class($this);
|
||||
}
|
||||
public $isStarted = false, $selfCounter = 0;
|
||||
|
||||
/**
|
||||
* Executed when entity starts task. It is recommended to set counter here.
|
||||
* @param EntityAI $ai
|
||||
*/
|
||||
abstract function onStart(EntityAI $ai);
|
||||
|
||||
/**
|
||||
* Every tick until counter will be not equal to 0. It is recommended to update value of counter here.
|
||||
* @param EntityAI $ai
|
||||
*/
|
||||
abstract function onUpdate(EntityAI $ai);
|
||||
|
||||
/**
|
||||
* On task end.
|
||||
* @param EntityAI $ai
|
||||
*/
|
||||
abstract function onEnd(EntityAI $ai);
|
||||
|
||||
/**
|
||||
* Can start the task
|
||||
* @param EntityAI $ai
|
||||
*/
|
||||
abstract function canBeExecuted(EntityAI $ai);
|
||||
|
||||
/**
|
||||
* @return number ticks
|
||||
*/
|
||||
function getIdleTimeAfterEnd(){
|
||||
return 0;
|
||||
}
|
||||
|
||||
function reset(){
|
||||
$this->isStarted = false;
|
||||
$this->selfCounter = 0;
|
||||
}
|
||||
|
||||
final function __toString(){
|
||||
return get_class($this);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -2,35 +2,35 @@
|
|||
|
||||
class TaskLookAround extends TaskBase
|
||||
{
|
||||
private $rotation;
|
||||
public function onStart(EntityAI $ai)
|
||||
{
|
||||
$this->selfCounter = 1;
|
||||
$this->rotation = mt_rand(-120, 120);
|
||||
}
|
||||
private $rotation;
|
||||
public function onStart(EntityAI $ai)
|
||||
{
|
||||
$this->selfCounter = 1;
|
||||
$this->rotation = mt_rand(-120, 120);
|
||||
}
|
||||
|
||||
public function onEnd(EntityAI $ai)
|
||||
{
|
||||
$ai->entity->idleTime = mt_rand(20, 40);
|
||||
}
|
||||
public function onEnd(EntityAI $ai)
|
||||
{
|
||||
$ai->entity->idleTime = mt_rand(20, 40);
|
||||
}
|
||||
|
||||
public function canBeExecuted(EntityAI $ai)
|
||||
{
|
||||
return !$ai->entity->isMoving() && Utils::randomFloat() < 0.02 && !$ai->isStarted("TaskLookAtPlayer") && !$ai->isStarted("TaskTempt"); /*Vanilla value*/
|
||||
}
|
||||
public function canBeExecuted(EntityAI $ai)
|
||||
{
|
||||
return !$ai->entity->isMoving() && Utils::randomFloat() < 0.02 && !$ai->isStarted("TaskLookAtPlayer") && !$ai->isStarted("TaskTempt"); /*Vanilla value*/
|
||||
}
|
||||
|
||||
public function onUpdate(EntityAI $ai)
|
||||
{
|
||||
if($this->rotation === 0){
|
||||
$this->selfCounter = 0;
|
||||
}
|
||||
$v = min(Utils::getSign($this->rotation) * 10, $this->rotation);
|
||||
$ai->entity->yaw += $v;
|
||||
$pk = new RotateHeadPacket(); //TODO headYaw auto update
|
||||
$pk->eid = $ai->entity->eid;
|
||||
$pk->yaw = $ai->entity->yaw;
|
||||
$ai->entity->server->api->player->broadcastPacket($ai->entity->level->players, $pk);
|
||||
$this->rotation -= $v;
|
||||
|
||||
}
|
||||
public function onUpdate(EntityAI $ai)
|
||||
{
|
||||
if($this->rotation === 0){
|
||||
$this->selfCounter = 0;
|
||||
}
|
||||
$v = min(Utils::getSign($this->rotation) * 10, $this->rotation);
|
||||
$ai->entity->yaw += $v;
|
||||
$pk = new RotateHeadPacket(); //TODO headYaw auto update
|
||||
$pk->eid = $ai->entity->eid;
|
||||
$pk->yaw = $ai->entity->yaw;
|
||||
$ai->entity->server->api->player->broadcastPacket($ai->entity->level->players, $pk);
|
||||
$this->rotation -= $v;
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,39 +2,39 @@
|
|||
|
||||
class TaskRandomWalk extends TaskBase
|
||||
{
|
||||
private $x, $z;
|
||||
public function onStart(EntityAI $ai)
|
||||
{
|
||||
$this->x = mt_rand(-10, 10);
|
||||
$this->z = mt_rand(-10, 10);
|
||||
if($this->x === 0 && $this->z === 0){
|
||||
$this->reset();
|
||||
return false;
|
||||
}
|
||||
$this->selfCounter = floor(5 * Utils::distance($ai->entity, $ai->entity->add($this->x, 0, $this->z)));
|
||||
}
|
||||
private $x, $z;
|
||||
public function onStart(EntityAI $ai)
|
||||
{
|
||||
$this->x = mt_rand(-10, 10);
|
||||
$this->z = mt_rand(-10, 10);
|
||||
if($this->x === 0 && $this->z === 0){
|
||||
$this->reset();
|
||||
return false;
|
||||
}
|
||||
$this->selfCounter = floor(5 * Utils::distance($ai->entity, $ai->entity->add($this->x, 0, $this->z)));
|
||||
}
|
||||
|
||||
public function onEnd(EntityAI $ai)
|
||||
{
|
||||
$this->x = $this->z = 0;
|
||||
}
|
||||
public function onEnd(EntityAI $ai)
|
||||
{
|
||||
$this->x = $this->z = 0;
|
||||
}
|
||||
|
||||
public function onUpdate(EntityAI $ai)
|
||||
{
|
||||
if($ai->entity instanceof Creeper && $ai->entity->isIgnited()) {
|
||||
return false; //TODO Better way: block movement
|
||||
}
|
||||
--$this->selfCounter;
|
||||
$ai->mobController->moveNonInstant($this->x, 0, $this->z);
|
||||
}
|
||||
public function onUpdate(EntityAI $ai)
|
||||
{
|
||||
if($ai->entity instanceof Creeper && $ai->entity->isIgnited()) {
|
||||
return false; //TODO Better way: block movement
|
||||
}
|
||||
--$this->selfCounter;
|
||||
$ai->mobController->moveNonInstant($this->x, 0, $this->z);
|
||||
}
|
||||
|
||||
public function canBeExecuted(EntityAI $ai)
|
||||
{
|
||||
if($ai->entity instanceof Creeper && $ai->entity->isIgnited()) {
|
||||
return false;
|
||||
}
|
||||
return !$ai->isStarted("TaskLookAround") && !$ai->isStarted("TaskLookAtPlayer") && mt_rand(0, 120) == 0;
|
||||
}
|
||||
public function canBeExecuted(EntityAI $ai)
|
||||
{
|
||||
if($ai->entity instanceof Creeper && $ai->entity->isIgnited()) {
|
||||
return false;
|
||||
}
|
||||
return !$ai->isStarted("TaskLookAround") && !$ai->isStarted("TaskLookAtPlayer") && mt_rand(0, 120) == 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue