コード例 #1
0
ファイル: Living.php プロジェクト: MunkySkunk/BukkitPE
 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
 }
コード例 #2
0
ファイル: Fire.php プロジェクト: MunkySkunk/BukkitPE
 public function onEntityCollide(Entity $entity)
 {
     if (!$entity->hasEffect(Effect::FIRE_RESISTANCE)) {
         $ev = new EntityDamageByBlockEvent($this, $entity, EntityDamageEvent::CAUSE_FIRE, 1);
         $entity->attack($ev->getFinalDamage(), $ev);
     }
     $ev = new EntityCombustByBlockEvent($this, $entity, 8);
     Server::getInstance()->getPluginManager()->callEvent($ev);
     if (!$ev->isCancelled()) {
         $entity->setOnFire($ev->getDuration());
     }
 }
コード例 #3
0
ファイル: Projectile.php プロジェクト: MunkySkunk/BukkitPE
 public function attack($damage, EntityDamageEvent $source)
 {
     if ($source->getCause() === EntityDamageEvent::CAUSE_VOID) {
         parent::attack($damage, $source);
     }
 }
コード例 #4
0
ファイル: Item.php プロジェクト: MunkySkunk/BukkitPE
 public function attack($damage, EntityDamageEvent $source)
 {
     if ($source->getCause() === EntityDamageEvent::CAUSE_VOID or $source->getCause() === EntityDamageEvent::CAUSE_FIRE_TICK or $source->getCause() === EntityDamageEvent::CAUSE_ENTITY_EXPLOSION or $source->getCause() === EntityDamageEvent::CAUSE_BLOCK_EXPLOSION) {
         parent::attack($damage, $source);
     }
 }
コード例 #5
0
ファイル: Cactus.php プロジェクト: MunkySkunk/BukkitPE
 public function onEntityCollide(Entity $entity)
 {
     $ev = new EntityDamageByBlockEvent($this, $entity, EntityDamageEvent::CAUSE_CONTACT, 1);
     $entity->attack($ev->getFinalDamage(), $ev);
 }
コード例 #6
0
ファイル: Effect.php プロジェクト: MunkySkunk/BukkitPE
 public function applyEffect(Entity $entity)
 {
     switch ($this->id) {
         case Effect::POISON:
             if ($entity->getHealth() > 1) {
                 $ev = new EntityDamageEvent($entity, EntityDamageEvent::CAUSE_MAGIC, 1);
                 $entity->attack($ev->getFinalDamage(), $ev);
             }
             break;
         case Effect::WITHER:
             $ev = new EntityDamageEvent($entity, EntityDamageEvent::CAUSE_MAGIC, 1);
             $entity->attack($ev->getFinalDamage(), $ev);
             break;
         case Effect::REGENERATION:
             if ($entity->getHealth() < $entity->getMaxHealth()) {
                 $ev = new EntityRegainHealthEvent($entity, 1, EntityRegainHealthEvent::CAUSE_MAGIC);
                 $entity->heal($ev->getAmount(), $ev);
             }
             break;
         case Effect::HUNGER:
             if ($entity instanceof Player) {
                 if ($entity->getFood() > 0) {
                     if ($entity->getFood() - 0.025 * ($this->getAmplifier() + 1) > 0) {
                         $entity->setFood($entity->getFood() - 0.025 * ($this->getAmplifier() + 1));
                     } else {
                         $entity->setFood(0);
                     }
                 }
             }
             break;
         case Effect::SATURATION:
             if ($entity instanceof Player) {
                 if ($entity->getFood() < 20) {
                     if ($entity->getFood() + 1 * ($this->getAmplifier() + 1) > 20) {
                         $entity->setFood(20);
                     } else {
                         $entity->setFood($entity->getFood() + 1 * ($this->getAmplifier() + 1));
                     }
                 }
             }
             break;
         case Effect::SPEED:
             if ($entity instanceof Player) {
                 $entity->setSpeed(0.1 + ($this->amplifier + 1) * 0.01);
             }
             break;
         case Effect::SLOWNESS:
             if ($entity instanceof Player) {
                 $entity->setSpeed(0.1 - ($this->amplifier + 1) * 0.01);
             }
             break;
     }
 }