本文整理匯總了PHP中pocketmine\event\entity\EntityDamageEvent::setDamage方法的典型用法代碼示例。如果您正苦於以下問題:PHP EntityDamageEvent::setDamage方法的具體用法?PHP EntityDamageEvent::setDamage怎麽用?PHP EntityDamageEvent::setDamage使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類pocketmine\event\entity\EntityDamageEvent
的用法示例。
在下文中一共展示了EntityDamageEvent::setDamage方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: onDamage
public function onDamage(EntityDamageEvent $event)
{
$player = $event->getEntity();
$entity = $event->getEntity();
if ($player instanceof Player && $event->getCause() === EntityDamageEvent::CAUSE_ENTITY_EXPLOSION) {
switch (mt_rand(1, 2)) {
case 1:
$event->setDamage(10);
break;
case 2:
$event->setDamage(8);
break;
}
}
}
示例2: 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);
}
}
示例3: fallenDamagePrevent
public function fallenDamagePrevent(EntityDamageEvent $event)
{
if ($event->getCause() == EntityDamageEvent::CAUSE_FALL) {
if (!$event->getEntity() instanceof Player) {
return;
}
if ($event->getEntity()->y > 0) {
$event->setDamage(0);
$event->setCancelled();
}
}
}
示例4: onEntityHitByProjectile
public function onEntityHitByProjectile(EntityDamageEvent $event)
{
if (!$event instanceof EntityDamageByEntityEvent) {
return;
}
$damager = $event->getDamager();
if (!$damager instanceof Projectile) {
return;
}
if (isset($damager->namedtag["ArcheryDamage"])) {
$event->setDamage($damager->namedtag["ArcheryDamage"]);
}
}
示例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: fallenDamagePrevent
public function fallenDamagePrevent(EntityDamageEvent $event)
{
if ($event->getCause() == EntityDamageEvent::CAUSE_FALL) {
if (!$event->getEntity() instanceof Player) {
return;
}
if (isset($this->fallen[$event->getEntity()->getName()])) {
$event->setDamage(0);
$this->fallen[$event->getEntity()->getName()]--;
if ($this->fallen[$event->getEntity()->getName()] == 0) {
unset($this->fallen[$event->getEntity()->getName()]);
}
}
}
}
示例12: 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);
}
示例13: onHurtf
public function onHurtf(EntityDamageEvent $event)
{
//$cause = $event->getCause();
//arrow check for the catchy phrase thing :PPP
$causet = $event->getCause();
if ($causet === 2) {
$arrowed = true;
} else {
$arrowed = false;
}
$pr = $event->getEntity();
$cause = $pr->getLastDamageCause();
if ($cause instanceof EntityDamageByEntityEvent) {
$dam = $event->getDamager()->getName();
$ent = $event->getEntity()->getPlayer()->getName();
if ($arrowed) {
if (!is_file($this->getDataFolder() . $dam . ".json")) {
return true;
}
$file = file_get_contents($this->getDataFolder() . $dam . ".json");
$decode = json_decode($file, true);
if (isset($decode["annihilator"]) and $decode["annihilator"] === "yes") {
$nt = $event->getEntity()->getPlayer();
$event->setDamage(0);
$spawn = $nt->getSpawn();
$nt->teleport($spawn, $nt->getYaw(), $nt->getPitch());
$this->getServer()->getPlayer($ent)->sendMessage("One-shot, one kill! You didn't even see that coming!");
return true;
} else {
return true;
}
}
$this->killer[$dam] = strval($ent);
if ($dam instanceof Player) {
$ms = $dam;
if (!\is_file($this->getDataFolder() . $ms . ".json")) {
return true;
}
$hhd = file_get_contents($this->getDataFolder() . $ms . ".json");
$dec = json_decode($hhd, true);
if (isset($dec["annihilator"])) {
if ($dec["annihilator"] === "yes") {
$event->setDamage(PHP_INT_MAX);
return true;
}
}
}
if ($dam instanceof Arrow) {
$this->getLogger()->info("yeah!");
}
}
}
示例14: 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);
}
}
}
示例15: 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;
}