本文整理汇总了PHP中pocketmine\entity\Human::attack方法的典型用法代码示例。如果您正苦于以下问题:PHP Human::attack方法的具体用法?PHP Human::attack怎么用?PHP Human::attack使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pocketmine\entity\Human
的用法示例。
在下文中一共展示了Human::attack方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: attack
public function attack($damage, EntityDamageEvent $source)
{
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 . "Herobrine attacked by Projectile");
$attacker = $attacker->shootingEntity;
}
if ($attacker instanceof Arrow) {
Server::getInstance()->getLogger()->info(Main::PREFIX . "Herobrine attacked by Arrow");
$attacker = $attacker->shootingEntity;
}
if ($attacker instanceof Snowball) {
Server::getInstance()->getLogger()->info(Main::PREFIX . "Herobrine attacked by Snowball");
$attacker = $attacker->shootingEntity;
}
if ($attacker instanceof Player || get_class($attacker) == "pocketmine\\Player") {
Server::getInstance()->getLogger()->info(Main::PREFIX . "Herobrine attacked by " . $attacker->getName());
// $attacker->setOnFire(3);
$attacker_effect = Effect::getEffect(Effect::CONFUSION);
$attacker_effect->setDuration(15 * 20);
$attacker->addEffect($attacker_effect);
// $newundeadplayer = new UndeadPlayer(new dummyChunk, new Compound, $attacker, $this, $this->plugin);
$this->poofAway();
} else {
Server::getInstance()->getLogger()->info(Main::PREFIX . "Herobrine attacked by " . get_class($attacker));
$this->poofAway();
}
}
示例2: attack
public function attack($damage, EntityDamageEvent $source)
{
if (!$this->isAlive()) {
return;
}
if ($this->isCreative() and $source->getCause() !== EntityDamageEvent::CAUSE_MAGIC 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($damage, $source);
if ($source->isCancelled()) {
return;
} elseif ($this->getLastDamageCause() === $source and $this->spawned) {
$pk = new EntityEventPacket();
$pk->eid = 0;
$pk->event = EntityEventPacket::HURT_ANIMATION;
$this->dataPacket($pk);
}
}
示例3: 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());
}
}
示例4: attack
public function attack($damage, $source = EntityDamageEvent::CAUSE_MAGIC)
{
if ($this->dead === true) {
return;
}
if ($this->isCreative()) {
if ($source instanceof EntityDamageEvent) {
$cause = $source->getCause();
} else {
$cause = $source;
}
if ($cause !== EntityDamageEvent::CAUSE_MAGIC and $cause !== EntityDamageEvent::CAUSE_SUICIDE and $cause !== EntityDamageEvent::CAUSE_VOID) {
if ($source instanceof EntityDamageEvent) {
$source->setCancelled();
}
return;
}
}
parent::attack($damage, $source);
if ($source instanceof EntityDamageEvent and $source->isCancelled()) {
return;
}
if ($this->getLastDamageCause() === $source) {
$pk = new EntityEventPacket();
$pk->eid = 0;
$pk->event = 2;
$this->dataPacket($pk);
}
}
示例5: attack
public function attack($damage, EntityDamageEvent $source)
{
if (!$this->isAlive()) {
return;
}
if ($this->isCreative() and $source->getCause() !== EntityDamageEvent::CAUSE_MAGIC 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();
} elseif ($source->getCause() === EntityDamageEvent::CAUSE_FALL) {
if ($this->getLevel()->getBlock($this->getPosition()->add(0, -1, 0))->getId() == Item::SLIME_BLOCK) {
if (!$this->isSneaking()) {
$source->setCancelled();
$this->resetFallDistance();
}
if (!$this->isSneaking() && !$this->getPosition()->distanceSquared($this->getPosition()->subtract(0, 1)) > 0.1) {
$this->setMotion($this->getMotion()->add(0, $this->getMotion()->getY() * 2 * 0.88, 0));
}
if ($this->motionY < 0) {
$this->motionY = -$this->motionY;
if (!$this instanceof Living) {
$this->motionY *= 0.8;
}
}
}
}
parent::attack($damage, $source);
if ($source->isCancelled()) {
return false;
} elseif ($this->getLastDamageCause() === $source and $this->spawned) {
$pk = new EntityEventPacket();
$pk->eid = 0;
$pk->event = EntityEventPacket::HURT_ANIMATION;
$this->dataPacket($pk);
if ($this->isSurvival()) {
$this->exhaust(0.3, PlayerExhaustEvent::CAUSE_DAMAGE);
}
}
return true;
}
示例6: attack
public function attack($damage, EntityDamageEvent $source)
{
if ($this->dead === true) {
return;
}
if ($this->isCreative() and $source->getCause() !== EntityDamageEvent::CAUSE_MAGIC and $source->getCause() !== EntityDamageEvent::CAUSE_SUICIDE and $source->getCause() !== EntityDamageEvent::CAUSE_VOID) {
$source->setCancelled();
}
parent::attack($damage, $source);
if ($source->isCancelled()) {
return;
} elseif ($this->getLastDamageCause() === $source and $this->spawned) {
$pk = new EntityEventPacket();
$pk->eid = $this->getId();
$pk->event = 2;
$this->dataPacket($pk->setChannel(Network::CHANNEL_WORLD_EVENTS));
}
}
示例7: 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);
}
}
}