reduce boilerplate around attribute handling

This commit is contained in:
Dylan K. Taylor
2019-07-31 16:41:09 +01:00
parent dc33b9e573
commit 296061d25d
10 changed files with 43 additions and 43 deletions

View File

@ -29,12 +29,12 @@ use pocketmine\entity\Living;
class SlownessEffect extends Effect{
public function add(Living $entity, EffectInstance $instance) : void{
$attr = $entity->getAttributeMap()->getAttribute(Attribute::MOVEMENT_SPEED);
$attr = $entity->getAttributeMap()->get(Attribute::MOVEMENT_SPEED);
$attr->setValue($attr->getValue() * (1 - 0.15 * $instance->getEffectLevel()), true);
}
public function remove(Living $entity, EffectInstance $instance) : void{
$attr = $entity->getAttributeMap()->getAttribute(Attribute::MOVEMENT_SPEED);
$attr = $entity->getAttributeMap()->get(Attribute::MOVEMENT_SPEED);
$attr->setValue($attr->getValue() / (1 - 0.15 * $instance->getEffectLevel()));
}
}

View File

@ -29,12 +29,12 @@ use pocketmine\entity\Living;
class SpeedEffect extends Effect{
public function add(Living $entity, EffectInstance $instance) : void{
$attr = $entity->getAttributeMap()->getAttribute(Attribute::MOVEMENT_SPEED);
$attr = $entity->getAttributeMap()->get(Attribute::MOVEMENT_SPEED);
$attr->setValue($attr->getValue() * (1 + 0.2 * $instance->getEffectLevel()));
}
public function remove(Living $entity, EffectInstance $instance) : void{
$attr = $entity->getAttributeMap()->getAttribute(Attribute::MOVEMENT_SPEED);
$attr = $entity->getAttributeMap()->get(Attribute::MOVEMENT_SPEED);
$attr->setValue($attr->getValue() / (1 + 0.2 * $instance->getEffectLevel()));
}
}