Class Spell

java.lang.Object
net.demilich.metastone.game.spells.Spell
All Implemented Interfaces:
java.io.Serializable, HasDesc<SpellDesc>
Direct Known Subclasses:
AbholosSpell, AbstractModifyEnchantmentSpell, AbstractRemoveCardSpell, ActivateTriggeredEffectSpell, ActorOrCardSpell, AddActorEffectsToTargetActorSpell, AddBattlecrySpell, AddDeathrattleSpell, AddEnchantmentSpell, AddQuestSpell, AddSecretSpell, AuraBuffSpell, AysaCloudsingerSpell, BaulPocuseSpell, BrothersInBloodSpell, CalamityBeckonsSpell, CardCostModifierSpell, CastAfterSequenceSpell, CastCardsSpell, CastFromGroupSpell, CastOnCardsInStorageSpell, CastOnEntitiesInStorageSpell, CastRandomSpellSpell, CastRepeatedlySpell, CastSpellSpell, CastSpellWithTargetOrElseSpell, CelestialConduitSpell, ChangeHeroPowerSpell, ChangeHeroSpell, ChangeSignatureSpell, ChooseAndReshuffleSpell, ChooseOneSpell, ChooseSignatureSpell, ClearOverloadSpell, ClearStorageSpell, CloneMinionSpell, ConditionalAttackBonusSpell, ConditionalEffectSpell, ConditionalSpell, CopyCardEnchantmentsSpell, CopyCardSpell, CopyEnchantmentsSpell, CopyLowestCostMinionSpell, CopyMinionSpell, CreateAndTeachSpell, CreateCardFromChoicesSpell, CreateCardSpell, CreateSummonSpell, CreationSpell, DamageAdjacentMinionsSpell, DamageOppositeMinionsSpell, DamageSpell, DecaySpell, DestroySecretsSpell, DestroySpell, DiluteSoulSpell, DiscardCardsFromDeckSpell, DiscoverClassSpell, DiscoverDiscardSpell, DiscoverOptionSpell, DiscoverSpell, DoubleAttackSpell, DrainSpell, DrawCardFromGraveyardSpell, DrawCardSpell, DrawCardUntilConditionSpell, EitherOrSpell, EnrageSpell, EquipWeaponSpell, FarseerNobundoSpell, FatigueSpell, FelfireDrakeSpell, FightSpell, FinalFeastSpell, ForceDeathPhaseSpell, FromDeckToHandSpell, FumbleSpell, GainManaSpell, GetChooseOneChoicesSpell, GuessCardSpell, HealAndBuffExcessAsDrainSpell, HealSpell, HeroPowerToSpellSpell, JailMinionSpell, JoustSpell, LambdaSpellDesc.LambdaSpell, LastMinionCardInDeckSpell, MergeSpell, MetaSpell, MindControlSpell, MisdirectSpell, ModifyDamageSpell, ModifyDurabilitySpell, ModifyMaxManaSpell, MultiTargetSpell, NullSpell, OverrideTargetSpell, PlayCardsRandomlySpell, ProphetWaRanSpell, PutCopyInHandSpell, PutDeckTopSpell, PutMinionOnBoardFromDeckSpell, PutMinionOnBoardSpell, PutOnBottomOfDeckSpell, PutRandomSecretIntoPlaySpell, QueryTargetSpell, RandomCardTargetSpell, RandomlyCastSpell, RecastMinionSpells, RecastWhileSpell, ReceiveCardsInStorageSpell, ReceiveCardSpell, RecruitSpell, RefreshAttacksSpell, RefreshHeroPowerSpell, RefreshManaSpell, RelativeToTargetEffectSpell, RemoveActorPeacefullySpell, RemoveBonusAttributes, RemoveEnchantmentSpell, RemoveTopUntilMinionAndSummonSpell, RenounceClassSpell, RepeatAllAftermathsSpell, RepeatAllOtherBattlecriesSpell, ReplaceCardsSpell, ResetDeckSpell, ResurrectFromBothSpell, ResurrectFromEntityStorageSpell, ResurrectSpell, ReturnTargetToHandSpell, RevealCardSpell, RevertableSpell, ReviveMinionSpell, SetAttackerSpell, SetAttackSpell, SetAttributeSpell, SetDescriptionSpell, SetHeroHpSpell, SetHpSpell, SetMaxManaSpell, SetRaceSpell, ShuffleToDeckSpell, SilenceSpell, SortDeckByManaCostSpell, SowDistrustSpell, StealCardSpell, StealRandomSecretSpell, StoreEntitySpell, StoreRaceToAttributeSpell, SummonCardFromAttributeSpell, SummonFriendlyMinionsThatDiedSpell, SummonSpell, SwapAttackAndHpSpell, SwapAttackSpell, SwapCardsSpell, SwapHpAndCostSpell, SwapHpSpell, SwapMinionSpell, SwipeSpell, TargetToSourceSecondaryToTargetSpell, TemporaryAttackSpell, TextifySpell, TransformCardSpell, TransformInHandSpell, TransformMinionSpell, TriggerDeathrattleSpell, TriggerOpenerSpell, TriggerQuickDrawSpell, TriggerSecretRevealSpell, TriggerSecretSpell, UseHeroPowerSpell, ValueToHowManySpell, VohkrovanisSpell, VolatileWisdomSpell, WeaponOnEquipEffectSpell, WeaponOnUnEquipEffectSpell, WitherSpell, YaganLifetakerSpell

public abstract class Spell
extends java.lang.Object
implements java.io.Serializable, HasDesc<SpellDesc>
The base class for "spells," or collections of effects in the engine.

Spell in this context means something broader than a spell card. It refers to anything that causes changes to the game, like a deathrattle or a triggered effect.

To browse all the possible effects, visit the deriving classes of this class.

These classes are the value for SpellArg.CLASS, i.e., what you write after "class": ... in the card JSON for spell objects. Each string in the "class" values corresponds exactly to a subclass of this class.

See Also:
Serialized Form
  • Constructor Summary

    Constructors 
    Constructor Description
    Spell()  
  • Method Summary

    Modifier and Type Method Description
    void cast​(GameContext context, Player player, SpellDesc desc, Entity source, java.util.List<Entity> targets)
    Casts a spell for the given arguments.
    protected void castForPlayer​(GameContext context, Player player, SpellDesc desc, Entity source, Entity target)
    Casts this spell on behalf of the specified player to the specified target.
    protected void checkArguments​(org.slf4j.Logger logger, GameContext context, Entity source, SpellDesc desc, SpellArg... validArgs)
    Allows an implementation to log when it encounters unexpected arguments.
    SpellDesc getDesc()  
    protected boolean isNativeStateful()
    Indicates this instance uses Java field memory to maintain state instead of GameContext memory like the environment or entities.
    protected abstract void onCast​(GameContext context, Player player, SpellDesc desc, Entity source, Entity target)
    Implementations of onCast are the meat-and-bones of a spell's effects.
    void setDesc​(Desc<?,​?> desc)  
    java.lang.String toString()  

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
  • Constructor Details

  • Method Details

    • cast

      @Suspendable public void cast​(GameContext context, Player player, SpellDesc desc, Entity source, java.util.List<Entity> targets)
      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.

      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:
      for the logic which filters the targets argument.
    • castForPlayer

      @Suspendable protected void castForPlayer​(GameContext context, Player player, SpellDesc desc, Entity source, Entity target)
      Casts this spell on behalf of the specified player to the specified target.

      When TargetPlayer.BOTH is specified by the SpellArg.TARGET_PLAYER in the desc, this effect occurs twice: first for the initiating player and then for that player's opponent.

      Parameters:
      context -
      player -
      desc -
      source -
      target -
    • onCast

      @Suspendable protected abstract void onCast​(GameContext context, Player player, SpellDesc desc, Entity source, Entity target)
      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.

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

      public java.lang.String toString()
      Overrides:
      toString in class java.lang.Object
    • checkArguments

      protected void checkArguments​(org.slf4j.Logger logger, GameContext context, Entity source, SpellDesc desc, SpellArg... validArgs)
      Allows an implementation to log when it encounters unexpected arguments.
      Parameters:
      logger - The logger to print to
      context - The context whose GameContext.getGameId() will be used to mark the log
      source - The source of this call
      desc - The description used in this call
      validArgs - The valid arguments
    • setDesc

      public void setDesc​(Desc<?,​?> desc)
      Specified by:
      setDesc in interface HasDesc<SpellDesc>
    • getDesc

      public SpellDesc getDesc()
      Specified by:
      getDesc in interface HasDesc<SpellDesc>
    • isNativeStateful

      protected boolean isNativeStateful()
      Indicates this instance uses Java field memory to maintain state instead of GameContext memory like the environment or entities.
      Returns: