Class GameLogic
- All Implemented Interfaces:
Serializable
,Cloneable
,IdFactory
This class processes all the changes to a game state (a variety of fields in a GameContext
between requests
for player actions. It does not make player action requests itself (the GameContext
is responsible for
that).
Most functions will accept a GameContext
as an argument and mutate it. You can use GameContext.clone()
to create an "immutable" equivalent behaviour.
Most effects are encoded in Spell
classes, which subsequently call functions in this class. However, a few
key functions are called by GameAction.execute(GameContext, int)
calls directly, like summon(int, Minion, Entity, int, boolean)
and fight(Player, Actor, Actor, PhysicalAttackAction)
.
- See Also:
-
Nested Class Summary
Modifier and TypeClassDescriptionstatic final class
Keeps track of data regarding a queued trigger firing (the tuple of event and trigger that needs to be processed)static class
Stores the result of a targeting resolution. -
Field Summary
Modifier and TypeFieldDescriptionprotected GameContext
static final int
static final int
The default amount of time a player has to mulligan in seconds.static final String
static final int
The default amount of time a player has to complete a turn in seconds.static final int
static final int
protected static org.slf4j.Logger
static final int
The maximum number of aftermath enchantments that can be added to an actor.static final int
The maximum number ofCard
entities that can be in aSpellsource.ZonesMessage.Zones.DECK
zone.static final int
The maximum number ofCard
entities that can be in aSpellsource.ZonesMessage.Zones.HAND
.static final int
The default maximumAttribute.HP
aHero
can have.static final int
The maximum amount of mana aPlayer
can have at the start of a turn.static final int
The maximum number ofMinion
entities that can be on aSpellsource.ZonesMessage.Zones.BATTLEFIELD
.static final int
Represents the maximum number of spells that can be evaluated by the game logic since the start of performing a game action.static final int
The maximum number ofQuest
entities that can be in aSpellsource.ZonesMessage.Zones.QUEST
.static final int
The maximum number ofSecret
entities that can be in aSpellsource.ZonesMessage.Zones.SECRET
.static final int
The number of attacks gained byAttribute.MEGA_WINDFURY
.static final Set<com.hiddenswitch.spellsource.rpc.Spellsource.ZonesMessage.Zones>
These zones are private: only the player that owns the entity in the zone ought to see notifications originating from that zone.static final int
static final int
The maximum number of turns until a game is forced into a draw.static final com.hiddenswitch.spellsource.rpc.Spellsource.ZonesMessage.Zones[]
static final int
The number of attacks gained byAttribute.WINDFURY
.Fields inherited from interface net.demilich.metastone.game.targeting.IdFactory
PLAYER_1, PLAYER_2, UNASSIGNED
-
Constructor Summary
ConstructorDescriptionCreates a new game logic instance whose next ID generated for anEntity.setId(int)
argument will be zero.GameLogic
(long seed) Creates a game logic instance with the specified seed.GameLogic
(IdFactoryImpl idFactory, long seed) Create a game logic instance with the specified seed and ID factory. -
Method Summary
Modifier and TypeMethodDescription@NotNull Optional<? extends Enchantment>
addEnchantment
(@NotNull Player player, @NotNull Entity effectSource, @NotNull Card enchantmentSource, @NotNull Entity host, AbstractEnchantmentDesc<?> enchantmentDesc, boolean force) @NotNull Optional<? extends Enchantment>
addEnchantment
(@NotNull Player player, @NotNull Entity effectSource, @NotNull Card enchantmentSource, @NotNull Entity host, AbstractEnchantmentDesc<?> enchantmentDesc, boolean copyToActor, boolean force) void
addEnchantment
(Player player, Enchantment enchantment, Entity effectSource, Entity host) @NotNull List<Enchantment>
addEnchantments
(@NotNull Player player, @NotNull Entity effectSource, @NotNull Card enchantmentSource, @NotNull Entity host) @NotNull List<Enchantment>
addEnchantments
(@NotNull Player player, @NotNull Entity effectSource, @NotNull Card enchantmentSource, @NotNull Entity host, boolean force) @NotNull List<Enchantment>
addEnchantments
(@NotNull Player player, @NotNull Entity effectSource, @NotNull Card enchantmentSource, @NotNull Entity host, boolean force, Predicate<? super AbstractEnchantmentDesc<?>> predicate) protected void
addEnchantmentZone
(Entity host, Enchantment enchantment) int
applyAmplify
(Player player, int baseValue, Attribute attribute) Calculates how much to amplify an attribute by.void
applyAttribute
(Entity entity, Attribute attr) void
applyAttribute
(Entity entity, Attribute attr, Entity source) protected int
applyDamageToActor
(Actor target, int baseDamage, Player player, Entity source, boolean ignoreSpellDamage, EnumSet<com.hiddenswitch.spellsource.rpc.Spellsource.DamageTypeMessage.DamageType> damageType) int
applyHeroPowerDamage
(Player player, int baseValue) Applies hero power damage increasesint
applySpellpower
(Player player, Entity source, int baseValue) Applies spell damage increasesprotected void
assignEntityIds
(Iterable<? extends Entity> cardList, int ownerIndex) boolean
attributeExists
(Attribute attr) boolean
canPlayCard
(int playerId, EntityReference entityReference) Determines whether the given player can play the given card.boolean
canPlayCard
(Player player, Card card) Determines whether the given player can play the given card.boolean
canPlayPact
(Player player, @NotNull Card card) Determines whether a player can play a pact.boolean
canPlayQuest
(Player player, @NotNull Card card) Determines whether a player can play a quest.boolean
canPlaySecret
(Player player, @NotNull Card card) Determines whether a player can play aSecret
.boolean
canSummonMoreMinions
(Player player) Determines whether or not a player can summon more minions.void
castChooseOneSpell
(int playerId, SpellDesc spellDesc, EntityReference sourceReference, EntityReference targetReference, String cardId, GameAction sourceAction) Casts one of the two options of a "Choose One" spell and handles all its sophisticated rules.void
castSpell
(int playerId, @NotNull SpellDesc spellDesc, EntityReference sourceReference, EntityReference targetReference, @NotNull TargetSelection targetSelection, boolean childSpell, @Nullable GameAction sourceAction) Casts a spell.void
changeHero
(Player player, Entity source, Hero hero) Changes the player's hero.void
changeHero
(Player player, Entity source, Hero hero, boolean resolveBattlecry) Changes the player's hero.void
changeOwner
(Entity target, int newOwnerId) Changes the owner of a target.boolean
checkAndDealFatigue
(Player player) Checks if the player's deck is empty.clone()
Clones the game logic.void
concede
(int playerId) Concedes the game for the specified player.boolean
conditionMet
(int localPlayerId, @NotNull Card card) Returnstrue
if any the card's conditions are met.void
Indicates that theGameContext
references in this instance is ready.copyEnchantments
(Player player, Entity effectSource, Entity source, Entity target) copyEnchantments
(Player player, Entity effectSource, Entity source, Entity target, Predicate<Enchantment> predicate) copyEnchantments
(Player player, Entity effectSource, Entity source, Entity target, Predicate<Enchantment> predicate, boolean includeExpired) void
corpse
(Actor target, EntityLocation actorPreviousLocation, boolean removeEnchantments) Corpses a target, setting it to be destroyed on the appropriate turn, firing a kill event, and clearing the environment variables associated with the kill event.int
Deals damage to a target.int
Deals damage to a target.int
damage
(Player player, Actor target, int baseDamage, Entity source, boolean ignoreSpellDamage, boolean ignoreLifesteal, EnumSet<com.hiddenswitch.spellsource.rpc.Spellsource.DamageTypeMessage.DamageType> damageType) Deals damage to a target.int
damage
(Player player, Actor target, int baseDamage, Entity source, boolean ignoreSpellDamage, EnumSet<com.hiddenswitch.spellsource.rpc.Spellsource.DamageTypeMessage.DamageType> damageType) Deals damage to a target.void
dealFatigueDamage
(Player player) Actually deal and increment fatigue damage to the specified player.void
Destroys the given targets, triggering their aftermaths if necessary.int
determineBeginner
(int... playerIds) Determines who is the first player of a list of player IDs.void
discardCard
(Player player, Card card) Discards a card from your hand, either through discard card effects or "overdraw" (forced destruction of cards due to too many cards in your hand).void
discoverCard
(int playerId, Card card) Indicates that the specified played discovered a card.void
dispose()
boolean
doesCardCostHealth
(Player player, Card card) Determines whether the specified card, from this player's point of view, costs health, due to various effects on the board.Draws a specific card into the hand.@Nullable Card
Draws a card for a player from the deck to the hand.void
Removes entities for whomEntity.isDestroyed()
is true, moving them to theSpellsource.ZonesMessage.Zones.GRAVEYARD
and triggering their deathrattles withresolveAftermaths(Player, Actor)
.void
endTurn
(int playerId) Ends the player's turn, triggeringTurnEndTrigger
triggers, clearing one-turn attributes and effects, and removing dead entities.void
equipWeapon
(int playerId, Weapon weapon, Card weaponCard, boolean resolveBattlecry) void
Expires a trigger.void
Expires all triggers in the game, to prevent end-of-game triggering from causing the game to glitch outvoid
fight
(Player player, Actor attacker, Actor defender, PhysicalAttackAction sourceAction) Causes two actors to fight.void
fireGameEvent
(GameEvent event) The core implementation of firing game events.static void
fireMissileEvent
(GameContext context, Player player, Entity source, List<Entity> targets, EnumSet<com.hiddenswitch.spellsource.rpc.Spellsource.DamageTypeMessage.DamageType> damageType) Fires a missile event if the criteria are met.void
fireNotification
(Notification notification) Fires a notification, which has no gameplay side effects.void
Gains armor and triggers anArmorChangedEvent
.Generates a card ID for creating cards on the fly inside the game.int
getActiveTriggers
(EntityReference hostReference) Gets the unexpired triggers (i.e.getAftermaths
(Entity host) getAftermathSpells
(Actor actor) getAnotherRandomTarget
(Player player, Actor attacker, Actor originalTarget, EntityReference potentialTargets) Gets a random target from a list of potential targets.int
getAttributeValue
(Player player, Attribute attr, int defaultValue) Returns the first value of the attribute encountered.getChooseOneAuraOverrides
(Player player, Card card) FindsChooseOneOverrideAura
auras that affect thecard
and indicates what choose one override is specified.int
getGreatestAttributeValue
(Player player, Attribute attr) Return the greatest value of an attribute from allActor
s of a player.int
getMatchResult
(Player player, Player opponent) Gets the current status of a match.int
getModifiedHealing
(Player player, int healing, Entity source, boolean applyHealingBonus) Compute the amount of healing given a specified base healing.int
getModifiedManaCost
(Player player, Card card) Gets the mana cost of a card considering anyCardCostModifier
objects that may apply to it.long
Get the amount of time the player has to mulligan, in milliseconds.int
Gets the player ID of the player who is going to take the next turn.<T> T
Choose a random item from a list of options.protected int
long
getSeed()
protected int
protected List<GameAction>
getTargetedOpenerActions
(OpenerAction battlecry, Player player) int
getTurnTimeMillis
(int playerId) Compute the turn time in milliseconds for the specified player.getValidActions
(int playerId) Computes all the valid actions a player can currently take.getValidTargets
(int playerId, GameAction action) Gets the list of valid targets for an action.Determines which player is the winner from the point of view of the given player.protected void
handleAfterSpellCasted
(int playerId, List<Entity> targets, Card sourceCard) void
handleMulligan
(Player player, boolean begins, List<Card> discardedCards) Sets the cards that the player discarded during the mulligan phase.boolean
hasAttribute
(Player player, Attribute attr) boolean
Checks whether a player has a card with the given card ID.boolean
hasTooManyAftermaths
(Entity host) Heals (restores hitpoints to) a target.boolean
Are hero powers disabled?boolean
hitShields
(Player player, int damage, Entity source, Actor target) Processes a hit against possible shields on thetarget
Actor
.void
Increments the number of actors that have been destroyed this sequence.initializePlayerAndMoveMulliganToSetAside
(int playerId, boolean begins) Configures the playerPlayer
,Hero
, and deck & handCard
entities with the correct IDs,EntityZone
locations and owners.void
innerChangeOwner
(Entity target, int newOwnerId) boolean
insertIntoDeck
(Player player, Card card, int index) Inserts a card into the specified location in the player's deck.boolean
insertIntoDeck
(Player player, Card card, int index, boolean quiet) Inserts a card into the specified location in the player's deck.static boolean
isCardType
(com.hiddenswitch.spellsource.rpc.Spellsource.CardTypeMessage.CardType thisType, com.hiddenswitch.spellsource.rpc.Spellsource.CardTypeMessage.CardType other) Indicates whether or not the instance is of the specified card type.static boolean
isEntityType
(com.hiddenswitch.spellsource.rpc.Spellsource.EntityTypeMessage.EntityType thisEntity, com.hiddenswitch.spellsource.rpc.Spellsource.EntityTypeMessage.EntityType other) Returnstrue
ifthisEntity
is a subset ofother
orother
is a subset ofthisEntity
.static boolean
isRarity
(com.hiddenswitch.spellsource.rpc.Spellsource.RarityMessage.Rarity thisRarity, com.hiddenswitch.spellsource.rpc.Spellsource.RarityMessage.Rarity other) Compares two rarities, taking into account that a free and common rarity are the same from a gameplay point of view.joust
(Player player, EntityFilter cardFilter, Entity source) A joust describes when cards are revealed from each player's deck, and the "winner" of a joust is determined by whoever draws a card with a higherCard.getBaseManaCost()
.void
Destroys both player's heroes to force a drawboolean
Combines two minions together using the rules of magnetization.void
markAsDestroyed
(Actor target, Entity source) Marks anActor
as destroyed.void
mindControl
(Player player, Minion minion, Entity source) void
modifyCurrentMana
(int playerId, int mana, boolean spent) Modifies the current mana that the player has.void
modifyDurability
(Weapon weapon, int durability) Modifies the durability (hitpoints) of a weapon.void
modifyHpSpell
(Entity source, Entity target, int hpBonus) Modifies thetarget
entity's HP, firing theMaxHpIncreasedEvent
and incrementing itsvoid
modifyMaxMana
(Player player, int delta) Increment or decrement thePlayer.getMaxMana()
property of aPlayer
protected void
performBattlecryAction
(int playerId, Actor actor, Player player, OpenerAction openerAction) void
performGameAction
(int playerId, GameAction action) Performs a game action, or a selection of what to do by a player from a list ofgetValidActions(int)
.void
playCard
(int playerId, EntityReference cardReference, EntityReference targetReference) Plays a card.void
Plays a quest from the hand.void
Plays the specified quest.void
Plays a quest from the hand.void
Plays the specified quest.void
playSecret
(Player player, Secret secret) Play a secret.void
playSecret
(Player player, Secret secret, boolean fromHand) Plays a secret.processTargetModifiers
(GameAction action) Modifies the target selection of the specified action and returns it.protected void
processTrigger
(GameEvent event, Trigger trigger) protected void
pushEventData
(GameEvent event) protected void
pushHostReference
(GameEvent event, Trigger trigger) void
questTriggered
(Player player, Quest quest) Indicates that a quest was successful (its spell was casted).int
random
(int max) Gets a random number.boolean
Gets a random boolean value.void
receiveCard
(int playerId, Card card) Receives a card into the player's hand.void
receiveCard
(int playerId, Card card, int copies) Receives a card into the player's hand.void
receiveCard
(int playerId, Card card, Entity source) Receives a card into the player's hand.receiveCard
(int playerId, Card card, Entity source, boolean isDrawnFromDeck) Receives a card into the player's hand, as though it was drawn.void
removeActor
(Actor actor, boolean peacefully) Removes an actor by moving it to...void
removeAttribute
(Player player, Entity source, Entity target, Attribute attribute) Removes an attribute from an entity.void
removeBonusAttributes
(Entity target) Removes all attributes that count as bonuses (essentially baked-in enchantments)void
removeCard
(Card card) Moves a card to theSpellsource.ZonesMessage.Zones.GRAVEYARD
.void
removeEnchantments
(Entity entity) void
removeEnchantments
(Entity entity, boolean removeAuras, boolean keepSelfCardCostModifiers, boolean removeAftermaths) void
removeEnchantments
(Entity entity, Predicate<Trigger> predicate) void
removePeacefully
(Entity entity) Removes the specified entity peacefully.<T> T
removeRandom
(com.google.common.collect.Multiset<T> weightedOptions) Choose and remove a random item from a weighted list of options<T> T
removeRandom
(List<T> options) Choose and remove a random item from a list of optionsvoid
removeSecrets
(Player player) Removes all the secrets for the player.protected void
repeatedlyDestroyHero
(int playerId) Repeatedly destroys the hero for the given player ID, to account for heroes that may replace themselves with new heroes on a deathrattle.replaceCard
(int playerId, Card oldCard, Card newCard) Replaces the specified old card with the specified new card.replaceCard
(int playerId, Card oldCard, Card newCard, boolean keepCardCostModifiers) Replaces the specified old card with the specified new card.requestAction
(Player player, List<GameAction> actions) Requests an action internally, allowing special request logic to be executed.void
resolveAftermaths
(int playerId, EntityReference sourceReference, List<SpellDesc> deathrattles, int sourceOwner, int boardPosition) Casts a list of deathrattle spells given information about the entity that "hosts" those deathrattlesvoid
resolveAftermaths
(int playerId, EntityReference sourceReference, List<SpellDesc> deathrattles, int sourceOwner, int boardPosition, boolean shouldAddToDeathrattlesTriggered) Casts a list of aftermath spells given information about the entity that "hosts" those aftermathvoid
resolveAftermaths
(Player player, Actor actor) Executes the deathrattle effect written for thisActor
.void
resolveAftermaths
(Player player, Actor actor, EntityLocation previousLocation) Executes the deathrattle effect written on thisActor
, wherever it is.protected void
resolveDamageEvent
(Player player, Actor target, Entity source, int damageDealt, boolean ignoreLifesteal, EnumSet<com.hiddenswitch.spellsource.rpc.Spellsource.DamageTypeMessage.DamageType> damageType) protected void
resolveDamageEvent
(Player player, Actor target, Entity source, int damageDealt, EnumSet<com.hiddenswitch.spellsource.rpc.Spellsource.DamageTypeMessage.DamageType> damageType) resolveOpeners
(int playerId, Actor actor) resolveTarget
(Player player, Entity source, EntityReference spellTarget, SpellDesc spellDesc, GameAction sourceAction) Resolves a targetingEntityReference
, triggering a target acquisition event on the board.void
revealCard
(Player player, Card cardToReveal) Reveals a card to both players.void
secretTriggered
(Player player, Secret secret) void
setContext
(GameContext context) void
setHpAndMaxHp
(Actor actor, int value) Increment or decrement theActor.getMaxHp()
property of aActor
void
setIdFactory
(IdFactoryImpl idFactory) void
setRandom
(XORShiftRandom random) boolean
shuffleToDeck
(Player player, Card card) Shuffles the specified card into the player's deck.boolean
shuffleToDeck
(Player player, Card card, boolean extraCopy) boolean
shuffleToDeck
(Player player, Card card, boolean extraCopy, int sourcePlayerId) Implements a "Shuffle into deck" text.boolean
shuffleToDeck
(Player player, @Nullable Entity relatedEntity, @NotNull Card card, boolean extraCopy, boolean keepCardCostModifiers) boolean
shuffleToDeck
(Player player, @Nullable Entity relatedEntity, @NotNull Card card, boolean extraCopy, boolean keepCardCostModifiers, int sourcePlayerId) Implements a "Shuffle into deck" text.void
Silence is an ability which removes all current card text, enchantments, and abilities from the targeted minion.boolean
spellsCastThrice
(Player player, Card card, Entity target) Determines if spells should be casting thrice.boolean
spellsCastTwice
(Player player, Card card, Entity target) Determines if spells should be casting twice.void
startGameForPlayer
(Player player) Activates all the appropriate enchantments for a player who has mulliganned, and gives that player the player'sGameStartEvent
.void
startTurn
(int playerId) Starts a turn.protected void
startTurnForEntity
(Player player, Entity entity) Resets turn temporary fields on the specified entity and prepares it for the next turn.boolean
stealCard
(Player newOwner, Entity source, Card card, com.hiddenswitch.spellsource.rpc.Spellsource.ZonesMessage.Zones destination) Steals the card, transferring its owner and moving its current zones.protected void
stealthForTurns
(Player player, Entity actor) boolean
summon
(int playerId, @NotNull Minion minion, @NotNull Entity source, int index, boolean resolveOpener) Summons aMinion
.protected @Nullable Entity
targetAcquisition
(@NotNull Player player, @Nullable Entity source, @Nullable GameAction sourceAction) Processes an action for its appropriate target overriding effects, if any, and triggers target acquisition.protected void
transferEnchantments
(Entity oldEntity, Entity newEntity, Predicate<Trigger> predicate) void
transformMinion
(SpellDesc spellDesc, Entity source, @NotNull Minion minion, @NotNull Minion newMinion, boolean enchant) tryCreateAftermath
(SpellDesc spellDesc, Entity effectSource, Card sourceCard, Entity host, boolean force) tryCreateAura
(Player player, AuraDesc auraDesc, Entity effectSource, Card enchantmentSource, Entity host, boolean force) tryCreateCardCostModifier
(CardCostModifierDesc cardCostModifierDesc, Entity effectSource, Card enchantmentSource, Entity host, boolean force) tryCreateEnchantment
(Player player, EnchantmentDesc enchantmentDesc, Entity effectSource, Card enchantmentSource, Entity host, boolean force) tryCreateEnchantmentCard
(GameContext context, Player player, Entity effectSource, Card enchantmentSource, Entity host, boolean force) tryCreateOpener
(Player player, OpenerDesc openerDesc, Entity effectSource, Card enchantmentSource, Entity host, boolean force)
-
Field Details
-
END_OF_SEQUENCE_MAX_DEPTH
public static final int END_OF_SEQUENCE_MAX_DEPTH- See Also:
-
PRIVATE
These zones are private: only the player that owns the entity in the zone ought to see notifications originating from that zone. -
VALID_ZONES
public static final com.hiddenswitch.spellsource.rpc.Spellsource.ZonesMessage.Zones[] VALID_ZONES -
LOGGER
protected static org.slf4j.Logger LOGGER -
MAX_MINIONS
public static final int MAX_MINIONSThe maximum number ofMinion
entities that can be on aSpellsource.ZonesMessage.Zones.BATTLEFIELD
.- See Also:
-
MAX_AFTERMATHS
public static final int MAX_AFTERMATHSThe maximum number of aftermath enchantments that can be added to an actor.- See Also:
-
MAX_HAND_CARDS
public static final int MAX_HAND_CARDSThe maximum number ofCard
entities that can be in aSpellsource.ZonesMessage.Zones.HAND
.- See Also:
-
MAX_HERO_HP
public static final int MAX_HERO_HPThe default maximumAttribute.HP
aHero
can have.- See Also:
-
STARTER_CARDS
public static final int STARTER_CARDS- See Also:
-
MAX_MANA
public static final int MAX_MANAThe maximum amount of mana aPlayer
can have at the start of a turn. Some effects allow a player to spend more thanMAX_MANA
mana in a turn, but never start with more.- See Also:
-
MAX_SECRETS
public static final int MAX_SECRETSThe maximum number ofSecret
entities that can be in aSpellsource.ZonesMessage.Zones.SECRET
.- See Also:
-
MAX_QUESTS
public static final int MAX_QUESTSThe maximum number ofQuest
entities that can be in aSpellsource.ZonesMessage.Zones.QUEST
.- See Also:
-
DECK_SIZE
public static final int DECK_SIZEThe maximum number ofCard
entities that aPlayer
can build aGameDeck
with. Some effects, like Prince Malchezaar's text, allow the player to start a game with more thanDECK_SIZE
cards.- See Also:
-
MAX_DECK_SIZE
public static final int MAX_DECK_SIZEThe maximum number ofCard
entities that can be in aSpellsource.ZonesMessage.Zones.DECK
zone.- See Also:
-
TURN_LIMIT
public static final int TURN_LIMITThe maximum number of turns until a game is forced into a draw.If both heroes take measures to survive for this long, the game ends in an unconditional draw at the start of the 90th turn, even if both players are Immune.
- See Also:
-
DEFAULT_TURN_TIME
public static final int DEFAULT_TURN_TIMEThe default amount of time a player has to complete a turn in seconds.- See Also:
-
DEFAULT_MULLIGAN_TIME
public static final int DEFAULT_MULLIGAN_TIMEThe default amount of time a player has to mulligan in seconds.- See Also:
-
WINDFURY_ATTACKS
public static final int WINDFURY_ATTACKSThe number of attacks gained byAttribute.WINDFURY
. -
MEGA_WINDFURY_ATTACKS
public static final int MEGA_WINDFURY_ATTACKSThe number of attacks gained byAttribute.MEGA_WINDFURY
. -
MAX_PROGRAM_COUNTER
public static final int MAX_PROGRAM_COUNTERRepresents the maximum number of spells that can be evaluated by the game logic since the start of performing a game action.This will probably be migrated to the entire game context when it becomes possible to programmatically perform a game action.
- See Also:
-
IMMUNE_TO_SILENCE
- See Also:
-
INFINITE
public static final int INFINITE- See Also:
-
DEFAULT_SIGNATURE
- See Also:
-
context
-
-
Constructor Details
-
GameLogic
public GameLogic()Creates a new game logic instance whose next ID generated for anEntity.setId(int)
argument will be zero. -
GameLogic
public GameLogic(long seed) Creates a game logic instance with the specified seed.- Parameters:
seed
- A random seed.
-
GameLogic
Create a game logic instance with the specified seed and ID factory.- Parameters:
idFactory
-seed
-
-
-
Method Details
-
fireMissileEvent
public static void fireMissileEvent(GameContext context, Player player, Entity source, List<Entity> targets, EnumSet<com.hiddenswitch.spellsource.rpc.Spellsource.DamageTypeMessage.DamageType> damageType) Fires a missile event if the criteria are met.- Parameters:
context
-player
-source
-targets
-damageType
-
-
tryCreateAftermath
public Optional<Aftermath> tryCreateAftermath(SpellDesc spellDesc, Entity effectSource, Card sourceCard, Entity host, boolean force) Converts aspellDesc
into anAftermath
if the host is in a valid zone for it or ifforce
istrue
.Putting an
Aftermath
onto a card will make sure that minions summoned from that card will gain the aftermath.- Parameters:
spellDesc
-effectSource
-sourceCard
-host
-force
- Force creation regardless of the host's zone- Returns:
Optional.empty()
if the aftermath should not be added, otherwise
-
hasTooManyAftermaths
-
tryCreateCardCostModifier
public Optional<CardCostModifier> tryCreateCardCostModifier(CardCostModifierDesc cardCostModifierDesc, Entity effectSource, Card enchantmentSource, Entity host, boolean force) - Parameters:
cardCostModifierDesc
-effectSource
-enchantmentSource
-host
-force
-- Returns:
-
tryCreateAura
-
tryCreateEnchantment
public Optional<Enchantment> tryCreateEnchantment(Player player, EnchantmentDesc enchantmentDesc, Entity effectSource, Card enchantmentSource, Entity host, boolean force) -
addEnchantmentZone
-
tryCreateOpener
-
modifyHpSpell
Modifies thetarget
entity's HP, firing theMaxHpIncreasedEvent
and incrementing its- Parameters:
source
-target
-hpBonus
-
-
addEnchantment
public void addEnchantment(Player player, Enchantment enchantment, Entity effectSource, Entity host) Adds aTrigger
to a specifiedEntity
. These are typicallyEnchantment
instances that react to game events.- Parameters:
player
- Usually the current turn player.enchantment
- A game event listener, like aAura
,Secret
orCardCostModifier
.effectSource
-host
- TheEntity
that will be pointed to byTrigger.getHostReference()
.- See Also:
-
generateId
public int generateId()- Specified by:
generateId
in interfaceIdFactory
-
applyAmplify
Calculates how much to amplify an attribute by. This is typically either a spell damage or healing effect multiplier.This implements Prophet Velen.
- Parameters:
player
- The friendly player.baseValue
- The value to multiply.attribute
- The attribute to look up in all entities.- Returns:
- The newly calculate spell or healing value.
- See Also:
-
applyAttribute
Gives anEntity
a booleanAttribute
.This addresses bugs with
Attribute.WINDFURY
and should be the place for special rules around attributes in the future. -
applyAttribute
Gives anEntity
a booleanAttribute
.This addresses bugs with
Attribute.WINDFURY
and should be the place for special rules around attributes in the future. -
applyHeroPowerDamage
Applies hero power damage increases- Parameters:
player
- The Player to grab additional hero power damage frombaseValue
- The base damage the hero power does- Returns:
- Increased hero power damage
-
applySpellpower
Applies spell damage increases- Parameters:
player
- The Player to grab the additional spell damage fromsource
- The source CardbaseValue
- The base damage the spell does- Returns:
- Increased spell damage
-
assignEntityIds
-
attributeExists
- Parameters:
attr
- The attribute to look up.- Returns:
true
if anyEntity
has the given attribute.
-
canPlayCard
Determines whether the given player can play the given card. Useful for drawing green borders around cards to signal to an end user that they can play a particular card. Takes into account whether or not a spell that requires targets has possible targets in the game.- Parameters:
playerId
- The player whose point of view should be considered for this method.entityReference
- A reference to the card.- Returns:
true
if the card can be played.
-
canPlayCard
Determines whether the given player can play the given card. Useful for drawing green borders around cards to signal to an end user that they can play a particular card. Takes into account whether or not a spell that requires targets has possible targets in the game.- Parameters:
player
- The player whose point of view should be considered for this method.card
- The card.- Returns:
true
if the card can be played.
-
heroPowersDisabled
public boolean heroPowersDisabled()Are hero powers disabled?Disables hero powers from being able to be played and disables their passive triggers.
This implements Mindbreaker
- Returns:
true
if hero powers are disabled.
-
canPlaySecret
Determines whether a player can play aSecret
.Players cannot have more than one copy of the same Secret active at any one time. Players are unable to play Secret cards which match one of their active Secrets.
When played directly from the hand, players can have up to 5 different Secrets active at a time. Once this limit is reached, the player will be unable to play further Secret cards.
- Parameters:
player
- The player whoseSpellsource.ZonesMessage.Zones.SECRET
zone should be inspected.card
- The secret card being evaluated.- Returns:
true
if the secret can be played.
-
canPlayQuest
Determines whether a player can play a quest.Quests count as secrets
- Parameters:
player
-card
-- Returns:
-
canPlayPact
Determines whether a player can play a pact.Pacts count as quests
- Parameters:
player
-card
-- Returns:
-
canSummonMoreMinions
Determines whether or not a player can summon more minions.- Parameters:
player
- The player whoseSpellsource.ZonesMessage.Zones.BATTLEFIELD
zone should be inspected for minions.- Returns:
true
if the player can summon more minions.
-
castChooseOneSpell
public void castChooseOneSpell(int playerId, SpellDesc spellDesc, EntityReference sourceReference, EntityReference targetReference, String cardId, GameAction sourceAction) Casts one of the two options of a "Choose One" spell and handles all its sophisticated rules.Choose One is an ability which allows a player to choose one of multiple possible effects when the card is played from the hand. Cards with this ability are limited to the druid class.
Choose One effects are similar to Discover effects, and certain other cards such as Tracking, which also allow you to choose between multiple options.
- Parameters:
playerId
- The player casting the choose one spell.spellDesc
- TheSpellDesc
of the chosen card, not the parent card that contains the choices.sourceReference
- The source of the spell, typically the originalCard
.targetReference
- The target selected for this choice.cardId
- The card that was chosen.sourceAction
-
-
castSpell
public void castSpell(int playerId, @NotNull @NotNull SpellDesc spellDesc, EntityReference sourceReference, EntityReference targetReference, @NotNull @NotNull TargetSelection targetSelection, boolean childSpell, @Nullable @Nullable GameAction sourceAction) Casts a spell.This method uses the
SpellDesc
(aMap
ofSpellArg
,Object
) to figure out what the spell should do. TheDesc.create()
method creates an instance of theSpell
class returned byspellDesc.getSpellClass()
, then calls itsSpell.cast(GameContext, Player, SpellDesc, Entity, List)
method to actually execute the code of the spell.For example, imagine a spell, "Deal 2 damage to all Fae." This would have a
SpellDesc
(1) whoseSpellArg.CLASS
would beDamageSpell
, (2) whoseSpellArg.FILTER
would be an instance ofEntityFilter
withEntityFilterArg.RACE
asRace.FAE
, (3) whoseSpellArg.VALUE
would be2
to deal 2 damage, and whose (4)SpellArg.TARGET
would beEntityReference.ALL_MINIONS
.Effects can modify spells or create new ones.
SpellDesc
allows the code to modify the "code" of a spell.This method is responsible for turning the
SpellArg.CLASS
argument into a spell instance. The particular spell class is then responsible for interpreting the rest of its arguments. This code also handles the player's chosen target whenever a spell had a target selection.- Parameters:
playerId
- The players from whose point of view this spell is cast (typically the owning player).spellDesc
- A description of the spell.sourceReference
- The origin of the spell. This is typically theMinion
if the spell is a battlecry or deathrattle; or, theCard
if this spell is coming from a card.targetReference
- A reference to the target the user selected, if the spell was supposed to have a target.targetSelection
- If notnull
, the spell must have at least oneEntity
satisfying this target selection requirement in order for it to be cast.childSpell
- Whentrue
, this spell is part an effect, like one of theSpellArg.SPELLS
of aMetaSpell
, and so it shouldn't trigger the firing of events likeSpellCastedTrigger
. Whenfalse
, this spell is what a player would interpret as a spell coming from a card (a "spell" in the sense of what is written on cards). Battlecries and deathrattles are, unusually,false
(not) child spells.sourceAction
- TheGameAction
, usually a invalid input: '{@link /*missing*/}'- See Also:
-
for the code that interprets the SpellArg#FILTER, and SpellArg#RANDOM_TARGET arguments.
Spell onCast
for the function that typically has the spell-specific code.onCast
actually implements the logic of a damage spell and interprets the SpellArg#VALUE attribute of the SpellDesc as damage.for the mechanism that multiple spells as children are chained together to create an effect.
for the code that turns a target selection into actions the player can take.
for the call to this function that a player actually does when they play a Card (as opposed to a battlecry or deathrattle).
for the call to this function that demonstrates a battlecry effect. Battlecries are spells in the sense that they are effects, though they're not Card objects.
-
handleAfterSpellCasted
-
copyEnchantments
-
copyEnchantments
public List<Enchantment> copyEnchantments(Player player, Entity effectSource, Entity source, Entity target, Predicate<Enchantment> predicate) -
copyEnchantments
public List<Enchantment> copyEnchantments(Player player, Entity effectSource, Entity source, Entity target, Predicate<Enchantment> predicate, boolean includeExpired) -
tryCreateEnchantmentCard
public Optional<Enchantment> tryCreateEnchantmentCard(GameContext context, Player player, Entity effectSource, Card enchantmentSource, Entity host, boolean force) -
resolveTarget
public GameLogic.TargetResolution resolveTarget(Player player, Entity source, EntityReference spellTarget, SpellDesc spellDesc, GameAction sourceAction) Resolves a targetingEntityReference
, triggering a target acquisition event on the board.- Parameters:
player
-source
-spellTarget
-spellDesc
-sourceAction
-- Returns:
-
targetAcquisition
@Nullable protected @Nullable Entity targetAcquisition(@NotNull @NotNull Player player, @Nullable @Nullable Entity source, @Nullable @Nullable GameAction sourceAction) Processes an action for its appropriate target overriding effects, if any, and triggers target acquisition.- Parameters:
player
- The player.source
- The source entity.sourceAction
- Whennull
, no overrides can occur.- Returns:
null
if this is not an overridable form of target acquisition; or, the intended target if the target was not overridden, or the new target.
-
changeHero
Changes the player's hero.A hero consists of the actual
Hero
actor, the hero's hero powerCard
specified on itsCardDesc.getHeroPower()
field, and possibly aWeapon
equipped by anEquipWeaponSpell
specified in its battlecry. Heroes that do not resolve battlecries (i.e., heroes that are not played from the hand) generally do not equip weapons, while heroes coming into play in any way generally change the hero powers.Many attributes of the current hero are retained, like its
Attribute.NUMBER_OF_ATTACKS
. Enchantments are removed. When the hero card specifies a newAttribute.MAX_HP
andAttribute.HP
, the hitpoints of the new hero are changed; otherwise, the old hitpoints are retained. AnAttribute.ARMOR
amount is added to the previous hero's armor, not replaced.Hero powers have their
CardDesc.getPassiveTrigger()
processed, because the hero power behaves like an extension of the hand, not a zone in play. Otherwise, theCardDesc.getTrigger()
is activated when the hero comes into play.The previous hero is not moved to the graveyard, because it was not destroyed. It is moved to
Spellsource.ZonesMessage.Zones.REMOVED_FROM_PLAY
.Some "boss" heroes, like Ragnaros, should not change the hero class of the player. They use the hero class
HeroClass.INHERIT
, which will set the player and hero's class to the previous hero's class. Note that in Spellsource, changing your hero to a different class will change the results of your discovers.Implements Lord Jaraxxus and hero cards. Resolves battlecries.
- Parameters:
player
- The player whose hero to change.source
-hero
- The new hero the player will have.
-
changeHero
Changes the player's hero.- Parameters:
player
- The player whose hero to change.source
-hero
- The new hero the player will haveresolveBattlecry
- Whether or not the battlecry specified on the hero should be resolved.- See Also:
-
endOfSequence
public void endOfSequence()Removes entities for whomEntity.isDestroyed()
is true, moving them to theSpellsource.ZonesMessage.Zones.GRAVEYARD
and triggering their deathrattles withresolveAftermaths(Player, Actor)
.Since deathrattles may destroy other entities (e.g., a
DamageSpell
deathrattle), this function calls itself recursively until there are no more dead entities on the board. -
clone
Clones the game logic. The only state in this instance is its debug history and the current ID of the ID Factory. -
damage
Deals damage to a target.- Parameters:
player
- The originating player of the damage.target
- The target to damage.baseDamage
- The base amount of damage to deal.source
- The source of the damage.- Returns:
- The amount of damage ultimately dealt, considering all on board effects.
- See Also:
-
damage
public int damage(Player player, Actor target, int baseDamage, Entity source, boolean ignoreSpellDamage) Deals damage to a target.- Parameters:
player
- The originating player of the damage.target
- The target to damage.baseDamage
- The base amount of damage to deal.source
- The source of the damage.ignoreSpellDamage
- Whentrue
, spell damage bonuses are not added to the damage dealt.- Returns:
- The amount of damage ultimately dealt, considering all on board effects.
- See Also:
-
damage
public int damage(Player player, Actor target, int baseDamage, Entity source, boolean ignoreSpellDamage, EnumSet<com.hiddenswitch.spellsource.rpc.Spellsource.DamageTypeMessage.DamageType> damageType) Deals damage to a target.Damage is measured by a number which is deducted from the armor first, followed by hitpoints, of an
Actor
. If theActor.getHp()
is reduced to zero (or below), it will be killed. Note that other types of harm that can be inflicted to characters (such as aDestroySpell
, freeze effects and the card Equality) are not considered damage for game purposes and, although most damage is dealt throughfight(Player, Actor, Actor, PhysicalAttackAction)
, dealing damage is not considered an "fight" for game purposes.Damage can activate a number of triggered effects, both from receiving it (such as Acolyte of Pain's
DamageReceivedTrigger
) and from dealing it (such as Lightning Automaton'sDamageCausedTrigger
). However, damage negated by anActor
withAttribute.DIVINE_SHIELD
orAttribute.IMMUNE
effects is not considered to have been successfully dealt, and thus will not trigger any on-damage triggered effects.A
Hero
with nonzeroActor.getArmor()
will have any damage deducted from their armor before their hitpoints: any damage beyond theActor
's current Armor will be deducted from their hitpoints. Armor will not prevent damage from being dealt: damage dealt only to Armor still counts as damage for the purpose of effects such as Lightning Automaton and Floating Watcher.- Parameters:
player
- The originating player of the damage.target
- The target to damage.baseDamage
- The base amount of damage to deal.source
- The source of the damage.ignoreSpellDamage
- Whentrue
, spell damage bonuses are not added to the damage dealt.damageType
- The type of damage dealt ot the target.- Returns:
- The amount of damage that was actually dealt
-
damage
public int damage(Player player, Actor target, int baseDamage, Entity source, boolean ignoreSpellDamage, boolean ignoreLifesteal, EnumSet<com.hiddenswitch.spellsource.rpc.Spellsource.DamageTypeMessage.DamageType> damageType) Deals damage to a target.Damage is measured by a number which is deducted from the armor first, followed by hitpoints, of an
Actor
. If theActor.getHp()
is reduced to zero (or below), it will be killed. Note that other types of harm that can be inflicted to characters (such as aDestroySpell
, freeze effects and the card Equality) are not considered damage for game purposes and, although most damage is dealt throughfight(Player, Actor, Actor, PhysicalAttackAction)
, dealing damage is not considered an "fight" for game purposes.Damage can activate a number of triggered effects, both from receiving it (such as Acolyte of Pain's
DamageReceivedTrigger
) and from dealing it (such as Lightning Automaton'sDamageCausedTrigger
). However, damage negated by anActor
withAttribute.DIVINE_SHIELD
orAttribute.IMMUNE
effects is not considered to have been successfully dealt, and thus will not trigger any on-damage triggered effects.A
Hero
with nonzeroActor.getArmor()
will have any damage deducted from their armor before their hitpoints: any damage beyond theActor
's current Armor will be deducted from their hitpoints. Armor will not prevent damage from being dealt: damage dealt only to Armor still counts as damage for the purpose of effects such as Lightning Automaton and Floating Watcher.- Parameters:
player
- The originating player of the damage.target
- The target to damage.baseDamage
- The base amount of damage to deal.source
- The source of the damage.ignoreSpellDamage
- Whentrue
, spell damage bonuses are not added to the damage dealt.ignoreLifesteal
-damageType
- The type of damage dealt ot the target.- Returns:
- The amount of damage that was actually dealt
-
resolveDamageEvent
-
resolveDamageEvent
-
applyDamageToActor
-
hitShields
Processes a hit against possible shields on thetarget
Actor
.Attribute.DIVINE_SHIELD
andAttribute.DEFLECT
are the two kinds of shields currently supported.This will have side effects for
Attribute.DEFLECT
.- Parameters:
player
- the caster of this effectdamage
- the damage that would be otherwise dealtsource
- the source of the damagetarget
- the target- Returns:
true
if a shield was hit, otherwisefalse
.
-
destroy
Destroys the given targets, triggering their aftermaths if necessary.- Parameters:
targets
- A list ofActor
targets that should be destroyed.- See Also:
-
corpse
Corpses a target, setting it to be destroyed on the appropriate turn, firing a kill event, and clearing the environment variables associated with the kill event.- Parameters:
target
-actorPreviousLocation
-
-
determineBeginner
public int determineBeginner(int... playerIds) Determines who is the first player of a list of player IDs.- Parameters:
playerIds
- The possible options for first player.- Returns:
- The ID of the player that should go first.
-
discardCard
Discards a card from your hand, either through discard card effects or "overdraw" (forced destruction of cards due to too many cards in your hand).Discarded cards are removed from the game, without activating Deathrattles. Discard effects are most commonly found on warlock cards. Discard effects are distinguished from overdraw, and Fel Reaver's remove from deck effect, both of which remove cards directly from the deck without entering the hand; and from Tracking's "discard" effect, which in fact removes cards directly from a special display zone without entering the hand. While similar to discard effects, neither is considered a discard for game purposes, and will not activate related effects.
This method handles all situations and correctly triggers a
DiscardEvent
only when a card is discarded from the hand.- Parameters:
player
- The player that owns the card getting discarded.card
- The card to discard.- See Also:
-
drawCard
Draws a card for a player from the deck to the hand.When a
GameDeck
is empty, the player'sHero
takes "fatigue" damage, which increases by 1 every time a card should have been drawn but is not.- Parameters:
playerId
- The player who should draw a card.source
- The card that is the origin of the drawing effect, ornull
if this is the draw from the beginning of a turn- Returns:
- The card that was drawn, or null if the deck was empty.
- See Also:
-
checkAndDealFatigue
Checks if the player's deck is empty. If it is, increments the fatigue amount and deals fatigue damange.Fatigue is a game mechanic that deals increasing damage to players who have already drawn all of the cards in their deck, whenever they attempt to draw another card.
Fatigue deals 1 damage to the hero, plus 1 damage for each time Fatigue has already dealt damage to the player. Fatigue therefore deals damage cumulatively, steadily increasing in power each time it deals damage.
If both heroes take measures to survive for this long, the game ends in an unconditional draw at the start of the 90th turn, even if both players are Immune.
Fatigue shouldn't count as having originated from anything.
- Parameters:
player
- ThePlayer
whose fatigue should be checked and dealt to.- Returns:
true
if fatigue damage was dealt.
-
dealFatigueDamage
Actually deal and increment fatigue damage to the specified player.- Parameters:
player
- The player to whom fatigue damage should be dealt.
-
drawCard
Draws a specific card into the hand.- Parameters:
playerId
- The player who should draw the card.card
- The specific card to draw.source
- TheEntity
that is responsible for this effect.- Returns:
- See Also:
-
endTurn
public void endTurn(int playerId) Ends the player's turn, triggeringTurnEndTrigger
triggers, clearing one-turn attributes and effects, and removing dead entities.- Parameters:
playerId
- The player whose turn should be ended.
-
removePeacefully
Removes the specified entity peacefully. This will prevent its deathrattles from being triggered or aKillEvent
from being raised.The entity will transition to the right zone after
endOfSequence()
is called.- Parameters:
entity
- The entity to remove peacefully.
-
equipWeapon
Equips aWeapon
for aHero
. Destroys the previous weapon if one was equipped and triggers its deathrattle effect.- Parameters:
playerId
- The player whose hero should equip the weapon.weapon
- The weapon to equip.weaponCard
-resolveBattlecry
- Iftrue
, the weapon's battlecrySpell
should be cast. This isfalse
if the weapon was equipped due to some other effect (typically a random weapon
-
fight
Causes two actors to fight.From Gamepedia:
A fight, or an "attack," is what occurs when a player commands one character to attack another, causing them to simultaneously deal damage to each other. Combat is the source of the majority of the damage dealt in many Hearthstone matches, especially those involving a large number of minions. The core combat mechanics are quite simple, but the mathematics of multiple minions and heroes attacking each other can require deep strategic analysis. Attacking can also activate a variety of triggered effects, making even a single attack a potentially complex process. Some players use "attack" to describe any damage or negative action directed toward the enemy, but in game terminology only the standard combat action described here counts as an attack and triggers related effects. Attacking in Hearthstone is usually understood to represent physical combat, particularly melee combat, in contrast to combat via spells. "Hit" and "swing" are other informal terms for attacking, as in "hit the face" or "swing into a minion".
Each character involved in an attack deals
damage(Player, Actor, int, Entity, boolean)
equal to itsActor.getAttack()
stat to the other. Combat is the primary way for most minions to affect the game, by attacking either the enemyHero
or theirMinion
s. Minions deal their attack damage both offensively and defensively, making them potentially dangerous on both sides of combat. Heroes can be involved in combat as either an attacker or defender too, but all sources of hero attack power only apply on their own turn. Therefore, enemy minions can hit the hero without harm during the opponent's turn.- Parameters:
player
- The player who is initiating the fight.attacker
- The attackingActor
defender
- The defendingActor
sourceAction
- The action corresponding to this fight, if one exists- See Also:
-
- Attack for more on this method and its rules.
for the main caller of this function.
for an example of a spell that causes actors to fight each other without a player initiatied action.
to see how to enumerate all the possible PhysicalAttackAction that determine what can fight what.
to see how minions with Attribute#TAUNT affect what can and cannot be fought by a player.
-
gainArmor
Gains armor and triggers anArmorChangedEvent
.- Parameters:
player
- The player whoseHero
should gain armor.armor
- The amount of armor to gain.- See Also:
-
generateCardId
Generates a card ID for creating cards on the fly inside the game.- Returns:
- A new
String
that describes a new card ID.
-
getAnotherRandomTarget
public Actor getAnotherRandomTarget(Player player, Actor attacker, Actor originalTarget, EntityReference potentialTargets) Gets a random target from a list of potential targets.Implements Misdirect and cards that have a 50% chance to hit the wrong target, like Ogre Brute.
- Parameters:
player
- The player whose actor is initiating a target acquisition.attacker
- The attacker that may missed its intended target.originalTarget
- The intended target.potentialTargets
- The other targets the attacker could hit.- Returns:
- The new target.
-
getAttributeValue
Returns the first value of the attribute encountered. This method should be used with caution, as the result is random if there are different values of the same attribute in play.- Parameters:
player
- The player whose actors should be queries.attr
- Which attribute to finddefaultValue
- The value returned if no occurrence of the attribute is found- Returns:
- the first occurrence of the value of attribute or defaultValue
-
getChooseOneAuraOverrides
FindsChooseOneOverrideAura
auras that affect thecard
and indicates what choose one override is specified.- Parameters:
player
-card
-- Returns:
- The override, or
ChooseOneOverride.NONE
if none is specified.
-
getGreatestAttributeValue
Return the greatest value of an attribute from allActor
s of a player.This method will return infinite if an Attribute value is negative, so use this method with caution.
- Parameters:
player
- Which player to checkattr
- Which attribute to find- Returns:
- The highest value from all sources. -1 is considered infinite.
-
getMatchResult
Gets the current status of a match.- Parameters:
player
- The player whose point of view to use for theGameStatus
opponent
- The player's opponent.- Returns:
- A
GameStatus
from the point of view of the given player.
-
getModifiedManaCost
Gets the mana cost of a card considering anyCardCostModifier
objects that may apply to it.If the card is not in play, the deck or the hand, returns the base mana cost of the card.
- Parameters:
player
- The player whose point of view to consider for the card cost.card
- The card to cost.- Returns:
- The modified mana cost of the card.
-
getValidActions
Computes all the valid actions a player can currently take.- Parameters:
playerId
- The player whose point of view should be considered.- Returns:
- A list of valid actions the player can take. If it is not the player's turn, no actions are returned.
- See Also:
-
getValidTargets
Gets the list of valid targets for an action.This method is primarily used for cards that change regular actions into "random" actions, like
CastRandomSpellSpell
- Parameters:
playerId
- The player that would take the action.action
- The action to get valid targets for.- Returns:
- A list of valid targets
- See Also:
-
getWinner
Determines which player is the winner from the point of view of the given player.- Parameters:
player
- The local player.opponent
- The player's opponent.- Returns:
- The player that is the winner, or
null
if there is no winner.
-
hasAttribute
Determines whether aPlayer
, the player'sHero
or a player'sMinion
entities have a given attribute.- Parameters:
player
- The player whose player entity and minions will be queries for the attribute.attr
- The attribute to query.- Returns:
true
if the player entity or its minions have the given attribute.
-
hasCard
Checks whether a player has a card with the given card ID.- Parameters:
player
- The player whose hand or hero power should be queries.card
- The card whose ID should be used for comparisons.- Returns:
true
if the card is contained in theSpellsource.ZonesMessage.Zones.HAND
orSpellsource.ZonesMessage.Zones.HERO_POWER
zones.
-
heal
-
heal
public HealingResult heal(Player player, Actor target, int healing, Entity source, boolean applyHealingBonus) Heals (restores hitpoints to) a target.Healing an
Actor
will increase theirActor.getHp()
by the stated amount, up to but not beyond their currentActor.getMaxHp()
.Healing comes from openers, aftermaths, spell triggers, hero powers and spell cards that cast a
HealSpell
. Most healing effects affect a singleActor
(these effects can be targetable or select the target automatically or at random), while some others have an area of effect.Healing is distinct from granting a minion increased hitpoints, which increases both the current and maximum Health for the target. Increasing a minion's hitpoints is usually achieved through enchantments (or removing them through
SilenceSpell
), while healing is usually achieved through effects.Although healing effects (including targetable ones) can target undamaged characters, attempting to restore hitpoints to an
Actor
already at their current maximum Health will have no effect and will not count as healing for game purposes (for example, on-heal triggers such asHealingTrigger
will not trigger).Excess healing triggers
ExcessHealingTrigger
.Healing a character to full hitpoints will remove its damaged status and thus any
Attribute.ENRAGED
effect currently active.- Parameters:
player
- The player who chose the target of the healing.target
- The target of the healing.healing
- The amount of healing.source
- TheEntity
, typically aCard
orMinion
with opener, that is the source of the healing.applyHealingBonus
- Whether or not to compute the effects ofAttribute.HEALING_BONUS
andAttribute.SPELL_HEAL_AMPLIFY_MULTIPLIER
on this card.- Returns:
- the amount of healing that was actually performed
- See Also:
-
getModifiedHealing
Compute the amount of healing given a specified base healing.- Parameters:
player
-healing
-source
-applyHealingBonus
-- Returns:
-
startGameForPlayer
Activates all the appropriate enchantments for a player who has mulliganned, and gives that player the player'sGameStartEvent
.- Parameters:
player
- Player who just finished mulligan phase, but before turn starts
-
initializePlayerAndMoveMulliganToSetAside
Configures the playerPlayer
,Hero
, and deck & handCard
entities with the correct IDs,EntityZone
locations and owners. Shuffles the deck.- Parameters:
playerId
- The player that should be initialized.begins
-- Returns:
- The initialized
Player
object.
-
getStarterCards
protected int getStarterCards() -
joust
A joust describes when cards are revealed from each player's deck, and the "winner" of a joust is determined by whoever draws a card with a higherCard.getBaseManaCost()
.From Hearthpedia:
Joust is an ability that causes a minion to be revealed at random from the deck of each player. If the player who initiated the Joust has the higher mana cost minion, a special secondary effect will be activated, depending on the Joust card. Once the Joust is complete, the two Jousting minions are shuffled back into their respective decks. Jousts are triggered through other abilities, most commonly Battlecry, but at least one card uses Deathrattle to Joust. Joust does not exist as a keyword, but is the official term for the card text, "Reveal a minion in each deck. If yours costs more, [secondary effect]."
- Parameters:
player
- The player who initiated the joust.cardFilter
-source
-- Returns:
- The joust event that was fired.
-
markAsDestroyed
Marks anActor
as destroyed. Used for "Destroy" effects.An actor marked this way gets moved to the
Spellsource.ZonesMessage.Zones.GRAVEYARD
by aendOfSequence()
call.- Parameters:
target
- TheActor
to mark as destroyed.source
-
-
incrementedDestroyedThisSequenceCount
public void incrementedDestroyedThisSequenceCount()Increments the number of actors that have been destroyed this sequence.This gets cleared at the end of the sequence.
-
mindControl
Mind control moves aMinion
from the opponent'sSpellsource.ZonesMessage.Zones.BATTLEFIELD
to their own battlefield and puts it under control of the givenPlayer
.Mind control effects or control effects are effects which allow a player to seize control of an enemy minion. Controlled minions are treated as belonging to the controlling player for all purposes, can be directed to attack its former allies and owner, and will immediately be transferred to the controlling player's side of the battlefield, to the far right of the board.
Control is generally a permanent state change, and as such cannot be changed through Silences, Return effects or other means. The exceptions to this are Shadow Madness and Potion of Madness, which grant temporary control of a minion through a one-turn enchantment.
If a player activates a mind control effect when their side of the battlefield is already full (i.e. they have the maximum 7 minions), the mind controlled minion will be instantly destroyed. Any Deathrattle that activates as a result of this will trigger as if their opponent still controlled the minion. It is often a good idea for a player to choose to intentionally destroy one of their own minions in order to be able to seize control of one of their opponent's, especially by sacrificing a weak minion in order to gain control of a very powerful one.
As with summoning effects such as Mirror Image and Feral Spirit, mind controlled minions will always join the board on the far right. Anticipating this can allow for superior placement of minions, important for positional effects. When planning to summon other minions that turn, the player can use the timing of the mind control effect to allow them to determine the final placement of the mind controlled minion. For example, a player with a Shieldbearer already on the board may take control of a Flametongue Totem, before then summoning a Sludge Belcher to the right of it, thereby ensuring the Totem's is placed between the two minions, making the most of its buff.
Minions that have just been mind controlled are normally
Attribute.SUMMONING_SICKNESS
for one turn and cannot attack, just as with minions that were summoned that turn. However, Shadow Madness and Potion of Madness do not cause its target to beAttribute.SUMMONING_SICKNESS
, allowing it to attack - the effect only lasts until end of turn, and would otherwise be nearly useless. Charge affects mind control exhaustion just as it affectsAttribute.SUMMONING_SICKNESS
- minions with that ability can attack on the same turn they are mind controlled.- Parameters:
player
- The new owner of a minion.minion
- The minion to mind control.source
-
-
changeOwner
Changes the owner of a target. Does not move its zones.- Parameters:
target
- TheEntity
whose ownership should change.newOwnerId
- The player ID of the new owner.- Throws:
ArrayStoreException
- if the target is in a zone that does not match the new owner.
-
innerChangeOwner
-
modifyCurrentMana
public void modifyCurrentMana(int playerId, int mana, boolean spent) Modifies the current mana that the player has.Fires a
ModifyCurrentManaEvent
if themana
does not equal zero and if themana
is negative, only ifspent
istrue
.- Parameters:
playerId
- The player whose mana should be modified.mana
- The amount to increment or decrement the mana by.spent
- Iftrue
, indicates the effect modifying this mana should be considered a form of spending.
-
modifyDurability
Modifies the durability (hitpoints) of a weapon.- Parameters:
weapon
- The weapon to modify.durability
- The amount of durability to increment or decrement to the weapon.- See Also:
-
setHpAndMaxHp
Increment or decrement theActor.getMaxHp()
property of aActor
- Parameters:
actor
- The actorvalue
- The amount to increment or decrement the amount of hitpoints.
-
modifyMaxMana
Increment or decrement thePlayer.getMaxMana()
property of aPlayer
- Parameters:
player
- The playerdelta
- The amount to increment or decrement the amount of mana the player has.
-
handleMulligan
Sets the cards that the player discarded during the mulligan phase.- Parameters:
player
-begins
-discardedCards
-
-
getSecondPlayerBonusStarterCards
protected int getSecondPlayerBonusStarterCards() -
performGameAction
Performs a game action, or a selection of what to do by a player from a list ofgetValidActions(int)
.This method is the primary entry point to turn a player's selected
GameAction
into modified game state. Typically this method will call the action'sGameAction.execute(GameContext, int)
overrider, and theGameAction
will then callGameLogic
methods again to do its business. This is a bit of a rigamarole and should probably be changed.- Parameters:
playerId
- The player performing the game action.action
- The game action to perform.- See Also:
-
doesCardCostHealth
Determines whether the specified card, from this player's point of view, costs health, due to various effects on the board. -
playCard
Plays a card.Playing a card from the hand moves it to the graveyard before its effects are resolved. This means its enchantments are removed.
A card is marked as played (by setting its turn played as
Attribute.PLAYED_FROM_HAND_OR_DECK
before its effects are resolved. The card is givenAttribute.BEING_PLAYED
, then its effects are evaluated, then the attribute is removed.playCard(int, EntityReference, EntityReference)
is always initiated by an action, like aPlayCardAction
. It represents playing a card from the hand. This method then deducts the appropriate amount of mana (or health, depending on the card). Then, it will check if theCard
was countered by Counter Spell (aSecret
which adds aAttribute.COUNTERED
attribute to the card that was raised in theCardPlayedEvent
). It applies theAttribute.OVERLOAD
amount to the mana the player has locked next turn. Finally, it removes the card from the player'sSpellsource.ZonesMessage.Zones.HAND
and puts it in theSpellsource.ZonesMessage.Zones.GRAVEYARD
.The actual effects of the card are evaluated in
PlayCardAction.innerExecute(GameContext, int)
overloads.- Parameters:
playerId
- The player that is playing the card.cardReference
- The card that got played.targetReference
-
-
spellsCastTwice
Determines if spells should be casting twice. Allows auras to control double spell casting.- Parameters:
player
- The player casting the spellcard
- The card that is the spell being casttarget
- The spell's target, if there is one- Returns:
-
spellsCastThrice
Determines if spells should be casting thrice. Allows auras to control triple spell casting.- Parameters:
player
- The player casting the spellcard
- The card that is the spell being casttarget
- The spell's target, if there is one- Returns:
-
playSecret
Play a secret.- Parameters:
player
- The player initiating the play.secret
- The secret the player wants to play.- See Also:
-
playSecret
Plays a secret.Takes a
Secret
entity, assigns it an ID, configures its trigger listening and adds it to the player'sSpellsource.ZonesMessage.Zones.SECRET
zone.The caller is responsible for enforcing that fewer than
MAX_SECRETS
are in play; that only distinct secrets are active; and, that theCard
is discarded. TheSecretPlayedEvent
is not censored here and has sensitive information that cannot be shown to the opponent.- Parameters:
player
- The player whose gaining the secret.secret
- The secret being played.fromHand
- Whentrue
, aSecretPlayedEvent
is fired; otherwise, the event is not fired.- See Also:
-
processTargetModifiers
Modifies the target selection of the specified action and returns it. RespectsTargetSelectionOverrideAura
entities that affect theGameAction.getSourceReference()
of the provided action.- Parameters:
action
-- Returns:
-
random
public int random(int max) Gets a random number.- Parameters:
max
- Upper bound of random number (exclusive)- Returns:
- Random number between 0 and max (exclusive)
-
getRandom
Choose a random item from a list of options.- Type Parameters:
T
- Typically entities or other- Parameters:
options
- Options items- Returns:
null
if the options array was of length zero, otherwise a choice.
-
removeRandom
Choose and remove a random item from a list of options- Type Parameters:
T
- The item type- Parameters:
options
- A list of items / options to choose from- Returns:
- An item returned from the options, or
null
if there were no options.
-
removeRandom
public <T> T removeRandom(com.google.common.collect.Multiset<T> weightedOptions) Choose and remove a random item from a weighted list of options- Type Parameters:
T
- The item type- Parameters:
weightedOptions
- A map of weights to items to choose from- Returns:
- An item returned from the weighted options, or
null
if there were no options.
-
randomBool
public boolean randomBool()Gets a random boolean value.- Returns:
- A random boolean.
-
receiveCard
Receives a card into the player's hand.- Parameters:
playerId
- The player receiving the card.card
- The card to receive.- See Also:
-
receiveCard
Receives a card into the player's hand.- Parameters:
playerId
- The player receiving the card.card
- The card to receive.copies
- The number of copies of this card to receive.- See Also:
-
receiveCard
Receives a card into the player's hand.- Parameters:
playerId
- The player receiving the card.card
- The card to receive.source
- TheEntity
that caused the card to be received, ornull
if this is due to drawing a card at the beginning of a turn.- See Also:
-
receiveCard
Receives a card into the player's hand, as though it was drawn. It moves a card from whatever currentSpellsource.ZonesMessage.Zones
zone it is in into theSpellsource.ZonesMessage.Zones.HAND
zone. Implements the "Draw a card" text.A card draw effect is an effect which causes the player to draw one or more cards directly from their deck. Cards with card draw effects are sometimes called "cantrips", after similar effects in other games.
Card draw effects are distinguished from generate effects, which place new cards into your hand without removing them from your deck; and from put into hand and put into battlefield effects, which place cards of a specific type into the hand or the battlefield directly from the player's deck, rather than simply drawing the next card in the deck. A few cards have special effects which trigger based on the drawing of cards.
Attempting to draw a card when you already have 10 cards in your hand will result in the drawn card being removed from play, something referred to as "overdraw". Overdrawn cards are revealed to both players, before the card is visually destroyed.
Overdrawing is similar to discarding, but does not count as a discard for game purposes. While discard effects remove cards from the hand, overdraw removes the card directly from the deck. Overdraw also does not count as card draw for game purposes, since the game never attempts to draw the card into the hand, but rather destroys it since there is no room.
Card draw effects draw from the top of the randomly ordered deck, unlike "put into battlefield" or "put into hand" effects, resulting in an even chance of getting any card remaining in the deck. However, it is possible to gain more control over drawing using Tracking, which gives the player a choice among the top three random draws.
- Parameters:
playerId
-card
-source
-isDrawnFromDeck
-true
if the card was drawn by a deck-drawing process, otherwisefalse
.- Returns:
- The card that was received (the card may have been transformed after it was received).
-
removeAttribute
Removes an attribute from an entity. Handles removingAttribute.WINDFURY
and its impact on the number of attacks a minion can make.- Parameters:
player
-source
- The source of this attribute removal effecttarget
- The entity to remove an attribute from.attribute
- The attribute to remove.
-
removeCard
Moves a card to theSpellsource.ZonesMessage.Zones.GRAVEYARD
. Removes eachEnchantment
associated with the card, if any.No events are raised.
Also removes all attributes added to the card that did not appear on the text.
- Parameters:
card
- The card to move to the graveyard.- See Also:
-
removeActor
Removes an actor by moving it to...- The
Spellsource.ZonesMessage.Zones.GRAVEYARD
if the actor is being removedpeacefully == false
. Also marks itAttribute.DESTROYED
. - The
Spellsource.ZonesMessage.Zones.SET_ASIDE_ZONE
if the actor is being removedpeacefully == true
. The caller is responsible for moving it elsewhere.
Deathrattles are not triggered.
- Parameters:
actor
- The actor to remove.peacefully
- Iftrue
, remove the card typically due to aReturnTargetToHandSpell
--that is, not due to a destruction of the minion. Otherwise, move theMinion
to theSpellsource.ZonesMessage.Zones.SET_ASIDE_ZONE
where it will be found byendOfSequence()
.- See Also:
- The
-
removeSecrets
Removes all the secrets for the player.This implements Eater of Secrets, Flare and Visibility Machine.
- Parameters:
player
- The players whose secrets must be removed.
-
removeEnchantments
-
removeEnchantments
-
removeEnchantments
public void removeEnchantments(Entity entity, boolean removeAuras, boolean keepSelfCardCostModifiers, boolean removeAftermaths) -
transferEnchantments
-
replaceCard
Replaces the specified old card with the specified new card. Deals with cards that haveAttribute.DECK_TRIGGERS
correctly.- Parameters:
playerId
- The player whoseSpellsource.ZonesMessage.Zones.DECK
will be manipulated.oldCard
- The oldCard
to find and replace in this deck.newCard
- The replacement card.
-
replaceCard
Replaces the specified old card with the specified new card. Deals with cards that haveAttribute.DECK_TRIGGERS
correctly.- Parameters:
playerId
- The player whoseSpellsource.ZonesMessage.Zones.DECK
will be manipulated.oldCard
- The oldCard
to find and replace in this deck.newCard
- The replacement card.keepCardCostModifiers
- Iftrue
, keeps card cost modifiers hosted by the old card, setting the host to the new card.
-
resolveOpeners
Resolves anActor
's opener, requesting an action from the player'sBehaviour
if necessary. Ends the sequence once the opener has been resolved.- Parameters:
playerId
-actor
-- Returns:
-
requestAction
Requests an action internally, allowing special request logic to be executed.- Parameters:
player
- The player whoseBehaviour
will be queried for an action.actions
- The possible actions.- Returns:
- The chosen action
-
getTargetedOpenerActions
-
performBattlecryAction
protected void performBattlecryAction(int playerId, Actor actor, Player player, OpenerAction openerAction) -
resolveAftermaths
Executes the deathrattle effect written for thisActor
.- Parameters:
player
- The player that owns the actor.actor
- The actor.
-
resolveAftermaths
Executes the deathrattle effect written on thisActor
, wherever it is.- Parameters:
player
- The player that owns the actor.actor
- The actor.previousLocation
- The position on the board the actor used to have. Important for adjacency deathrattle
-
getAftermathSpells
-
getAftermaths
-
resolveAftermaths
public void resolveAftermaths(int playerId, EntityReference sourceReference, List<SpellDesc> deathrattles, int sourceOwner, int boardPosition) Casts a list of deathrattle spells given information about the entity that "hosts" those deathrattles- Parameters:
playerId
- The casting playersourceReference
- A reference to the sourcedeathrattles
- The actual deathrattles to castsourceOwner
- The owner of the sourceboardPosition
- The former board position of the source
-
resolveAftermaths
public void resolveAftermaths(int playerId, EntityReference sourceReference, List<SpellDesc> deathrattles, int sourceOwner, int boardPosition, boolean shouldAddToDeathrattlesTriggered) Casts a list of aftermath spells given information about the entity that "hosts" those aftermath- Parameters:
playerId
- The casting playersourceReference
- A reference to the sourcedeathrattles
- The actual deathrattles to castsourceOwner
- The owner of the sourceboardPosition
- The former board position of the sourceshouldAddToDeathrattlesTriggered
-true
if the deathrattle should be recorded in the list of triggered deathrattles
-
secretTriggered
This method is where theGameLogic
handles the firing of aSecret
. It removes the secret from play and raises aSecretRevealedEvent
.- Parameters:
player
- The player that owns the secret.secret
- The secret that got triggered.- See Also:
-
setContext
-
insertIntoDeck
Inserts a card into the specified location in the player's deck. UseEntityZone.size()
as the index for the top of the deck, and0
for the bottom.- Returns:
true
if the card was successfully inserted,false
if the deck was full (size wasMAX_DECK_SIZE
).
-
insertIntoDeck
Inserts a card into the specified location in the player's deck. UseEntityZone.size()
as the index for the top of the deck, and0
for the bottom.- Parameters:
player
-card
-index
-quiet
- Iftrue
, does not fire theCardAddedToDeckEvent
.- Returns:
true
if the card was successfully inserted,false
if the deck was full (size wasMAX_DECK_SIZE
).
-
shuffleToDeck
- Parameters:
player
- The player whose deck this card is getting shuffled into.card
- The card to shuffle into that player's deck.extraCopy
- Iftrue
, indicates this is an "extra copy" and should not recursively trigger certain kinds of shuffle-copying effects.- Returns:
- See Also:
-
shuffleToDeck
Implements a "Shuffle into deck" text. This will select a random location for the card to go without shuffling the deck (i.e., changing the existing order of the cards).Removes the enchantments on the card before shuffling it into the deck. This removes card cost modification enchantments.
- Parameters:
player
- The player whose deck this card is getting shuffled into.card
- The card to shuffle into that player's deck.extraCopy
- Iftrue
, indicates this is an "extra copy" and should not recursively trigger certain kinds of shuffle-copying effects.sourcePlayerId
- The caster of the spell that is executing the shuffleToDeck method.- See Also:
-
shuffleToDeck
public boolean shuffleToDeck(Player player, @Nullable @Nullable Entity relatedEntity, @NotNull @NotNull Card card, boolean extraCopy, boolean keepCardCostModifiers) - Parameters:
player
- The player whose deck this card is getting shuffled into.relatedEntity
- The entity related to the card that is getting shuffled. For example, when shuffling acard
- The card to shuffle into that player's deck.extraCopy
- Iftrue
, indicates this is an "extra copy" and should not recursively trigger certain kinds of shuffle-copying effects.keepCardCostModifiers
- Iftrue
, keeps card cost modifiers whoseEnchantment.getHostReference()
is the targeted card and whoseCardCostModifierArg.TARGET
isEntityReference.SELF
or exactly the host entity's ID (i.e., self-targeting card cost modifiers).
-
shuffleToDeck
public boolean shuffleToDeck(Player player, @Nullable @Nullable Entity relatedEntity, @NotNull @NotNull Card card, boolean extraCopy, boolean keepCardCostModifiers, int sourcePlayerId) Implements a "Shuffle into deck" text. This will select a random location for the card to go without shuffling the deck (i.e., changing the existing order of the cards).Removes the enchantments on the card before shuffling it into the deck. If
keepCardCostModifiers
istrue
, those enchantments will not be removed.- Parameters:
player
- The player whose deck this card is getting shuffled into.relatedEntity
- The entity related to the card that is getting shuffled. For example, when shuffling a minion (Actor
) to the deck, that minion should be this argument.card
- The card to shuffle into that player's deck.extraCopy
- Iftrue
, indicates this is an "extra copy" and should not recursively trigger certain kinds of shuffle-copying effects.keepCardCostModifiers
- Iftrue
, keeps card cost modifiers whoseEnchantment.getHostReference()
is the targeted card and whoseCardCostModifierArg.TARGET
isEntityReference.SELF
or exactly the host entity's ID (i.e., self-targeting card cost modifiers).sourcePlayerId
- The caster of the spell that is executing the shuffleToDeck method.- See Also:
-
shuffleToDeck
Shuffles the specified card into the player's deck.Removes all enchantments written on the card, including card cost modifying enchantments. See the overloaded methods to control this behaviour.
- Parameters:
player
-card
-- Returns:
true
if the card was successfully shuffled into the player's deck.
-
silence
Silence is an ability which removes all current card text, enchantments, and abilities from the targeted minion. It does not remove damage or minion type.- Parameters:
playerId
- The ID of the player (typically the owner of the target). This is used byMindControlOneTurnSpell
to reverse the mind control of a minion that somehow gets silenced during the turn that spell is cast.target
- AMinion
to silence.- See Also:
-
- Silence for a complete description of the silencing game rules.
-
removeBonusAttributes
Removes all attributes that count as bonuses (essentially baked-in enchantments)- Parameters:
target
- The target to remove these attributes from.
-
startTurn
public void startTurn(int playerId) Starts a turn.At the start of each of their turns, the player gains
Player.getMaxMana()
(up to a maximum ofMAX_MANA
), and attempts to draw a card. The player is then free (but not forced) to take an action by playing cards, using their Hero Power, and/or attacking with their minions or hero. Once all possible actions have been taken, the "End Turn" button will light up.All minions with
Attribute.SUMMONING_SICKNESS
will have that attribute cleared;Attribute.OVERLOAD
will cause the player'sPlayer.getMana()
to decline byPlayer.getLockedMana()
; and temporary bonuses likeAttribute.TEMPORARY_ATTACK_BONUS
will be lost.- Parameters:
playerId
- The player that is starting their turn.
-
startTurnForEntity
Resets turn temporary fields on the specified entity and prepares it for the next turn.- Parameters:
player
-entity
-
-
stealthForTurns
-
summon
public boolean summon(int playerId, @NotNull @NotNull Minion minion, @NotNull @NotNull Entity source, int index, boolean resolveOpener) Summons aMinion
.Playing a minion card places that minion onto the battlefield. This process is known as 'summoning'. Each minion has a mana cost indicated by
Card.getManaCost(GameContext, Player)
, which shows the amount of mana you must pay to summon the minion.This method returns
false
if the summon failed, typically due to a rule violation. The caller is responsible for handling a failed summon. Summons can fail because players can normally have a maximum ofMAX_MINIONS
minions on the battlefield at any time. OnceMAX_MINIONS
friendly minions are on the field, the player will not be able to summon further minions. Minion cards and summon effects such as Totemic Call will not be playable, and any minion Battlecries and Deathrattles that summon other minions will be wasted.Minions summoned by a summon effect written on a card other than a
Card
are not played directly from the hand, and therefore will not trigger Openers or Overload. However, they will work with triggered effects which respond to the summoning of minions, likeMinionSummonedTrigger
.A minion's
AfterMinionSummonedTrigger
andAfterMinionPlayedTrigger
enchantments will fire off this minion's summoning. ItsMinionSummonedTrigger
,MinionPlayedTrigger
,BeforeMinionSummonedTrigger
andBeforeMinionPlayedTrigger
enchantments will not trigger off this minion's summonining.- Parameters:
playerId
- The player who will own the minion (not the initiator of the summon, which may be the opponent).minion
- The minion to summon a minion from. Uses itsEntity.getSourceCard()
to find its enchantments.source
- TheCard
orEntity
responsible for summoning this minion. If this is aSpellsource.EntityTypeMessage.EntityType.CARD
ofSpellsource.CardTypeMessage.CardType.MINION
and the source has the attributeAttribute.PLAYED_FROM_HAND_OR_DECK
, this summoning is considered to have been a minion "played" as opposed to merely summoned.index
- The location on theSpellsource.ZonesMessage.Zones.BATTLEFIELD
to place this minion.resolveOpener
- Iftrue
, the opener should be cast. The opener will still be cancelled if the minion is transformed between theBeforeSummonEvent
andSummonEvent
.- Returns:
true
if the summoning was successful.
-
addEnchantments
-
addEnchantments
-
addEnchantments
@NotNull public @NotNull List<Enchantment> addEnchantments(@NotNull @NotNull Player player, @NotNull @NotNull Entity effectSource, @NotNull @NotNull Card enchantmentSource, @NotNull @NotNull Entity host, boolean force, Predicate<? super AbstractEnchantmentDesc<?>> predicate) -
addEnchantment
@NotNull public @NotNull Optional<? extends Enchantment> addEnchantment(@NotNull @NotNull Player player, @NotNull @NotNull Entity effectSource, @NotNull @NotNull Card enchantmentSource, @NotNull @NotNull Entity host, AbstractEnchantmentDesc<?> enchantmentDesc, boolean force) -
addEnchantment
@NotNull public @NotNull Optional<? extends Enchantment> addEnchantment(@NotNull @NotNull Player player, @NotNull @NotNull Entity effectSource, @NotNull @NotNull Card enchantmentSource, @NotNull @NotNull Entity host, AbstractEnchantmentDesc<?> enchantmentDesc, boolean copyToActor, boolean force) -
magnetize
Combines two minions together using the rules of magnetization.From Gamepedia: Magnetic is an ability exclusive to certain Mech minions which allows multiple minions to be merged together. Playing a Magnetic minion to the left of an existing Mech will automatically cause the two minions' stats and card text to be combined into a single minion.
- A Magnetic card cannot be played if the player's board is full, even to Magnetize onto another minion.[3]
- If you use a Magnetic card to upgrade a mech, that upgrade is treated as an enchantment, not as a transformation. So, for example, if the mech is silenced or returned to the hand, it loses all the effects it got from the magnetizing.
- In-hand enchantments given to Magnetic minions are considered part of the Magnetic effect when attached to another Mech. For example, Kangor's Endless Army will resurrect a Mech with both the Magnetic buff and the in-hand enchantment.
- In-hand enchantments which give Deathrattle-effects (i.e. Val'anyr) are attached to the Target Mech-Unit all the same. The Deathrattle-effect of the Unit which has been enhanced by a magnetic unit with an In-hand Deathrattle enchantment does not show up in the tooltip of that unit. The Deathrattle-Symbol under the unit does show up however and the Deathrattle-effect is excecuted upon destruction of the unit as expected.
- Parameters:
playerId
-card
-targetMinion
-- Returns:
-
transformMinion
public void transformMinion(SpellDesc spellDesc, Entity source, @NotNull @NotNull Minion minion, @NotNull @NotNull Minion newMinion, boolean enchant) Transforms aMinion
into a newMinion
.The caller is responsible for making sure the new minion is created with
Minion.getCopy()
if the minion was the result of targeting an existing minion on the battlefield.Transform is an ability which irreversibly transforms a minion into something else. This removes all card text, abilities and enchantments, and does not trigger any Deathrattles.
Transformation is not an
Aura
but rather a permanent change, which cannot be undone.silence(int, Actor)
ing the transformed minion or returning it to its owner's hand will not revert the transformation.While transform effects effectively create a new minion in place of the old one, they do not summon minions and so will not trigger effects such as Knife Juggler or Starving Buzzard. The process appears to continue the summoning process precisely, with the new minion in place of the old.
Minions produced by transformations will have
Attribute.SUMMONING_SICKNESS
, as though they had just been summoned. This is true even if the minion which was transformed was previously ready to attack. However, if the resulting minion hasAttribute.CHARGE
it will not suffer fromAttribute.SUMMONING_SICKNESS
.Minions removed from play due to being transformed are not considered to have died, and so cannot be resummoned by effects like Resurrect or Kel'Thuzad.
- Parameters:
spellDesc
- The spell responsible for this transform minion effectsource
-minion
- The original minion in playnewMinion
- The new minion to transform intoenchant
-- See Also:
-
getRandom
-
setRandom
-
getIdFactory
-
setIdFactory
-
concede
public void concede(int playerId) Concedes the game for the specified player.Concession is implemented by destroy's the player's
Hero
.- Parameters:
playerId
- The player that should concede.
-
playQuest
Plays a quest from the hand.- Parameters:
player
-quest
-- See Also:
-
playQuest
Plays the specified quest. The quest goes into theSpellsource.ZonesMessage.Zones.QUEST
zone and triggers using the enchantment'sEnchantment.getCountUntilCast()
functionality.- Parameters:
player
- The player that triggered the quest.quest
- The quest to put into play.fromHand
- Iftrue
, fires aQuestPlayedEvent
.
-
playPact
Plays a quest from the hand.- Parameters:
player
-pact
-- See Also:
-
playPact
Plays the specified quest. The quest goes into theSpellsource.ZonesMessage.Zones.QUEST
zone and triggers using the enchantment'sEnchantment.getCountUntilCast()
functionality.- Parameters:
player
- The player that triggered the quest.pact
- The pact to put into play.fromHand
- Iftrue
, fires aQuestPlayedEvent
.
-
questTriggered
Indicates that a quest was successful (its spell was casted).- Parameters:
player
- The player that triggered the quest. May be different than its owner.quest
- The questEnchantment
living inside theSpellsource.ZonesMessage.Zones.QUEST
zone.
-
getNextActivePlayerId
public int getNextActivePlayerId()Gets the player ID of the player who is going to take the next turn.Takes into account
Attribute.EXTRA_TURN
.Implements Open the Waygate.
- Returns:
- The player ID.
-
getMulliganTimeMillis
public long getMulliganTimeMillis()Get the amount of time the player has to mulligan, in milliseconds.- Returns:
- The default mulligan time for now.
-
revealCard
Reveals a card to both players.Implements Dragon's Fury.
- Parameters:
player
- The player who is revealing the card.cardToReveal
- The card that should be revealed.
-
discoverCard
Indicates that the specified played discovered a card.- Parameters:
playerId
-card
-
-
getInternalId
public int getInternalId() -
contextReady
public void contextReady()Indicates that theGameContext
references in this instance is ready. -
getSeed
public long getSeed() -
conditionMet
Returnstrue
if any the card's conditions are met.If the card does not contain any conditions, returns
false
.For cards with spells that contain multiple conditions, it's unlikely they are supposed to be interpreted as all of them are met.
- Parameters:
localPlayerId
-card
-- Returns:
true
if there are conditions and any are met, otherwisefalse
.
-
loseBothPlayers
public void loseBothPlayers()Destroys both player's heroes to force a draw -
repeatedlyDestroyHero
protected void repeatedlyDestroyHero(int playerId) Repeatedly destroys the hero for the given player ID, to account for heroes that may replace themselves with new heroes on a deathrattle.- Parameters:
playerId
- The player whose hero (and subsequent new heroes) should be destroyed
-
getTurnTimeMillis
public int getTurnTimeMillis(int playerId) Compute the turn time in milliseconds for the specified player.TODO: Consider how many turns the player has skipped.
- Returns:
- The turn time in milliseconds.
-
dispose
public void dispose() -
fireNotification
Fires a notification, which has no gameplay side effects.- Parameters:
notification
-
-
fireGameEvent
The core implementation of firing game events.This method processes an
event
, checking each trigger to see if it should respond to that particular event.This method also manages various environment stacks, like the
GameContext.getEventValueStack()
if the event has a value (like aDamageEvent
or theGameContext.getEventTargetStack()
that helps theEntityReference.EVENT_TARGET
entity reference to work.- Parameters:
event
-
-
pushHostReference
-
pushEventData
-
processTrigger
-
getActiveTriggers
Gets the unexpired triggers (i.e.Enchantment
) that are hosted by the specified reference.- Parameters:
hostReference
-- Returns:
-
expire
Expires a trigger.- Parameters:
trigger
-
-
expireAll
public void expireAll()Expires all triggers in the game, to prevent end-of-game triggering from causing the game to glitch out