Class Player

All Implemented Interfaces:
Serializable, Cloneable, Comparable<Entity>, HasCard

public class Player extends Entity implements Serializable
The Player class stores almost the state that corresponds to a particular player, like a collection of EntityZone objects and select Attribute and PlayerAttribute attributes as an Entity that exists in the game.

Unusually, the Spellsource.ZonesMessage.Zones.WEAPON and Spellsource.ZonesMessage.Zones.HERO_POWER zones are located on the Hero entity retrievable by getHero().

More state is discoverable on the GameContext.getEnvironment() and GameContext.getTriggers() fields.

Player entities are the appropriate target of many effects, especially text that seems to "live on" after a card is played. For example, take the card Mark of the Future, which reads: "The next minion you play gains +2/+2 and Taunt." The Enchantment (called also a "trigger" in the card JSON format described by CardDesc) that actually gives the next minion played its buff lives on the EntityReference.FRIENDLY_PLAYER, not on the spell.

See Also:
  • Field Details

  • Constructor Details

    • Player

      public Player()
      Use build from config to actually build the class.
    • Player

      public Player(GameDeck deck)
      Creates a player from the specified deck.
      Parameters:
      deck - The deck instance to use.
    • Player

      public Player(GameDeck deck, String name)
      Creates a player from the specified deck.
      Parameters:
      deck - The deck instance to use.
    • Player

      public Player(String heroClass)
      Creates a player with the hero card of the specified hero class
      Parameters:
      heroClass -
  • Method Details

    • empty

      public static Player empty()
      Create an empty player instance.
      Returns:
      A player specified with an GameDeck.EMPTY and a ChooseLastBehaviour.
    • forUser

      public static Player forUser(String userId, int id, GameDeck deck)
      Creates a player for the given integer id, userId and deck.
      Parameters:
      userId - The networked user ID of the player.
      id - The player's ID, IdFactory.PLAYER_1 or IdFactory.PLAYER_2
      deck - The deck to initialize the player with.
      Returns:
      A new player instance with the specified settings and a ChooseLastBehaviour.
    • clone

      public Player clone()
      Clones the underlying data and behaviour of this player instance.
      Overrides:
      clone in class Entity
      Returns:
      A new clone.
    • getDeck

      public CardZone getDeck()
      Retrieves the deck for this player as it is in game. This CardZone is mutated over time. This is distinct from a GameDeck object, which is better interpreted as the base deck from which this object was initialized.
      Returns:
      The player's deck in game.
    • getEntityType

      public com.hiddenswitch.spellsource.rpc.Spellsource.EntityTypeMessage.EntityType getEntityType()
      Description copied from class: Entity
      Gets the type of entity this is. These will very nearly match up with the classes, but are primarily used for filters that e.g. draw a Spell or destroy all Secrets.
      Specified by:
      getEntityType in class Entity
      Returns:
      An Spellsource.EntityTypeMessage.EntityType
    • getGraveyard

      public EntityZone<Entity> getGraveyard()
      Retrieves the player's graveyard.
      Returns:
      An EntityZone containing played cards and dead minions.
      See Also:
      • for more about the graveyard.
    • getHand

      public CardZone getHand()
      Retrieves the player's hand.
      Returns:
      A CardZone containing the player's current hand.
      See Also:
      • for more about the hand.
    • getHero

      public Hero getHero()
      Retrieves the hero specified inside the heroZone field, an EntityZone that typically holds just one hero object for the player.
      Returns:
      A Hero instance.
      See Also:
    • getLockedMana

      public int getLockedMana()
      Gets the player's mana locked by the Overload mechanic. The locked mana is set to the amount of mana overloaded the previous turn.
      Returns:
      The amount of mana that is unusable this turn due to playing a card with Attribute.OVERLOAD last turn.
      See Also:
    • getMana

      public int getMana()
      Retrieves the current amount of mana the player has to spend this turn. This amount of mana is set to getMaxMana() minus the amount of getLockedMana() at the start of the player's turn/
      Returns:
      The amount of mana available to spend.
    • getMaxMana

      public int getMaxMana()
      The maximum amount of mana the player can currently have. At the start of the turn, the player's mana is set to this value.
      Returns:
      The maximum amount of mana this player can have.
    • getMinions

      public EntityZone<Minion> getMinions()
      Gets the minions on this player's side of the battlefield.
      Returns:
      An EntityZone of minions.
    • getSecretCardIds

      public Set<String> getSecretCardIds()
      Retrieves the card IDs of the secrets owned by this player. Used to enforce that players can only have at most one of each secret in their secretZone.
      Returns:
      The set of secret card IDs.
      See Also:
    • getSecrets

      public EntityZone<Secret> getSecrets()
      Retrieves the secrets owned by this player.
      Returns:
      Secret entities.
    • getSetAsideZone

      public EntityZone<Entity> getSetAsideZone()
      Retrieves the set aside zone, or the location where cards are temporarily moved during complex interactions.
      Returns:
      The zone.
      See Also:
      • for more about the set aside zone.
    • getStatistics

      public GameStatistics getStatistics()
      Retrieves statistics collected about this player in the current game.
      Returns:
      A GameStatistics object.
    • setHero

      public void setHero(Hero hero)
      Sets the player's current hero. If a Hero currently exists in the hero zone, it is removed.
      Parameters:
      hero - The hero entity.
      See Also:
    • setLockedMana

      public void setLockedMana(int lockedMana)
      Sets the amount of mana that was overloaded.
      Parameters:
      lockedMana - The amount of mana to lock this turn.
      See Also:
    • setMana

      public void setMana(int mana)
      Sets the current mana this player has. Usually invoked by spells that increase mana temporarily or when cards are played.
      Parameters:
      mana - The amount of mana this player should now have.
    • setMaxMana

      public void setMaxMana(int maxMana)
      Gives the player this many "empty mana crystals."
      Parameters:
      maxMana - The maximum amount of mana a player can have. Increased by one each turn.
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • equals

      public boolean equals(Object other)
      Compares two player objects.

      They are considered equal if their IDs and names match.

      Overrides:
      equals in class Object
      Parameters:
      other - The other player object.
      Returns:
      true if the other player object's ID and name matches this one's. Otherwise, false.
    • setId

      public void setId(int id)
      Sets the player's ID. Can only be called once. Sets the owner fields on the zones stored in this player object.
      Overrides:
      setId in class Entity
      Parameters:
      id - The ID to set to, either IdFactory.PLAYER_1 or IdFactory.PLAYER_2.
    • getCopy

      public Player getCopy()
      Clones this player.
      Specified by:
      getCopy in class Entity
      Returns:
      A clone.
    • getZone

      public EntityZone getZone(com.hiddenswitch.spellsource.rpc.Spellsource.ZonesMessage.Zones zone)
      Retrieves a zone by key.
      Parameters:
      zone - The key.
      Returns:
      An EntityZone for the corresponding zone. For Spellsource.ZonesMessage.Zones.PLAYER, a new zone is created on the fly containing this player entity. For Spellsource.ZonesMessage.Zones.NONE, an empty zone is returned.
    • getHeroZone

      public EntityZone<Hero> getHeroZone()
      Retrieves the hero zone.
      Returns:
      The zone that stores this player's hero entity.
    • getHeroPowerZone

      public EntityZone<Card> getHeroPowerZone()
      Retrieves the hero power zone stored inside the hero entity.
      Returns:
      The hero power stored by this hero.
      See Also:
    • getWeaponZone

      public EntityZone<Weapon> getWeaponZone()
      Retrieves the weapon zone belonging to this player's hero entity.
      Returns:
      A weapon zone.
      See Also:
    • getDiscoverZone

      public CardZone getDiscoverZone()
      Retrieves the cards the player is currently discovering.
      Returns:
      A CardZone of cards.
    • getRemovedFromPlay

      public EntityZone<Entity> getRemovedFromPlay()
      Retrieves entities that are removed from play. Typically enchantments like Quest and Secret go here, and cards created during a DiscoverSpell go here.

      Entities that are in Spellsource.ZonesMessage.Zones.REMOVED_FROM_PLAY should not be targetable, so it would be unusual to iterate through this zone.

      Returns:
      Entities removed from play.
      See Also:
    • getOwner

      public int getOwner()
      Description copied from class: Entity
      Gets the owner of this entity, or IdFactory.UNASSIGNED if it has no owner.

      Owners are mutable because the owner of an entity, especially minions, can change.

      The owner should match the Entity.getEntityLocation()'s owner. The minion's location should be changed first, then its owner.

      Overrides:
      getOwner in class Entity
      Returns:
      GameContext.PLAYER_1, GameContext.PLAYER_2, or IdFactory.UNASSIGNED.
    • getQuests

      public EntityZone<Quest> getQuests()
      Gets the Quest entities that are in play from this player.
      Returns:
      An EntityZone.
    • getSourceCard

      public Card getSourceCard()
      For a player entity, its source card corresponds to the hero's source card.
      Specified by:
      getSourceCard in interface HasCard
      Overrides:
      getSourceCard in class Entity
      Returns:
      The Hero's source card, or null if no hero is set.
    • toTargetPlayer

      public TargetPlayer toTargetPlayer()
      Returns a TargetPlayer specifier for this player.
      Returns:
      Either TargetPlayer.PLAYER_1 or TargetPlayer.PLAYER_2.
    • updateLookup

      public void updateLookup(@NotNull @NotNull Entity entity)
      Updates the lookup table with the specified entity's ID
      Parameters:
      entity -
    • findEntity

      public <T extends Entity> Optional<T> findEntity(int id)
    • getLookup

      public Map<Integer,Entity> getLookup()
    • getWeapon

      public Weapon getWeapon()