From 0f84d692b78f12b385c7e2ef362a688bff7e8e2c Mon Sep 17 00:00:00 2001 From: GameHerobrine Date: Wed, 6 Mar 2024 03:50:11 +0300 Subject: [PATCH] better spider attacks --- src/entity/Entity.php | 6 +++--- src/entity/Monster.php | 3 ++- src/entity/ai/tasks/TaskAttackPlayer.php | 7 ++----- src/entity/monster/Creeper.php | 5 +++-- src/entity/monster/Spider.php | 18 +++++++++++++++++- 5 files changed, 27 insertions(+), 12 deletions(-) diff --git a/src/entity/Entity.php b/src/entity/Entity.php index 2dc140e1..54d53b70 100644 --- a/src/entity/Entity.php +++ b/src/entity/Entity.php @@ -195,8 +195,8 @@ class Entity extends Position return in_array($this->type, func_get_args()); } - public function attackEntity($entity){ - + public function attackEntity($entity, $distance){ + return false; } public function setInWeb(){ @@ -654,7 +654,7 @@ class Entity extends Position $aaBBs = $this->level->getCubes($this, $this->boundingBox->addCoord($dx, $dy, $dz)); - foreach($aaBBs as $bb){ //TODO optimize + foreach($aaBBs as $bb){ $dy = $bb->calculateYOffset($this->boundingBox, $dy); } $this->boundingBox->offset(0, $dy, 0); diff --git a/src/entity/Monster.php b/src/entity/Monster.php index c9831eba..58743128 100644 --- a/src/entity/Monster.php +++ b/src/entity/Monster.php @@ -9,7 +9,8 @@ class Monster extends Creature{ return 2; } - public function attackEntity($entity){ + public function attackEntity($entity, $distance){ $entity->harm($this->getAttackDamage(), $this->eid); + return true; } } diff --git a/src/entity/ai/tasks/TaskAttackPlayer.php b/src/entity/ai/tasks/TaskAttackPlayer.php index eba7d316..2687d381 100644 --- a/src/entity/ai/tasks/TaskAttackPlayer.php +++ b/src/entity/ai/tasks/TaskAttackPlayer.php @@ -28,8 +28,7 @@ class TaskAttackPlayer extends TaskBase $ai->mobController->setLookPosition($ai->entity->target->x, $ai->entity->target->y + 0.12, $ai->entity->target->z, 10, $ai->entity->getVerticalFaceSpeed()); --$this->attackCounter; - $mult = $ai->entity instanceof Spider ? 1 : 2; - $v1 = $ai->entity->width * $ai->entity->width * $mult*$mult; + $v1 = $ai->entity->width * $ai->entity->width * 4; $e = $ai->entity; $t = $e->target; @@ -39,9 +38,7 @@ class TaskAttackPlayer extends TaskBase $dist = ($xDiff*$xDiff + $yDiff*$yDiff + $zDiff*$zDiff); if($dist <= $v1){ if($this->attackCounter <= 0){ - $this->attackCounter = 20; - - $e->attackEntity($t); + $this->attackCounter = $e->attackEntity($t, sqrt($dist)) ? 20 : 0; } } diff --git a/src/entity/monster/Creeper.php b/src/entity/monster/Creeper.php index 2978df34..8c1d7fbc 100644 --- a/src/entity/monster/Creeper.php +++ b/src/entity/monster/Creeper.php @@ -57,11 +57,12 @@ class Creeper extends Monster{ $this->timeUntilExplode = self::EXPL_TIME; } - public function attackEntity($entity){ + public function attackEntity($entity, $distance){ if(Utils::distance_noroot($entity, $this) <= 49 && !$this->isIgnited()){ $this->ignite(); + return true; } - + return false; } public function update($now){ if($this->isIgnited() && $this->target instanceof Entity && Utils::distance_noroot($this->target, $this) > 49){ //TODO move somewhere else diff --git a/src/entity/monster/Spider.php b/src/entity/monster/Spider.php index a6128c3b..7a041e1c 100644 --- a/src/entity/monster/Spider.php +++ b/src/entity/monster/Spider.php @@ -12,7 +12,23 @@ class Spider extends Monster{ $this->ai->addTask(new TaskSwimming()); $this->ai->addTask(new TaskAttackPlayer(1.0, 16)); //TODO fix range? } - + public function attackEntity($entity, $distance){ + if($distance > 2.0 && $distance < 6.0){ + if($this->onGround){ + $diffX = $entity->x - $this->x; + $diffZ = $entity->z - $this->z; + $dist = sqrt($diffX*$diffX + $diffZ*$diffZ); + + $this->speedX = $diffX / $dist*0.5*0.8 + $this->speedX*0.2; + $this->speedZ = $diffZ / $dist*0.5*0.8 + $this->speedZ*0.2; + $this->speedY = 0.4; + } + return false; + }else{ + return parent::attackEntity($entity, $distance); + } + + } public function getDrops(){ return [ [STRING, 0, mt_rand(0,2)]