Fixed botch-job implementation of Health Boost, will now actually work and not crash the server

This commit is contained in:
Dylan K. Taylor 2017-03-12 20:06:39 +00:00
parent f58ee2028e
commit 955dc38be4
3 changed files with 58 additions and 35 deletions

View File

@ -263,27 +263,42 @@ class Effect{
$entity->dataPacket($pk); $entity->dataPacket($pk);
} }
if($this->id === Effect::INVISIBILITY){ switch($this->id){
$entity->setDataFlag(Entity::DATA_FLAGS, Entity::DATA_FLAG_INVISIBLE, true); case Effect::INVISIBILITY:
$entity->setNameTagVisible(false); $entity->setDataFlag(Entity::DATA_FLAGS, Entity::DATA_FLAG_INVISIBLE, true);
}elseif($this->id === Effect::SPEED){ $entity->setNameTagVisible(false);
$attr = $entity->getAttributeMap()->getAttribute(Attribute::MOVEMENT_SPEED); break;
if($ev->willModify() and $oldEffect !== null){ case Effect::SPEED:
$speed = $attr->getValue() / (1 + 0.2 * $oldEffect->getAmplifier()); $attr = $entity->getAttributeMap()->getAttribute(Attribute::MOVEMENT_SPEED);
}else{ if($ev->willModify() and $oldEffect !== null){
$speed = $attr->getValue(); $speed = $attr->getValue() / (1 + 0.2 * $oldEffect->getAmplifier());
} }else{
$speed *= (1 + 0.2 * $this->amplifier); $speed = $attr->getValue();
$attr->setValue($speed); }
}elseif($this->id === Effect::SLOWNESS){ $speed *= (1 + 0.2 * $this->amplifier);
$attr = $entity->getAttributeMap()->getAttribute(Attribute::MOVEMENT_SPEED); $attr->setValue($speed);
if($ev->willModify() and $oldEffect !== null){ break;
$speed = $attr->getValue() / (1 - 0.15 * $oldEffect->getAmplifier()); case Effect::SLOWNESS:
}else{ $attr = $entity->getAttributeMap()->getAttribute(Attribute::MOVEMENT_SPEED);
$speed = $attr->getValue(); if($ev->willModify() and $oldEffect !== null){
} $speed = $attr->getValue() / (1 - 0.15 * $oldEffect->getAmplifier());
$speed *= (1 - 0.15 * $this->amplifier); }else{
$attr->setValue($speed, true); $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); $entity->dataPacket($pk);
} }
if($this->id === Effect::INVISIBILITY){ switch($this->id){
$entity->setDataFlag(Entity::DATA_FLAGS, Entity::DATA_FLAG_INVISIBLE, false); case Effect::INVISIBILITY:
$entity->setNameTagVisible(true); $entity->setDataFlag(Entity::DATA_FLAGS, Entity::DATA_FLAG_INVISIBLE, false);
}elseif($this->id === Effect::SPEED){ $entity->setNameTagVisible(true);
$attr = $entity->getAttributeMap()->getAttribute(Attribute::MOVEMENT_SPEED); break;
$attr->setValue($attr->getValue() / (1 + 0.2 * $this->amplifier)); case Effect::SPEED:
}elseif($this->id === Effect::SLOWNESS){ $attr = $entity->getAttributeMap()->getAttribute(Attribute::MOVEMENT_SPEED);
$attr = $entity->getAttributeMap()->getAttribute(Attribute::MOVEMENT_SPEED); $attr->setValue($attr->getValue() / (1 + 0.2 * $this->amplifier));
$attr->setValue($attr->getValue() / (1 - 0.15 * $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;
} }
} }
} }

View File

@ -484,10 +484,6 @@ abstract class Entity extends Location implements Metadatable{
$this->effects[$effect->getId()] = $effect; $this->effects[$effect->getId()] = $effect;
$this->recalculateEffectColor(); $this->recalculateEffectColor();
if($effect->getId() === Effect::HEALTH_BOOST){
$this->setHealth($this->getHealth() + 4 * ($effect->getAmplifier() + 1));
}
} }
protected function recalculateEffectColor(){ protected function recalculateEffectColor(){
@ -811,7 +807,7 @@ abstract class Entity extends Location implements Metadatable{
* @return int * @return int
*/ */
public function getMaxHealth(){ public function getMaxHealth(){
return $this->maxHealth + ($this->hasEffect(Effect::HEALTH_BOOST) ? 4 * ($this->getEffect(Effect::HEALTH_BOOST)->getAmplifier() + 1) : 0); return $this->maxHealth;
} }
/** /**

View File

@ -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){ public function setMaxHealth($amount){
$this->attributeMap->getAttribute(Attribute::HEALTH)->setMaxValue($amount); $this->attributeMap->getAttribute(Attribute::HEALTH)->setMaxValue($amount);
} }