Class AddEnchantmentSpell

java.lang.Object
net.demilich.metastone.game.spells.Spell
net.demilich.metastone.game.spells.AddEnchantmentSpell
All Implemented Interfaces:
Serializable, HasDesc<SpellDesc>
Direct Known Subclasses:
AddEnchantmentToMinionCardSpell, ReceiveCardNextTurnSpell, TransformToAndBackSpell

public class AddEnchantmentSpell extends Spell
Adds an SpellArg.AURA (Aura) or a Enchantment (in the SpellArg.TRIGGER) to the specified target and immediately puts that aura/enchantment into play (i.e., activates it).

If a SpellArg.CARD is specified, the spell will interpret the card as an Spellsource.CardTypeMessage.CardType.ENCHANTMENT, adding each of its triggers as specified to the target and the deathrattle as a MinionDeathTrigger whose TargetType is TargetType.IGNORE_OTHER_TARGETS. If no triggers are present on the card, a dummy enchantment is created for later use in the RemoveEnchantmentSpell and HasEnchantmentFilter.

If a SpellArg.REVERT_TRIGGER is specified, creates an enchantment on the casting player's Player entity that triggers with the specified EventTrigger and removes trigger, aura and enchantment cards added by this spell. To model more sophisticated effects, consider creating a dedicate trigger with a card ID corresponding to the enchantment card with the core effects.

Enchantments and auras are only in play if their Enchantment.getHostReference() is Entity.isInPlay(). Currently, auras and enchantments are immediately active and listening to events. However, auras only evaluate which entities they affect on the next event they react to, which is typically a BoardChangedEvent or WillEndSequenceTrigger. Thus, auras aren't really in play until those triggers fire (or the aura's AuraArg.SECONDARY_TRIGGER fires).

This example implements the text, "At the start of your next turn, summon four 1/1 Silver Hand Recruits." Notice that EntityReference.FRIENDLY_PLAYER is used as the target of an enchantment for effects that don't really belong to specific actors like minions.

   {
     "class": "AddEnchantmentSpell",
     "target": "FRIENDLY_PLAYER",
     "trigger": {
       "eventTrigger": {
         "class": "TurnStartTrigger",
         "targetPlayer": "SELF"
       },
       "spell": {
         "class": "SummonSpell",
         "cards": [
           "token_silver_hand_recruit",
           "token_silver_hand_recruit",
           "token_silver_hand_recruit",
           "token_silver_hand_recruit"
         ]
       },
       "oneTurn": true
     }
   }
 
This example shows an easy way to remove the trigger added this way. This implements the text, "Give +1/+1 to all minions summoned until the start of your next turn."
   {
     "class": "AddEnchantmentSpell",
     "target": "FRIENDLY_PLAYER",
     "trigger": {
       "eventTrigger": {
         "class": "MinionSummonedTrigger",
         "targetPlayer": "BOTH"
       },
       "spell": {
         "class": "BuffSpell",
         "value": 1,
         "target": "EVENT_TARGET"
       }
     },
     "revertTrigger": {
       "class": "TurnStartTrigger",
       "targetPlayer": "SELF"
     }
   }
 

This powerful spell can be chained together to do counting, to put auras into play, etc. Browse cards that use the spell for more complete examples.

See Also:
  • Constructor Details

    • AddEnchantmentSpell

      public AddEnchantmentSpell()
  • Method Details

    • create

      public static SpellDesc create(EntityReference target, EnchantmentDesc trigger)
    • create

      public static SpellDesc create(EntityReference target, Aura aura)
    • create

      public static SpellDesc create(EnchantmentDesc trigger)
    • 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: