Class Trigger

All Implemented Interfaces:
EntityRenderedListener, EntityRenderListener, ICollisionEntity, IEntity, IUpdateable, Tweenable, EventListener

public class Trigger extends CollisionEntity implements IUpdateable
TODO: Triggers should be able to call entity actions (similar to the current message approach)
  • Constructor Details

    • Trigger

      public Trigger(Trigger.TriggerActivation activation, String message)
      Instantiates a new Trigger entity.
      Parameters:
      activation - The activation method for this trigger.
      message - The message that gets sent by this trigger upon activation.
    • Trigger

      public Trigger(Trigger.TriggerActivation activation, String name, String message)
      Instantiates a new Trigger entity.
      Parameters:
      activation - The activation method for this trigger.
      name - The name of this trigger.
      message - The message that gets sent by this trigger upon activation.
    • Trigger

      public Trigger(Trigger.TriggerActivation activation, String message, boolean isOneTime)
      Instantiates a new Trigger entity.
      Parameters:
      activation - The activation method for this trigger.
      message - The message that gets sent by this trigger upon activation.
      isOneTime - A flag, indicating whether this instance can only be triggered once.
    • Trigger

      public Trigger(Trigger.TriggerActivation activation, String name, String message, boolean isOneTime)
      Instantiates a new Trigger entity.
      Parameters:
      activation - The activation method for this trigger.
      name - The name of this trigger.
      message - The message that gets sent by this trigger upon activation.
      isOneTime - A flag, indicating whether this instance can only be triggered once.
    • Trigger

      public Trigger(Trigger.TriggerActivation activation, String message, boolean isOneTime, int cooldown)
      Initializes a new instance of the Trigger class.
      Parameters:
      activation - The activation method for this trigger.
      message - The message that gets sent by this trigger upon activation.
      isOneTime - A flag, indicating whether this instance can only be triggered once.
      cooldown - The cooldown that needs to be respected between two activation events.
  • Method Details

    • addTriggerListener

      public void addTriggerListener(TriggerListener listener)
      Adds a TriggerListener to this trigger.
      Parameters:
      listener - the TriggerListener to add
    • removeTriggerListener

      public void removeTriggerListener(TriggerListener listener)
      Removes a TriggerListener from this trigger.
      Parameters:
      listener - the TriggerListener to remove
    • addActivatedListener

      public void addActivatedListener(TriggerActivatedListener listener)
      Adds a TriggerActivatedListener to this trigger.
      Parameters:
      listener - the TriggerActivatedListener to add
    • removeActivatedListener

      public void removeActivatedListener(TriggerActivatedListener listener)
      Removes a TriggerActivatedListener from this trigger.
      Parameters:
      listener - the TriggerActivatedListener to remove
    • addActivatingCondition

      public void addActivatingCondition(TriggerActivatingCondition condition)
      Adds a TriggerActivatingCondition to this trigger.
      Parameters:
      condition - the TriggerActivatingCondition to add
    • removeActivatingCondition

      public void removeActivatingCondition(TriggerActivatingCondition condition)
      Removes a TriggerActivatingCondition from this trigger.
      Parameters:
      condition - the TriggerActivatingCondition to remove
    • addDeactivatedListener

      public void addDeactivatedListener(TriggerDeactivatedListener listener)
      Adds a TriggerDeactivatedListener to this trigger.
      Parameters:
      listener - the TriggerDeactivatedListener to add
    • removeDeactivatedListener

      public void removeDeactivatedListener(TriggerDeactivatedListener listener)
      Removes a TriggerDeactivatedListener from this trigger.
      Parameters:
      listener - the TriggerDeactivatedListener to remove
    • addActivator

      public void addActivator(int mapId)
      Adds an activator by map ID.
      Parameters:
      mapId - the map ID of the activator to add
    • addActivator

      public void addActivator(IEntity activator)
      Adds an activator entity.
      Parameters:
      activator - the activator entity to add
    • addTarget

      public void addTarget(int mapId)
      Adds a target by map ID.
      Parameters:
      mapId - the map ID of the target to add
    • addTarget

      public void addTarget(IEntity target)
      Adds a target entity.
      Parameters:
      target - the target entity to add
    • getActivationType

      public Trigger.TriggerActivation getActivationType()
      Gets the activation type of this trigger.
      Returns:
      the activation type
    • getActivators

      public List<Integer> getActivators()
      Gets the list of activators.
      Returns:
      the list of activators
    • getMessage

      public String getMessage()
      Gets the message sent by this trigger upon activation.
      Returns:
      the message
    • getTargets

      public List<Integer> getTargets()
      Gets the list of targets.
      Returns:
      the list of targets
    • getCooldown

      public int getCooldown()
      Gets the cooldown time between activations.
      Returns:
      the cooldown time
    • canTrigger

      public boolean canTrigger(ICollisionEntity entity)
      Checks whether the specified entity can interact with this trigger.
      Parameters:
      entity - The entity.
      Returns:
      True if the entity can interact with the trigger; otherwise false.
    • isOneTimeTrigger

      public boolean isOneTimeTrigger()
      Checks if this trigger can only be activated once.
      Returns:
      true if this is a one-time trigger, false otherwise.
    • isActivated

      public boolean isActivated()
      Checks if this trigger is currently activated.
      Returns:
      true if the trigger is activated, false otherwise.
    • interact

      public boolean interact(IEntity sender)
      Interacts with this trigger using the specified sender entity. If the activation type is COLLISION or the sender is null, the interaction will not proceed. If the activators list is empty or contains the sender's map ID, the trigger will be activated. Otherwise, a log message will be generated indicating that the sender was not allowed to activate the trigger.
      Parameters:
      sender - the entity attempting to interact with the trigger
      Returns:
      true if the trigger was successfully activated, false otherwise
    • setMessage

      public void setMessage(String message)
      Sets the message that gets sent by this trigger upon activation.
      Parameters:
      message - the message to set
    • setHeight

      public void setHeight(double height)
      Description copied from interface: IEntity
      Sets the height of the entity.
      Specified by:
      setHeight in interface IEntity
      Overrides:
      setHeight in class CollisionEntity
      Parameters:
      height - The new height of the entity.
    • setWidth

      public void setWidth(double width)
      Description copied from interface: IEntity
      Sets the width of the entity.
      Specified by:
      setWidth in interface IEntity
      Overrides:
      setWidth in class CollisionEntity
      Parameters:
      width - The new width of the entity.
    • setSize

      public void setSize(double width, double height)
      Description copied from interface: IEntity
      Sets the size of the entity.
      Specified by:
      setSize in interface IEntity
      Overrides:
      setSize in class CollisionEntity
      Parameters:
      width - The new width of the entity.
      height - The new height of the entity.
    • setCooldown

      public void setCooldown(int cooldown)
      Sets the cooldown time between activations.
      Parameters:
      cooldown - the cooldown time to set
    • update

      public void update()
      Description copied from interface: IUpdateable
      This method is called by the game loop on all objects that are attached to the loop. It's called on every tick of the loop and the frequency can be configured using the ClientConfiguration.
      Specified by:
      update in interface IUpdateable
      See Also: