Class SpellUtils
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic class
An object that contains results of adetermineCastingPlayer(GameContext, Player, Entity, TargetPlayer)
call. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic 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.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)
.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 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 (typicallyReceiveCardSpell
with that card.static boolean
evaluateOperation
(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 theauraClass
hosted byEntity.isInPlay()
entities belonging to theplayerId
or 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 int
getBoardPosition
(GameContext context, Player player, SpellDesc desc, Entity source) Interprets theSpellArg.BOARD_POSITION_ABSOLUTE
orSpellArg.BOARD_POSITION_RELATIVE
in adesc
given thesource
entity.static SpellDesc[]
getBonusesFromAura
(GameContext context, int playerId, Class<? extends Aura> auraClass, Entity source, Entity target) Retrieves an array of spells corresponding to theAuraArg.APPLY_EFFECT
field on an aura whose condition is null or fulfilled for the givensource
andtarget
.static Card
getCard
(GameContext context, SpellDesc spell) Gets a card out of aSpellDesc
.static Card
getCardFromContextOrDiscover
(GameContext context, String cardId) Retrieves a reference to a newly generated card currently in theSpellsource.ZonesMessage.Zones.DISCOVER
if the givencardId
can be found there.static CardList
Filters a card list.static CardList
Retrieves the cards specified in theSpellDesc
, either in theSpellArg.CARD
orSpellArg.CARDS
properties or as specified by aCardSource
andCardFilter
.static CardList
getCards
(GameContext context, Player player, Entity target, Entity source, SpellDesc desc, int count) Retrieves the cards specified in theSpellDesc
, either in theSpellArg.CARD
orSpellArg.CARDS
properties or as specified by aCardSource
andCardFilter
.static Card[]
getCards
(GameContext context, SpellDesc spell) Retrieves the cards specified inside theSpellArg.CARD
andSpellArg.CARDS
arguments.Gets a list of special card IDs.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.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 theplayerId
host an unexpired, active instance of theauraClass
aura.static boolean
isRecursive
(Class<? extends Spell> callingClass) Returnstrue
if the caller is in a recursive stackstatic boolean
playCardRandomly
(GameContext context, Player player, Card card, Entity source, boolean summonRightmost, boolean resolveOpener, boolean onlyWhileSourceInPlay, boolean randomChooseOnes, boolean playFromHand) Plays a card "randomly."static DiscoverAction
postDiscover
(GameContext context, Player player, Iterable<? extends Card> cards, List<GameAction> discoverActions) Moves the card put into theSpellsource.ZonesMessage.Zones.DISCOVER
by 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
- Whentrue
andCard.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.CHOICES
made.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:
true
if the evaluation is truue.
-
getCards
Filters a card list. Does not copy source cards.- Parameters:
source
- ACardList
source.filter
- A function that returnstrue
when the card should be kept, ornull
to include all cards.- Returns:
- A
CardList
backed by a mutable, non-copyCardArrayList
.
-
getCard
Gets a card out of aSpellDesc
. Typically only consults theSpellArg.CARD
property.- Parameters:
context
- The context.spell
- TheSpellDesc
.- Returns:
- A card.
-
getCards
Retrieves the cards specified inside theSpellArg.CARD
andSpellArg.CARDS
arguments.- 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
Card
entities. - See Also:
-
getCardFromContextOrDiscover
Retrieves a reference to a newly generated card currently in theSpellsource.ZonesMessage.Zones.DISCOVER
if the givencardId
can 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 (typicallyReceiveCardSpell
with 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 aSpell
from thisSpellDesc
and set itsSpellArg.CARD
argument to the discoverable card. Typically, thisSpellDesc
defines aReceiveCardSpell
,ReceiveCardAndDoSomethingSpell
, or aChangeHeroPowerSpell
. These spells all receive cards as arguments. This argument allows aDiscoverAction
to do more sophisticated things than just put cards into hands.cards
- ACardList
of cards that get copied, added to theSpellsource.ZonesMessage.Zones.DISCOVER
zone of the player and shown in the discover card UI to the player.- Returns:
- The
DiscoverAction
that 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.DISCOVER
by 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
- TheGameContext
player
- ThePlayer
desc
- ASpellDesc
to 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 theCard
that initiated this call.- Returns:
- A
DiscoverAction
whoseDiscoverAction.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_ABSOLUTE
orSpellArg.BOARD_POSITION_RELATIVE
in adesc
given thesource
entity.- Parameters:
context
-player
-desc
-source
-- Returns:
- An index in the
source
entity'sSpellsource.ZonesMessage.Zones
zone.
-
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
- TheGameContext
to 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)
player
argument.spell
- The sub spell, typically from thedesc
argument'sSpellArg.SPELL
key.source
- The source entity.target
-output
- The card. Whennull
or 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.CARD
orSpellArg.CARDS
properties or as specified by aCardSource
andCardFilter
. 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.VALUE
specified in thedesc
argument, defaulting to 1.- Parameters:
context
- The game contextplayer
- The player from whose point of view these cards should be retrievedtarget
- The target, which can benull
source
- The source or hostEntity
, typically the origin of this spell cast.desc
- TheSpellDesc
typically 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.CARD
orSpellArg.CARDS
properties or as specified by aCardSource
andCardFilter
. If neither of those are specified, uses the target'sEntity.getSourceCard()
as the targeted card.The
SpellDesc
given indesc
is inspected for a variety of arguments. If there is aSpellArg.CARD_SOURCE
orSpellArg.CARD_FILTER
specified, 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.CARD
orSpellArg.CARDS
is specified, the card IDs in those args are added to the list of cards returned by this method.If no arguments are specified, the
target
entity'sEntity.getSourceCard()
is added to the list of cards returned by this method. This means that providing aSpellDesc
that contains neitherSpellArg.CARD
,SpellArg.CARDS
,SpellArg.CARD_SOURCE
norSpellArg.CARD_FILTER
will be interpreted as trying to retrieve the target's base card.Cards are not generated as copies unless the
CardSource
has theHasCardCreationSideEffects
trait and is used as an arg in thedesc
.By default, when a
SpellArg.CARD_FILTER
is specified and aSpellArg.CARD_SOURCE
is 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 benull
source
- The source or hostEntity
, typically the origin of this spell cast.desc
- TheSpellDesc
typically 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()
, wherecards
is 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 theplayerId
host an unexpired, active instance of theauraClass
aura.- Type Parameters:
T
-- Parameters:
context
-playerId
-auraClass
-- Returns:
true
if 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 theauraClass
hosted byEntity.isInPlay()
entities belonging to theplayerId
or 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_EFFECT
field on an aura whose condition is null or fulfilled for the givensource
andtarget
.- 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.OPPONENT
is chosen here, then the opponent of the owner of thesource
will be used.- Returns:
- An object containing information related to who is the casting player and whether or not the source has been destroyed.
-
isRecursive
Returnstrue
if the caller is in a recursive stack- Parameters:
callingClass
-
-
getSpecialCards
Gets a list of special card IDs.- Returns:
-