Class GameLogic

java.lang.Object
net.demilich.metastone.game.logic.GameLogic
All Implemented Interfaces:
Serializable, Cloneable, IdFactory

public class GameLogic extends Object implements Cloneable, Serializable, IdFactory
The game logic class implements the basic primitives of gameplay.

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:
  • Field Details

    • END_OF_SEQUENCE_MAX_DEPTH

      public static final int END_OF_SEQUENCE_MAX_DEPTH
      See Also:
    • PRIVATE

      public static final Set<com.hiddenswitch.spellsource.rpc.Spellsource.ZonesMessage.Zones> 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_MINIONS
      The maximum number of Minion entities that can be on a Spellsource.ZonesMessage.Zones.BATTLEFIELD.
      See Also:
    • MAX_AFTERMATHS

      public static final int MAX_AFTERMATHS
      The maximum number of aftermath enchantments that can be added to an actor.
      See Also:
    • MAX_HAND_CARDS

      public static final int MAX_HAND_CARDS
      The maximum number of Card entities that can be in a Spellsource.ZonesMessage.Zones.HAND.
      See Also:
    • MAX_HERO_HP

      public static final int MAX_HERO_HP
      The default maximum Attribute.HP a Hero can have.
      See Also:
    • STARTER_CARDS

      public static final int STARTER_CARDS
      The number of Card entities that a Player should start with at the beginning of a game.
      See Also:
    • MAX_MANA

      public static final int MAX_MANA
      The maximum amount of mana a Player can have at the start of a turn. Some effects allow a player to spend more than MAX_MANA mana in a turn, but never start with more.
      See Also:
    • MAX_SECRETS

      public static final int MAX_SECRETS
      The maximum number of Secret entities that can be in a Spellsource.ZonesMessage.Zones.SECRET.
      See Also:
    • MAX_QUESTS

      public static final int MAX_QUESTS
      The maximum number of Quest entities that can be in a Spellsource.ZonesMessage.Zones.QUEST.
      See Also:
    • DECK_SIZE

      public static final int DECK_SIZE
      The maximum number of Card entities that a Player can build a GameDeck with. Some effects, like Prince Malchezaar's text, allow the player to start a game with more than DECK_SIZE cards.
      See Also:
    • MAX_DECK_SIZE

      public static final int MAX_DECK_SIZE
      The maximum number of Card entities that can be in a Spellsource.ZonesMessage.Zones.DECK zone.
      See Also:
    • TURN_LIMIT

      public static final int TURN_LIMIT
      The 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_TIME
      The default amount of time a player has to complete a turn in seconds.
      See Also:
    • DEFAULT_MULLIGAN_TIME

      public static final int DEFAULT_MULLIGAN_TIME
      The default amount of time a player has to mulligan in seconds.
      See Also:
    • WINDFURY_ATTACKS

      public static final int WINDFURY_ATTACKS
      The number of attacks gained by Attribute.WINDFURY.
      See Also:
    • MEGA_WINDFURY_ATTACKS

      public static final int MEGA_WINDFURY_ATTACKS
      The number of attacks gained by Attribute.MEGA_WINDFURY.
      See Also:
    • MAX_PROGRAM_COUNTER

      public static final int MAX_PROGRAM_COUNTER
      Represents 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

      public static final Set<Attribute> IMMUNE_TO_SILENCE
      This Set stores each Attribute that is not cleared when an Entity is silenced.
      See Also:
    • INFINITE

      public static final int INFINITE
      See Also:
    • DEFAULT_SIGNATURE

      public static final String DEFAULT_SIGNATURE
      See Also:
    • context

      protected transient GameContext context
  • Constructor Details

    • GameLogic

      public GameLogic()
      Creates a new game logic instance whose next ID generated for an Entity.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

      public GameLogic(IdFactoryImpl idFactory, long seed)
      Create a game logic instance with the specified seed and ID factory.
      Parameters:
      idFactory -
      seed -
  • Method Details

    • isCardType

      public 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.

      Use this instead of direct comparisons to interpret a choose one card as a spell card.

      Parameters:
      thisType -
      other - The card type to compare to.
      Returns:
      true if this instance is of the cardType.
    • isRarity

      public 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.
      Parameters:
      thisRarity -
      other -
      Returns:
    • isEntityType

      public static boolean isEntityType(com.hiddenswitch.spellsource.rpc.Spellsource.EntityTypeMessage.EntityType thisEntity, com.hiddenswitch.spellsource.rpc.Spellsource.EntityTypeMessage.EntityType other)
      Returns true if thisEntity is a subset of other or other is a subset of thisEntity.
      Parameters:
      thisEntity -
      other -
      Returns:
    • 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 a spellDesc into an Aftermath if the host is in a valid zone for it or if force is true.

      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

      public boolean hasTooManyAftermaths(Entity host)
    • tryCreateCardCostModifier

      public Optional<CardCostModifier> tryCreateCardCostModifier(CardCostModifierDesc cardCostModifierDesc, Entity effectSource, Card enchantmentSource, Entity host, boolean force)
      Parameters:
      cardCostModifierDesc -
      effectSource -
      enchantmentSource -
      host -
      force -
      Returns:
    • tryCreateAura

      public Optional<Aura> tryCreateAura(Player player, AuraDesc auraDesc, Entity effectSource, Card enchantmentSource, Entity host, boolean force)
    • tryCreateEnchantment

      public Optional<Enchantment> tryCreateEnchantment(Player player, EnchantmentDesc enchantmentDesc, Entity effectSource, Card enchantmentSource, Entity host, boolean force)
    • addEnchantmentZone

      protected void addEnchantmentZone(Entity host, Enchantment enchantment)
    • tryCreateOpener

      public Optional<Opener> tryCreateOpener(Player player, OpenerDesc openerDesc, Entity effectSource, Card enchantmentSource, Entity host, boolean force)
    • modifyHpSpell

      public void modifyHpSpell(Entity source, Entity target, int hpBonus)
      Modifies the target entity's HP, firing the MaxHpIncreasedEvent and incrementing its
      Parameters:
      source -
      target -
      hpBonus -
    • addEnchantment

      public void addEnchantment(Player player, Enchantment enchantment, Entity effectSource, Entity host)
      Adds a Trigger to a specified Entity. These are typically Enchantment instances that react to game events.
      Parameters:
      player - Usually the current turn player.
      enchantment - A game event listener, like a Aura, Secret or CardCostModifier.
      effectSource -
      host - The Entity that will be pointed to by Trigger.getHostReference().
      See Also:
    • generateId

      public int generateId()
      Specified by:
      generateId in interface IdFactory
    • applyAmplify

      public int applyAmplify(Player player, int baseValue, Attribute attribute)
      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

      public void applyAttribute(Entity entity, Attribute attr)
      Gives an Entity a boolean Attribute.

      This addresses bugs with Attribute.WINDFURY and should be the place for special rules around attributes in the future.

      Parameters:
      entity - An Entity
      attr - An Attribute
    • applyAttribute

      public void applyAttribute(Entity entity, Attribute attr, Entity source)
      Gives an Entity a boolean Attribute.

      This addresses bugs with Attribute.WINDFURY and should be the place for special rules around attributes in the future.

      Parameters:
      entity - An Entity
      attr - An Attribute
      source - A source entity for the attribute application.
    • applyHeroPowerDamage

      public int applyHeroPowerDamage(Player player, int baseValue)
      Applies hero power damage increases
      Parameters:
      player - The Player to grab additional hero power damage from
      baseValue - The base damage the hero power does
      Returns:
      Increased hero power damage
    • applySpellpower

      public int applySpellpower(Player player, Entity source, int baseValue)
      Applies spell damage increases
      Parameters:
      player - The Player to grab the additional spell damage from
      source - The source Card
      baseValue - The base damage the spell does
      Returns:
      Increased spell damage
    • assignEntityIds

      protected void assignEntityIds(Iterable<? extends Entity> cardList, int ownerIndex)
      Assigns an Entity.getId() and Entity.getOwner() to each Card in a given GameDeck.
      Parameters:
      cardList - The GameDeck whose cards should have IDs and owners assigned.
      ownerIndex - The owner to assign to this CardList
    • attributeExists

      public boolean attributeExists(Attribute attr)
      Checks if any Entity in the game has the given Attribute.
      Parameters:
      attr - The attribute to look up.
      Returns:
      true if any Entity has the given attribute.
    • canPlayCard

      public boolean canPlayCard(int playerId, EntityReference entityReference)
      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

      public boolean canPlayCard(Player player, Card card)
      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

      public boolean canPlaySecret(Player player, @NotNull @NotNull Card card)
      Determines whether a player can play a Secret.

      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 whose Spellsource.ZonesMessage.Zones.SECRET zone should be inspected.
      card - The secret card being evaluated.
      Returns:
      true if the secret can be played.
    • canPlayQuest

      public boolean canPlayQuest(Player player, @NotNull @NotNull Card card)
      Determines whether a player can play a quest.

      Quests count as secrets

      Parameters:
      player -
      card -
      Returns:
    • canPlayPact

      public boolean canPlayPact(Player player, @NotNull @NotNull Card card)
      Determines whether a player can play a pact.

      Pacts count as quests

      Parameters:
      player -
      card -
      Returns:
    • canSummonMoreMinions

      public boolean canSummonMoreMinions(Player player)
      Determines whether or not a player can summon more minions.
      Parameters:
      player - The player whose Spellsource.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 - The SpellDesc of the chosen card, not the parent card that contains the choices.
      sourceReference - The source of the spell, typically the original Card.
      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 (a Map of SpellArg, Object) to figure out what the spell should do. The Desc.create() method creates an instance of the Spell class returned by spellDesc.getSpellClass(), then calls its Spell.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) whose SpellArg.CLASS would be DamageSpell, (2) whose SpellArg.FILTER would be an instance of EntityFilter with EntityFilterArg.RACE as Race.FAE, (3) whose SpellArg.VALUE would be 2 to deal 2 damage, and whose (4) SpellArg.TARGET would be EntityReference.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 the Minion if the spell is a battlecry or deathrattle; or, the Card 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 not null, the spell must have at least one Entity satisfying this target selection requirement in order for it to be cast.
      childSpell - When true, this spell is part an effect, like one of the SpellArg.SPELLS of a MetaSpell, and so it shouldn't trigger the firing of events like SpellCastedTrigger. When false, 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 - The GameAction, usually a invalid input: '{@link /*missing*/}'
      See Also:
    • handleAfterSpellCasted

      protected void handleAfterSpellCasted(int playerId, List<Entity> targets, Card sourceCard)
    • copyEnchantments

      public List<Enchantment> copyEnchantments(Player player, Entity effectSource, Entity source, Entity target)
    • 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 targeting EntityReference, 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 - When null, 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

      public void changeHero(Player player, Entity source, Hero hero)
      Changes the player's hero.

      A hero consists of the actual Hero actor, the hero's hero power Card specified on its CardDesc.getHeroPower() field, and possibly a Weapon equipped by an EquipWeaponSpell 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 new Attribute.MAX_HP and Attribute.HP, the hitpoints of the new hero are changed; otherwise, the old hitpoints are retained. An Attribute.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, the CardDesc.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

      public void changeHero(Player player, Entity source, Hero hero, boolean resolveBattlecry)
      Changes the player's hero.
      Parameters:
      player - The player whose hero to change.
      source -
      hero - The new hero the player will have
      resolveBattlecry - Whether or not the battlecry specified on the hero should be resolved.
      See Also:
    • endOfSequence

      public void endOfSequence()
      Removes entities for whom Entity.isDestroyed() is true, moving them to the Spellsource.ZonesMessage.Zones.GRAVEYARD and triggering their deathrattles with resolveAftermaths(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

      public GameLogic clone()
      Clones the game logic. The only state in this instance is its debug history and the current ID of the ID Factory.
      Overrides:
      clone in class Object
      Returns:
      A clone of this logic.
      See Also:
    • damage

      public int damage(Player player, Actor target, int baseDamage, Entity source)
      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 - When true, 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 the Actor.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 a DestroySpell, freeze effects and the card Equality) are not considered damage for game purposes and, although most damage is dealt through fight(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's DamageCausedTrigger). However, damage negated by an Actor with Attribute.DIVINE_SHIELD or Attribute.IMMUNE effects is not considered to have been successfully dealt, and thus will not trigger any on-damage triggered effects.

      A Hero with nonzero Actor.getArmor() will have any damage deducted from their armor before their hitpoints: any damage beyond the Actor'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 - When true, 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 the Actor.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 a DestroySpell, freeze effects and the card Equality) are not considered damage for game purposes and, although most damage is dealt through fight(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's DamageCausedTrigger). However, damage negated by an Actor with Attribute.DIVINE_SHIELD or Attribute.IMMUNE effects is not considered to have been successfully dealt, and thus will not trigger any on-damage triggered effects.

      A Hero with nonzero Actor.getArmor() will have any damage deducted from their armor before their hitpoints: any damage beyond the Actor'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 - When true, 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

      protected void resolveDamageEvent(Player player, Actor target, Entity source, int damageDealt, EnumSet<com.hiddenswitch.spellsource.rpc.Spellsource.DamageTypeMessage.DamageType> damageType)
    • resolveDamageEvent

      protected void resolveDamageEvent(Player player, Actor target, Entity source, int damageDealt, boolean ignoreLifesteal, EnumSet<com.hiddenswitch.spellsource.rpc.Spellsource.DamageTypeMessage.DamageType> damageType)
    • applyDamageToActor

      protected int applyDamageToActor(Actor target, int baseDamage, Player player, Entity source, boolean ignoreSpellDamage, EnumSet<com.hiddenswitch.spellsource.rpc.Spellsource.DamageTypeMessage.DamageType> damageType)
    • hitShields

      public boolean hitShields(Player player, int damage, Entity source, Actor target)
      Processes a hit against possible shields on the target Actor.

      Attribute.DIVINE_SHIELD and Attribute.DEFLECT are the two kinds of shields currently supported.

      This will have side effects for Attribute.DEFLECT.

      Parameters:
      player - the caster of this effect
      damage - the damage that would be otherwise dealt
      source - the source of the damage
      target - the target
      Returns:
      true if a shield was hit, otherwise false.
    • destroy

      public void destroy(Actor... targets)
      Destroys the given targets, triggering their aftermaths if necessary.
      Parameters:
      targets - A list of Actor targets that should be destroyed.
      See Also:
    • corpse

      public 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.
      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

      public 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).

      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

      @Nullable public @Nullable Card drawCard(int playerId, Entity source)
      Draws a card for a player from the deck to the hand.

      When a GameDeck is empty, the player's Hero 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, or null 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

      public boolean checkAndDealFatigue(Player player)
      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 - The Player whose fatigue should be checked and dealt to.
      Returns:
      true if fatigue damage was dealt.
    • dealFatigueDamage

      public void dealFatigueDamage(Player player)
      Actually deal and increment fatigue damage to the specified player.
      Parameters:
      player - The player to whom fatigue damage should be dealt.
    • drawCard

      public Card drawCard(int playerId, Card card, Entity source)
      Draws a specific card into the hand.
      Parameters:
      playerId - The player who should draw the card.
      card - The specific card to draw.
      source - The Entity that is responsible for this effect.
      Returns:
      See Also:
    • endTurn

      public void endTurn(int playerId)
      Ends the player's turn, triggering TurnEndTrigger triggers, clearing one-turn attributes and effects, and removing dead entities.
      Parameters:
      playerId - The player whose turn should be ended.
    • removePeacefully

      public void removePeacefully(Entity entity)
      Removes the specified entity peacefully. This will prevent its deathrattles from being triggered or a KillEvent from being raised.

      The entity will transition to the right zone after endOfSequence() is called.

      Parameters:
      entity - The entity to remove peacefully.
    • equipWeapon

      public void equipWeapon(int playerId, Weapon weapon, Card weaponCard, boolean resolveBattlecry)
      Equips a Weapon for a Hero. 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 - If true, the weapon's battlecry Spell should be cast. This is false if the weapon was equipped due to some other effect (typically a random weapon
    • fight

      public void fight(Player player, Actor attacker, Actor defender, PhysicalAttackAction sourceAction)
      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 its Actor.getAttack() stat to the other. Combat is the primary way for most minions to affect the game, by attacking either the enemy Hero or their Minions. 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 attacking Actor
      defender - The defending Actor
      sourceAction - The action corresponding to this fight, if one exists
      See Also:
    • gainArmor

      public void gainArmor(Player player, int armor)
      Gains armor and triggers an ArmorChangedEvent.
      Parameters:
      player - The player whose Hero should gain armor.
      armor - The amount of armor to gain.
      See Also:
    • generateCardId

      public String 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

      public int getAttributeValue(Player player, Attribute attr, int defaultValue)
      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 find
      defaultValue - The value returned if no occurrence of the attribute is found
      Returns:
      the first occurrence of the value of attribute or defaultValue
    • getChooseOneAuraOverrides

      public ChooseOneOverride getChooseOneAuraOverrides(Player player, Card card)
      Finds ChooseOneOverrideAura auras that affect the card and indicates what choose one override is specified.
      Parameters:
      player -
      card -
      Returns:
      The override, or ChooseOneOverride.NONE if none is specified.
    • getGreatestAttributeValue

      public int getGreatestAttributeValue(Player player, Attribute attr)
      Return the greatest value of an attribute from all Actors 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 check
      attr - Which attribute to find
      Returns:
      The highest value from all sources. -1 is considered infinite.
    • getMatchResult

      public GameStatus getMatchResult(Player player, Player opponent)
      Gets the current status of a match.
      Parameters:
      player - The player whose point of view to use for the GameStatus
      opponent - The player's opponent.
      Returns:
      A GameStatus from the point of view of the given player.
    • getModifiedManaCost

      public int getModifiedManaCost(Player player, Card card)
      Gets the mana cost of a card considering any CardCostModifier 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

      public List<GameAction> getValidActions(int playerId)
      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

      public List<Entity> getValidTargets(int playerId, GameAction action)
      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

      public Player getWinner(Player player, Player opponent)
      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

      public boolean hasAttribute(Player player, Attribute attr)
      Determines whether a Player, the player's Hero or a player's Minion 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

      public boolean hasCard(Player player, Card card)
      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 the Spellsource.ZonesMessage.Zones.HAND or Spellsource.ZonesMessage.Zones.HERO_POWER zones.
    • heal

      public HealingResult heal(Player player, Actor target, int healing, Entity source)
    • 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 their Actor.getHp() by the stated amount, up to but not beyond their current Actor.getMaxHp().

      Healing comes from openers, aftermaths, spell triggers, hero powers and spell cards that cast a HealSpell. Most healing effects affect a single Actor (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 as HealingTrigger 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 - The Entity, typically a Card or Minion with opener, that is the source of the healing.
      applyHealingBonus - Whether or not to compute the effects of Attribute.HEALING_BONUS and Attribute.SPELL_HEAL_AMPLIFY_MULTIPLIER on this card.
      Returns:
      the amount of healing that was actually performed
      See Also:
    • getModifiedHealing

      public int getModifiedHealing(Player player, int healing, Entity source, boolean applyHealingBonus)
      Compute the amount of healing given a specified base healing.
      Parameters:
      player -
      healing -
      source -
      applyHealingBonus -
      Returns:
    • startGameForPlayer

      public void startGameForPlayer(Player player)
      Activates all the appropriate enchantments for a player who has mulliganned, and gives that player the player's GameStartEvent.
      Parameters:
      player - Player who just finished mulligan phase, but before turn starts
    • initializePlayerAndMoveMulliganToSetAside

      public Player initializePlayerAndMoveMulliganToSetAside(int playerId, boolean begins)
      Configures the player Player, Hero, and deck & hand Card 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

      public JoustEvent 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 higher Card.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

      public void markAsDestroyed(Actor target, Entity source)
      Marks an Actor as destroyed. Used for "Destroy" effects.

      An actor marked this way gets moved to the Spellsource.ZonesMessage.Zones.GRAVEYARD by a endOfSequence() call.

      Parameters:
      target - The Actor 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

      public void mindControl(Player player, Minion minion, Entity source)
      Mind control moves a Minion from the opponent's Spellsource.ZonesMessage.Zones.BATTLEFIELD to their own battlefield and puts it under control of the given Player.

      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 be Attribute.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 affects Attribute.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 -
    • stealCard

      public boolean stealCard(Player newOwner, Entity source, Card card, com.hiddenswitch.spellsource.rpc.Spellsource.ZonesMessage.Zones destination) throws IllegalArgumentException
      Steals the card, transferring its owner and moving its current zones. Keeps all associated Trigger objects and changes all trigger owners whose Trigger.isPersistentOwner() property is false.

      Similar to mindControl(Player, Minion, Entity) but for Card entities.

      To implement King Togwaggle, stealing to the Spellsource.ZonesMessage.Zones.SET_ASIDE_ZONE first is supported.

      Parameters:
      newOwner - The new owner's player ID.
      source - The source of the card theft (typically the card that is casting the stealing spell). Corresponds to the drawCard(int, Card, Entity) source argument.
      card - The Card to steal
      destination - The destination Spellsource.ZonesMessage.Zones. Only Spellsource.ZonesMessage.Zones.DECK, Spellsource.ZonesMessage.Zones.HAND and Spellsource.ZonesMessage.Zones.SET_ASIDE_ZONE are currently valid.
      Throws:
      IllegalArgumentException - if the destination is invalid (not Spellsource.ZonesMessage.Zones.HAND, Spellsource.ZonesMessage.Zones.DECK and Spellsource.ZonesMessage.Zones.SET_ASIDE_ZONE.
    • changeOwner

      public void changeOwner(Entity target, int newOwnerId) throws ArrayStoreException
      Changes the owner of a target. Does not move its zones.
      Parameters:
      target - The Entity 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

      public void innerChangeOwner(Entity target, int newOwnerId)
    • modifyCurrentMana

      public void modifyCurrentMana(int playerId, int mana, boolean spent)
      Modifies the current mana that the player has.

      Fires a ModifyCurrentManaEvent if the mana does not equal zero and if the mana is negative, only if spent is true.

      Parameters:
      playerId - The player whose mana should be modified.
      mana - The amount to increment or decrement the mana by.
      spent - If true, indicates the effect modifying this mana should be considered a form of spending.
    • modifyDurability

      public void modifyDurability(Weapon weapon, int durability)
      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

      public void setHpAndMaxHp(Actor actor, int value)
      Increment or decrement the Actor.getMaxHp() property of a Actor
      Parameters:
      actor - The actor
      value - The amount to increment or decrement the amount of hitpoints.
    • modifyMaxMana

      public void modifyMaxMana(Player player, int delta)
      Increment or decrement the Player.getMaxMana() property of a Player
      Parameters:
      player - The player
      delta - The amount to increment or decrement the amount of mana the player has.
    • handleMulligan

      public void handleMulligan(Player player, boolean begins, List<Card> discardedCards)
      Sets the cards that the player discarded during the mulligan phase.
      Parameters:
      player -
      begins -
      discardedCards -
    • getSecondPlayerBonusStarterCards

      protected int getSecondPlayerBonusStarterCards()
    • performGameAction

      public void performGameAction(int playerId, GameAction action)
      Performs a game action, or a selection of what to do by a player from a list of getValidActions(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's GameAction.execute(GameContext, int) overrider, and the GameAction will then call GameLogic 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

      public 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.
      Parameters:
      player - The Player who would play the card.
      card - The Card
      Returns:
      true if this card costs health, otherwise false.
    • playCard

      public void playCard(int playerId, EntityReference cardReference, EntityReference targetReference)
      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 given Attribute.BEING_PLAYED, then its effects are evaluated, then the attribute is removed.

      playCard(int, EntityReference, EntityReference) is always initiated by an action, like a PlayCardAction. 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 the Card was countered by Counter Spell (a Secret which adds a Attribute.COUNTERED attribute to the card that was raised in the CardPlayedEvent). It applies the Attribute.OVERLOAD amount to the mana the player has locked next turn. Finally, it removes the card from the player's Spellsource.ZonesMessage.Zones.HAND and puts it in the Spellsource.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

      public boolean spellsCastTwice(Player player, Card card, Entity target)
      Determines if spells should be casting twice. Allows auras to control double spell casting.
      Parameters:
      player - The player casting the spell
      card - The card that is the spell being cast
      target - The spell's target, if there is one
      Returns:
    • spellsCastThrice

      public boolean spellsCastThrice(Player player, Card card, Entity target)
      Determines if spells should be casting thrice. Allows auras to control triple spell casting.
      Parameters:
      player - The player casting the spell
      card - The card that is the spell being cast
      target - The spell's target, if there is one
      Returns:
    • playSecret

      public void playSecret(Player player, Secret secret)
      Play a secret.
      Parameters:
      player - The player initiating the play.
      secret - The secret the player wants to play.
      See Also:
    • playSecret

      public void playSecret(Player player, Secret secret, boolean fromHand)
      Plays a secret.

      Takes a Secret entity, assigns it an ID, configures its trigger listening and adds it to the player's Spellsource.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 the Card is discarded. The SecretPlayedEvent 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 - When true, a SecretPlayedEvent is fired; otherwise, the event is not fired.
      See Also:
    • processTargetModifiers

      public GameAction processTargetModifiers(GameAction action)
      Modifies the target selection of the specified action and returns it. Respects TargetSelectionOverrideAura entities that affect the GameAction.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

      public <T> T getRandom(List<T> options)
      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

      public <T> T removeRandom(List<T> options)
      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

      public void receiveCard(int playerId, Card card)
      Receives a card into the player's hand.
      Parameters:
      playerId - The player receiving the card.
      card - The card to receive.
      See Also:
    • receiveCard

      public void receiveCard(int playerId, Card card, int copies)
      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

      public void receiveCard(int playerId, Card card, Entity source)
      Receives a card into the player's hand.
      Parameters:
      playerId - The player receiving the card.
      card - The card to receive.
      source - The Entity that caused the card to be received, or null if this is due to drawing a card at the beginning of a turn.
      See Also:
    • receiveCard

      public Card receiveCard(int playerId, Card card, Entity source, boolean isDrawnFromDeck)
      Receives a card into the player's hand, as though it was drawn. It moves a card from whatever current Spellsource.ZonesMessage.Zones zone it is in into the Spellsource.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, otherwise false.
      Returns:
      The card that was received (the card may have been transformed after it was received).
    • removeAttribute

      public void removeAttribute(Player player, Entity source, Entity target, Attribute attribute)
      Removes an attribute from an entity. Handles removing Attribute.WINDFURY and its impact on the number of attacks a minion can make.
      Parameters:
      player -
      source - The source of this attribute removal effect
      target - The entity to remove an attribute from.
      attribute - The attribute to remove.
    • removeCard

      public void removeCard(Card card)
      Moves a card to the Spellsource.ZonesMessage.Zones.GRAVEYARD. Removes each Enchantment 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

      public void removeActor(Actor actor, boolean peacefully)
      Removes an actor by moving it to...
      • The Spellsource.ZonesMessage.Zones.GRAVEYARD if the actor is being removed peacefully == false. Also marks it Attribute.DESTROYED.
      • The Spellsource.ZonesMessage.Zones.SET_ASIDE_ZONE if the actor is being removed peacefully == true. The caller is responsible for moving it elsewhere.

      Deathrattles are not triggered.

      Parameters:
      actor - The actor to remove.
      peacefully - If true, remove the card typically due to a ReturnTargetToHandSpell--that is, not due to a destruction of the minion. Otherwise, move the Minion to the Spellsource.ZonesMessage.Zones.SET_ASIDE_ZONE where it will be found by endOfSequence().
      See Also:
    • removeSecrets

      public void removeSecrets(Player player)
      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

      public void removeEnchantments(Entity entity)
    • removeEnchantments

      public void removeEnchantments(Entity entity, Predicate<Trigger> predicate)
    • removeEnchantments

      public void removeEnchantments(Entity entity, boolean removeAuras, boolean keepSelfCardCostModifiers, boolean removeAftermaths)
    • transferEnchantments

      protected void transferEnchantments(Entity oldEntity, Entity newEntity, Predicate<Trigger> predicate)
    • replaceCard

      public Card replaceCard(int playerId, Card oldCard, Card newCard)
      Replaces the specified old card with the specified new card. Deals with cards that have Attribute.DECK_TRIGGERS correctly.
      Parameters:
      playerId - The player whose Spellsource.ZonesMessage.Zones.DECK will be manipulated.
      oldCard - The old Card to find and replace in this deck.
      newCard - The replacement card.
    • replaceCard

      public Card replaceCard(int playerId, Card oldCard, Card newCard, boolean keepCardCostModifiers)
      Replaces the specified old card with the specified new card. Deals with cards that have Attribute.DECK_TRIGGERS correctly.
      Parameters:
      playerId - The player whose Spellsource.ZonesMessage.Zones.DECK will be manipulated.
      oldCard - The old Card to find and replace in this deck.
      newCard - The replacement card.
      keepCardCostModifiers - If true, keeps card cost modifiers hosted by the old card, setting the host to the new card.
    • resolveOpeners

      public OpenerAction[] resolveOpeners(int playerId, Actor actor)
      Resolves an Actor's opener, requesting an action from the player's Behaviour if necessary. Ends the sequence once the opener has been resolved.
      Parameters:
      playerId -
      actor -
      Returns:
    • requestAction

      public GameAction requestAction(Player player, List<GameAction> actions)
      Requests an action internally, allowing special request logic to be executed.
      Parameters:
      player - The player whose Behaviour will be queried for an action.
      actions - The possible actions.
      Returns:
      The chosen action
    • getTargetedOpenerActions

      protected List<GameAction> getTargetedOpenerActions(OpenerAction battlecry, Player player)
    • performBattlecryAction

      protected void performBattlecryAction(int playerId, Actor actor, Player player, OpenerAction openerAction)
    • resolveAftermaths

      public void resolveAftermaths(Player player, Actor actor)
      Executes the deathrattle effect written for this Actor.
      Parameters:
      player - The player that owns the actor.
      actor - The actor.
    • resolveAftermaths

      public void resolveAftermaths(Player player, Actor actor, EntityLocation previousLocation)
      Executes the deathrattle effect written on this Actor, 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

      @NotNull public @NotNull List<SpellDesc> getAftermathSpells(Actor actor)
    • getAftermaths

      @NotNull public @NotNull Stream<Aftermath> getAftermaths(Entity host)
    • 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 player
      sourceReference - A reference to the source
      deathrattles - The actual deathrattles to cast
      sourceOwner - The owner of the source
      boardPosition - 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 player
      sourceReference - A reference to the source
      deathrattles - The actual deathrattles to cast
      sourceOwner - The owner of the source
      boardPosition - The former board position of the source
      shouldAddToDeathrattlesTriggered - true if the deathrattle should be recorded in the list of triggered deathrattles
    • secretTriggered

      public void secretTriggered(Player player, Secret secret)
      This method is where the GameLogic handles the firing of a Secret. It removes the secret from play and raises a SecretRevealedEvent.
      Parameters:
      player - The player that owns the secret.
      secret - The secret that got triggered.
      See Also:
    • setContext

      public void setContext(GameContext context)
    • insertIntoDeck

      public boolean insertIntoDeck(Player player, Card card, int index)
      Inserts a card into the specified location in the player's deck. Use EntityZone.size() as the index for the top of the deck, and 0 for the bottom.
      Returns:
      true if the card was successfully inserted, false if the deck was full (size was MAX_DECK_SIZE).
    • insertIntoDeck

      public boolean insertIntoDeck(Player player, Card card, int index, boolean quiet)
      Inserts a card into the specified location in the player's deck. Use EntityZone.size() as the index for the top of the deck, and 0 for the bottom.
      Parameters:
      player -
      card -
      index -
      quiet - If true, does not fire the CardAddedToDeckEvent.
      Returns:
      true if the card was successfully inserted, false if the deck was full (size was MAX_DECK_SIZE).
    • shuffleToDeck

      public boolean shuffleToDeck(Player player, Card card, boolean extraCopy)
      Parameters:
      player - The player whose deck this card is getting shuffled into.
      card - The card to shuffle into that player's deck.
      extraCopy - If true, indicates this is an "extra copy" and should not recursively trigger certain kinds of shuffle-copying effects.
      Returns:
      See Also:
    • shuffleToDeck

      public boolean shuffleToDeck(Player player, Card card, boolean extraCopy, 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. 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 - If true, 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 a
      card - The card to shuffle into that player's deck.
      extraCopy - If true, indicates this is an "extra copy" and should not recursively trigger certain kinds of shuffle-copying effects.
      keepCardCostModifiers - If true, keeps card cost modifiers whose Enchantment.getHostReference() is the targeted card and whose CardCostModifierArg.TARGET is EntityReference.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 is true, 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 - If true, indicates this is an "extra copy" and should not recursively trigger certain kinds of shuffle-copying effects.
      keepCardCostModifiers - If true, keeps card cost modifiers whose Enchantment.getHostReference() is the targeted card and whose CardCostModifierArg.TARGET is EntityReference.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

      public boolean shuffleToDeck(Player player, Card card)
      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

      public void silence(int playerId, Actor target)
      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 by MindControlOneTurnSpell to reverse the mind control of a minion that somehow gets silenced during the turn that spell is cast.
      target - A Minion to silence.
      See Also:
      • Silence for a complete description of the silencing game rules.
    • removeBonusAttributes

      public void removeBonusAttributes(Entity target)
      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 of MAX_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's Player.getMana() to decline by Player.getLockedMana(); and temporary bonuses like Attribute.TEMPORARY_ATTACK_BONUS will be lost.

      Parameters:
      playerId - The player that is starting their turn.
    • startTurnForEntity

      protected void startTurnForEntity(Player player, Entity entity)
      Resets turn temporary fields on the specified entity and prepares it for the next turn.
      Parameters:
      player -
      entity -
    • stealthForTurns

      protected void stealthForTurns(Player player, Entity actor)
    • summon

      public boolean summon(int playerId, @NotNull @NotNull Minion minion, @NotNull @NotNull Entity source, int index, boolean resolveOpener)
      Summons a Minion.

      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 of MAX_MINIONS minions on the battlefield at any time. Once MAX_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, like MinionSummonedTrigger.

      A minion's AfterMinionSummonedTrigger and AfterMinionPlayedTrigger enchantments will fire off this minion's summoning. Its MinionSummonedTrigger, MinionPlayedTrigger, BeforeMinionSummonedTrigger and BeforeMinionPlayedTrigger 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 its Entity.getSourceCard() to find its enchantments.
      source - The Card or Entity responsible for summoning this minion. If this is a Spellsource.EntityTypeMessage.EntityType.CARD of Spellsource.CardTypeMessage.CardType.MINION and the source has the attribute Attribute.PLAYED_FROM_HAND_OR_DECK, this summoning is considered to have been a minion "played" as opposed to merely summoned.
      index - The location on the Spellsource.ZonesMessage.Zones.BATTLEFIELD to place this minion.
      resolveOpener - If true, the opener should be cast. The opener will still be cancelled if the minion is transformed between the BeforeSummonEvent and SummonEvent.
      Returns:
      true if the summoning was successful.
    • addEnchantments

      @NotNull public @NotNull List<Enchantment> addEnchantments(@NotNull @NotNull Player player, @NotNull @NotNull Entity effectSource, @NotNull @NotNull Card enchantmentSource, @NotNull @NotNull Entity host)
    • 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)
    • 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

      public boolean magnetize(int playerId, Card card, Minion targetMinion)
      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 a Minion into a new Minion.

      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 has Attribute.CHARGE it will not suffer from Attribute.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 effect
      source -
      minion - The original minion in play
      newMinion - The new minion to transform into
      enchant -
      See Also:
    • getRandom

      public XORShiftRandom getRandom()
    • setRandom

      public void setRandom(XORShiftRandom random)
    • getIdFactory

      public IdFactory getIdFactory()
    • setIdFactory

      public void setIdFactory(IdFactoryImpl idFactory)
    • 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

      public void playQuest(Player player, Quest quest)
      Plays a quest from the hand.
      Parameters:
      player -
      quest -
      See Also:
    • playQuest

      public void playQuest(Player player, Quest quest, boolean fromHand)
      Plays the specified quest. The quest goes into the Spellsource.ZonesMessage.Zones.QUEST zone and triggers using the enchantment's Enchantment.getCountUntilCast() functionality.
      Parameters:
      player - The player that triggered the quest.
      quest - The quest to put into play.
      fromHand - If true, fires a QuestPlayedEvent.
    • playPact

      public void playPact(Player player, Quest pact)
      Plays a quest from the hand.
      Parameters:
      player -
      pact -
      See Also:
    • playPact

      public void playPact(Player player, Quest pact, boolean fromHand)
      Plays the specified quest. The quest goes into the Spellsource.ZonesMessage.Zones.QUEST zone and triggers using the enchantment's Enchantment.getCountUntilCast() functionality.
      Parameters:
      player - The player that triggered the quest.
      pact - The pact to put into play.
      fromHand - If true, fires a QuestPlayedEvent.
    • questTriggered

      public void questTriggered(Player player, Quest quest)
      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 quest Enchantment living inside the Spellsource.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

      public void revealCard(Player player, Card cardToReveal)
      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

      public void discoverCard(int playerId, Card card)
      Indicates that the specified played discovered a card.
      Parameters:
      playerId -
      card -
    • getInternalId

      public int getInternalId()
    • contextReady

      public void contextReady()
      Indicates that the GameContext references in this instance is ready.
    • getSeed

      public long getSeed()
    • conditionMet

      public boolean conditionMet(int localPlayerId, @NotNull @NotNull Card card)
      Returns true 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, otherwise false.
    • 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

      public void fireNotification(Notification notification)
      Fires a notification, which has no gameplay side effects.
      Parameters:
      notification -
    • fireGameEvent

      public void fireGameEvent(GameEvent event)
      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 a DamageEvent or the GameContext.getEventTargetStack() that helps the EntityReference.EVENT_TARGET entity reference to work.

      Parameters:
      event -
    • pushHostReference

      protected void pushHostReference(GameEvent event, Trigger trigger)
    • pushEventData

      protected void pushEventData(GameEvent event)
    • processTrigger

      protected void processTrigger(GameEvent event, Trigger trigger)
    • getActiveTriggers

      public List<Trigger> getActiveTriggers(EntityReference hostReference)
      Gets the unexpired triggers (i.e. Enchantment) that are hosted by the specified reference.
      Parameters:
      hostReference -
      Returns:
    • expire

      public void expire(Trigger trigger)
      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