Class Effect

java.lang.Object
de.gurkenlabs.litiengine.abilities.effects.Effect
All Implemented Interfaces:
IUpdateable
Direct Known Subclasses:
AbilityEffect, AttributeEffect, ForceEffect, SoundEffect

public abstract class Effect extends Object implements IUpdateable
The `Effect` class represents an abstract base class for applying effects to combat entities. Effects are applied based on a `TargetingStrategy` and may affect multiple entities within a defined impact area. Effects are applied for a set duration and may have follow-up effects.

This class handles effect application, event listeners for when effects are applied or ceased, and the management of active appliances (ongoing effect instances).

  • Constructor Details

    • Effect

      protected Effect(TargetingStrategy targetingStrategy)
      Constructs a new `Effect` with the specified targeting strategy.
      Parameters:
      targetingStrategy - The strategy used to target entities for this effect.
    • Effect

      protected Effect(TargetingStrategy targetingStrategy, ICombatEntity executor)
      Constructs a new `Effect` with the specified targeting strategy and executor.
      Parameters:
      targetingStrategy - The strategy used to target entities for this effect.
      executor - The entity applying the effect, or null if none.
    • Effect

      protected Effect(TargetingStrategy targetingStrategy, ICombatEntity executor, int duration)
      Constructs a new `Effect` with the specified targeting strategy, executor, and duration.
      Parameters:
      targetingStrategy - The strategy used to target entities for this effect.
      executor - The entity applying the effect, or null if none.
      duration - The duration the effect will last.
  • Method Details

    • onEffectApplied

      public void onEffectApplied(Effect.EffectAppliedListener listener)
      Registers a listener for when the effect is applied.
      Parameters:
      listener - The listener to register.
    • removeEffectAppliedListener

      public void removeEffectAppliedListener(Effect.EffectAppliedListener listener)
    • onEffectCeased

      public void onEffectCeased(Effect.EffectCeasedListener listener)
      Registers a listener for when the effect ceases.
      Parameters:
      listener - The listener to register.
    • removeEffectCeasedListener

      public void removeEffectCeasedListener(Effect.EffectCeasedListener listener)
    • apply

      public void apply(Shape impactArea)
      Applies the effect to all entities within the specified impact area.
      Parameters:
      impactArea - The area where the effect is applied.
    • cease

      public void cease(ICombatEntity entity)
      Ceases the effect for the specified entity.
      Parameters:
      entity - The entity for which the effect will cease.
    • getExecutingEntity

      public ICombatEntity getExecutingEntity()
      Returns the entity that is executing this effect.
      Returns:
      The executor of this effect.
    • getActiveAppliances

      public List<EffectApplication> getActiveAppliances()
      Returns the list of active effect applications.
      Returns:
      The list of active effect applications.
    • getDelay

      public int getDelay()
      Returns the delay before this effect is applied.
      Returns:
      The delay in ticks.
    • getDuration

      public int getDuration()
      Returns the duration this effect lasts once applied.
      Returns:
      The effect duration in ticks.
    • getTargetingStrategy

      public TargetingStrategy getTargetingStrategy()
      Returns the targeting strategy used by this effect.
      Returns:
      The targeting strategy.
    • getFollowUpEffects

      public List<Effect> getFollowUpEffects()
      Returns the list of follow-up effects that are applied after the main effect ends.
      Returns:
      The list of follow-up effects.
    • isActive

      public boolean isActive(ICombatEntity entity)
      Checks if the effect is active on the specified entity.
      Parameters:
      entity - The entity to check.
      Returns:
      True if the effect is active on the entity, false otherwise.
    • setDelay

      public void setDelay(int delay)
      Sets the delay before this effect is applied.
      Parameters:
      delay - the delay in ticks
    • setDuration

      public void setDuration(int duration)
      Sets the duration this effect lasts once applied.
      Parameters:
      duration - the effect duration in ticks
    • update

      public void update()
      Updates the effect, checking for appliances that have reached their duration and applying follow-up effects if needed. Removes appliances that have ended and detaches the effect from the game loop if no active appliances remain.
      Specified by:
      update in interface IUpdateable
      See Also:
    • apply

      protected void apply(ICombatEntity entity)
      Applies the effect to the specified entity, adding this effect to the entity's list of applied effects and notifying all registered listeners that the effect has been applied.
      Parameters:
      entity - the entity to which the effect is applied
    • cease

      protected void cease(EffectApplication appliance)
      Ceases the effect for the specified application and applies follow-up effects.
      Parameters:
      appliance - The application to cease.
    • getTotalDuration

      protected long getTotalDuration()
      Returns the total duration of the effect, including the delay.
      Returns:
      The total effect duration.
    • hasEnded

      protected boolean hasEnded(EffectApplication appliance)
      Checks if the specified effect application has ended.
      Parameters:
      appliance - The application to check.
      Returns:
      True if the effect duration has passed, false otherwise.