Class ConsumableComponent

java.lang.Object
com.csse3200.game.components.Component
com.csse3200.game.components.items.ConsumableComponent

public class ConsumableComponent extends Component
Component representing a consumable item that can apply one or more Effects to an entity when used.

A consumable may directly apply effects (e.g., healing, buffs), or it may trigger projectile-like behavior if the entity also has a WeaponsStatsComponent.

Effects can also be nested within an AreaEffect, which bundles multiple effects together.

  • Constructor Details

    • ConsumableComponent

      public ConsumableComponent(ArrayList<Effect> effects, int duration)
      Creates a consumable component with the specified effects and duration.
      Parameters:
      effects - list of effects this consumable applies
      duration - how long the effects last
  • Method Details

    • getEffects

      public ArrayList<Effect> getEffects()
      Retrieves all effects associated with this consumable.
      Returns:
      the list of effects
    • getEffect

      public Effect getEffect(Class<? extends Effect> effectClass)
      Retrieves the first effect of the specified type from this consumable.

      If the consumable contains an AreaEffect, its inner effects are also searched recursively.

      Parameters:
      effectClass - the class of effect to search for
      Returns:
      the first matching effect, or null if none found
    • getDuration

      public int getDuration()
      Gets the duration of this consumable's effects.
      Returns:
      duration of effects
    • firesProjectile

      public boolean firesProjectile()
      Checks whether this consumable triggers projectile behavior.

      A consumable is considered to fire a projectile if its entity has a WeaponsStatsComponent.

      Returns:
      true if the consumable fires a projectile, false otherwise