本文整理匯總了PHP中pocketmine\event\entity\EntityDamageEvent::getDamage方法的典型用法代碼示例。如果您正苦於以下問題:PHP EntityDamageEvent::getDamage方法的具體用法?PHP EntityDamageEvent::getDamage怎麽用?PHP EntityDamageEvent::getDamage使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類pocketmine\event\entity\EntityDamageEvent
的用法示例。
在下文中一共展示了EntityDamageEvent::getDamage方法的13個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: onDeath
public function onDeath(EntityDamageEvent $event)
{
$damage = $event->getDamage();
$health = $event->getDamager()->getHealth();
if ($health <= $damage) {
$player = $event->getDamager();
$money = $this->getConfig()->get("money");
$player->sendMessage("You've Earned 8 Coins");
$this->addMoney($player->getName(), $money);
}
}
示例2: onDamage
public function onDamage(EntityDamageEvent $event)
{
if (!$event->getEntity() instanceof Entity) {
return;
}
if ($event->getDamage() < 3) {
$color = TextFormat::GREEN;
} else {
if ($event->getDamage() < 6) {
$color = TextFormat::YELLOW;
} else {
$color = TextFormat::RED;
}
}
$pos = $event->getEntity()->add(0.1 * mt_rand(1, 9) * mt_rand(-1, 1), 0.1 * mt_rand(5, 9), 0.1 * mt_rand(1, 9) * mt_rand(-1, 1));
$damageParticle = new FloatingTextParticle($pos, "", $color . "-" . $event->getDamage());
if ($event->getEntity()->getHealth() < 7) {
$color = TextFormat::RED;
} else {
if ($event->getEntity()->getHealth() < 14) {
$color = TextFormat::YELLOW;
} else {
$color = TextFormat::GREEN;
}
}
$pos = $event->getEntity()->add(0, 2.5, 0);
$healthParticle = new FloatingTextParticle($pos, "", $color . ($event->getEntity()->getHealth() - $event->getDamage()) . " / " . $event->getEntity()->getMaxHealth());
$this->getServer()->getScheduler()->scheduleDelayedTask(new EventCheckTask($this, $damageParticle, $event->getEntity()->getLevel(), $event), 1);
$this->getServer()->getScheduler()->scheduleDelayedTask(new EventCheckTask($this, $healthParticle, $event->getEntity()->getLevel(), $event), 1);
}
示例3: onEntityDamage
public function onEntityDamage(EntityDamageEvent $event)
{
if (!$event->isCancelled() && $event instanceof EntityDamageByEntityEvent) {
$e = $event->getEntity();
$arrow = $event->getDamager();
$damage = round($event->getDamage() / 2);
if ($arrow instanceof AbilityArrow) {
$shoter = $arrow->shootingEntity;
if ($shoter instanceof Player) {
if ($arrow instanceof FireArrow) {
$e->setOnFire(rand(3, 10));
} elseif ($arrow instanceof TeleportArrow) {
$shoter->teleport($e);
} elseif ($arrow instanceof SpiderArrow) {
$e->getLevel()->setBlock($e, Block::get(30));
} elseif ($arrow instanceof HealArrow) {
$damage = -$damage;
} elseif ($arrow instanceof PowerArrow) {
$damage = round($damage * rand(2, 3) / 2);
} else {
return;
}
$arrow->kill();
}
}
$event->setDamage($damage);
}
}
示例4: onDamage
/**
* @priority MONITOR
*/
public function onDamage(EntityDamageEvent $ev)
{
if ($ev->isCancelled()) {
return;
}
$damage = $ev->getDamage();
$player = $ev->getEntity();
if (!$player instanceof Player) {
return;
}
for ($i = 0; $i < $damage; $i++) {
$player->getLevel()->addParticle(new RedstoneParticle(self::randVector($player), mt_rand() / mt_getrandmax() * 2));
}
}
示例5: onDamage
/**
* @priority LOWEST
*/
public function onDamage(EntityDamageEvent $event)
{
// Try keep the player alive while on transit...
$victim = $event->getEntity();
if (!$victim instanceof Player) {
return;
}
$vname = $victim->getName();
if (!isset($this->teleporters[$vname])) {
return;
}
if (time() - $this->teleporters[$vname] > 2) {
unset($this->teleporters[$vname()]);
return;
}
$victim->heal($event->getDamage());
$event->setDamage(0);
$event->setCancelled(true);
}
示例6: onHurt
public function onHurt(EntityDamageEvent $ev)
{
$p = $ev->getEntity();
if ($ev instanceof EntityDamageByEntityEvent) {
$damager = $ev->getDamager();
if ($damager instanceof Player) {
if ($damager->getInventory()->getItemInHand()->getId() === 369) {
$ev->setKnockBack(0.5);
$ev->setDamage($ev->getDamage() + 3);
$x = $p->getX();
$y = $p->getY();
$z = $p->getZ();
$r = mt_rand(0, 255);
$g = mt_rand(0, 255);
$b = mt_rand(0, 255);
$p->getLevel()->addParticle(new DustParticle(new Vector3($x, $y, $z), $r, $g, $b));
$p->addEffect(Effect::getEffect(9)->setAmplifier(1)->setDuration(20)->setVisible(true));
$level = $damager->getLevel();
$damager->getLevel()->addSound(new AnvilFallSound($damager->getLocation()));
}
}
}
}
示例7: AllDamage
public function AllDamage(EntityDamageEvent $event)
{
//僵屍擊退修複
if ($event instanceof EntityDamageByEntityEvent) {
$p = $event->getDamager();
$zo = $event->getEntity();
if (isset($this->animals[$zo->getId()]) and $zo instanceof Zombie or $zo instanceof Villager) {
if ($p instanceof Player) {
$weapon = $p->getInventory()->getItemInHand()->getID();
//得到玩家手中的武器
$high = 0;
if ($weapon == 258 or $weapon == 271 or $weapon == 275) {
//擊退x5
$back = 0.7;
} elseif ($weapon == 267 or $weapon == 272 or $weapon == 279 or $weapon == 283 or $weapon == 286) {
//擊退x1
$back = 1;
} elseif ($weapon == 276) {
//擊退x2
$back = 2;
} elseif ($weapon == 292) {
//擊退x10
$back = 10;
$high = 5;
} else {
$back = 0.5;
}
$zom =& $this->animals[$zo->getId()];
if (isset($this->dogs[$zo->getId()])) {
if ($weapon = 352) {
$dog =& $this->dogs[$zo->getId()];
if ($dog['love'] != 9999) {
if ($p->getinventory()->getItemInHand()->getID() == 352) {
//var_dump("玩家".$p->getName()."喂養了ID為".$zo->getId()."的wolf");
$p->getinventory()->removeItem(new Item(352, $p->getInventory()->getItemInHand()->getDamage(), 1));
$pos3 = new Vector3($zom['x'], $zom['y'] + 1, $zom['z'], $zo->getLevel());
$pos4 = new Vector3($zom['x'], $zom['y'], $zom['z'], $zo->getLevel());
$w1 = new HeartParticle($pos3);
$w2 = new HeartParticle($pos4);
$zo->getLevel()->addParticle($w1);
$zo->getLevel()->addParticle($w2);
if ($dog['love'] == 10 or $dog['love'] == 9999) {
$dog['love'] = 9999;
$dog['owner'] = $p->getName();
$p->sendTip(TextFormat::GREEN . "馴養成功!");
} else {
$dog['love'] = $dog['love'] + 1;
$dog['owner'] = $p->getName();
}
$event->setDamage(0);
$event->setKnockBack(0);
}
} else {
$zom['IsChasing'] = $p->getName();
}
}
}
@$zo->knockBack($p, 0, -$zom['xxx'] * $back, -$zom['zzz'] * $back, 0.4);
//var_dump("玩家".$p->getName()."攻擊了ID為".$zo->getId()."的僵屍");
$zom['x'] = $zom['x'] - $zom['xxx'] * $back;
$zom['y'] = $zo->getY() + $high;
$zom['z'] = $zom['z'] - $zom['zzz'] * $back;
$pos2 = new Vector3($zom['x'], $zom['y'], $zom['z']);
//目標坐標
$zo->setPosition($pos2);
if ($zo->getHealth() - $event->getDamage() <= 0) {
//var_dump("玩家".$p->getName()."殺死了ID為".$zo->getId()."的僵屍");
unset($this->animals[$zo->getId()]);
}
}
}
}
}
示例8: onEntityDamageEvent
public function onEntityDamageEvent(EntityDamageEvent $event)
{
if ($event instanceof EntityDamageByEntityEvent) {
if ($event->getDamager() instanceof ExperienceOrb) {
$event->setCancelled();
return;
}
if ($event->getDamager() instanceof Player) {
$attribute = $this->attributeprovider->getAttribute($event->getDamager());
$enhance = $event->getDamage() * ($attribute->getExpLevel() / 100);
$damage = $event->getDamage() + $enhance <= 15 ? $event->getDamage() - $enhance : 15;
$event->setDamage($damage);
HungerSystem::exhaustion($event->getDamager(), HungerSystem::RECEIVING_ANY_DAMAGE);
}
if ($event->getEntity() instanceof Player) {
$attribute = $this->attributeprovider->getAttribute($event->getEntity());
$protect = $event->getDamage() * ($attribute->getExpLevel() / 100);
$damage = $event->getDamage() + $protect >= 1 ? $event->getDamage() - $protect : 1;
$event->setDamage($damage);
HungerSystem::exhaustion($event->getEntity(), HungerSystem::RECEIVING_ANY_DAMAGE);
}
}
}
示例9: 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);
}
}
示例10: onDamage
public function onDamage(EntityDamageEvent $event)
{
if ($event->getEntity() instanceof Entities and $event instanceof EntityDamageByEntityEvent) {
if (!$event->getDamager() instanceof Player) {
return;
}
switch ($event->getEntity()->getType()) {
case 10:
if (!isset($this->damage_delay[$event->getDamager()->getName()][$event->getEntity()->getId()])) {
if ($this->dead_id[$event->getDamager()->getName()] == $event->getEntity()->getId()) {
return;
}
$this->dead_id[$event->getDamager()->getName()] = $event->getEntity()->getId();
$event->getDamager()->getInventory()->addItem(Item::get($this->rewardList["chickin-item-id"], 0, $this->rewardList["chickin-item-count"]));
$event->getDamager()->sendMessage(TextFormat::DARK_AQUA . $this->get("success-get-egg"));
$this->damage_delay[$event->getDamager()->getName()][$event->getEntity()->getId()] = $this->makeTimestamp(date("Y-m-d H:i:s"));
} else {
$before = $this->damage_delay[$event->getDamager()->getName()][$event->getEntity()->getId()];
$after = $this->makeTimestamp(date("Y-m-d H:i:s"));
$timeout = intval($after - $before);
if ($timeout < $this->config["Reward-DelayTime"]) {
$event->getDamager()->sendMessage(TextFormat::RED . $this->get("not-yet-ready-egg"));
} else {
if ($this->dead_id[$event->getDamager()->getName()] == $event->getEntity()->getId()) {
return;
}
$this->dead_id[$event->getDamager()->getName()] = $event->getEntity()->getId();
$event->getDamager()->getInventory()->addItem(Item::get($this->rewardList["chickin-item-id"], 0, $this->rewardList["chickin-item-count"]));
$event->getDamager()->sendMessage(TextFormat::DARK_AQUA . $this->get("success-get-egg"));
unset($this->damage_delay[$event->getDamager()->getName()][$event->getEntity()->getId()]);
}
}
$event->setCancelled();
break;
case 11:
if (!isset($this->damage_delay[$event->getDamager()->getName()][$event->getEntity()->getId()])) {
$event->setDamage(0);
if ($this->dead_id[$event->getDamager()->getName()] == $event->getEntity()->getId()) {
return;
}
$this->dead_id[$event->getDamager()->getName()] = $event->getEntity()->getId();
$event->getDamager()->getInventory()->addItem(Item::get($this->rewardList["cow-item-id"], 0, $this->rewardList["cow-item-count"]));
$event->getDamager()->sendMessage(TextFormat::DARK_AQUA . $this->get("success-get-steak"));
$this->damage_delay[$event->getDamager()->getName()][$event->getEntity()->getId()] = $this->makeTimestamp(date("Y-m-d H:i:s"));
} else {
$before = $this->damage_delay[$event->getDamager()->getName()][$event->getEntity()->getId()];
$after = $this->makeTimestamp(date("Y-m-d H:i:s"));
$timeout = intval($after - $before);
if ($timeout < $this->config["Reward-DelayTime"]) {
$event->getDamager()->sendMessage(TextFormat::RED . $this->get("not-yet-ready-steak"));
$event->setCancelled();
} else {
$event->setDamage(0);
if ($this->dead_id[$event->getDamager()->getName()] == $event->getEntity()->getId()) {
return;
}
$this->dead_id[$event->getDamager()->getName()] = $event->getEntity()->getId();
$event->getDamager()->getInventory()->addItem(Item::get($this->rewardList["cow-item-id"], 0, $this->rewardList["cow-item-count"]));
$event->getDamager()->sendMessage(TextFormat::DARK_AQUA . $this->get("success-get-steak"));
unset($this->damage_delay[$event->getDamager()->getName()][$event->getEntity()->getId()]);
}
}
break;
case 12:
if (!isset($this->damage_delay[$event->getDamager()->getName()][$event->getEntity()->getId()])) {
$event->setDamage(0);
if ($this->dead_id[$event->getDamager()->getName()] == $event->getEntity()->getId()) {
return;
}
$this->dead_id[$event->getDamager()->getName()] = $event->getEntity()->getId();
$event->getDamager()->getInventory()->addItem(Item::get($this->rewardList["pig-item-id"], 0, $this->rewardList["pig-item-count"]));
$event->getDamager()->sendMessage(TextFormat::DARK_AQUA . $this->get("success-get-pork"));
$this->damage_delay[$event->getDamager()->getName()][$event->getEntity()->getId()] = $this->makeTimestamp(date("Y-m-d H:i:s"));
} else {
$before = $this->damage_delay[$event->getDamager()->getName()][$event->getEntity()->getId()];
$after = $this->makeTimestamp(date("Y-m-d H:i:s"));
$timeout = intval($after - $before);
if ($timeout < $this->config["Reward-DelayTime"]) {
$event->getDamager()->sendMessage(TextFormat::RED . $this->get("not-yet-ready-pork"));
$event->setCancelled();
} else {
$event->setDamage(0);
if ($this->dead_id[$event->getDamager()->getName()] == $event->getEntity()->getId()) {
return;
}
$this->dead_id[$event->getDamager()->getName()] = $event->getEntity()->getId();
$event->getDamager()->getInventory()->addItem(Item::get($this->rewardList["pig-item-id"], 0, $this->rewardList["pig-item-count"]));
$event->getDamager()->sendMessage(TextFormat::DARK_AQUA . $this->get("success-get-pork"));
unset($this->damage_delay[$event->getDamager()->getName()][$event->getEntity()->getId()]);
}
}
break;
case 13:
if (!isset($this->damage_delay[$event->getDamager()->getName()][$event->getEntity()->getId()])) {
if ($this->dead_id[$event->getDamager()->getName()] == $event->getEntity()->getId()) {
return;
}
$this->dead_id[$event->getDamager()->getName()] = $event->getEntity()->getId();
$event->getDamager()->getInventory()->addItem(Item::get($this->rewardList["sheep-item-id"], 0, $this->rewardList["sheep-item-count"]));
$event->getDamager()->sendMessage(TextFormat::DARK_AQUA . $this->get("success-get-wool"));
//.........這裏部分代碼省略.........
示例11: 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);
}
}
}
示例12: onEntityDamage
public function onEntityDamage(EntityDamageEvent $event)
{
if ($event instanceof EntityDamageByEntityEvent && $event->getDamager() instanceof Player && $event->getEntity() instanceof Player) {
if ($this->playerIsInGame($event->getEntity()) !== false && $this->playerIsInGame($event->getDamager()) !== false) {
if ($this->gameStatus <= 2) {
$event->setCancelled();
} else {
if ($this->players[$event->getEntity()->getName()]->gameInfo->isFinder != $this->players[$event->getDamager()->getName()]->gameInfo->isFinder) {
if ($event->getEntity()->getHealth() - $event->getDamage() <= 0) {
if ($this->players[$event->getDamager()->getName()]->gameInfo->isFinder) {
$event->setCancelled();
$this->sendToAll("[遊戲係統] [躲貓貓] 尋找者" . $event->getDamager()->getName() . "發現了" . $event->getEntity()->getName());
$this->players[$event->getEntity()->getName()]->gameInfo->isFinder = true;
$event->getEntity()->setHealth($event->getEntity()->getMaxHealth());
$this->kit($event->getEntity(), true);
$event->getEntity()->sendMessage("[遊戲係統] [躲貓貓] 你成為了一名尋找者");
} else {
$this->sendToAll("[遊戲係統] [躲貓貓] 偽裝者" . $event->getDamager()->getName() . "殺死了" . $event->getEntity()->getName());
}
}
} else {
$event->setCancelled();
}
}
}
}
}
示例13: onPlayerDeath
public function onPlayerDeath(EntityDamageEvent $event)
{
if ($event->getEntity() instanceof Player) {
if ($this->disablePlayerDeath) {
if ($event->getDamage() >= $event->getEntity()->getHealth()) {
$event->setDamage(0.0);
$event->getEntity()->setHealth(20);
}
}
}
return;
}