better spider attacks

This commit is contained in:
GameHerobrine 2024-03-06 03:50:11 +03:00
parent 7a1bf49ca0
commit 0f84d692b7
5 changed files with 27 additions and 12 deletions

View file

@ -195,8 +195,8 @@ class Entity extends Position
return in_array($this->type, func_get_args()); return in_array($this->type, func_get_args());
} }
public function attackEntity($entity){ public function attackEntity($entity, $distance){
return false;
} }
public function setInWeb(){ public function setInWeb(){
@ -654,7 +654,7 @@ class Entity extends Position
$aaBBs = $this->level->getCubes($this, $this->boundingBox->addCoord($dx, $dy, $dz)); $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); $dy = $bb->calculateYOffset($this->boundingBox, $dy);
} }
$this->boundingBox->offset(0, $dy, 0); $this->boundingBox->offset(0, $dy, 0);

View file

@ -9,7 +9,8 @@ class Monster extends Creature{
return 2; return 2;
} }
public function attackEntity($entity){ public function attackEntity($entity, $distance){
$entity->harm($this->getAttackDamage(), $this->eid); $entity->harm($this->getAttackDamage(), $this->eid);
return true;
} }
} }

View file

@ -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()); $ai->mobController->setLookPosition($ai->entity->target->x, $ai->entity->target->y + 0.12, $ai->entity->target->z, 10, $ai->entity->getVerticalFaceSpeed());
--$this->attackCounter; --$this->attackCounter;
$mult = $ai->entity instanceof Spider ? 1 : 2; $v1 = $ai->entity->width * $ai->entity->width * 4;
$v1 = $ai->entity->width * $ai->entity->width * $mult*$mult;
$e = $ai->entity; $e = $ai->entity;
$t = $e->target; $t = $e->target;
@ -39,9 +38,7 @@ class TaskAttackPlayer extends TaskBase
$dist = ($xDiff*$xDiff + $yDiff*$yDiff + $zDiff*$zDiff); $dist = ($xDiff*$xDiff + $yDiff*$yDiff + $zDiff*$zDiff);
if($dist <= $v1){ if($dist <= $v1){
if($this->attackCounter <= 0){ if($this->attackCounter <= 0){
$this->attackCounter = 20; $this->attackCounter = $e->attackEntity($t, sqrt($dist)) ? 20 : 0;
$e->attackEntity($t);
} }
} }

View file

@ -57,11 +57,12 @@ class Creeper extends Monster{
$this->timeUntilExplode = self::EXPL_TIME; $this->timeUntilExplode = self::EXPL_TIME;
} }
public function attackEntity($entity){ public function attackEntity($entity, $distance){
if(Utils::distance_noroot($entity, $this) <= 49 && !$this->isIgnited()){ if(Utils::distance_noroot($entity, $this) <= 49 && !$this->isIgnited()){
$this->ignite(); $this->ignite();
return true;
} }
return false;
} }
public function update($now){ public function update($now){
if($this->isIgnited() && $this->target instanceof Entity && Utils::distance_noroot($this->target, $this) > 49){ //TODO move somewhere else if($this->isIgnited() && $this->target instanceof Entity && Utils::distance_noroot($this->target, $this) > 49){ //TODO move somewhere else

View file

@ -12,7 +12,23 @@ class Spider extends Monster{
$this->ai->addTask(new TaskSwimming()); $this->ai->addTask(new TaskSwimming());
$this->ai->addTask(new TaskAttackPlayer(1.0, 16)); //TODO fix range? $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(){ public function getDrops(){
return [ return [
[STRING, 0, mt_rand(0,2)] [STRING, 0, mt_rand(0,2)]