Class Player
- All Implemented Interfaces:
Serializable
,Cloneable
,Comparable<Entity>
,HasCard
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:
-
for more on what player entities are requests to do.
for a description of the difference zones (i.e. lists) of entities that each player has.
for a description of the class that stores the Entity objects in the game.
- Serialized Form
-
Field Summary
Fields inherited from class net.demilich.metastone.game.entities.Entity
attributes, effectSource, entityLocation, name, NO_OWNER, sourceCard
-
Constructor Summary
ConstructorDescriptionPlayer()
Use build from config to actually build the class.Creates a player with the hero card of the specified hero classCreates a player from the specified deck.Creates a player from the specified deck. -
Method Summary
Modifier and TypeMethodDescriptionclone()
Clones the underlying data and behaviour of this player instance.static Player
empty()
Create an empty player instance.boolean
Compares two player objects.findEntity
(int id) static Player
Creates a player for the given integer id, userId and deck.getCopy()
Clones this player.getDeck()
Retrieves the deck for this player as it is in game.Retrieves the cards the player is currently discovering.com.hiddenswitch.spellsource.rpc.Spellsource.EntityTypeMessage.EntityType
Gets the type of entity this is.Retrieves the player's graveyard.getHand()
Retrieves the player's hand.getHero()
Retrieves the hero specified inside theheroZone
field, anEntityZone
that typically holds just one hero object for the player.Retrieves the hero power zone stored inside the hero entity.Retrieves the hero zone.int
Gets the player's mana locked by the Overload mechanic.int
getMana()
Retrieves the current amount of mana the player has to spend this turn.int
The maximum amount of mana the player can currently have.Gets the minions on this player's side of the battlefield.int
getOwner()
Gets the owner of this entity, orIdFactory.UNASSIGNED
if it has no owner.Gets theQuest
entities that are in play from this player.Retrieves entities that are removed from play.Retrieves the card IDs of the secrets owned by this player.Retrieves the secrets owned by this player.Retrieves the set aside zone, or the location where cards are temporarily moved during complex interactions.For a player entity, its source card corresponds to the hero's source card.Retrieves statistics collected about this player in the current game.Retrieves the weapon zone belonging to this player's hero entity.getZone
(com.hiddenswitch.spellsource.rpc.Spellsource.ZonesMessage.Zones zone) Retrieves a zone by key.int
hashCode()
void
Sets the player's current hero.void
setId
(int id) Sets the player's ID.void
setLockedMana
(int lockedMana) Sets the amount of mana that was overloaded.void
setMana
(int mana) Sets the current mana this player has.void
setMaxMana
(int maxMana) Gives the player this many "empty mana crystals."toString()
Returns aTargetPlayer
specifier for this player.void
updateLookup
(@NotNull Entity entity) Updates the lookup table with the specified entity's IDMethods inherited from class net.demilich.metastone.game.entities.Entity
compareTo, diedOnBattlefield, evaluateDescriptions, getAttribute, getAttributes, getAttributeValue, getAttributeValue, getCardInventoryId, getCopySource, getDescription, getDescription, getDynamicDescription, getEffectSource, getEntityLocation, getGameTriggers, getId, getIndex, getMaxNumberOfAttacks, getName, getRace, getReference, getUserId, getZone, hasAttribute, hasPersistentEffects, isDestroyed, isInPlay, isRemovedPeacefully, modifyAttribute, modifyHpBonus, moveOrAddTo, moveOrAddTo, resetEntityLocations, setAttribute, setAttribute, setAttribute, setDescription, setEffectSource, setEntityLocation, setName, setOwner, setSourceCard, setUserId, transformResolved, transformResolved
-
Field Details
-
deck
-
-
Constructor Details
-
Player
public Player()Use build from config to actually build the class. -
Player
Creates a player from the specified deck.- Parameters:
deck
- The deck instance to use.
-
Player
Creates a player from the specified deck.- Parameters:
deck
- The deck instance to use.
-
Player
Creates a player with the hero card of the specified hero class- Parameters:
heroClass
-
-
-
Method Details
-
empty
Create an empty player instance.- Returns:
- A player specified with an
GameDeck.EMPTY
and aChooseLastBehaviour
.
-
forUser
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
orIdFactory.PLAYER_2
deck
- The deck to initialize the player with.- Returns:
- A new player instance with the specified settings and a
ChooseLastBehaviour
.
-
clone
Clones the underlying data and behaviour of this player instance. -
getDeck
Retrieves the deck for this player as it is in game. ThisCardZone
is mutated over time. This is distinct from aGameDeck
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 classEntity
- Returns:
- An
Spellsource.EntityTypeMessage.EntityType
-
getGraveyard
Retrieves the player's graveyard.- Returns:
- An
EntityZone
containing played cards and dead minions. - See Also:
-
for more about the graveyard.
-
getHand
Retrieves the player's hand.- Returns:
- A
CardZone
containing the player's current hand. - See Also:
-
for more about the hand.
-
getHero
Retrieves the hero specified inside theheroZone
field, anEntityZone
that typically holds just one hero object for the player.- Returns:
- A
Hero
instance. - See Also:
-
for the one-item EntityZone that this field consults for the Hero entity.
for more about the hero zone.
-
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 togetMaxMana()
minus the amount ofgetLockedMana()
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'smana
is set to this value.- Returns:
- The maximum amount of mana this player can have.
-
getMinions
Gets the minions on this player's side of the battlefield.- Returns:
- An
EntityZone
of minions.
-
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 theirsecretZone
.- Returns:
- The set of secret card IDs.
- See Also:
-
getSecrets
Retrieves the secrets owned by this player.- Returns:
- Secret entities.
-
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
Retrieves statistics collected about this player in the current game.- Returns:
- A
GameStatistics
object.
-
setHero
Sets the player's current hero. If aHero
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
-
hashCode
public int hashCode() -
equals
Compares two player objects.They are considered equal if their IDs and names match.
-
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 classEntity
- Parameters:
id
- The ID to set to, eitherIdFactory.PLAYER_1
orIdFactory.PLAYER_2
.
-
getCopy
Clones this player. -
getHeroZone
Retrieves the hero zone.- Returns:
- The zone that stores this player's hero entity.
-
getHeroPowerZone
Retrieves the hero power zone stored inside the hero entity.- Returns:
- The hero power stored by this hero.
- See Also:
-
getWeaponZone
Retrieves the weapon zone belonging to this player's hero entity.- Returns:
- A weapon zone.
- See Also:
-
getDiscoverZone
Retrieves the cards the player is currently discovering.- Returns:
- A
CardZone
of cards.
-
getRemovedFromPlay
Retrieves entities that are removed from play. Typically enchantments likeQuest
andSecret
go here, and cards created during aDiscoverSpell
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, orIdFactory.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 classEntity
- Returns:
GameContext.PLAYER_1
,GameContext.PLAYER_2
, orIdFactory.UNASSIGNED
.
-
getQuests
Gets theQuest
entities that are in play from this player.- Returns:
- An
EntityZone
.
-
getSourceCard
For a player entity, its source card corresponds to the hero's source card.- Specified by:
getSourceCard
in interfaceHasCard
- Overrides:
getSourceCard
in classEntity
- Returns:
- The
Hero
's source card, ornull
if no hero is set.
-
toTargetPlayer
Returns aTargetPlayer
specifier for this player.- Returns:
- Either
TargetPlayer.PLAYER_1
orTargetPlayer.PLAYER_2
.
-
updateLookup
Updates the lookup table with the specified entity's ID- Parameters:
entity
-
-
findEntity
-
getLookup
-
getWeapon
-