Class ReceiveCardSpell
- All Implemented Interfaces:
Serializable
,HasDesc<SpellDesc>
- Direct Known Subclasses:
ReceiveCardAndDoSomethingSpell
,ReceiveLastCardSpell
,ReceiveOpponentsCastSpellsSpell
When a SpellArg.CARD
is specified as the only argument, this spell creates that card and puts it in the
player's hand.
When SpellArg.CARDS
is specified, this spell will put every card in that array into the player's hand. To
choose one of those cards at random, set SpellArg.RANDOM_TARGET
to true
.
When a SpellArg.CARD_FILTER
and/or SpellArg.CARD_SOURCE
is specified, this spell will generate the
cards specified by that source and filter, assuming an AndFilter
(i.e., all cards accepted) and a CatalogueSource
by default.
If the available cards to choose from after applying this filter to the source is zero (i.e., there are no cards to
choose from), the spell will instead put the card specified by SpellArg.CARD
into the player's hand. This
should be interpreted as the "replacement" card.
If neither a SpellArg.CARD_FILTER
, SpellArg.CARD_SOURCE
, SpellArg.CARD
nor SpellArg.CARDS
arguments are specified, the spell will interpret the target
(either from the parent spell or
the SpellArg.TARGET
) as the card to receive as long as the target
is a Card
.
When a SpellArg.VALUE
is specified, the spell will interpret the value as either copies of a single card or
how many cards to choose from a collection of SpellArg.CARDS
or the filtered cards. This value is 1
by default.
The rules for how to interpret SpellArg.VALUE
go as follows:
SpellArg.CARDS
argument set,SpellArg.RANDOM_TARGET
=false
(by default):SpellArg.VALUE
copies of each card inSpellArg.CARDS
.SpellArg.CARDS
argument set,SpellArg.RANDOM_TARGET
=true
:SpellArg.VALUE
cards will be drawn with replacement from the collection specified by theSpellArg.CARDS
argument.- Any
SpellArg.CARD_FILTER
orSpellArg.CARD_SOURCE
:SpellArg.VALUE
cards will be drawn without replacement from the filtered list of cards. - All other
situations (i.e.,
target
is aCard
:SpellArg.VALUE
will be ignored.
SpellArg.TARGET_PLAYER
indicates who will receive the cards.
If the card is successfully put into the player's hand, subspells specified in SpellArg.SPELL
will be cast,
where the target
is this spell's target
and EntityReference.OUTPUT
references the created
card.
For example, to receive one of three cards:
{ "class": "ReceiveCardSpell", "cards": [ "spell_i_am_murloc", "spell_power_of_the_horde", "spell_rogues_do_it" ], "randomTarget": true, "targetPlayer": "SELF" }By contrast, to receive all three cards specified (notice that
SpellArg.RANDOM_TARGET
is omitted because it
is false
by default):
{ "class": "ReceiveCardSpell", "cards": [ "spell_i_am_murloc", "spell_power_of_the_horde", "spell_rogues_do_it" ], "targetPlayer": "SELF" }To get a copy of a random minion in the opponent's deck, or a Shadow of Nothing if your opponent had no minion cards (adapted from Mindgames):
{ "class": "ReceiveCardSpell", "card": "token_shadow_of_nothing", "cardFilter": { "class": "CardFilter", "cardType": "MINION" }, "cardSource": { "class": "DeckSource", "targetPlayer": "OPPONENT" } }To receive a random minion and give it +2/+2 in your hand (notice the
SpellArg.TARGET
of the BuffSpell
is EntityReference.OUTPUT
):
{ "class": "ReceiveCardSpell", "cardFilter": { "class": "CardFilter", "cardType": "MINION" }, "spell": { "class": "BuffSpell", "target": "OUTPUT", "attackBonus": 2, "hpBonus": 2 } }
This spell will not receive a Card
target
if its owner does not match the player.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic SpellDesc
create()
Creates this spell to simply receive thetarget
.static SpellDesc
Creates this spell to receive the specified card.static SpellDesc
Creates this spell to receive one of the specified cards.static SpellDesc
create
(EntityFilter filter, int cards) Creates this spell to putcards
amount of cards filtered from the catalogue into the player's hand.static SpellDesc
create
(CardSource source, EntityFilter filter, int cards) Creates this spell to putcards
amount of cards filtered from thesource
into the player's hand.static SpellDesc
create
(EntityReference target) Creates this spell to receive the specified target.protected Card
getAndRemoveCard
(GameContext context, List<Card> cards) protected void
Implementations ofonCast
are the meat-and-bones of a spell's effects.Methods inherited from class net.demilich.metastone.game.spells.Spell
cast, castForPlayer, checkArguments, getDesc, isNativeStateful, setDesc, toString
-
Constructor Details
-
ReceiveCardSpell
public ReceiveCardSpell()
-
-
Method Details
-
onCast
protected void onCast(GameContext context, Player player, SpellDesc desc, Entity source, Entity target) Description copied from class:Spell
Implementations ofonCast
are the meat-and-bones of a spell's effects. This should actually call a variety of methods inGameLogic
, generate cards usingSpellUtils.getCards(GameContext, Player, Entity, Entity, SpellDesc)
, interpretSpellArg
keys in thedesc
, etc.Observe that subclasses of
Spell
mostly just need to implement this function. Also, observe that instances ofSpell
are stateless: all the state is provided as arguments to this function.- Specified by:
onCast
in classSpell
- Parameters:
context
- The game contextplayer
- The casting playerdesc
- The collection ofSpellArg
keys and values that are interpreted by the implementation of this function to actually cause effects in a gamesource
- The entity from which this effect is happening (typically a card or a minion if it's a battlecry).target
- The particular target of this invocation of the spell. When a spell hits multiple targets, like an AoE damage effect, this method is called once for each target in the list of targets.- See Also:
-
getAndRemoveCard
-
create
Creates this spell to simply receive thetarget
.- Returns:
- The spell
-
create
Creates this spell to receive the specified card.- Parameters:
cardId
- The ID of the card to receive.- Returns:
- The spell
-
create
Creates this spell to receive the specified target.- Parameters:
target
- AnEntityReference
to a card.- Returns:
- The spell
-
create
Creates this spell to receive one of the specified cards.- Parameters:
cardIds
- The cards to choose from, randomly.- Returns:
- The spell
-
create
Creates this spell to putcards
amount of cards filtered from the catalogue into the player's hand.- Parameters:
filter
- A filter to apply to aCatalogueSource
. Typically, you should specify aCardFilter
with a specifiedEntityFilterArg.CARD_TYPE
.cards
- How many cards should be received from the filtered cards, without replacement. This means each card will be distinct as long as the source gave distinct cards.- Returns:
- The spell
-
create
Creates this spell to putcards
amount of cards filtered from thesource
into the player's hand.- Parameters:
source
- TheCardSource
to use to filter. Whennull
, defaults to aCatalogueSource
.filter
- A filter to apply to thesource
. Typically, you should specify aCardFilter
with a specifiedEntityFilterArg.CARD_TYPE
.cards
- How many cards should be received from the filtered cards, without replacement. This means each card will be distinct as long as the source gave distinct cards.- Returns:
- The spell
-