mirror of
https://github.com/oldminecraftcommunity/NostalgiaCore.git
synced 2026-11-21 20:19:44 +00:00
mobs will attack now, fixed division by 0(i hate php)
This commit is contained in:
parent
616c933d3d
commit
b8589c9dd4
13 changed files with 71 additions and 5 deletions
39
src/entity/ai/tasks/TaskAttackPlayer.php
Normal file
39
src/entity/ai/tasks/TaskAttackPlayer.php
Normal file
|
|
@ -0,0 +1,39 @@
|
|||
<?php
|
||||
/**
|
||||
* A Tempt but for Monsters
|
||||
*/
|
||||
class TaskAttackPlayer extends TaskTempt
|
||||
{
|
||||
public $attackTime = 0;
|
||||
public function onStart(EntityAI $ai)
|
||||
{
|
||||
$this->selfCounter = 1;
|
||||
}
|
||||
public function onUpdate(EntityAI $ai)
|
||||
{
|
||||
if(($this->target instanceof Entity && !$this->target->isPlayer()) || $this->target->distanceSquared($ai->entity) > 100 || $this->target->level->getName() != $ai->entity->level->getName()){
|
||||
$this->reset();
|
||||
return;
|
||||
}
|
||||
|
||||
$ai->mobController->moveTo($this->target->x, floor($ai->entity->y), $this->target->z);
|
||||
$ai->mobController->lookOn($this->target);
|
||||
if($ai->entity->boundingBox->intersectsWith($this->target->boundingBox) && $this->attackTime <= 0){
|
||||
$this->attackTime = 20;
|
||||
$this->target->harm($ai->entity->getAttackDamage(), $ai->entity->eid);
|
||||
}
|
||||
--$this->attackTime;
|
||||
|
||||
}
|
||||
public function canBeExecuted(EntityAI $ai)
|
||||
{
|
||||
$target = $this->findTarget($ai->entity, 10);
|
||||
if($target instanceof Entity && $target->class === ENTITY_PLAYER && $target->isPlayer()){
|
||||
$this->target = $target;
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -23,7 +23,6 @@ class TaskTempt extends TaskBase
|
|||
}
|
||||
|
||||
$ai->mobController->moveTo($this->target->x, floor($ai->entity->y), $this->target->z);
|
||||
|
||||
$ai->mobController->lookOn($this->target);
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue