diff --git a/src/pocketmine/entity/Effect.php b/src/pocketmine/entity/Effect.php index f55c4b1de..ccbe3d109 100644 --- a/src/pocketmine/entity/Effect.php +++ b/src/pocketmine/entity/Effect.php @@ -263,27 +263,42 @@ class Effect{ $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, true); + switch($this->id){ + case Effect::INVISIBILITY: + $entity->setDataFlag(Entity::DATA_FLAGS, Entity::DATA_FLAG_INVISIBLE, true); + $entity->setNameTagVisible(false); + break; + case 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); + break; + case 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, true); + break; + case Effect::HEALTH_BOOST: + $attr = $entity->getAttributeMap()->getAttribute(Attribute::HEALTH); + if($ev->willModify() and $oldEffect !== null){ + $max = $attr->getMaxValue() - (4 * ($this->amplifier + 1)); + }else{ + $max = $attr->getMaxValue(); + } + + $max += (4 * ($this->amplifier + 1)); + $attr->setMaxValue($max); + break; } } @@ -301,15 +316,23 @@ class Effect{ $entity->dataPacket($pk); } - if($this->id === Effect::INVISIBILITY){ - $entity->setDataFlag(Entity::DATA_FLAGS, Entity::DATA_FLAG_INVISIBLE, false); - $entity->setNameTagVisible(true); - }elseif($this->id === Effect::SPEED){ - $attr = $entity->getAttributeMap()->getAttribute(Attribute::MOVEMENT_SPEED); - $attr->setValue($attr->getValue() / (1 + 0.2 * $this->amplifier)); - }elseif($this->id === Effect::SLOWNESS){ - $attr = $entity->getAttributeMap()->getAttribute(Attribute::MOVEMENT_SPEED); - $attr->setValue($attr->getValue() / (1 - 0.15 * $this->amplifier)); + switch($this->id){ + case Effect::INVISIBILITY: + $entity->setDataFlag(Entity::DATA_FLAGS, Entity::DATA_FLAG_INVISIBLE, false); + $entity->setNameTagVisible(true); + break; + case Effect::SPEED: + $attr = $entity->getAttributeMap()->getAttribute(Attribute::MOVEMENT_SPEED); + $attr->setValue($attr->getValue() / (1 + 0.2 * $this->amplifier)); + break; + case Effect::SLOWNESS: + $attr = $entity->getAttributeMap()->getAttribute(Attribute::MOVEMENT_SPEED); + $attr->setValue($attr->getValue() / (1 - 0.15 * $this->amplifier)); + break; + case Effect::HEALTH_BOOST: + $attr = $entity->getAttributeMap()->getAttribute(Attribute::HEALTH); + $attr->setMaxValue($attr->getMaxValue() - (4 * ($this->amplifier + 1))); + break; } } } diff --git a/src/pocketmine/entity/Entity.php b/src/pocketmine/entity/Entity.php index e3edaccd8..3c09d906d 100644 --- a/src/pocketmine/entity/Entity.php +++ b/src/pocketmine/entity/Entity.php @@ -484,10 +484,6 @@ abstract class Entity extends Location implements Metadatable{ $this->effects[$effect->getId()] = $effect; $this->recalculateEffectColor(); - - if($effect->getId() === Effect::HEALTH_BOOST){ - $this->setHealth($this->getHealth() + 4 * ($effect->getAmplifier() + 1)); - } } protected function recalculateEffectColor(){ @@ -811,7 +807,7 @@ abstract class Entity extends Location implements Metadatable{ * @return int */ public function getMaxHealth(){ - return $this->maxHealth + ($this->hasEffect(Effect::HEALTH_BOOST) ? 4 * ($this->getEffect(Effect::HEALTH_BOOST)->getAmplifier() + 1) : 0); + return $this->maxHealth; } /** diff --git a/src/pocketmine/entity/Living.php b/src/pocketmine/entity/Living.php index e9b8d2429..b8510434f 100644 --- a/src/pocketmine/entity/Living.php +++ b/src/pocketmine/entity/Living.php @@ -77,6 +77,10 @@ abstract class Living extends Entity implements Damageable{ } } + public function getMaxHealth(){ + return $this->attributeMap->getAttribute(Attribute::HEALTH)->getMaxValue(); + } + public function setMaxHealth($amount){ $this->attributeMap->getAttribute(Attribute::HEALTH)->setMaxValue($amount); }