Class Event<C extends Context>

java.lang.Object
modelarium.entities.attributes.AttributeBase<C>
modelarium.entities.attributes.events.Event<C>
Type Parameters:
C - the type of context this event is given
All Implemented Interfaces:
Attribute
Direct Known Subclasses:
AgentEvent, EnvironmentEvent

public abstract sealed class Event<C extends Context> extends AttributeBase<C> permits AgentEvent, EnvironmentEvent
Abstract class for representing an attribute whose behaviour only runs when a trigger condition is met.

Each tick, an event's trigger condition is checked, its behaviour is run if the condition holds, and (if the event is logged) the trigger state is recorded. This class is extended by AgentEvent and EnvironmentEvent.

  • Method Details

    • toString

      public String toString()
      Returns the string representation of the event's triggered status.
      Overrides:
      toString in class Object
      Returns:
      the event's triggered status as a string
    • isTriggered

      public boolean isTriggered()
      Returns whether this event's trigger condition is currently met.
      Returns:
      true if the event is triggered, false otherwise
    • run

      public void run()
      Runs this event's behaviour for the current tick.
    • isTriggered

      protected abstract boolean isTriggered(C context)
      Determines whether this event's trigger condition is met. Must be implemented by subclasses.
      Parameters:
      context - the context the event can use in its trigger logic
      Returns:
      true if the event is triggered, false otherwise
    • run

      protected abstract void run(C context)
      Runs this event's behaviour. Must be implemented by subclasses.
      Parameters:
      context - the context the event can use in its behaviour
    • getAsImmutable

      public ReadOnlyEvent getAsImmutable()
      Creates and returns an immutable version of this attribute.
      Returns:
      the new ReadOnlyEvent instance