Class GameState

java.lang.Object
com.hiddenswitch.spellsource.common.GameState
All Implemented Interfaces:
Serializable, Cloneable

public class GameState extends Object implements Serializable, Cloneable
The fields that correspond to a complete state of the game.

This game state is used, in practice, as a snapshot of the game in a specific point in time using GameContext.getGameStateCopy() and to copy games using GameContext.setGameState(GameState).

Creating a game state using GameContext.getGameState() produces an instance whose objects are shared with the GameContext. Mutating the player objects, for example, in such a game state will also mutate the player objects in the context. To retrieve a copy, use GameContext.getGameState() or clone() the state.

While the fields in this instance are immutable, the engine does not prevent changes to fields within the fields. This is not an immutable data type.

See Also:
  • Constructor Details

  • Method Details

    • getSerialVersionUID

      public static long getSerialVersionUID()
    • getEntities

      protected Stream<Entity> getEntities()
    • getMap

      protected Map<Integer,EntityLocation> getMap()
      Gets a map containing all the EntityLocation objects in this game state.
      Returns:
      A map.
    • to

      public com.google.common.collect.MapDifference<Integer,EntityLocation> to(GameState nextState)
      Gets a difference between this game state and the nextState in terms of entity locations.
      Parameters:
      nextState - A state in the future.
      Returns:
      The difference.
    • start

      public com.google.common.collect.MapDifference<Integer,EntityLocation> start()
      Gets a MapDifference that corresponds to this state being the first state.
      Returns:
      A Maps.difference(Map, Map) call where an empty map is the left argument and this game state is the right argument.
    • clone

      public GameState clone()
      Overrides:
      clone in class Object
    • getPlayer1

      public Player getPlayer1()
      A player object corresponding to the arbitrarily-decided first player of the game.
      See Also:
    • getPlayer2

      public Player getPlayer2()
      A player object corresponding to the arbitrarily-decided second player of the game.
      See Also:
    • getTempCards

      public CardList getTempCards()
      A CardList of cards that are temporarily created in this game.
    • getEnvironment

      public Map<Environment,Object> getEnvironment()
      Gets a reference to the game context's environment, a piece of game state that keeps tracks of which minions are currently being summoned, which targets are being targeted, how much damage is set to be dealt, etc.

      This helps implement a variety of complex rules in the game.

      See Also:
    • getCurrentId

      public int getCurrentId()
      The next ID to generate in an IdFactoryImpl/
    • getActivePlayerId

      public int getActivePlayerId()
      The currently active player.
    • getTurnState

      public TurnState getTurnState()
      The current TurnState of the game.
    • getTimestamp

      public long getTimestamp()
      The timestamp of when this GameState was accessed.
    • getTurnNumber

      public int getTurnNumber()
      The current turn number.
    • getDeckFormat

      public DeckFormat getDeckFormat()
      The deck format of this game.
    • getMillisRemaining

      public Long getMillisRemaining()
      The amount of time left in a timer, such as an end of turn or mulligan timer, until the player's actions are automatically terminated. When null, no timer is set.
    • getVariables

      public Map<String,AtomicInteger> getVariables()
      Gets the variables in the game. Spells are responsible for managing their own state here.
    • getTriggers

      public List<Trigger> getTriggers()