當前位置: 首頁>>代碼示例>>PHP>>正文


PHP EntityDamageByEntityEvent::setDamage方法代碼示例

本文整理匯總了PHP中pocketmine\event\entity\EntityDamageByEntityEvent::setDamage方法的典型用法代碼示例。如果您正苦於以下問題:PHP EntityDamageByEntityEvent::setDamage方法的具體用法?PHP EntityDamageByEntityEvent::setDamage怎麽用?PHP EntityDamageByEntityEvent::setDamage使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在pocketmine\event\entity\EntityDamageByEntityEvent的用法示例。


在下文中一共展示了EntityDamageByEntityEvent::setDamage方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: onPlayerDamagedByEntity

 public function onPlayerDamagedByEntity(EntityDamageByEntityEvent $event)
 {
     $attacker = $event->getDamager();
     $victim = $event->getEntity();
     if (!$victim instanceof Player) {
         return;
     }
     if (($vipVictim = $this->getVip($victim)) !== null and $vipVictim->refuseToPvp() or ($vipAttacker = $this->getVip($attacker)) !== null and $vipAttacker->refuseToPvp()) {
         $event->setDamage(0);
         $event->setCancelled(true);
         return;
     }
     if ($attacker instanceof Arrow and ($arrowIndex = array_search($attacker->getId(), $this->arrowQueue)) !== false) {
         $victim->setOnFire(10);
         unset($this->arrowQueue[$arrowIndex]);
     }
 }
開發者ID:nesgohood,項目名稱:PMMP-Plugins,代碼行數:17,代碼來源:VIPPlus.php

示例2: onHit

 public function onHit(\pocketmine\event\entity\EntityDamageByEntityEvent $ev)
 {
     if (!$ev->getEntity() instanceof Player or !$ev->getDamager() instanceof Player) {
         return;
     }
     if ($this->status !== 2) {
         $ev->setCancelled();
         $ev->getDamager()->sendMessage("[CrashBang] 정숙");
         return;
     }
     if ($this->skill[$ev->getDamager()->getName()] === Skills::INVINCIBLE and $this->ps[$ev->getDamager()->getName()] > microtime(true) or $this->skill[$ev->getEntity()->getName()] === Skills::INVINCIBLE and $this->ps[$ev->getEntity()->getName()] > microtime(true)) {
         $ev->setCancelled();
         $ev->getDamager()->sendMessage("[CrashBang] 당신 또는 대상이 무적 상태이므로 공격이 무시됩니다.");
         return;
     }
     if (in_array($this->skill[$ev->getDamager()->getName()], [Skills::BERSERKER, Skills::VAMPIRE, Skills::STEALTH, Skills::UPGRADE, Skills::POISONED_DAGGER])) {
         switch ($this->skill[$ev->getDamager()->getName()]) {
             case Skills::BERSERKER:
                 $ev->setDamage(floor((20 - $ev->getDamager()->getHealth()) / 4) * 2, 5);
                 break;
             case Skills::VAMPIRE:
                 $e = new EntityRegainHealthEvent($ev->getDamager(), 2, EntityRegainHealthEvent::CAUSE_MAGIC);
                 $ev->getDamager()->heal(2, $e);
                 break;
             case Skills::STEALTH:
                 $ev->getDamager()->removeEffect(Effect::INVISIBILITY);
                 break;
             case Skills::UPGRADE:
                 $ev->setDamage($this->ps[$ev->getDamager()->getName()], 5);
                 break;
             case Skills::POISONED_DAGGER:
                 $this->startCooldown($this->getDamager());
                 $ev->setDamage(5, 5);
                 break;
         }
     } else {
         if ($this->skill[$ev->getEntity()->getName()] === Skills::EYE_FOR_EYE and $this->ps[$ev->getEntity()->getName()]-- > 0) {
             if ($this->skill[$ev->getDamager()->getName()] === Skills::EYE_FOR_EYE) {
                 return;
             }
             $e = new EntityDamageByEntityEvent($ev->getEntity(), $ev->getDamager(), EntityDamageEvent::CAUSE_ENTITY_ATTACK, floor($ev->getFinalDamage() * 0.7));
             $ev->getDamager()->attack($e->getFinalDamage(), $e);
         } else {
             if ($ev->getDamager()->getInventory()->getItemInHand()->getID() === Item::BLAZE_ROD and in_array($this->skill[$ev->getDamager()->getName()], [Skills::ASSASSIN, Skills::TRACE])) {
                 $ev->setCancelled();
                 if ($this->cooldown[$ev->getDamager()->getName()] > 0) {
                     $ev->getDamager()->sendMessage("[CrashBang] 아직 스킬을 사용할 수 없습니다.");
                     $ev->setCancelled(false);
                     return;
                 }
                 switch ($this->skill[$ev->getDamager()->getName()]) {
                     case Skills::ASSASSIN:
                         $n = mt_rand(0, 99);
                         $ev->setCancelled(false);
                         if ($n < 30) {
                             $ev->setDamage(9999);
                         } else {
                             $e = new EntityDamageByEntityEvent($ev->getEntity(), $ev->getDamager(), EntityDamageEvent::CAUSE_ENTITY_ATTACK, 15);
                             $ev->getDamager()->attack($ev->getFinalDamage(), $e);
                             $ev->setDamage(15);
                         }
                         break;
                     case Skills::TRACE:
                         $this->getServer()->getScheduler()->scheduleDelayedTask(new TraceTask($this, $ev->getDamager(), $ev->getEntity()), 7 * 20);
                         $ev->getDamager()->sendMessage("[CrashBang] 7초 후 추적 대상" . $ev->getEntity()->getName() . "에게 이동합니다.");
                         break;
                 }
                 $this->startCooldown($ev->getDamager());
             }
         }
     }
 }
開發者ID:cr0sh,項目名稱:CrashBang,代碼行數:72,代碼來源:CrashBang.php


注:本文中的pocketmine\event\entity\EntityDamageByEntityEvent::setDamage方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。