Class ConsumableComponent
java.lang.Object
com.csse3200.game.components.Component
com.csse3200.game.components.items.ConsumableComponent
Component representing a consumable item that can apply one or more
Effect
s
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.
-
Field Summary
-
Constructor Summary
ConstructorsConstructorDescriptionConsumableComponent
(ArrayList<Effect> effects, int duration) Creates a consumable component with the specified effects and duration. -
Method Summary
Modifier and TypeMethodDescriptionboolean
Checks whether this consumable triggers projectile behavior.int
Gets the duration of this consumable's effects.Retrieves the first effect of the specified type from this consumable.Retrieves all effects associated with this consumable.Methods inherited from class com.csse3200.game.components.Component
create, dispose, earlyUpdate, getEntity, getPrio, setEnabled, setEntity, toString, triggerEarlyUpdate, triggerUpdate, update
-
Constructor Details
-
ConsumableComponent
Creates a consumable component with the specified effects and duration.- Parameters:
effects
- list of effects this consumable appliesduration
- how long the effects last
-
-
Method Details
-
getEffects
Retrieves all effects associated with this consumable.- Returns:
- the list of effects
-
getEffect
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
-