pocketmine\entity\Effect::add PHP Method

add() public method

public add ( Entity $entity, $modify = false, Effect $oldEffect = null )
$entity Entity
$oldEffect Effect
    public function add(Entity $entity, $modify = false, Effect $oldEffect = null)
    {
        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 ($modify) {
                $pk->eventId = MobEffectPacket::EVENT_MODIFY;
            } else {
                $pk->eventId = MobEffectPacket::EVENT_ADD;
            }
            $entity->dataPacket($pk);
            if ($this->id === Effect::SPEED) {
                $attr = $entity->getAttributeMap()->getAttribute(Attribute::MOVEMENT_SPEED);
                if ($modify and $oldEffect !== null) {
                    $speed = $attr->getValue() / (1 + 0.2 * ($oldEffect->getAmplifier() + 1));
                } else {
                    $speed = $attr->getValue();
                }
                $speed *= 1 + 0.2 * ($this->amplifier + 1);
                $attr->setValue($speed);
            } elseif ($this->id === Effect::SLOWNESS) {
                $attr = $entity->getAttributeMap()->getAttribute(Attribute::MOVEMENT_SPEED);
                if ($modify and $oldEffect !== null) {
                    $speed = $attr->getValue() / (1 - 0.15 * ($oldEffect->getAmplifier() + 1));
                } else {
                    $speed = $attr->getValue();
                }
                $speed *= 1 - (0.15 * $this->amplifier + 1);
                $attr->setValue($speed);
            }
        }
        if ($this->id === Effect::INVISIBILITY) {
            $entity->setDataFlag(Entity::DATA_FLAGS, Entity::DATA_FLAG_INVISIBLE, true);
            $entity->setDataProperty(Entity::DATA_SHOW_NAMETAG, Entity::DATA_TYPE_BYTE, 0);
        }
    }

Usage Example

コード例 #1
0
ファイル: Entity.php プロジェクト: RedstoneAlmeida/Steadfast2
 public function addEffect(Effect $effect)
 {
     if (isset($this->effects[$effect->getId()])) {
         $oldEffect = $this->effects[$effect->getId()];
         if (abs($effect->getAmplifier()) <= $oldEffect->getAmplifier() or abs($effect->getAmplifier()) === abs($oldEffect->getAmplifier()) and $effect->getDuration() < $oldEffect->getDuration()) {
             return;
         }
         $effect->add($this, true);
     } else {
         $effect->add($this, false);
     }
     $this->effects[$effect->getId()] = $effect;
     $this->recalculateEffectColor();
     if ($effect->getId() === Effect::HEALTH_BOOST) {
         $this->setHealth($this->getHealth() + 4 * ($effect->getAmplifier() + 1));
     }
 }
All Usage Examples Of pocketmine\entity\Effect::add