Class ReceiveCardSpell

java.lang.Object
net.demilich.metastone.game.spells.Spell
net.demilich.metastone.game.spells.ReceiveCardSpell
All Implemented Interfaces:
java.io.Serializable, HasDesc<SpellDesc>
Direct Known Subclasses:
ReceiveCardAndDoSomethingSpell, ReceiveLastCardSpell, ReceiveOpponentsCastSpellsSpell

public class ReceiveCardSpell
extends Spell
Puts a card in your hand.

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

See Also:
for how to steal/move cards from the opponent's possession to the target player's possession., for how to copy a card., Serialized Form
  • Constructor Details

  • Method Details

    • onCast

      @Suspendable protected void onCast​(GameContext context, Player player, SpellDesc desc, Entity source, Entity target)
      Description copied from class: Spell
      Implementations of onCast are the meat-and-bones of a spell's effects. This should actually call a variety of methods in GameLogic, generate cards using SpellUtils.getCards(GameContext, Player, Entity, Entity, SpellDesc), interpret SpellArg keys in the desc, etc.

      Observe that subclasses of Spell mostly just need to implement this function. Also, observe that instances of Spell are stateless: all the state is provided as arguments to this function.

      Specified by:
      onCast in class Spell
      Parameters:
      context - The game context
      player - The casting player
      desc - The collection of SpellArg keys and values that are interpreted by the implementation of this function to actually cause effects in a game
      source - 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:
      for an example of a complex spell implementation.
    • getAndRemoveCard

      protected Card getAndRemoveCard​(GameContext context, java.util.List<Card> cards)
    • create

      public static SpellDesc create()
      Creates this spell to simply receive the target.
      Returns:
      The spell
    • create

      public static SpellDesc create​(java.lang.String cardId)
      Creates this spell to receive the specified card.
      Parameters:
      cardId - The ID of the card to receive.
      Returns:
      The spell
    • create

      public static SpellDesc create​(EntityReference target)
      Creates this spell to receive the specified target.
      Parameters:
      target - An EntityReference to a card.
      Returns:
      The spell
    • create

      public static SpellDesc create​(java.lang.String... cardIds)
      Creates this spell to receive one of the specified cards.
      Parameters:
      cardIds - The cards to choose from, randomly.
      Returns:
      The spell
    • create

      public static SpellDesc create​(EntityFilter filter, int cards)
      Creates this spell to put cards amount of cards filtered from the catalogue into the player's hand.
      Parameters:
      filter - A filter to apply to a CatalogueSource. Typically, you should specify a CardFilter with a specified EntityFilterArg.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

      public static SpellDesc create​(CardSource source, EntityFilter filter, int cards)
      Creates this spell to put cards amount of cards filtered from the source into the player's hand.
      Parameters:
      source - The CardSource to use to filter. When null, defaults to a CatalogueSource.
      filter - A filter to apply to the source. Typically, you should specify a CardFilter with a specified EntityFilterArg.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