当前位置: 首页>>代码示例>>PHP>>正文


PHP Human::attack方法代码示例

本文整理汇总了PHP中pocketmine\entity\Human::attack方法的典型用法代码示例。如果您正苦于以下问题:PHP Human::attack方法的具体用法?PHP Human::attack怎么用?PHP Human::attack使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在pocketmine\entity\Human的用法示例。


在下文中一共展示了Human::attack方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: attack

 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();
     }
 }
开发者ID:mwvent,项目名称:WattzMCPE,代码行数:34,代码来源:Herobrine.php

示例2: attack

 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);
     }
 }
开发者ID:NewDelion,项目名称:PocketMine-0.13.x,代码行数:20,代码来源:Player.php

示例3: attack

 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());
     }
 }
开发者ID:mwvent,项目名称:WattzMCPE,代码行数:32,代码来源:UndeadPlayer.php

示例4: attack

 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);
     }
 }
开发者ID:rryy,项目名称:PocketMine-MP,代码行数:29,代码来源:Player.php

示例5: attack

 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;
 }
开发者ID:robske110,项目名称:ClearSky,代码行数:40,代码来源:Player.php

示例6: attack

 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));
     }
 }
开发者ID:TylerGames,项目名称:PocketMine-MP,代码行数:18,代码来源:Player.php

示例7: attack

 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);
         }
     }
 }
开发者ID:Cecil107,项目名称:PocketMine-0.13.0,代码行数:45,代码来源:Player.php


注:本文中的pocketmine\entity\Human::attack方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。