Class StatusEffectComponent

java.lang.Object
com.csse3200.game.components.Component
com.csse3200.game.minigames.maze.components.StatusEffectComponent

public class StatusEffectComponent extends Component
Component that allows status effects to be applied to an entity and trigger effects for a limited or unlimited amount of time.
  • 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.
      Overrides:
      create in class Component
    • 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.
      Overrides:
      update in class Component
    • registerStatusEffect

      public StatusEffectComponent registerStatusEffect(String status, StatusEffect effect)
      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 status
      effect - the effect to attach to the status
      Returns:
      this
    • setStatusExpiry

      public void setStatusExpiry(String status, float duration)
      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 status
      duration - the duration (in seconds)
    • addStatusExpiry

      public void addStatusExpiry(String status, float duration)
      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 status
      duration - the duration to add (in seconds)
    • setMinStatusExpiry

      public void setMinStatusExpiry(String status, float duration)
      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 status
      duration - the minimum expiry duration (in seconds)
    • setExpiryIfInactive

      public void setExpiryIfInactive(String status, float duration)
      Sets the time before a status expires only if the entity does not currently have that status.
      Parameters:
      status - the status
      duration - the duration (in seconds)
    • addStatus

      public void addStatus(String status)
      Permanently applies a status to the entity (until removed).
      Parameters:
      status - the status
    • removeStatus

      public void removeStatus(String status)
      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

      public boolean hasStatus(String status)
      Checks whether the entity has a given status.
      Parameters:
      status - the status
      Returns:
      whether the entity has this status
    • hasEffect

      public boolean hasEffect(String status)
      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

      public Set<String> getActiveStatuses()
      Returns:
      A set of all active statuses applied to the entity.