상속: extends EntityEvent, implements pocketmine\event\Cancellable
예제 #1
0
파일: Entity.php 프로젝트: kniffo80/Genisys
 public function addEffect(Effect $effect)
 {
     Server::getInstance()->getPluginManager()->callEvent($ev = new EntityEffectAddEvent($this, $effect));
     if ($ev->isCancelled()) {
         return false;
     }
     if ($effect->getId() === Effect::HEALTH_BOOST) {
         $this->setHealth($this->getHealth() + 4 * ($effect->getAmplifier() + 1));
     }
     if ($effect->getId() === Effect::ABSORPTION and $this instanceof Human) {
         $this->setAbsorption(4 * ($effect->getAmplifier() + 1));
     }
     if (isset($this->effects[$effect->getId()])) {
         $oldEffect = $this->effects[$effect->getId()];
         if ($effect->getAmplifier() <= $oldEffect->getAmplifier() and $effect->getDuration() < $oldEffect->getDuration()) {
             return;
         }
         $effect->add($this, true, $oldEffect);
     } else {
         $effect->add($this, false);
     }
     $this->effects[$effect->getId()] = $effect;
     $this->recalculateEffectColor();
     return true;
 }
예제 #2
0
 public function add(Entity $entity, $modify = false, Effect $oldEffect = null)
 {
     $entity->getLevel()->getServer()->getPluginManager()->callEvent($ev = new EntityEffectAddEvent($entity, $this, $modify, $oldEffect));
     if ($ev->isCancelled()) {
         return;
     }
     if ($entity instanceof Player) {
         $pk = new MobEffectPacket();
         $pk->eid = 0;
         $pk->effectId = $this->getId();
         $pk->amplifier = $this->getAmplifier();
         $pk->particles = $this->isVisible();
         $pk->duration = $this->getDuration();
         if ($ev->willModify()) {
             $pk->eventId = MobEffectPacket::EVENT_MODIFY;
         } else {
             $pk->eventId = MobEffectPacket::EVENT_ADD;
         }
         $entity->dataPacket($pk);
     }
     if ($this->id === Effect::INVISIBILITY) {
         $entity->setDataFlag(Entity::DATA_FLAGS, Entity::DATA_FLAG_INVISIBLE, true);
         $entity->setNameTagVisible(false);
     } elseif ($this->id === Effect::SPEED) {
         $attr = $entity->getAttributeMap()->getAttribute(Attribute::MOVEMENT_SPEED);
         if ($ev->willModify() and $oldEffect !== null) {
             $speed = $attr->getValue() / (1 + 0.2 * $oldEffect->getAmplifier());
         } else {
             $speed = $attr->getValue();
         }
         $speed *= 1 + 0.2 * $this->amplifier;
         $attr->setValue($speed);
     } elseif ($this->id === Effect::SLOWNESS) {
         $attr = $entity->getAttributeMap()->getAttribute(Attribute::MOVEMENT_SPEED);
         if ($ev->willModify() and $oldEffect !== null) {
             $speed = $attr->getValue() / (1 - 0.15 * $oldEffect->getAmplifier());
         } else {
             $speed = $attr->getValue();
         }
         $speed *= 1 - 0.15 * $this->amplifier;
         $attr->setValue($speed);
     }
 }