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


PHP EntityDamageEvent::isApplicable方法代码示例

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


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

示例1: onDamage

 /**
  * @param EntityDamageEvent $event
  * @priority LOWEST
  */
 public function onDamage(EntityDamageEvent $event)
 {
     if ($event->isApplicable(EntityDamageEvent::MODIFIER_ARMOR) and ($damage = $event->getDamage(EntityDamageEvent::MODIFIER_ARMOR)) > 0) {
         $event->setDamage(-floor($event->getDamage() * 0.04 * $damage), EntityDamageEvent::MODIFIER_ARMOR);
     }
 }
开发者ID:barnseyminesuk,项目名称:Small-ZC-Plugins,代码行数:10,代码来源:RARFix.php

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