de.gurkenlabs.litiengine.abilities.effects.AttributeEffect Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of litiengine Show documentation
Show all versions of litiengine Show documentation
The FOSS 2D Java game engine.
The newest version!
package de.gurkenlabs.litiengine.abilities.effects;
import de.gurkenlabs.litiengine.abilities.Ability;
import de.gurkenlabs.litiengine.attributes.Attribute;
import de.gurkenlabs.litiengine.attributes.AttributeModifier;
import de.gurkenlabs.litiengine.attributes.Modification;
import de.gurkenlabs.litiengine.entities.ICombatEntity;
/**
* An attribute effect appies an attribute modifier to the affected entity when applied and removes it when ceased.
*
* @param
* the generic type
*/
public abstract class AttributeEffect extends Effect {
/** The modifier. */
private final AttributeModifier modifier;
protected AttributeEffect(
final Ability ability,
final Modification modification,
final double delta,
final EffectTarget... targets) {
super(ability, targets);
this.modifier = new AttributeModifier<>(modification, delta);
}
@Override
public void cease(final ICombatEntity affectedEntity) {
super.cease(affectedEntity);
this.getAttribute(affectedEntity).removeModifier(this.getModifier());
}
public AttributeModifier getModifier() {
return this.modifier;
}
@Override
protected void apply(final ICombatEntity affectedEntity) {
super.apply(affectedEntity);
this.getAttribute(affectedEntity).addModifier(this.getModifier());
}
protected abstract Attribute getAttribute(final ICombatEntity entity);
}