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


PHP EntityDamageEvent::getFinalDamage方法代码示例

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


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

示例1: onDamage

 public function onDamage(EntityDamageEvent $ev)
 {
     /***
      *    http://docs.pocketmine.net/d6/d5c/_entity_damage_by_entity_event_8php_source.html
      *    public function getDamager(){
      *    return $this->damager;
      */
     $e = $ev->getEntity();
     if ($e instanceof Player && $ev->getFinalDamage() - $e->getHealth() <= 0) {
         $e->getPlayer()->getInventory()->addItem(Item::get(262, 0, 1));
     }
 }
开发者ID:xHFx,项目名称:ArrowPlugin,代码行数:12,代码来源:main.php

示例2: 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

示例3: onEntityDamage

 public function onEntityDamage(EntityDamageEvent $event)
 {
     if ($event instanceof EntityDamageByEntityEvent) {
         if (($Victim = $event->getEntity()) && ($Player = $event->getDamager())) {
             if ($Player instanceof Human) {
                 $Level = $Player->getLevel();
                 if ($Victim instanceof Villager) {
                     $Type = $Level->getFolderName() == $this->plugin->lobby_name ? 1 : 0;
                     $X = round($Victim->getX() - 0.5);
                     $Z = round($Victim->getZ() - 0.5);
                     if ($Level->getBlockIdAt($X, 0, $Z) != 54) {
                         $Level->setBlock(new Vector3($X, 0, $Z), Block::get(54), true, true);
                         $chest = new Chest($Level->getChunk($X >> 4, $Z >> 4, true), new Compound(false, array(new Int("x", $X), new Int("y", 0), new Int("z", $Z), new String("id", Tile::CHEST))), $this->plugin);
                         $Level->addTile($chest);
                     } else {
                         $chest = $Level->getTile(new Vector3($X, 0, $Z));
                     }
                     if ($Level->getBlockIdAt($X, 1, $Z) != 54) {
                         $Level->setBlock(new Vector3($X, 1, $Z), Block::get(0), true, true);
                     }
                     $chest = new BuyingInventory($Level->getTile(new Vector3($X, 0, $Z)), $Player);
                     $contents = [];
                     switch ($Type) {
                         case 0:
                             foreach ($this->plugin->buys_Values as $Buy_Value) {
                                 $contents[] = Item::get($Buy_Value[0], 0, 1);
                             }
                             break;
                         case 1:
                             if ($this->plugin->status == 0) {
                                 foreach ($this->plugin->mapList as $Map) {
                                     $contents[] = Item::get(35, $Map[0], $Map[4] == 0 ? 99 : $Map[4]);
                                 }
                             } else {
                                 $contents[] = Item::get(345, 0, 1);
                                 foreach ($this->plugin->game->Teams as $Name => $Team) {
                                     $contents[] = Item::get(35, $this->plugin->getTeamDataByName($Name), count($Team->Players) == 0 ? 99 : count($Team->Players));
                                 }
                             }
                             break;
                     }
                     $chest->setContents($contents);
                     $this->plugin->setState("buying_chest", $Player, $chest);
                     $this->plugin->setState("buying_type", $Player, $Type);
                     $this->plugin->setState("buying_menu", $Player, -1);
                     $Player->addWindow($chest);
                     $event->setCancelled(true);
                 } elseif ($Victim instanceof Human) {
                     if ($Level->getFolderName() == $this->plugin->lobby_name) {
                         $event->setCancelled(true);
                         return;
                     }
                     if (!$this->plugin->game || $this->plugin->game->level_name != $Level->getFolderName()) {
                         return;
                     }
                     $event->setCancelled($this->plugin->game->getTeamByPlayer($Player) == $this->plugin->game->getTeamByPlayer($Victim));
                     $HandItem = $Player->getInventory()->getItemInHand();
                     switch ($HandItem->getId()) {
                         case 259:
                             $Victim->setOnFire(5);
                             $event->setKnockBack(0);
                             break;
                         case 280:
                             $event->setKnockBack(0.6);
                             break;
                     }
                     if ($Victim->getHealth() - $event->getFinalDamage() <= 0) {
                         $this->plugin->game->PopupInfo2->PlayersData[strtolower($Player->getName())][1] += $this->plugin->game->PopupInfo2->PlayersData[strtolower($Victim->getName())][1];
                         $this->plugin->game->PopupInfo2->PlayersData[strtolower($Victim->getName())][1] = 0;
                     }
                 } elseif ($Victim instanceof Villager) {
                     $Level = $Victim->getLevel();
                     if ($Level->getFolderName() == $this->plugin->lobby_name) {
                         $event->setCancelled(true);
                         return;
                     }
                     if (!$this->plugin->game || $this->plugin->game->level_name != $Level->getFolderName()) {
                         return;
                     }
                     $event->setCancelled(true);
                 }
             }
         }
     } else {
         if (($Player = $event->getEntity()) instanceof Entity) {
             $Level = $Player->getLevel();
             if (!$this->plugin->game || $this->plugin->game->level_name != $Level->getFolderName()) {
                 return;
             }
             $X = $Player->getFloorX();
             $Y = $Player->getFloorY() - 1;
             $Z = $Player->getFloorZ();
             $Block = $Level->getBlock(new Vector3($X, $Y, $Z));
             if ($Block->getId() == 133) {
                 $event->setCancelled(true);
             }
         }
     }
 }
开发者ID:MateiGamingYTB,项目名称:BedWarsPE,代码行数:99,代码来源:EventListener.php

示例4: onEntityDamage

 public function onEntityDamage(EntityDamageEvent $event)
 {
     if ($event->isCancelled()) {
         return;
     }
     $damagedEntity = $event->getEntity();
     if ($event instanceof EntityDamageByEntityEvent && $event->getFinalDamage() > $damagedEntity->getHealth()) {
         $attacker = $event->getDamager();
         if ($attacker instanceof Player) {
             if ($damagedEntity instanceof Player && !self::$pvpEnabled) {
                 $event->setCancelled();
                 return;
             }
             $attackerPlayer = $this->getRPGPlayerByName($attacker->getName());
             if ($attackerPlayer !== null) {
                 $xp = 0;
                 $xpPercentage = 0;
                 foreach ($this->getConfiguration("kill-exp", ["default" => 10]) as $id => $amount) {
                     if ($id === "default" || $id === $damagedEntity::NETWORK_ID) {
                         $xp = $amount;
                     }
                 }
                 foreach ($this->getConfiguration("kill-exp-percentage", ["default" => 0.01]) as $id => $amount) {
                     if ($id === "default" || $id === $damagedEntity::NETWORK_ID) {
                         $xpPercentage = $amount;
                     }
                 }
                 $attackerPlayer->addXp($xp + $attackerPlayer->getNeededXP() * ($xpPercentage / 100));
             }
         }
     }
     if (!$damagedEntity instanceof Player) {
         return;
     }
     if (!$this->isValidPlayer($damagedEntity)) {
         return;
     }
     $formerHealth = $this->players[$damagedEntity->getName()]->getHealth();
     $this->getRPGPlayerByName($damagedEntity->getName())->setHealth($formerHealth - $event->getFinalDamage());
     $event->setDamage(0);
     $event->setDamage(0, EntityDamageEvent::MODIFIER_STRENGTH);
     $event->setDamage(0, EntityDamageEvent::MODIFIER_WEAKNESS);
     $event->setDamage(0, EntityDamageEvent::MODIFIER_ARMOR);
     $event->setDamage(0, EntityDamageEvent::MODIFIER_RESISTANCE);
 }
开发者ID:HelloWorld017,项目名称:ToAruPG,代码行数:45,代码来源:ToAruPG.php

示例5: onPlayerDamageByEntity

 public function onPlayerDamageByEntity(EntityDamageEvent $event)
 {
     if (!$event->getEntity() instanceof Player) {
         return true;
     }
     $entityGameId = $this->players[$event->getEntity()->getName()];
     if ($entityGameId !== "NONE" && !$this->config["IS_DAMAGE_ENABLED"]) {
         $event->setCancelled(true);
     } elseif ($entityGameId === "NONE") {
         return true;
     }
     if (!$event instanceof EntityDamageByEntityEvent) {
         return true;
     }
     if (!$event->getDamager() instanceof Player) {
         return true;
     }
     $event->setCancelled(true);
     if (!GameGenius::$IS_KILL_TOUCH) {
         $this->touch($event->getDamager(), $event->getEntity());
     } else {
         if ($this->players[$event->getDamager()->getName()] === $entityGameId && $entityGameId !== "NONE") {
             $touchTest = $this->games[$entityGameId]->canTouch($event->getDamager()->getName(), $event->getEntity()->getName());
             if ($touchTest === GameManager::RETURNTYPE_TOUCH_SUCCEED) {
                 $event->setCancelled(false);
                 if ($event->getFinalDamage() >= $event->getEntity()->getHealth()) {
                     $returnVal = $this->touch($event->getDamager(), $event->getEntity());
                     if ($returnVal !== GameManager::RETURNTYPE_TOUCH_SUCCEED || $returnVal === false) {
                         $event->setCancelled(true);
                     }
                 }
             } else {
                 switch ($touchTest) {
                     case GameManager::RETURNTYPE_TOUCH_ALREADY_TOUCED_FAILED:
                         $event->getDamager()->sendMessage(TextFormat::RED . $this->getTranslation("TOUCH_ALREADY_TOUCHED"));
                         break;
                     case GameManager::RETURNTYPE_TOUCH_IN_PREPARATION_OR_REST_FAILED:
                         $event->getDamager()->sendMessage(TextFormat::RED . $this->getTranslation("PREPARATION_OR_REST"));
                         break;
                 }
             }
         }
     }
     return false;
 }
开发者ID:EpicArtz08999,项目名称:ZombieGame,代码行数:45,代码来源:GameGenius.php


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