Class SetHpSpell

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

public class SetHpSpell extends Spell
Sets the Actor or Card's hitpoints to the specified SpellArg.VALUE, overriding any existing bonuses stored in Attribute.HP_BONUS.

When an actor is targeted, the actor's hitpoints and maximum hitpoints are both increased or decreased down to the new value.

When a card is targeted, the client will correctly render the change in hitpoints, and the summoned minion will have a silenceable enchantment that sets its hitpoints to the value specified.

If SpellArg.EXCLUSIVE is true (the default), the effect can be silenced. If it is false, the effect changes the Attribute.BASE_HP of the actor or card, and therefore cannot be silenced. Use a false exclusive argument in order to create minions on the fly.

For example, to set a minion's hitpoints to its attack:

     {
         "class": "SetHpSpell",
         "value": {
             "class": "AttributeValueProvider",
             "attribute": "ATTACK"
         }
     }
 
Suppose we wanted to implement the text, "At the start of your turn, summon a Penguin. The next Penguin has +1/+1 compared to the last." The idea is that Penguins, like Jade Golems, do not have a silenceable buff but a permanent number of hitpoints. Here will will use the SpellArg.EXCLUSIVE argument and set it to false:
     "trigger": {
         "eventTrigger": {
             "class": "TurnStartTrigger",
             "targetPlayer": "SELF"
         },
         "spell": {
             "class": "MetaSpell",
             "spells": [
                  {
                      "class": "SummonSpell",
                      "card": "minion_snowflipper_penguin",
                      "spell": {
                          "class": "MetaSpell",
                          "spells": [
                              {
                                  "class": "SetHpSpell",
                                  "target": "OUTPUT",
                                  "exclusive": false,
                                  "value": {
                                      "class": "AttributeValueProvider",
                                      "attribute": "RESERVED_INTEGER_1",
                                      "target": "TRIGGER_HOST"
                                  }
                              },
                              {
                                  "class": "SetAttackSpell",
                                  "target": "OUTPUT",
                                  "exclusive": false,
                                  "value": {
                                      "class": "AttributeValueProvider",
                                      "attribute": "RESERVED_INTEGER_1",
                                      "target": "TRIGGER_HOST"
                                  }
                              }
                          ]
                      }
                  },
                  {
                      "class": "ModifyAttributeSpell",
                      "target": "TRIGGER_HOST",
                      "attribute": "RESERVED_INTEGER_1",
                      "value": 1
                  }
             ]
         }
     }
 
The complex example above also uses Attribute.RESERVED_INTEGER_1 as a counter; the special target EntityReference.OUTPUT to cast a spell on the minion that was summoned by a SummonSpell; and the special target EntityReference.TRIGGER_HOST to modify the host of the trigger instead of the GameEvent.getTarget() entity, the default target of spells cast by triggers.
See Also:
  • Constructor Details

    • SetHpSpell

      public SetHpSpell()
  • Method Details

    • create

      public static SpellDesc create(int hp)
    • create

      public static SpellDesc create(int value, boolean immuneToSilence)
    • 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: