Class ForceEffect

java.lang.Object
de.gurkenlabs.litiengine.abilities.effects.Effect
de.gurkenlabs.litiengine.abilities.effects.ForceEffect
All Implemented Interfaces:
IUpdateable

public abstract class ForceEffect extends Effect
The `ForceEffect` represents an effect that applies a physical force to mobile entities. It extends the `Effect` class and is used to manipulate the movement of entities based on the applied force, such as knockbacks or pulls.

This effect can be applied to entities that implement the `IMobileEntity` interface. The `ForceEffect` uses a targeting strategy to determine which entities are affected and applies a force with a given strength to them.

  • Constructor Details

    • ForceEffect

      protected ForceEffect(TargetingStrategy targetingStrategy, float strength)
      Constructs a new `ForceEffect` with the specified targeting strategy and force strength.
      Parameters:
      targetingStrategy - The strategy used to select which entities will be affected by the effect.
      strength - The strength of the applied force.
    • ForceEffect

      protected ForceEffect(TargetingStrategy targetingStrategy, ICombatEntity executingEntity, float strength)
      Constructs a new `ForceEffect` with the specified targeting strategy, executing entity, and force strength.
      Parameters:
      targetingStrategy - The strategy used to select which entities will be affected by the effect.
      executingEntity - The entity executing the effect (e.g., a player or NPC).
      strength - The strength of the applied force.
  • Method Details

    • apply

      public void apply(ICombatEntity affectedEntity)
      Applies the effect to a specified combat entity. If the affected entity is mobile, a force is created and applied to manipulate its movement. The applied force is stored in a map for later reference.
      Overrides:
      apply in class Effect
      Parameters:
      affectedEntity - The combat entity that will be affected by the force.
    • getStrength

      public float getStrength()
      Gets the strength of the applied force.
      Returns:
      The force strength.
    • createForce

      protected abstract Force createForce(IMobileEntity affectedEntity)
      Abstract method that must be implemented to define how the force is created for each entity.
      Parameters:
      affectedEntity - The mobile entity to which the force is applied.
      Returns:
      The created `Force` object representing the force to be applied.
    • cease

      public void cease(ICombatEntity entity)
      Stops the effect on a specified entity. If a force was applied to the entity, it is ended and removed from the map tracking applied forces.
      Overrides:
      cease in class Effect
      Parameters:
      entity - The entity on which the effect will cease.
    • hasEnded

      protected boolean hasEnded(EffectApplication appliance)
      Checks whether the effect has ended. The effect is considered ended if it has naturally ended according to its duration, or if all forces applied have ended.
      Overrides:
      hasEnded in class Effect
      Parameters:
      appliance - The current application of the effect.
      Returns:
      `true` if the effect has ended, `false` otherwise.