Class StatusEffectComponent
java.lang.Object
com.csse3200.game.components.Component
com.csse3200.game.minigames.maze.components.StatusEffectComponent
Component that allows status effects to be applied to an entity and trigger effects for a
limited or unlimited amount of time.
-
Field Summary
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoid
Permanently applies a status to the entity (until removed).void
addStatusExpiry
(String status, float duration) Increases the duration before a status expires by a specified amount.void
Removes all status effects applied to the entity.void
create()
Called when entity is spawned.boolean
Checks whether the entity has an effect attached to a given status.boolean
Checks whether the entity has a given status.registerStatusEffect
(String status, StatusEffect effect) Register an effect to a given status.void
removeStatus
(String status) Remove a status from being applied to the entity.void
setExpiryIfInactive
(String status, float duration) Sets the time before a status expires only if the entity does not currently have that status.void
setMinStatusExpiry
(String status, float duration) Sets the duration before a status expires to at least a specified amount.void
setStatusExpiry
(String status, float duration) Sets the time before a status expires.void
update()
Called every frame of game.Methods inherited from class com.csse3200.game.components.Component
dispose, earlyUpdate, getEntity, setEnabled, setEntity, toString, triggerEarlyUpdate, triggerUpdate
-
Constructor Details
-
StatusEffectComponent
public StatusEffectComponent()Initialise status effect component.
-
-
Method Details
-
create
public void create()Called when entity is spawned. Creates all registered status effects. -
update
public void update()Called every frame of game. Checks which status effects have timed out and should no longer be applied. Calls the update function of all effects registered to a status. -
registerStatusEffect
Register an effect to a given status. When this status is applied to the entity, the effect's start method is executed. Every frame of the game while this entity has this status, the effect's update method is executed. When this times out or is removed from the entity, the effect's stop method is executed.- Parameters:
status
- the statuseffect
- the effect to attach to the status- Returns:
- this
-
setStatusExpiry
Sets the time before a status expires. If the entity does not currently have this status, the start method of the effect attached to this status will be called.- Parameters:
status
- the statusduration
- the duration (in seconds)
-
addStatusExpiry
Increases the duration before a status expires by a specified amount. If the entity does not currently have this status, equivalent to setStatusExpiry.- Parameters:
status
- the statusduration
- the duration to add (in seconds)
-
setMinStatusExpiry
Sets the duration before a status expires to at least a specified amount. If the status is active and has a longer duration, does nothing. If the status does not exist, equivalent to setStatusExpiry.- Parameters:
status
- the statusduration
- the minimum expiry duration (in seconds)
-
setExpiryIfInactive
Sets the time before a status expires only if the entity does not currently have that status.- Parameters:
status
- the statusduration
- the duration (in seconds)
-
addStatus
Permanently applies a status to the entity (until removed).- Parameters:
status
- the status
-
removeStatus
Remove a status from being applied to the entity.- Parameters:
status
- the status
-
clearStatus
public void clearStatus()Removes all status effects applied to the entity. -
hasStatus
Checks whether the entity has a given status.- Parameters:
status
- the status- Returns:
- whether the entity has this status
-
hasEffect
Checks whether the entity has an effect attached to a given status.- Parameters:
status
- the status- Returns:
- whether the entity has an effect attached to this status.
-
getActiveStatuses
- Returns:
- A set of all active statuses applied to the entity.
-