All Downloads are FREE. Search and download functionalities are using the official Maven repository.

de.gurkenlabs.litiengine.abilities.effects.AttributeEffect Maven / Gradle / Ivy

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);
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy