Class QueryTargetSpell

java.lang.Object
net.demilich.metastone.game.spells.Spell
net.demilich.metastone.game.spells.QueryTargetSpell
All Implemented Interfaces:
Serializable, HasDesc<SpellDesc>

public class QueryTargetSpell extends Spell
Interprets the spell arguments as a query of targets and casts SpellArg.SPELL on each resulting target in order.

This is a very powerful decorator spell that can be used to do selections on cards, like "Destroy the three highest health minions on the board," or "Draw the next three murlocs in your deck." If you encounter a pattern like this, use QueryTargetSpell.

No effects are cast when the result of the query is empty. Targeting: First, the original list of targets is collected. When SpellArg.TARGET is specified, the query is executed against the full collection of targets. When it is not specified, the query is executed on the cards returned by SpellArg.CARD_SOURCE. Shuffling: If SpellArg.RANDOM_TARGET is true, the list is now shuffled. Filtering: The targets are filtered using SpellArg.FILTER or SpellArg.CARD_FILTER. If SpellArg.TARGET is specified with a SpellArg.CARD_FILTER, the source cards of the targets are used. Otherwise, if a SpellArg.FILTER is specified, the filter is evaluated normally. Sorting: If a SpellArg.VALUE is provided, that value is evaluated against every element in the targets list and used to sort in ascending order. If a value is not provided, the natural order (i.e., index in the zone or catalogue) is used. To reverse the list, set ValueProviderArg.MULTIPLIER to -1. Skips and Limits: The first SpellArg.SECONDARY_VALUE targets are skipped, defaulting to 0. Then, the next SpellArg.HOW_MANY targets are taken, defaulting to 1.

If the player chose a target (EntityReference.TARGET is set) or we are currently evaluating an event (EntityReference.EVENT_TARGET is set), ValueProvider specifications given for either of these arguments will be evaluated with the target given by EntityReference.TARGET or EntityReference.EVENT_TARGET, or null. Casting: Finally, the SpellArg.SPELL is cast on each target in order. You should not use EntityReference.OUTPUT here, the selected target is passed directly as a target of the spell. If a SpellArg.CONDITION is specified, casting only continues so long as there are elements and the condition is true, evaluated with the target we are currently potentially casting on.

For example, to target the top 5 minions in your deck:

   {
       "class": "QueryTargetSpell",
       "howMany": 5,
       "cardSource": {
         "class": "DeckSource",
         "targetPlayer": "SELF"
       },
       "cardFilter": {
         "class": "CardFilter",
         "cardType": "MINION"
       },
       "value": {
         "class": "AttributeValueProvider",
         "attribute": "INDEX",
         "multiplier": -1
       },
       "spell": {
         (Your spell here, cast on each target, do not use OUTPUT)
       }
     }
 
To destroy all the opponent's minions except the one with the highest attack:
   {
     "class": "QueryTargetSpell",
     "spell": {
       "class": "DestroySpell"
     },
     "target": "ENEMY_MINIONS",
     "value": {
       "class": "AttributeValueProvider",
       "attribute": "ATTACK",
       "multiplier": -1
     },
     "secondaryValue": 1
   }
 
See Also:
  • Constructor Details

    • QueryTargetSpell

      public QueryTargetSpell()
  • Method Details

    • cast

      public void cast(GameContext context, Player player, SpellDesc desc, Entity source, List<Entity> targets)
      Description copied from class: Spell
      Casts a spell for the given arguments.

      If there is at least one valid target in targets and SpellArg.RANDOM_TARGET is true, a single target from the list will be chosen at random.

      If targets is null, this is a spell that does not ordinarily receive targets, so it will be cast once.

      If targets.size() is 0, this spell takes targets but none were found, so the spell is not cast.

      The EntityFilter specified in SpellArg.FILTER is applied to the list of targets to filter it. Therefore, this spell casting code is responsible for interpreting the SpellArg.FILTER and SpellArg.RANDOM_TARGET attributes of a SpellDesc.

      Typically the targets list is generated by either using the player's single target choice from a combination of the spell or battlecry's TargetSelection applied through a SpellArg.FILTER (resulting in a list of length one), or the resolved SpellArg.TARGET predefined target reference (usually a group reference) resulting in a list of length zero or greater.

      Overrides:
      cast in class Spell
      Parameters:
      context - The game context
      player - The casting player. This can be overridden by the SpellArg.TARGET_PLAYER arg in the desc.
      desc - The spell description
      source - The source entity of this spell cast
      targets - A list of targets
      See Also:
    • onCast

      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: