Class AreaEffect

java.lang.Object
com.csse3200.game.effects.Effect
com.csse3200.game.effects.AreaEffect

public class AreaEffect extends Effect
An Effect that applies multiple inner effects to all valid entities within a certain radius of a central entity.

AreaEffect is typically used for area-of-effect (AoE) items, such as explosions, healing zones, or buffs/debuffs that impact multiple nearby entities at once.

Validation rules:

  • The effect list cannot be null or empty.
  • Inner effects cannot contain null values.
  • Nested AreaEffects are not allowed (to prevent infinite recursion).
  • Radius must be strictly positive.
  • Field Details

    • effects

      public ArrayList<Effect> effects
      The list of effects to apply to each entity within the area.
    • radius

      public int radius
      The radius of the area (in world units).
  • Constructor Details

    • AreaEffect

      public AreaEffect(List<Effect> effects, int radius)
      Creates a new AreaEffect.
      Parameters:
      effects - list of effects to apply to entities in range
      radius - radius of the effect area (must be positive)
      Throws:
      IllegalArgumentException - if arguments are invalid (see validation rules)
  • Method Details

    • getEffects

      public ArrayList<Effect> getEffects()
      Gets the list of inner effects that this area effect applies.
      Returns:
      list of effects
    • getRadius

      public int getRadius()
      Gets the radius of the area in which this effect applies.
      Returns:
      radius of the effect
    • apply

      public boolean apply(Entity center)
      Applies this area effect to all entities within range of the given center entity.

      Entities are affected if:

      • They are within the radius (distance calculated from their center positions).
      • They have a CombatStatsComponent.
      • They are not the player (identified by PlayerActions).
      Each valid entity receives all inner effects in sequence.
      Specified by:
      apply in class Effect
      Parameters:
      center - the entity at the center of the area effect
      Returns:
      true if at least one effect was successfully applied, otherwise false