Class SpellUtils
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classAn object that contains results of adetermineCastingPlayer(GameContext, Player, Entity, TargetPlayer)call. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic voidcastChildSpell(GameContext context, Player player, SpellDesc spell, Entity source, Entity target) Sets up the source and target references for casting a child spell, typically an "effect" of a spell defined on a card.static voidcastChildSpell(GameContext context, Player player, SpellDesc spell, Entity source, Entity target, Entity output) Casts a subspell on a card that was returned byGameLogic.receiveCard(int, Card).determineCastingPlayer(GameContext context, Player player, Entity source, TargetPlayer castingTargetPlayer) Tries to determine the currently casting player from the point of view of a source, considering if the source has changed owners or if it was destroyed.static DiscoverActiondiscoverCard(GameContext context, Player player, Entity source, SpellDesc desc, CardList cards) Requests that the player chooses from a selection of cards and casts a spell (typicallyReceiveCardSpellwith that card.static booleanevaluateOperation(ComparisonOperation operation, int actualValue, int targetValue) Given a filterComparisonOperation, return a boolean representing whether that operation is satisfied.getAuras(GameContext context, int playerId, @NotNull Class<T> auraClass) Retrieves all of the unexpired, active auras that are instances of theauraClasshosted byEntity.isInPlay()entities belonging to theplayerIdor passive auras hosted by hero powers and cards.getAuras(GameContext context, Class<T> auraClass, Entity target) Get the auras that are affecting the specified target of the given class.static intgetBoardPosition(GameContext context, Player player, SpellDesc desc, Entity source) Interprets theSpellArg.BOARD_POSITION_ABSOLUTEorSpellArg.BOARD_POSITION_RELATIVEin adescgiven thesourceentity.static SpellDesc[]getBonusesFromAura(GameContext context, int playerId, Class<? extends Aura> auraClass, Entity source, Entity target) Retrieves an array of spells corresponding to theAuraArg.APPLY_EFFECTfield on an aura whose condition is null or fulfilled for the givensourceandtarget.static CardgetCard(GameContext context, SpellDesc spell) Gets a card out of aSpellDesc.static CardgetCardFromContextOrDiscover(GameContext context, String cardId) Retrieves a reference to a newly generated card currently in theSpellsource.ZonesMessage.Zones.DISCOVERif the givencardIdcan be found there.static CardListFilters a card list.static CardListRetrieves the cards specified in theSpellDesc, either in theSpellArg.CARDorSpellArg.CARDSproperties or as specified by aCardSourceandCardFilter.static CardListgetCards(GameContext context, Player player, Entity target, Entity source, SpellDesc desc, int count) Retrieves the cards specified in theSpellDesc, either in theSpellArg.CARDorSpellArg.CARDSproperties or as specified by aCardSourceandCardFilter.static Card[]getCards(GameContext context, SpellDesc spell) Retrieves the cards specified inside theSpellArg.CARDandSpellArg.CARDSarguments.Gets a list of special card IDs.static DiscoverActiongetSpellDiscover(GameContext context, Player player, SpellDesc desc, List<SpellDesc> spells, Entity source) Requests that the player chooses from a selection of cards, then returns just the spell from the cards.getValidTargets(GameContext context, Player player, List<Entity> allTargets, EntityFilter filter, Entity host) Filters a list of targets.static <T extends Aura>
booleanhasAura(GameContext context, int playerId, Class<T> auraClass) Determines whether any of theEntity.isInPlay()entities belonging to theplayerIdhost an unexpired, active instance of theauraClassaura.static booleanisRecursive(Class<? extends Spell> callingClass) Returnstrueif the caller is in a recursive stackstatic booleanplayCardRandomly(GameContext context, Player player, Card card, Entity source, boolean summonRightmost, boolean resolveOpener, boolean onlyWhileSourceInPlay, boolean randomChooseOnes, boolean playFromHand) Plays a card "randomly."static DiscoverActionpostDiscover(GameContext context, Player player, Iterable<? extends Card> cards, List<GameAction> discoverActions) Moves the card put into theSpellsource.ZonesMessage.Zones.DISCOVERby adiscoverCard(GameContext, Player, Entity, SpellDesc, CardList)action back to where it came from.
-
Constructor Details
-
SpellUtils
public SpellUtils()
-
-
Method Details
-
castChildSpell
public static void castChildSpell(GameContext context, Player player, SpellDesc spell, Entity source, Entity target) Sets up the source and target references for casting a child spell, typically an "effect" of a spell defined on a card.- Parameters:
context- The game context.player- The player casting the spell.spell- The child spell to cast.source- The source of the spell, typically the spell card or minion whose battlecry is being called.target- The target reference.
-
playCardRandomly
public static boolean playCardRandomly(GameContext context, Player player, Card card, Entity source, boolean summonRightmost, boolean resolveOpener, boolean onlyWhileSourceInPlay, boolean randomChooseOnes, boolean playFromHand) Plays a card "randomly."This will cause it to select random targets if, after target selection modification, it accepts targets.
- Parameters:
context-player-card-source-summonRightmost- WhentrueandCard.isActor(), summons the card in the rightmost position. Otherwise, summons it to a random position.resolveOpener- Whentrue, also resolves the battlecry with a random target. Otherwise, the battlecry is ignored.onlyWhileSourceInPlay- Whentrue,randomChooseOnes- Whentrue, randomly chooses the choose-one effects. Otherwise, checks if the card has had aAttribute.CHOICESmade.playFromHand- Whentrue, the card is counterable, mana is deducted and played card stats are incremented. Otherwise, only the effects of the card, like putting a minion into play or the underlying spell effects, are executed.- Returns:
-
evaluateOperation
public static boolean evaluateOperation(ComparisonOperation operation, int actualValue, int targetValue) Given a filterComparisonOperation, return a boolean representing whether that operation is satisfied.- Parameters:
operation- The algebraic operation.actualValue- The left hand side.targetValue- The right hand side.- Returns:
trueif the evaluation is truue.
-
getCards
Filters a card list. Does not copy source cards.- Parameters:
source- ACardListsource.filter- A function that returnstruewhen the card should be kept, ornullto include all cards.- Returns:
- A
CardListbacked by a mutable, non-copyCardArrayList.
-
getCard
Gets a card out of aSpellDesc. Typically only consults theSpellArg.CARDproperty.- Parameters:
context- The context.spell- TheSpellDesc.- Returns:
- A card.
-
getCards
Retrieves the cards specified inside theSpellArg.CARDandSpellArg.CARDSarguments.- Parameters:
context- The game context to use for orGameContext.getOutputCard()lookups.spell- The spell description to retrieve the cards from.- Returns:
- A new array of
Cardentities. - See Also:
-
getCardFromContextOrDiscover
Retrieves a reference to a newly generated card currently in theSpellsource.ZonesMessage.Zones.DISCOVERif the givencardIdcan be found there.This allows spells to be cast on cards while they are in the discover zone, even though the spells casting effects on them are supposed to be executing their effects on base cards.
- Parameters:
context-cardId-- Returns:
-
discoverCard
public static DiscoverAction discoverCard(GameContext context, Player player, Entity source, SpellDesc desc, CardList cards) Requests that the player chooses from a selection of cards and casts a spell (typicallyReceiveCardSpellwith that card.This method makes a network request if required.
- Parameters:
context- The game context that hosts the player and state for this request.player- The player that will choose from the cards.source-desc- For every card the player can discover, this method will create aSpellfrom thisSpellDescand set itsSpellArg.CARDargument to the discoverable card. Typically, thisSpellDescdefines aReceiveCardSpell,ReceiveCardAndDoSomethingSpell, or aChangeHeroPowerSpell. These spells all receive cards as arguments. This argument allows aDiscoverActionto do more sophisticated things than just put cards into hands.cards- ACardListof cards that get copied, added to theSpellsource.ZonesMessage.Zones.DISCOVERzone of the player and shown in the discover card UI to the player.- Returns:
- The
DiscoverActionthat corresponds to the card the player chose. - See Also:
-
postDiscover
public static DiscoverAction postDiscover(GameContext context, Player player, Iterable<? extends Card> cards, List<GameAction> discoverActions) Moves the card put into theSpellsource.ZonesMessage.Zones.DISCOVERby adiscoverCard(GameContext, Player, Entity, SpellDesc, CardList)action back to where it came from. If it was a newly generated card it is removed from play.- Parameters:
context-player-cards-discoverActions-- Returns:
-
getSpellDiscover
public static DiscoverAction getSpellDiscover(GameContext context, Player player, SpellDesc desc, List<SpellDesc> spells, Entity source) Requests that the player chooses from a selection of cards, then returns just the spell from the cards.Removes all the cards from play unless otherwise specified, since these cards aren't actually used.
- Parameters:
context- TheGameContextplayer- ThePlayerdesc- ASpellDescto use as the "parent" of the discovered spells. The mana cost and targets are inherited from this spell.spells- A list of spells from which to generate virtual cards.source- The source entity, typically theCardthat initiated this call.- Returns:
- A
DiscoverActionwhoseDiscoverAction.getCard()property corresponds to the selected card. To retrieve the spell, get the card's spell withCard.getSpell().
-
getValidTargets
public static List<Entity> getValidTargets(GameContext context, Player player, List<Entity> allTargets, EntityFilter filter, Entity host) Filters a list of targets.- Parameters:
context-player-allTargets-filter-host-- Returns:
-
getBoardPosition
public static int getBoardPosition(GameContext context, Player player, SpellDesc desc, Entity source) Interprets theSpellArg.BOARD_POSITION_ABSOLUTEorSpellArg.BOARD_POSITION_RELATIVEin adescgiven thesourceentity.- Parameters:
context-player-desc-source-- Returns:
- An index in the
sourceentity'sSpellsource.ZonesMessage.Zoneszone.
-
castChildSpell
public static void castChildSpell(GameContext context, Player player, SpellDesc spell, Entity source, Entity target, Entity output) Casts a subspell on a card that was returned byGameLogic.receiveCard(int, Card). Will not execute if the output is null or in theSpellsource.ZonesMessage.Zones.GRAVEYARD.- Parameters:
context- TheGameContextto operate on.player- The player from whose point of view we are casting this sub spell. This should be passed down from theSpell.onCast(GameContext, Player, SpellDesc, Entity, Entity)playerargument.spell- The sub spell, typically from thedescargument'sSpellArg.SPELLkey.source- The source entity.target-output- The card. Whennullor the card is located in theSpellsource.ZonesMessage.Zones.GRAVEYARD.
-
getCards
public static CardList getCards(GameContext context, Player player, Entity target, Entity source, SpellDesc desc) Retrieves the cards specified in theSpellDesc, either in theSpellArg.CARDorSpellArg.CARDSproperties or as specified by aCardSourceandCardFilter. If neither of those are specified, uses the target'sEntity.getSourceCard()as the targeted card.The number of cards randomly retrieved is equal to the
SpellArg.VALUEspecified in thedescargument, defaulting to 1.- Parameters:
context- The game contextplayer- The player from whose point of view these cards should be retrievedtarget- The target, which can benullsource- The source or hostEntity, typically the origin of this spell cast.desc- TheSpellDesctypically of the calling spell.- Returns:
- A list of cards.
- See Also:
-
getCards
public static CardList getCards(GameContext context, Player player, Entity target, Entity source, SpellDesc desc, int count) Retrieves the cards specified in theSpellDesc, either in theSpellArg.CARDorSpellArg.CARDSproperties or as specified by aCardSourceandCardFilter. If neither of those are specified, uses the target'sEntity.getSourceCard()as the targeted card.The
SpellDescgiven indescis inspected for a variety of arguments. If there is aSpellArg.CARD_SOURCEorSpellArg.CARD_FILTERspecified, the card source generates a list of cards usingCardSource.getCards(GameContext, Entity, Player), and that list is filtered usingEntityFilter.matches(GameContext, Player, Entity, Entity).Anytime
SpellArg.CARDorSpellArg.CARDSis specified, the card IDs in those args are added to the list of cards returned by this method.If no arguments are specified, the
targetentity'sEntity.getSourceCard()is added to the list of cards returned by this method. This means that providing aSpellDescthat contains neitherSpellArg.CARD,SpellArg.CARDS,SpellArg.CARD_SOURCEnorSpellArg.CARD_FILTERwill be interpreted as trying to retrieve the target's base card.Cards are not generated as copies unless the
CardSourcehas theHasCardCreationSideEffectstrait and is used as an arg in thedesc.By default, when a
SpellArg.CARD_FILTERis specified and aSpellArg.CARD_SOURCEis not, the default card source used isUnweightedCatalogueSource.The cards are chosen randomly without replacement.
- Parameters:
context- The game contextplayer- The player from whose point of view these cards should be retrievedtarget- The target, which can benullsource- The source or hostEntity, typically the origin of this spell cast.desc- TheSpellDesctypically of the calling spell.count- The maximum number of cards to return, exclusively and randomly, from the generated card list. Or, returns all the cards ifcount > cards.size(), wherecardsis all the possible cards.- Returns:
- A list of cards.
-
hasAura
public static <T extends Aura> boolean hasAura(GameContext context, int playerId, Class<T> auraClass) Determines whether any of theEntity.isInPlay()entities belonging to theplayerIdhost an unexpired, active instance of theauraClassaura.- Type Parameters:
T-- Parameters:
context-playerId-auraClass-- Returns:
trueif such an aura is found.- See Also:
-
getAuras
public static <T extends Aura> List<T> getAuras(GameContext context, int playerId, @NotNull @NotNull Class<T> auraClass) Retrieves all of the unexpired, active auras that are instances of theauraClasshosted byEntity.isInPlay()entities belonging to theplayerIdor passive auras hosted by hero powers and cards.- Type Parameters:
T-- Parameters:
context-playerId-auraClass-- Returns:
- A list of aura instances.
-
getAuras
public static <T extends Aura> List<T> getAuras(GameContext context, Class<T> auraClass, Entity target) Get the auras that are affecting the specified target of the given class.- Type Parameters:
T-- Parameters:
context-auraClass-target-- Returns:
-
getBonusesFromAura
public static SpellDesc[] getBonusesFromAura(GameContext context, int playerId, Class<? extends Aura> auraClass, Entity source, Entity target) Retrieves an array of spells corresponding to theAuraArg.APPLY_EFFECTfield on an aura whose condition is null or fulfilled for the givensourceandtarget.- Parameters:
context-playerId-auraClass-source-target-- Returns:
- A list of spells
-
determineCastingPlayer
public static SpellUtils.DetermineCastingPlayer determineCastingPlayer(GameContext context, Player player, Entity source, TargetPlayer castingTargetPlayer) Tries to determine the currently casting player from the point of view of a source, considering if the source has changed owners or if it was destroyed.- Parameters:
context- The game contextplayer- The casting playersource- The source from whose point of view the casting player should be determinedcastingTargetPlayer- Whose point of view the determination should be made. For example, ifTargetPlayer.OPPONENTis chosen here, then the opponent of the owner of thesourcewill be used.- Returns:
- An object containing information related to who is the casting player and whether or not the source has been destroyed.
-
isRecursive
Returnstrueif the caller is in a recursive stack- Parameters:
callingClass-
-
getSpecialCards
Gets a list of special card IDs.- Returns:
-