Beispiel #1
0
 public function attack($damage, EntityDamageEvent $source)
 {
     if ($this->attackTime > 0 or $this->noDamageTicks > 0) {
         $lastCause = $this->getLastDamageCause();
         if ($lastCause !== null and $lastCause->getDamage() >= $damage) {
             $source->setCancelled();
         }
     }
     parent::attack($damage, $source);
     if ($source->isCancelled()) {
         return;
     }
     if ($source instanceof EntityDamageByEntityEvent) {
         $e = $source->getDamager();
         if ($source instanceof EntityDamageByChildEntityEvent) {
             $e = $source->getChild();
         }
         if ($e->isOnFire() > 0) {
             $this->setOnFire(2 * $this->server->getDifficulty());
         }
         $deltaX = $this->x - $e->x;
         $deltaZ = $this->z - $e->z;
         $this->knockBack($e, $damage, $deltaX, $deltaZ, $source->getKnockBack());
     }
     $pk = new EntityEventPacket();
     $pk->eid = $this->getId();
     $pk->event = $this->getHealth() <= 0 ? EntityEventPacket::DEATH_ANIMATION : EntityEventPacket::HURT_ANIMATION;
     // Ouch!
     Server::broadcastPacket($this->hasSpawned, $pk);
     $this->attackTime = 10;
     //0.5 seconds cooldown
 }
Beispiel #2
0
 public function attack($damage, EntityDamageEvent $source)
 {
     if (!$this->isAlive()) {
         return;
     }
     if ($this->isCreative() and $source->getCause() !== EntityDamageEvent::CAUSE_MAGIC and $source->getCause() !== EntityDamageEvent::CAUSE_SUICIDE and $source->getCause() !== EntityDamageEvent::CAUSE_VOID) {
         $source->setCancelled();
     } elseif ($this->allowFlight and $source->getCause() === EntityDamageEvent::CAUSE_FALL) {
         $source->setCancelled();
     }
     parent::attack($damage, $source);
     if ($source->isCancelled()) {
         return;
     } elseif ($this->getLastDamageCause() === $source and $this->spawned) {
         $pk = new EntityEventPacket();
         $pk->eid = 0;
         $pk->event = EntityEventPacket::HURT_ANIMATION;
         $this->dataPacket($pk);
         if ($this->getHealth() < 0 or $this->getHealth() == 0) {
             $pk = new RespawnPacket();
             $pos = $this->getSpawn();
             $pk->x = $pos->x;
             $pk->y = $pos->y;
             $pk->z = $pos->z;
             $this->dataPacket($pk);
         }
     }
 }
Beispiel #3
0
 /**
  * @param float             $damage
  * @param EntityDamageEvent $source
  *
  */
 public function attack($damage, EntityDamageEvent $source)
 {
     if ($this->hasEffect(Effect::FIRE_RESISTANCE) and ($source->getCause() === EntityDamageEvent::CAUSE_FIRE or $source->getCause() === EntityDamageEvent::CAUSE_FIRE_TICK or $source->getCause() === EntityDamageEvent::CAUSE_LAVA)) {
         $source->setCancelled();
     }
     if ($source instanceof EntityDamageByEntityEvent && $source->getCause() === EntityDamageEvent::CAUSE_PROJECTILE) {
         $e = $source->getDamager();
         if ($source instanceof EntityDamageByChildEntityEvent) {
             $e = $source->getChild();
         }
         if ($e instanceof ThrownExpBottle || $e instanceof ThrownPotion) {
             $source->setCancelled();
         }
     }
     $this->server->getPluginManager()->callEvent($source);
     if ($source->isCancelled()) {
         return;
     }
     $this->setLastDamageCause($source);
     $this->getHealth() - $source->getFinalDamage() <= 0 ? $this->setHealth(0) : $this->setHealth($this->getHealth() - $source->getFinalDamage());
 }