Class Card

All Implemented Interfaces:
java.io.Serializable, java.lang.Cloneable, java.lang.Comparable<Entity>, HasChooseOneActions, HasCard

public class Card
extends Entity
implements HasChooseOneActions
The Card class is an entity that contains card information.

Cards are typically in the hand, deck or graveyard. They are playable from the hand or as hero powers. They may be created by other cards. Like all entities, they have attributes and are mutable.

See Also:
for a way to retrieve the card that backs an entity. For a summoned from the hand, this typically corresponds to a in the . This saves you from doing many kinds of casts for objects., for the class that is the base of the serialized representation of cards., Serialized Form
  • Field Details

  • Constructor Details

    • Card

      protected Card()
    • Card

      public Card​(CardDesc desc)
      Creates a card from a description of a card.
      Parameters:
      desc - The Card description.
  • Method Details

    • minion

      public Minion minion()
      Creates a minion from the attributes written on the card.

      By default, all the attributes written on the card except those contained in IGNORED_MINION_ATTRIBUTES are copied onto the minion created here. The Attribute.REMOVES_SELF_AT_END_OF_TURN attribute is also removed if it was present on the card.

      Text is applied using the applyRace(Actor) method, which works for all actors.

      Returns:
      A new Minion instance.
    • hero

      public Hero hero()
      Creates a hero entity from the text on the card. Works similarly to minion(), except for heroes.
      Returns:
      A new hero instance.
    • clone

      public Card clone()
      Clones a card's base fields, like name and description, and its current attributes. The entity ID and location match the source object and are not cleared. getCopy() is typically more appropriate choice for when copies of cards are needed.
      Overrides:
      clone in class Entity
      Returns:
      An exact clone.
    • getBaseManaCost

      public int getBaseManaCost()
      The base mana cost of a card. This is the cost that's written on the card.
      Returns:
      The base mana cost of a card.
    • getCardId

      public java.lang.String getCardId()
      Gets the card's ID as it corresponds to the card catalogue. This is the base definition of the card.
      Returns:
      The card ID as set by an aura, a permanent effect or in the description.
    • getOriginalCardId

      public java.lang.String getOriginalCardId()
      Gets the card ID of the CardDesc that was originally used to create this instance.
      Returns:
    • getHero

      public java.lang.String getHero()
      For a CardType.CLASS, specifies the default hero (champion).
      Returns:
    • getCardSet

      public java.lang.String getCardSet()
      Gets the set that the card belongs to.
      Returns:
      The card set
    • getCardSets

      public java.lang.String[] getCardSets()
      Gets the sets that this card lists.
      Returns:
      The card sets
    • getCardType

      public com.hiddenswitch.spellsource.client.models.CardType getCardType()
      Gets the card type, like Hero, Secret, Spell or Minion.
      Returns:
      The card type
    • getHeroClass

      public java.lang.String getHeroClass()
      Gets the hero class that this card belongs to. Valid classes include ANY (neutral) or any of the main 9 classes.
      Returns:
      The hero class
    • setHeroClass

      public void setHeroClass​(java.lang.String heroClass)
    • getHeroClasses

      public java.lang.String[] getHeroClasses()
      Some cards have multiple hero classes. This field stores those multiple classes when they are defined.
      Returns:
      The hero classes (the gang)
    • getCopy

      public Card getCopy()
      Gets a copy of the card with some attributes like its attack or HP bonuses and mana cost modifiers removed. The ID and owner is set to unassigned.

      Typically you should use the GameLogic.receiveCard(int, Card) method in order to put a copy into e.g. the player's hand.

      Take a look at its logic to see how to assign an ID and an owner to a card for other uses of copies. A copy can become valid for play like this: Card copiedCard = card.getCopy(); int owningPlayer = player.getId(); copiedCard.setId(getGameLogic().getIdFactory().generateId(); copiedCard.setOwner(owningPlayer); <p> // Add to an appropriate zone. For example, to add the card to the end of the owning player's deck... context.getPlayer(owningPlayer).getDeck().add(copiedCard);

      Specified by:
      getCopy in class Entity
      Returns:
      A copy of the card with no ID or owner (and therefore no location).
    • getDescription

      public java.lang.String getDescription()
      Gets a cleaned up description of the card. In the future, this description should "fill in the blanks" for cards that have variables, like which minion will be summoned or how much spell damage the spell will deal.
      Overrides:
      getDescription in class Entity
      Returns:
      The value of the Attribute.DESCRIPTION on this Card, if it is not null. Otherwise, the CardDesc.getDescription() field.
    • getEntityType

      public com.hiddenswitch.spellsource.client.models.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 EntityType
    • getManaCost

      @Suspendable public int getManaCost​(GameContext context, Player player)
      Gets the mana cost of this card from the point of view of the specified card, player and a given context. Does NOT consider the effect of card cost modifiers.

      Costs can be modified lots of different ways, so this method ensures the cost is calculate considering all the rules that are on the board.

      Parameters:
      context - The GameContext to compute the cost against.
      player - The Player whose point of view should be considered for the cost. This is almost always the owner.
      Returns:
      The cost.
      See Also:
      for the best method to get the cost of a card.
    • getManaCostModification

      @Suspendable public int getManaCostModification​(GameContext context, Player player)
      Computes the modificatation of this card's built in mana cost modifier for a given context / player. Positive numbers are a reduction in cost, while negative numbers are an increase, so the result of this method should usually be subtracted.
      Parameters:
      context - The GameContext to compute the cost modification against.
      player - The Player whose point of view should be considered, i.e. the owner.
      Returns:
      The cost modfication
    • getManaCostModifier

      protected ValueProvider getManaCostModifier()
    • getRarity

      public com.hiddenswitch.spellsource.client.models.Rarity getRarity()
      A rarity of the card. Rarer cards are generally more powerful; they appear in card packs less frequently; and Rarity.LEGENDARY cards can only appear once in a deck.
      Returns:
      A Rarity
    • getRace

      @NotNull public @NotNull java.lang.String getRace()
      Gets the race of a card. Typically only applies to Card that summon minions when played.
      Overrides:
      getRace in class Entity
      Returns:
      A Race
    • hasHeroClass

      public boolean hasHeroClass​(java.lang.String heroClass)
      Checks if the hero class specified is in its list of hero classes when this card belongs to multiple hero classes.
      Parameters:
      heroClass - The HeroClass to search.
      Returns:
      True if this card has the specified class.
    • isCollectible

      public boolean isCollectible()
      Collectible cards can be put into decks. Non-collectible cards are typically either "tokens," or cards that are spawned by other cards, or narrative cards.

      Even though tokens are almost always minions, effects like ReturnTargetToHandSpell can create a card that represents a minion.

      Returns:
      True if the card is collectible.
    • play

      @Suspendable public PlayCardAction play()
      Create an action representing playing the card.
      Returns:
      An action that should be evaluated by GameLogic.performGameAction(int, GameAction).
    • hasChoices

      public boolean hasChoices()
    • toString

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

      public CardDesc getDesc()
      Gets the original CardDesc that was used to create this card or the desc of the card described by the CardAttributeMap.getOverrideCardId() overridden card ID. Modifying this description does not modify the card, and the CardDesc may be referenced by multiple instances of Card.
      Returns:
      A CardDesc
    • getNonOverriddenDesc

      public CardDesc getNonOverriddenDesc()
      Returns the CardDesc ignoring the Attribute.AURA_CARD_ID and Attribute.CARD_ID values.
      Returns:
    • getSourceCard

      public Card getSourceCard()
      The card source of a card is itself.
      Specified by:
      getSourceCard in interface HasCard
      Overrides:
      getSourceCard in class Entity
      Returns:
      A reference to this instance.
    • getPassiveTriggers

      public EnchantmentDesc[] getPassiveTriggers()
      Retrieves the card's triggers that are active while the card is in the Zones.HAND or Zones.HERO_POWER.
      Returns:
      The triggers
    • hasPersistentEffects

      public boolean hasPersistentEffects()
      Indicates the card has effects that need to be persisted to a database between matches.
      Overrides:
      hasPersistentEffects in class Entity
      Returns:
      true if the card has effects that need to be persisted
      See Also:
      for an example of a persistent attribute that needs to be stored between matches.
    • getDeckTriggers

      public EnchantmentDesc[] getDeckTriggers()
      Returns the triggers that are active when the card is in the deck.
      Returns:
      A list of EnchantmentDesc objects.
    • setDesc

      public void setDesc​(CardDesc desc)
    • getSpell

      public SpellDesc getSpell()
      Retrieves the spell effects for this card. Secrets and quests automatically wrap their effects in a AddSecretSpell and AddQuestSpell.
      Returns:
      The spell
    • getTargetSelection

      public TargetSelection getTargetSelection()
      Retrieves the card's target requirements.

      This method does not return a reasonable answer for non-spell cards. While a minion card's target requirement is technically friendly minions, it can be played even if there is no friendly minion on the board.

      Returns:
      The target requirements
    • processTargetSelectionOverride

      public void processTargetSelectionOverride​(GameContext context, Player player)
      Determines if the card's target selection ought to be overrided, and does so via applying or removing Attribute.TARGET_SELECTION on the card.
    • isActor

      public boolean isActor()
      Indicates this card plays an actor, like a minion, weapon or hero, from the hand.
      Returns:
      true if this is an actor card
    • playOptions

      @NotNull public @NotNull PlayCardAction[] playOptions()
      Retrieves the play options from choose one cards. If the card is not actually a choose one card, it returns an empty array.
      Specified by:
      playOptions in interface HasChooseOneActions
      Returns:
      The play options array of length 2
    • getChooseOneCardIds

      public java.lang.String[] getChooseOneCardIds()
      Retrieves the card IDs of the choices corresponding to this choose one spell.
      Returns:
      The array of card IDs of the choices of length 2
    • getChooseOneBattlecries

      public OpenerDesc[] getChooseOneBattlecries()
      Retreives the battlecries of the choices corresponding to this choose one actor.
      Returns:
      The battlecry array of length 2
    • playBothOptions

      @Nullable public @Nullable PlayCardAction playBothOptions()
      Returns the action that executes both choose ones for this spell or actor card.
      Specified by:
      playBothOptions in interface HasChooseOneActions
      Returns:
      The action
    • getChooseBothCardId

      public java.lang.String getChooseBothCardId()
      Gets the card ID of the card that executes both choose one effects for this choose one card.
      Returns:
      The card ID
    • hasBothOptions

      public boolean hasBothOptions()
      Does this card have both choose one options?
      Specified by:
      hasBothOptions in interface HasChooseOneActions
      Returns:
      true if this card specified a choose both action.
    • weapon

      public Weapon weapon()
      Gets the weapon equipped by a EquipWeaponSpell in this hero's battlecry.
      Returns:
      A weapon card, or null if none was found.
    • getWeapon

      public Card getWeapon()
      Gets the weapon that is equipped as a side-effect of playing this actor from the hand, not the underlying weapon actor represented by playing this card.

      Useful for determining the "attack" of a CardType.HERO while the card is in the player's hand/deck.

      Returns:
      The weapon card
    • canBeCast

      public boolean canBeCast​(GameContext context, Player player)
      Indicates whether this spell can be cast generally, given its target selection. Does not provide logical answers for non-spell cards (returns true in such cases).

      Will return true even if the player isn't the owner of this card.

      Parameters:
      context -
      player -
      Returns:
      true if the card can be cast
    • isQuest

      public boolean isQuest()
      Returns true if this is a quest.
      Returns:
    • canBeCastOn

      public boolean canBeCastOn​(GameContext context, Player player, Entity target)
      Given the filter written on this card, indicates whether this spell can be cast on the specified target.

      Used for rolling out actions.

      Parameters:
      context -
      player -
      target -
      Returns:
    • getCondition

      public ConditionDesc getCondition()
      Gets the condition written on this card. Cards with failed conditions cannot be played.
      Returns:
    • hasBeenUsed

      public int hasBeenUsed()
      Indicates if this card was used. Typically intended only for CardType.HERO_POWER cards.
      Returns:
    • markUsed

      public void markUsed()
      Marks this card as used. Typically intended only for CardType.HERO_POWER cards.
    • setUsed

      public void setUsed​(int used)
    • applyRace

      public void applyRace​(Actor instance)
      Applies the actor's Attribute.RACE to the specified instance
      Parameters:
      instance -
    • getAttack

      public int getAttack()
    • getBonusAttack

      public int getBonusAttack()
    • getHp

      public int getHp()
    • getBonusHp

      public int getBonusHp()
    • getBaseAttack

      public int getBaseAttack()
    • getBaseHp

      public int getBaseHp()
    • hasTrigger

      public boolean hasTrigger()
    • hasAura

      public boolean hasAura()
    • hasCardCostModifier

      public boolean hasCardCostModifier()
    • hasBattlecry

      public boolean hasBattlecry()
    • getBattlecryDescription

      public java.lang.String getBattlecryDescription​(int index)
    • getBattlecryName

      public java.lang.String getBattlecryName​(int index)
    • getDamage

      public int getDamage()
    • getBonusDamage

      public int getBonusDamage()
    • getDurability

      public int getDurability()
    • getBonusDurability

      public int getBonusDurability()
    • getBaseDamage

      public int getBaseDamage()
    • getBaseDurability

      public int getBaseDurability()
    • getArmor

      public int getArmor()
    • getGroup

      public SpellDesc[] getGroup()
    • setTargetRequirement

      public void setTargetRequirement​(TargetSelection targetRequirement)
    • isSecret

      public boolean isSecret()
      Returns true if this card is a secret.
      Returns:
    • isSpell

      public boolean isSpell()
    • isChooseOne

      public boolean isChooseOne()
    • getName

      public java.lang.String getName()
      Determines how this card should be named.
      Overrides:
      getName in class Entity
      Returns:
      The value of the Attribute.NAME attribute, or the underlying CardDesc.getName() field.
    • getAttributes

      public CardAttributeMap getAttributes()
      Description copied from class: Entity
      Gets the complete attribute map reference (not a copy). This can be mutated like a normal Map.
      Overrides:
      getAttributes in class Entity
      Returns:
      The AttributeMap.
    • isHeroPower

      public boolean isHeroPower()
    • compareTo

      public int compareTo​(@NotNull @NotNull Entity o)
      Specified by:
      compareTo in interface java.lang.Comparable<Entity>
      Overrides:
      compareTo in class Entity
    • getTargetSelectionCondition

      public ConditionDesc getTargetSelectionCondition()
    • getTargetSelectionOverride

      public TargetSelection getTargetSelectionOverride()
    • setTargetSelectionCondition

      public void setTargetSelectionCondition​(ConditionDesc targetSelectionCondition)
    • setTargetSelectionOverride

      public void setTargetSelectionOverride​(TargetSelection targetSelectionOverride)