Merge #826: use getEffectLevel() instead of getAmplifier() + 1

Closes #412
This commit is contained in:
smarticles101 2017-05-05 18:58:54 +08:00 committed by SOFe
parent 76ceddf266
commit 8a7259aa73
No known key found for this signature in database
GPG Key ID: A0379676C4D9D5D9
6 changed files with 33 additions and 26 deletions

View File

@ -222,9 +222,17 @@ class Effect{
return $this;
}
/**
* Returns the level of this effect, which is always one higher than the amplifier.
*
* @return int
*/
public function getEffectLevel() : int{
return $this->amplifier + 1;
}
/**
* Returns the amplifier of this effect.
* TODO: fix mess of amplifier used instead of level for effect calculation.
*
* @return int
*/
@ -337,19 +345,19 @@ class Effect{
case Effect::HUNGER:
if($entity instanceof Human){
$entity->exhaust(0.5 * $this->amplifier, PlayerExhaustEvent::CAUSE_POTION);
$entity->exhaust(0.5 * $this->getEffectLevel(), PlayerExhaustEvent::CAUSE_POTION);
}
break;
case Effect::INSTANT_HEALTH:
//TODO: add particles (witch spell)
if($entity->getHealth() < $entity->getMaxHealth()){
$amount = 2 * (2 ** (($this->amplifier + 1) % 32));
$amount = 2 * (2 ** ($this->getEffectLevel() % 32));
$entity->heal($amount, new EntityRegainHealthEvent($entity, $amount, EntityRegainHealthEvent::CAUSE_MAGIC));
}
break;
case Effect::INSTANT_DAMAGE:
//TODO: add particles (witch spell)
$amount = 2 * (2 ** (($this->amplifier + 1) % 32));
$amount = 2 * (2 ** ($this->getEffectLevel() % 32));
$entity->attack($amount, new EntityDamageEvent($entity, EntityDamageEvent::CAUSE_MAGIC, $amount));
break;
}
@ -410,42 +418,41 @@ class Effect{
case Effect::SPEED:
$attr = $entity->getAttributeMap()->getAttribute(Attribute::MOVEMENT_SPEED);
if($ev->willModify() and $oldEffect !== null){
$speed = $attr->getValue() / (1 + 0.2 * $oldEffect->getAmplifier());
$speed = $attr->getValue() / (1 + 0.2 * $oldEffect->getEffectLevel());
}else{
$speed = $attr->getValue();
}
$speed *= (1 + 0.2 * $this->amplifier);
$speed *= (1 + 0.2 * $this->getEffectLevel());
$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());
$speed = $attr->getValue() / (1 - 0.15 * $oldEffect->getEffectLevel());
}else{
$speed = $attr->getValue();
}
$speed *= (1 - 0.15 * $this->amplifier);
$speed *= (1 - 0.15 * $this->getEffectLevel());
$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 * ($oldEffect->getAmplifier() + 1));
$max = $attr->getMaxValue() - (4 * $oldEffect->getEffectLevel());
}else{
$max = $attr->getMaxValue();
}
$max += (4 * ($this->amplifier + 1));
$max += (4 * $this->getEffectLevel());
$attr->setMaxValue($max);
break;
case Effect::ABSORPTION:
$new = (4 * ($this->amplifier + 1));
$new = (4 * $this->getEffectLevel());
if($new > $entity->getAbsorption()){
$entity->setAbsorption($new);
}
break;
}
}
@ -475,15 +482,15 @@ class Effect{
break;
case Effect::SPEED:
$attr = $entity->getAttributeMap()->getAttribute(Attribute::MOVEMENT_SPEED);
$attr->setValue($attr->getValue() / (1 + 0.2 * $this->amplifier));
$attr->setValue($attr->getValue() / (1 + 0.2 * $this->getEffectLevel()));
break;
case Effect::SLOWNESS:
$attr = $entity->getAttributeMap()->getAttribute(Attribute::MOVEMENT_SPEED);
$attr->setValue($attr->getValue() / (1 - 0.15 * $this->amplifier));
$attr->setValue($attr->getValue() / (1 - 0.15 * $this->getEffectLevel()));
break;
case Effect::HEALTH_BOOST:
$attr = $entity->getAttributeMap()->getAttribute(Attribute::HEALTH);
$attr->setMaxValue($attr->getMaxValue() - (4 * ($this->amplifier + 1)));
$attr->setMaxValue($attr->getMaxValue() - 4 * $this->getEffectLevel());
break;
case Effect::ABSORPTION:
$entity->setAbsorption(0);

View File

@ -512,10 +512,10 @@ abstract class Entity extends Location implements Metadatable{
foreach($this->effects as $effect){
if($effect->isVisible() and $effect->hasBubbles()){
$c = $effect->getColor();
$color[0] += $c[0] * ($effect->getAmplifier() + 1);
$color[1] += $c[1] * ($effect->getAmplifier() + 1);
$color[2] += $c[2] * ($effect->getAmplifier() + 1);
$count += $effect->getAmplifier() + 1;
$color[0] += $c[0] * $effect->getEffectLevel();
$color[1] += $c[1] * $effect->getEffectLevel();
$color[2] += $c[2] * $effect->getEffectLevel();
$count += $effect->getEffectLevel();
if(!$effect->isAmbient()){
$ambient = false;
}
@ -1178,7 +1178,7 @@ abstract class Entity extends Location implements Metadatable{
}
public function fall($fallDistance){
$damage = floor($fallDistance - 3 - ($this->hasEffect(Effect::JUMP) ? $this->getEffect(Effect::JUMP)->getAmplifier() + 1 : 0));
$damage = floor($fallDistance - 3 - ($this->hasEffect(Effect::JUMP) ? $this->getEffect(Effect::JUMP)->getEffectLevel() : 0));
if($damage > 0){
$ev = new EntityDamageEvent($this, EntityDamageEvent::CAUSE_FALL, $damage);
$this->attack($ev->getFinalDamage(), $ev);

View File

@ -122,7 +122,7 @@ abstract class Living extends Entity implements Damageable{
* @return float
*/
public function getJumpVelocity() : float{
return $this->jumpVelocity + ($this->hasEffect(Effect::JUMP) ? (($this->getEffect(Effect::JUMP)->getAmplifier() + 1) / 10) : 0);
return $this->jumpVelocity + ($this->hasEffect(Effect::JUMP) ? ($this->getEffect(Effect::JUMP)->getEffectLevel() / 10) : 0);
}
/**

View File

@ -50,11 +50,11 @@ class EntityDamageByEntityEvent extends EntityDamageEvent{
protected function addAttackerModifiers(Entity $damager){
if($damager->hasEffect(Effect::STRENGTH)){
$this->setDamage($this->getDamage(self::MODIFIER_BASE) * 0.3 * ($damager->getEffect(Effect::STRENGTH)->getAmplifier() + 1), self::MODIFIER_STRENGTH);
$this->setDamage($this->getDamage(self::MODIFIER_BASE) * 0.3 * $damager->getEffect(Effect::STRENGTH)->getEffectLevel(), self::MODIFIER_STRENGTH);
}
if($damager->hasEffect(Effect::WEAKNESS)){
$this->setDamage(-($this->getDamage(self::MODIFIER_BASE) * 0.2 * ($damager->getEffect(Effect::WEAKNESS)->getAmplifier() + 1)), self::MODIFIER_WEAKNESS);
$this->setDamage(-($this->getDamage(self::MODIFIER_BASE) * 0.2 * $damager->getEffect(Effect::WEAKNESS)->getEffectLevel()), self::MODIFIER_WEAKNESS);
}
}

View File

@ -86,7 +86,7 @@ class EntityDamageEvent extends EntityEvent implements Cancellable{
}
if($entity->hasEffect(Effect::DAMAGE_RESISTANCE)){
$this->setDamage(-($this->getDamage(self::MODIFIER_BASE) * 0.20 * ($entity->getEffect(Effect::DAMAGE_RESISTANCE)->getAmplifier() + 1)), self::MODIFIER_RESISTANCE);
$this->setDamage(-($this->getDamage(self::MODIFIER_BASE) * 0.20 * $entity->getEffect(Effect::DAMAGE_RESISTANCE)->getEffectLevel()), self::MODIFIER_RESISTANCE);
}
}

View File

@ -1601,11 +1601,11 @@ class Level implements ChunkManager, Metadatable{
}
if($player->hasEffect(Effect::HASTE)){
$breakTime *= 1 - (0.2 * ($player->getEffect(Effect::HASTE)->getAmplifier() + 1));
$breakTime *= 1 - (0.2 * $player->getEffect(Effect::HASTE)->getEffectLevel());
}
if($player->hasEffect(Effect::MINING_FATIGUE)){
$breakTime *= 1 + (0.3 * ($player->getEffect(Effect::MINING_FATIGUE)->getAmplifier() + 1));
$breakTime *= 1 + (0.3 * $player->getEffect(Effect::MINING_FATIGUE)->getEffectLevel());
}
$breakTime -= 1; //1 tick compensation