attackEntity method was added

This commit is contained in:
GameHerobrine 2023-01-23 11:38:40 +03:00
parent 89ee29a30a
commit 45b36cb034
4 changed files with 50 additions and 40 deletions

View file

@ -189,6 +189,10 @@ class Entity extends Position
return in_array($this->type, func_get_args());
}
public function attackEntity($entity){
}
public function addVelocity($vX, $vY = 0, $vZ = 0)
{
if($vX instanceof Vector3){

View file

@ -1,11 +1,15 @@
<?php
class Monster extends Creature{
public function __construct(Level $level, $eid, $class, $type = 0, $data = []){
parent::__construct($level, $eid, $class, $type, $data);
$this->ai->addTask(new TaskAttackPlayer());
}
public function getAttackDamage(){
return 2;
}
public function __construct(Level $level, $eid, $class, $type = 0, $data = []){
parent::__construct($level, $eid, $class, $type, $data);
$this->ai->addTask(new TaskAttackPlayer());
}
public function getAttackDamage(){
return 2;
}
public function attackEntity($entity){
$entity->harm($this->getAttackDamage(), $this->eid);
}
}

View file

@ -4,36 +4,36 @@
*/
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;
}
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){
$ai->entity->attackEntity($this->target);
$this->attackTime = 20;
}
--$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;
}
}

View file

@ -22,6 +22,8 @@ class Creeper extends Monster{
$this->setState($v === null ? !$this->getState() : $v);
}
/**
* @return boolean
*/
@ -74,4 +76,4 @@ class Creeper extends Monster{
[GUNPOWDER, 0, mt_rand(0,2)]
];
}
}
}