Beispiel #1
0
 public function attack($damage, EntityDamageEvent $source)
 {
     parent::attack($damage, $source);
     if ($source instanceof EntityDamageByEntityEvent) {
         $attacker = $source->getDamager();
         if ($source instanceof EntityDamageByChildEntityEvent) {
             $attacker = $source->getDamager();
         }
     }
     if ($attacker instanceof Projectile) {
         Server::getInstance()->getLogger()->info(Main::PREFIX . "Herobrine attacked by Projectile");
         $attacker = $attacker->shootingEntity;
     }
     if ($attacker instanceof Arrow) {
         Server::getInstance()->getLogger()->info(Main::PREFIX . "Herobrine attacked by Arrow");
         $attacker = $attacker->shootingEntity;
     }
     if ($attacker instanceof Snowball) {
         Server::getInstance()->getLogger()->info(Main::PREFIX . "Herobrine attacked by Snowball");
         $attacker = $attacker->shootingEntity;
     }
     if ($attacker instanceof Player || get_class($attacker) == "pocketmine\\Player") {
         Server::getInstance()->getLogger()->info(Main::PREFIX . "Herobrine attacked by " . $attacker->getName());
         // $attacker->setOnFire(3);
         $attacker_effect = Effect::getEffect(Effect::CONFUSION);
         $attacker_effect->setDuration(15 * 20);
         $attacker->addEffect($attacker_effect);
         //  $newundeadplayer = new UndeadPlayer(new dummyChunk, new Compound, $attacker, $this, $this->plugin);
         $this->poofAway();
     } else {
         Server::getInstance()->getLogger()->info(Main::PREFIX . "Herobrine attacked by " . get_class($attacker));
         $this->poofAway();
     }
 }
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);
     }
 }
Beispiel #3
0
 public function attack($damage, EntityDamageEvent $source)
 {
     $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->setLastDamageCause($source);
     $this->setHealth($this->getHealth() - $source->getFinalDamage());
     parent::attack($damage, $source);
     if ($source instanceof EntityDamageByEntityEvent) {
         $attacker = $source->getDamager();
         if ($source instanceof EntityDamageByChildEntityEvent) {
             $attacker = $source->getDamager();
         }
     }
     if ($attacker instanceof Projectile) {
         Server::getInstance()->getLogger()->info(Main::PREFIX . $this->thisname . " attacked by Projectile");
         $attacker = $attacker->shootingEntity;
     }
     if ($attacker instanceof Arrow) {
         Server::getInstance()->getLogger()->info(Main::PREFIX . $this->thisname . " attacked by Arrow");
         $attacker = $attacker->shootingEntity;
     }
     if ($attacker instanceof Snowball) {
         Server::getInstance()->getLogger()->info(Main::PREFIX . $this->thisname . " attacked by Snowball");
         $attacker = $attacker->shootingEntity;
     }
     if ($attacker instanceof Player || get_class($attacker) == "pocketmine\\Player") {
         Server::getInstance()->getLogger()->info(Main::PREFIX . $this->thisname . " attacked by " . $attacker->getName());
     }
 }
Beispiel #4
0
 public function attack($damage, $source = EntityDamageEvent::CAUSE_MAGIC)
 {
     if ($this->dead === true) {
         return;
     }
     if ($this->isCreative()) {
         if ($source instanceof EntityDamageEvent) {
             $cause = $source->getCause();
         } else {
             $cause = $source;
         }
         if ($cause !== EntityDamageEvent::CAUSE_MAGIC and $cause !== EntityDamageEvent::CAUSE_SUICIDE and $cause !== EntityDamageEvent::CAUSE_VOID) {
             if ($source instanceof EntityDamageEvent) {
                 $source->setCancelled();
             }
             return;
         }
     }
     parent::attack($damage, $source);
     if ($source instanceof EntityDamageEvent and $source->isCancelled()) {
         return;
     }
     if ($this->getLastDamageCause() === $source) {
         $pk = new EntityEventPacket();
         $pk->eid = 0;
         $pk->event = 2;
         $this->dataPacket($pk);
     }
 }
Beispiel #5
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();
     } elseif ($source->getCause() === EntityDamageEvent::CAUSE_FALL) {
         if ($this->getLevel()->getBlock($this->getPosition()->add(0, -1, 0))->getId() == Item::SLIME_BLOCK) {
             if (!$this->isSneaking()) {
                 $source->setCancelled();
                 $this->resetFallDistance();
             }
             if (!$this->isSneaking() && !$this->getPosition()->distanceSquared($this->getPosition()->subtract(0, 1)) > 0.1) {
                 $this->setMotion($this->getMotion()->add(0, $this->getMotion()->getY() * 2 * 0.88, 0));
             }
             if ($this->motionY < 0) {
                 $this->motionY = -$this->motionY;
                 if (!$this instanceof Living) {
                     $this->motionY *= 0.8;
                 }
             }
         }
     }
     parent::attack($damage, $source);
     if ($source->isCancelled()) {
         return false;
     } elseif ($this->getLastDamageCause() === $source and $this->spawned) {
         $pk = new EntityEventPacket();
         $pk->eid = 0;
         $pk->event = EntityEventPacket::HURT_ANIMATION;
         $this->dataPacket($pk);
         if ($this->isSurvival()) {
             $this->exhaust(0.3, PlayerExhaustEvent::CAUSE_DAMAGE);
         }
     }
     return true;
 }
Beispiel #6
0
 public function attack($damage, EntityDamageEvent $source)
 {
     if ($this->dead === true) {
         return;
     }
     if ($this->isCreative() and $source->getCause() !== EntityDamageEvent::CAUSE_MAGIC and $source->getCause() !== EntityDamageEvent::CAUSE_SUICIDE and $source->getCause() !== EntityDamageEvent::CAUSE_VOID) {
         $source->setCancelled();
     }
     parent::attack($damage, $source);
     if ($source->isCancelled()) {
         return;
     } elseif ($this->getLastDamageCause() === $source and $this->spawned) {
         $pk = new EntityEventPacket();
         $pk->eid = $this->getId();
         $pk->event = 2;
         $this->dataPacket($pk->setChannel(Network::CHANNEL_WORLD_EVENTS));
     }
 }
Beispiel #7
0
 public function attack($damage, EntityDamageEvent $source)
 {
     if (!$this->isAlive()) {
         return;
     }
     $source->setDamage(-floor($source->getDamage() * $this->inventory->calculateArmorModifiers($source) * 0.04), EntityDamageEvent::MODIFIER_ARMOR);
     if ($this->isCreative() 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($source->getFinalDamage(), $source);
     if ($source->isCancelled()) {
         return;
     }
     if ($source instanceof EntityDamageByEntityEvent || $source instanceof EntityDamageByChildEntityEvent) {
         $damager = $source->getDamager();
         $damage = 0;
         foreach ($this->inventory->getArmorContents() as $item) {
             if (($ench = $item->getEnchantment(Enchantment::TYPE_ARMOR_THORNS)) != null) {
                 $rnd = mt_rand(1, 100);
                 if ($rnd <= $ench->getLevel() * 15) {
                     $damage = mt_rand(1, 4);
                 }
             }
         }
         if ($damage > 0) {
             $damager->attack($damage, new EntityDamageEvent($damager, EntityDamageEvent::CAUSE_MAGIC, $damage));
         }
     }
     if ($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);
         }
     }
 }