Class AddDeathrattleSpell

java.lang.Object
net.demilich.metastone.game.spells.Spell
net.demilich.metastone.game.spells.AddDeathrattleSpell
All Implemented Interfaces:
Serializable, HasDesc<SpellDesc>
Direct Known Subclasses:
AddDeathrattleSecondaryAsTargetSpell, AnobiiSpell, CopyDeathrattleSpell, ElorthaNoShandraSpell, RafaamThiefSpell

public class AddDeathrattleSpell extends Spell
Adds the deathrattle specified by the SpellArg.SPELL to the SpellArg.TARGET or target.

If the target is a Card, the deathrattle will be added to the resulting actor when the minion is brought into play. To add an effect that occurs when a card is removed from the hand, use an AddEnchantmentSpell with a DiscardTrigger.

Deathrattles are equivalent to an AddEnchantmentSpell with a MinionDeathTrigger, TargetType.IGNORE_OTHER_TARGETS.

Minions removed peacefully with GameLogic.removePeacefully(Entity) do not trigger deathrattles.

All weapon removals trigger deathrattles, whether by replacement, destruction or by depleting their durability.

Deathrattles resolve from the Spellsource.ZonesMessage.Zones.GRAVEYARD. However, the SpellArg.BOARD_POSITION_ABSOLUTE argument is set to where the minion used to be.

If a SpellArg.VALUE is specified on this spell, it will be computed at the time the effect is applied and copied onto the sub-spell.

For example, to give a minion a the deathrattle, "Resummon this minion,":

     {
       "class": "AddDeathrattleSpell",
       "spell": {
         "class": "ReviveMinionSpell",
         "target": "SELF"
       }
     }
 

Many jail effects, like "Battlecry: Choose a minion. Deathrattle: Summon a copy of it" require "storing" a reference to an entity. Use AddDeathrattleSecondaryAsTargetSpell for this effect. Or, to implement it in code, create a new class that extends Spell and implement its onCast method to create a new deathrattle spell. For example, to implement the text "Battlecry: Choose a minion. Deathrattle: Summon a copy of it:"

 
   SpellDesc summonDesc = new SpellDesc(SummonSpell.class);
   // The target is the minion chosen by the battlecry. It gets baked in here.
   summonDesc.put(SpellArg.TARGET, target.getReference());
   SpellDesc addDeathrattleSpell = AddDeathrattleSpell.create(EntityReference.SELF, summonDesc);
   SpellUtils.castChildSpell(context, player, addDeathrattleSpell, source, target);
 
 
Observe that the target reference gets baked in and a deathrattle is added to the casting minion by this battlecry, as opposed to setting the "deathrattle" field on the minion's card JSON.
See Also:
  • Constructor Details

    • AddDeathrattleSpell

      public AddDeathrattleSpell()
  • Method Details

    • create

      public static SpellDesc create(EntityReference target, SpellDesc deathrattle)
      Creates this spell to add the specified deathrattle to the target.
      Parameters:
      target - The target entity reference
      deathrattle - The spell to cast when that Actor dies.
      Returns:
      A spell instance.
    • create

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