fixed target invalidation for 2 tasks

This commit is contained in:
GameHerobrine 2024-03-20 04:10:06 +03:00
parent 773e18282c
commit b81438ee23
5 changed files with 24 additions and 9 deletions

View file

@ -197,7 +197,11 @@ class Entity extends Position
public function isType(){
return in_array($this->type, func_get_args());
}
/**
* @param Entity $entity
* @param int $distance
* @return boolean
*/
public function attackEntity($entity, $distance){
return false;
}

View file

@ -8,9 +8,16 @@ class Monster extends Creature{
public function getAttackDamage(){
return 2;
}
/**
*
* @see Entity::attackEntity()
*/
public function attackEntity($entity, $distance){
$entity->harm($this->getAttackDamage(), $this->eid);
return true;
if($distance < 2.0 && $entity->boundingBox->maxX > $this->boundingBox->minY && $entity->boundingBox->minY < $this->boundingBox->maxY){
$entity->harm($this->getAttackDamage(), $this->eid);
return true;
}else{
return false;
}
}
}

View file

@ -22,6 +22,7 @@ class TaskAttackPlayer extends TaskBase
{
if(!$this->isTargetValid($ai)){
$this->reset();
$this->onEnd($ai);
return false;
}
$ai->mobController->setMovingTarget($ai->entity->target->x, $ai->entity->target->y, $ai->entity->target->z, $this->speedMultiplier);
@ -100,7 +101,7 @@ class TaskAttackPlayer extends TaskBase
public function onEnd(EntityAI $ai)
{
$ai->entity->target = false;
}
}

View file

@ -4,6 +4,7 @@ class TaskTempt extends TaskBase
{
public function __construct($speed){
$this->speedMultiplier = $speed;
$this->targetDistance = 10*10;
}
public function onStart(EntityAI $ai)
@ -13,12 +14,14 @@ class TaskTempt extends TaskBase
public function onEnd(EntityAI $ai)
{
$ai->entity->target = false;
}
public function onUpdate(EntityAI $ai)
{
if(!$this->isTargetValid($ai) || $ai->entity->inPanic || $ai->isStarted("TaskMate")){
$this->reset();
$this->onEnd($ai);
return false;
}
@ -42,7 +45,7 @@ class TaskTempt extends TaskBase
$xDiff = ($t->x - $e->x);
$yDiff = ($t->y - $e->y);
$zDiff = ($t->z - $e->z);
return ($xDiff*$xDiff + $yDiff*$yDiff + $zDiff*$zDiff) <= 36;
return ($xDiff*$xDiff + $yDiff*$yDiff + $zDiff*$zDiff) <= $this->targetDistance;
}
return false;
}
@ -59,7 +62,7 @@ class TaskTempt extends TaskBase
$xDiff = ($t->x - $e->x);
$yDiff = ($t->y - $e->y);
$zDiff = ($t->z - $e->z);
if(($xDiff*$xDiff + $yDiff*$yDiff + $zDiff*$zDiff) <= 36){
if(($xDiff*$xDiff + $yDiff*$yDiff + $zDiff*$zDiff) <= $this->targetDistance){
return true;
}
}
@ -72,7 +75,7 @@ class TaskTempt extends TaskBase
$yDiff = $pt->y - $e->y;
$zDiff = $pt->z - $e->z;
$d = ($xDiff*$xDiff + $yDiff*$yDiff + $zDiff*$zDiff);
if($d <= 36){
if($d <= $this->targetDistance){
if($bestTargetDistance >= $d){
$closestTarget = $pt;
$bestTargetDistance = $d;

View file

@ -27,7 +27,7 @@ class Spider extends Monster{
$this->speedY = 0.4;
}
return false;
}elseif($distance <= 2.0){
}else{
return parent::attackEntity($entity, $distance);
}