Class Enchantment

All Implemented Interfaces:
Serializable, Cloneable, Comparable<Entity>, HasCard, Trigger
Direct Known Subclasses:
Aftermath, Aura, CardCostModifier, Opener, Quest, Secret, WhereverTheyAreEnchantment

public class Enchantment extends Entity implements Trigger
An enchantment is a type of entity that reacts to certain events using a trigger by casting a spell.

Enchantments live inside GameLogic.getActiveTriggers(EntityReference); some enchantments, like Secret and Quest, live in their respective zones Spellsource.ZonesMessage.Zones.QUEST and Spellsource.ZonesMessage.Zones.SECRET.

Enchantments consistent of two important features: a EventTrigger built from an EventTriggerDesc, and a SpellDesc indicating which spell should be cast when the enchantment's EventTrigger and its conditions EventTrigger.innerQueues(GameEvent, Enchantment, Entity).

Enchantments are specified by a EnchantmentDesc in the card JSON. They can also be specified as fields in e.g., AddEnchantmentSpell.

The lifecycle of an enchantment looks like the following:

  • onAdd: Called when the enchantment comes into play. At this moment, the number of times the enchantment has been fired is set to zero; it is not expired, and
  • onGameEvent: Gives the enchantment a chance to look at a GameEvent, evaluate a EventTrigger against it, and determine whether its EnchantmentDesc.getSpell() should be cast.
  • onRemove: Expires the enchantment, ensuring it will never fire again.
An enchantment's lifecycle matches the entity it is hosted by, like an Actor, the Player entity (when e.g. AddEnchantmentSpell has a SpellArg.TARGET of EntityReference.FRIENDLY_PLAYER) or itself (in the case of a quest and secret). This means that EntityReference.FRIENDLY_PLAYER is a natural host for Enchantment objects that should not be removed for any reason like minion death.
See Also:
  • Field Details

    • triggers

      protected List<EventTrigger> triggers
    • expirationTriggers

      protected List<EventTrigger> expirationTriggers
    • activationTriggers

      protected List<EventTrigger> activationTriggers
    • spell

      protected SpellDesc spell
    • hostReference

      protected EntityReference hostReference
    • oneTurn

      protected boolean oneTurn
    • activated

      protected boolean activated
    • expired

      protected boolean expired
    • persistentOwner

      protected boolean persistentOwner
    • keepAfterTransform

      protected boolean keepAfterTransform
    • countUntilCast

      protected Integer countUntilCast
    • countByValue

      protected boolean countByValue
    • usesSpellTrigger

      protected boolean usesSpellTrigger
    • maxFiresPerSequence

      protected Integer maxFiresPerSequence
    • firesThisSequence

      protected int firesThisSequence
    • copyToActor

      protected boolean copyToActor
    • zones

      protected com.hiddenswitch.spellsource.rpc.Spellsource.ZonesMessage.Zones[] zones
    • added

      protected boolean added
  • Constructor Details

    • Enchantment

      public Enchantment()
    • Enchantment

      public Enchantment(HasEntrySet<?,?> entrySet)
  • Method Details

    • clone

      public Enchantment clone()
      Description copied from class: Entity
      Clone an entity, including its ID and location.

      Use this method for emulating an "immutable" view on an entity. This kind of cloning is not suitable for most gameplay situations, because using the clone will cause two entities with identical IDs and locations to exist. Instead, a subclass will provide a getCopy() method that is more helpful for gameplay.

      Specified by:
      clone in interface Trigger
      Overrides:
      clone in class Entity
      Returns:
      An exact clone.
    • getDefaultTriggers

      protected EventTriggerDesc[] getDefaultTriggers()
    • getEntityType

      public com.hiddenswitch.spellsource.rpc.Spellsource.EntityTypeMessage.EntityType getEntityType()
      Description copied from class: Entity
      Gets the type of entity this is. These will very nearly match up with the classes, but are primarily used for filters that e.g. draw a Spell or destroy all Secrets.
      Specified by:
      getEntityType in class Entity
      Returns:
      An Spellsource.EntityTypeMessage.EntityType
    • expire

      public void expire(GameContext context)
      Description copied from interface: Trigger
      Expires the trigger; marks it for removal and prevents it from executing in the future.
      Specified by:
      expire in interface Trigger
    • getHostReference

      public EntityReference getHostReference()
      Description copied from interface: Trigger
      Gets a reference to the Entity that is "hosting," or owning, the trigger.
      Specified by:
      getHostReference in interface Trigger
      Returns:
      An entity reference. This is typically not null.
    • getSpell

      public SpellDesc getSpell()
    • interestedIn

      public boolean interestedIn(com.hiddenswitch.spellsource.rpc.Spellsource.GameEventTypeMessage.GameEventType eventType)
      Description copied from interface: Trigger
      Returns true if this trigger is a listener for the given Spellsource.GameEventTypeMessage.GameEventType.
      Specified by:
      interestedIn in interface Trigger
      Parameters:
      eventType - The event type.
      Returns:
      true if this trigger wants its Trigger.onGameEvent(GameEvent) method called whenever it Trigger.queues(GameEvent) to the specified eventType.
    • isExpired

      public boolean isExpired()
      Description copied from interface: Trigger
      Checks if, due to the execution of possibly complex rules inside or outside the trigger, the trigger is expired (no longer should fire).
      Specified by:
      isExpired in interface Trigger
      Returns:
      true if the trigger should be removed and will no longer fire.
    • onAdd

      public void onAdd(GameContext context, Player player, Entity source, Entity host)
      Description copied from interface: Trigger
      Called when the trigger is added into a GameContext's state.
      Specified by:
      onAdd in interface Trigger
      Parameters:
      context - The game context.
    • process

      protected boolean process(int ownerId, SpellDesc spell, GameEvent event)
      Casts the effects of this enchantment.
      Parameters:
      ownerId -
      spell -
      event -
      Returns:
      true if processing succeeded.
    • cast

      protected void cast(int ownerId, SpellDesc spell, GameEvent event)
    • onGameEvent

      public void onGameEvent(GameEvent event)
      Description copied from interface: Trigger
      Specified by:
      onGameEvent in interface Trigger
      Parameters:
      event - The game event this trigger is now processing.
    • shouldNotifyEnchantmentFired

      protected boolean shouldNotifyEnchantmentFired(GameEvent event)
    • setHostReference

      public void setHostReference(EntityReference reference)
      Description copied from interface: Trigger
      Sets or changes the Entity that is the owner / host of this trigger.
      Specified by:
      setHostReference in interface Trigger
      Parameters:
      reference - The host Entity/
    • getCopy

      public Enchantment getCopy()
      Specified by:
      getCopy in class Entity
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • queues

      public final boolean queues(GameEvent event)
      Description copied from interface: Trigger
      Checks if a trigger should queue in response to a specific event.
      Specified by:
      queues in interface Trigger
      Parameters:
      event - A game event.
      Returns:
      true if the trigger should queue in response to this event.
    • innerQueues

      protected boolean innerQueues(GameEvent event, Entity host)
    • isPersistentOwner

      public boolean isPersistentOwner()
      Description copied from interface: Trigger
      Indicates this trigger cannot change owners. For example, a Secret does not have a persistent owner, because card texts can steal secrets. However, the trigger described by Blessing of Wisdom does have a persistent owner, since the casting player of that spell should always draw the card it receives.
      Specified by:
      isPersistentOwner in interface Trigger
      Returns:
      true if the trigger's Trigger.onGameEvent(GameEvent) should be evaluated from the point of view of the owner when the trigger was created, as opposed to what the owner is right now (which may have changed).
    • setPersistentOwner

      public void setPersistentOwner(boolean persistentOwner)
    • oneTurnOnly

      public boolean oneTurnOnly()
      Description copied from interface: Trigger
      Indicates this trigger is only active for the current turn, then it should Trigger.expire(GameContext).
      Specified by:
      oneTurnOnly in interface Trigger
      Returns:
      true if this is a one-turn long trigger.
    • fires

      public boolean fires(GameEvent event)
      Description copied from interface: Trigger
      Returns true if the trigger fire in response to the given GameEvent.

      It is already queued in this situation.

      Specified by:
      fires in interface Trigger
      Parameters:
      event - The currently raised event.
      Returns:
      true if the trigger can fire.
    • getSourceCard

      public Card getSourceCard()
      Specified by:
      getSourceCard in interface HasCard
      Overrides:
      getSourceCard in class Entity
    • getFires

      public int getFires()
    • getMaxFires

      public Integer getMaxFires()
    • setMaxFires

      public void setMaxFires(Integer maxFires)
    • setKeepAfterTransform

      public void setKeepAfterTransform(boolean keepAfterTransform)
    • isKeptAfterTransform

      public boolean isKeptAfterTransform()
    • setCountUntilCast

      public void setCountUntilCast(Integer countUntilCast)
    • getCountUntilCast

      public Integer getCountUntilCast()
    • setSpell

      public Enchantment setSpell(SpellDesc spell)
    • setCountByValue

      public void setCountByValue(boolean countByValue)
    • isCountByValue

      public boolean isCountByValue()
      Indicates that the HasValue.getValue() of the event should be used to increment the enchantment's counter (typically its fires) instead of the value 1 (i.e., every event that causes a trigger to fire increments the number of fires by 1).
      Returns:
      true if the enchantment increases its fires counter by the event's value.
    • getTriggers

      public List<EventTrigger> getTriggers()
      Get the triggers that fire this enchantment.
      Returns:
      A list of triggers.
    • setMaxFiresPerSequence

      public void setMaxFiresPerSequence(Integer maxFiresPerSequence)
    • getMaxFiresPerSequence

      public Integer getMaxFiresPerSequence()
    • endOfSequence

      public void endOfSequence()
      Signals to the enchantment that the currently processing sequence is over.
    • setTriggers

      public Enchantment setTriggers(List<EventTrigger> triggers)
    • setExpirationTriggers

      public void setExpirationTriggers(List<EventTrigger> expirationTriggers)
    • getExpirationTriggers

      public List<EventTrigger> getExpirationTriggers()
    • isActivated

      public boolean isActivated()
      Specified by:
      isActivated in interface Trigger
    • activate

      public void activate()
    • getActivationTriggers

      public List<EventTrigger> getActivationTriggers()
    • setActivationTriggers

      public void setActivationTriggers(List<EventTrigger> activationTriggers)
    • setActivated

      public Enchantment setActivated(boolean activated)
    • getZones

      public com.hiddenswitch.spellsource.rpc.Spellsource.ZonesMessage.Zones[] getZones()
    • setZones

      public Enchantment setZones(com.hiddenswitch.spellsource.rpc.Spellsource.ZonesMessage.Zones[] zones)
    • getDefaultZones

      protected com.hiddenswitch.spellsource.rpc.Spellsource.ZonesMessage.Zones[] getDefaultZones()
    • setOneTurn

      public Enchantment setOneTurn(boolean oneTurn)
    • getOneTurn

      public boolean getOneTurn()
    • setUsesSpellTrigger

      public void setUsesSpellTrigger(boolean usesSpellTrigger)
    • getUsesSpellTrigger

      public boolean getUsesSpellTrigger()
    • setFires

      protected Enchantment setFires(int fires)
    • getDefaultBattlefieldZones

      public static com.hiddenswitch.spellsource.rpc.Spellsource.ZonesMessage.Zones[] getDefaultBattlefieldZones()
    • getDefaultPassiveZones

      public static com.hiddenswitch.spellsource.rpc.Spellsource.ZonesMessage.Zones[] getDefaultPassiveZones()
    • getDefaultGameZones

      public static com.hiddenswitch.spellsource.rpc.Spellsource.ZonesMessage.Zones[] getDefaultGameZones()
    • getDefaultDeckZones

      public static com.hiddenswitch.spellsource.rpc.Spellsource.ZonesMessage.Zones[] getDefaultDeckZones()
    • getDefaultBattlefieldZonesSet

      public static Set<com.hiddenswitch.spellsource.rpc.Spellsource.ZonesMessage.Zones> getDefaultBattlefieldZonesSet()
    • isCopyToActor

      public boolean isCopyToActor()
    • setCopyToActor

      public Enchantment setCopyToActor(boolean giveToActor)
    • getEntrySet

      public HasEntrySet<?,?> getEntrySet()