Record Class GameEndTriggeredEvent

java.lang.Object
java.lang.Record
megamek.server.scriptedEvents.GameEndTriggeredEvent
Record Components:
trigger - The trigger that decides if victory has occurred
All Implemented Interfaces:
TriggeredEvent

public record GameEndTriggeredEvent(Trigger trigger) extends Record implements TriggeredEvent
This class represents events that can be added programmatically or from MM scenarios to check for game end. When the game ends and no victory conditions are met, the game is a draw. Note: The Trigger must *not* be a one-time trigger.

Some examples for game end triggers:

To end the game after the 10th round:

game.addScriptedEvent(new GameEndTriggeredEvent(new SpecificRoundEndTrigger(10)));

To end the game after after the unit with ID 102 has been killed:

game.addScriptedEvent(new GameEndTriggeredEvent(new UnitKilledTrigger(102)));

To end the game after after the units with IDs 10 and 18 have both fled:

game.addScriptedEvent(new GameEndTriggeredEvent(new FledUnitsTrigger(null, 2, List.of(10, 18))));

Adding multiple conditions to the game is equivalent to OR-ing them. Conditions can be ANDed or NOTed as well using the AndTrigger and NotTrigger:

game.addScriptedEvent(new GameEndTriggeredEvent( new AndTrigger( new UnitKilledTrigger(2), new FledUnitsTrigger(null, 1))));

See Also:
  • Constructor Details

    • GameEndTriggeredEvent

      public GameEndTriggeredEvent(Trigger trigger)
      Creates an instance of a GameEndTriggeredEvent record class.
      Parameters:
      trigger - the value for the trigger record component
  • Method Details

    • toString

      @Nonnull public String toString()
      Returns a string representation of this record class. The representation contains the name of the class, followed by the name and value of each of the record components.
      Specified by:
      toString in class Record
      Returns:
      a string representation of this object
    • isGameEnding

      public boolean isGameEnding()
      Specified by:
      isGameEnding in interface TriggeredEvent
    • hashCode

      public final int hashCode()
      Returns a hash code value for this object. The value is derived from the hash code of each of the record components.
      Specified by:
      hashCode in class Record
      Returns:
      a hash code value for this object
    • equals

      public final boolean equals(Object o)
      Indicates whether some other object is "equal to" this one. The objects are equal if the other object is of the same class and if all the record components are equal. All components in this record class are compared with Objects::equals(Object,Object).
      Specified by:
      equals in class Record
      Parameters:
      o - the object with which to compare
      Returns:
      true if this object is the same as the o argument; false otherwise.
    • trigger

      public Trigger trigger()
      Returns the value of the trigger record component.
      Specified by:
      trigger in interface TriggeredEvent
      Returns:
      the value of the trigger record component