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


PHP EntityDamageEvent::getChild方法代码示例

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


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

示例1: onDamage

 public function onDamage(EntityDamageEvent $event)
 {
     $damaged = $event->getEntity();
     if (!$damaged instanceof Player or !($session = $this->getMain()->getSessions()->getSession($damaged)) instanceof Session or !$session->inSession($this)) {
         return;
     }
     if ($event instanceof EntityDamageByChildEntityEvent) {
         $entity = $event->getDamager();
         if ($entity instanceof Player) {
             $ses = $this->main->getSessions()->getSession($entity);
             if ($ses instanceof Session and $ses->inSession($this)) {
                 $data = $this->getPlayerData($ses);
                 if ($data->isPlaying() and $data->getArena()->isPlaying()) {
                     $projectile = $event->getChild();
                     if ($projectile instanceof Snowball) {
                         $event->setCancelled(false);
                         $event->setKnockBack($event->getKnockBack() * 2);
                     }
                 }
             }
         }
     }
 }
开发者ID:LegionPE,项目名称:LegionPE-Eta,代码行数:23,代码来源:SpleefGame.php

示例2: attack

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

示例3: i_onDamage

 public function i_onDamage(EntityDamageEvent $event, &$victimSession)
 {
     $victim = $event->getEntity();
     if (!$victim instanceof Player) {
         return;
     }
     $victimSession = $this->getMain()->getSessions()->getSession($victim);
     if (!$victimSession->inSession($this)) {
         return;
     }
     $origCancelled = $event->isCancelled();
     $event->setCancelled(false);
     if (!$event instanceof EntityDamageByEntityEvent) {
         if ($event->getCause() === EntityDamageEvent::CAUSE_SUFFOCATION) {
             $event->setCancelled();
             $victimSession->teleport(Settings::kitpvp_spawn($this->getMain()->getServer()));
             return;
         }
         if ($event->getCause() === EntityDamageEvent::CAUSE_FALL) {
             $fallCause = $victim->getLastDamageCause();
             if ($fallCause instanceof EntityDamageByEntityEvent) {
                 if (isset($fallCause->_legionpeEta_timestamp) and microtime(true) - $fallCause->_legionpeEta_timestamp < 2) {
                     /** @noinspection PhpUndefinedFieldInspection */
                     $event->_legionpeEta_fallCause = $fallCause;
                 }
             }
         }
         return;
     }
     $victim = $event->getEntity();
     $damager = $event->getDamager();
     if (!$victim instanceof Player or !$damager instanceof Player) {
         return;
     }
     $attackerSession = $this->main->getSessions()->getSession($damager);
     if (!$attackerSession->inSession($this)) {
         $event->setCancelled($origCancelled);
         return;
     }
     $hitterData = $this->playerData[$attackerSession->getUID()];
     $victimData = $this->playerData[$victimSession->getUID()];
     if ($hitterData->invulnerable) {
         $attackerSession->tell("You are in invulnerability mode!");
         $event->setCancelled();
         return;
     }
     if ($victimData->invulnerable) {
         $attackerSession->tell("The vicitm is in invulnerability mode!");
         $event->setCancelled();
         return;
     }
     if (Settings::kitpvp_isSafeArea($victim) or Settings::kitpvp_isSafeArea($damager)) {
         $event->setCancelled();
         $attackerSession->tell("You may not attack players at/from spawn!");
     } elseif ($hitterData->areFriends($victimSession->getUID())) {
         $event->setCancelled();
     } else {
         /** @noinspection PhpUndefinedFieldInspection */
         $event->_legionpeEta_timestamp = microtime(true);
         /** @noinspection PhpUndefinedFieldInspection */
         $event->_legionpeEta_isLadder = $victim->getLevel()->getBlockIdAt($victim->getFloorX(), $victim->getFloorY(), $victim->getFloorZ()) === Block::LADDER;
         if ($event instanceof EntityDamageByChildEntityEvent) {
             $child = $event->getChild();
             if ($child instanceof Snowball) {
                 $event->setKnockBack($event->getKnockBack() * 2.5);
             } elseif ($child instanceof Arrow) {
                 $points = 0;
                 if (!$event->isApplicable(EntityDamageEvent::MODIFIER_ARMOR)) {
                     $armorValues = [Item::LEATHER_CAP => 1, Item::LEATHER_TUNIC => 3, Item::LEATHER_PANTS => 2, Item::LEATHER_BOOTS => 1, Item::CHAIN_HELMET => 1, Item::CHAIN_CHESTPLATE => 5, Item::CHAIN_LEGGINGS => 4, Item::CHAIN_BOOTS => 1, Item::GOLD_HELMET => 1, Item::GOLD_CHESTPLATE => 5, Item::GOLD_LEGGINGS => 3, Item::GOLD_BOOTS => 1, Item::IRON_HELMET => 2, Item::IRON_CHESTPLATE => 6, Item::IRON_LEGGINGS => 5, Item::IRON_BOOTS => 2, Item::DIAMOND_HELMET => 3, Item::DIAMOND_CHESTPLATE => 8, Item::DIAMOND_LEGGINGS => 6, Item::DIAMOND_BOOTS => 3];
                     foreach ($attackerSession->getPlayer()->getInventory()->getArmorContents() as $armor) {
                         if (isset($armorValues[$armor->getId()])) {
                             $points += $armorValues[$armor->getId()];
                         }
                     }
                 }
                 list(, , , $damage, $fire, $knockPct) = Settings::kitpvp_getBowInfo($hitterData->getBowLevel());
                 $event->setDamage(max($damage - $points, 0));
                 if ($fire > 0) {
                     $victim->setOnFire($fire / 20);
                     $this->getMain()->getServer()->getScheduler()->scheduleDelayedTask(new CallbackPluginTask($this->getMain(), function () use($victim) {
                         $victim->setOnFire(0);
                     }), $fire);
                 }
                 if ($knockPct > 0) {
                     $event->setKnockBack($event->getKnockBack() * (1 + $knockPct / 100));
                     // what the, I put / as *?
                 }
             }
         }
     }
 }
开发者ID:LegionPE,项目名称:LegionPE-Eta,代码行数:91,代码来源:PvpGame.php


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