Class Card

All Implemented Interfaces:
Serializable, Cloneable, 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:
  • Field Details


      public static final Set<Attribute> IGNORED_MINION_ATTRIBUTES

      protected static final Set<Attribute> HERO_ATTRIBUTES
  • Constructor Details

    • Card

      protected Card()
    • Card

      public Card(CardDesc desc)
      Creates a card from a description of a card.
      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.

      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.
      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.
      clone in class Entity
      An exact clone.
    • getBaseManaCost

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

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

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

      public String getHero()
      For a Spellsource.CardTypeMessage.CardType.CLASS, specifies the default hero (champion).
    • getCardSet

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

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

      public com.hiddenswitch.spellsource.rpc.Spellsource.CardTypeMessage.CardType getCardType()
      Gets the card type, like Hero, Secret, Spell or Minion.
      The card type
    • getHeroClass

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

      public void setHeroClass(String heroClass)
    • getHeroClasses

      public String[] getHeroClasses()
      Some cards have multiple hero classes. This field stores those multiple classes when they are defined.
      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
      A copy of the card with no ID or owner (and therefore no location).
    • getDescription

      public 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.
      getDescription in class Entity
      The value of the Attribute.DESCRIPTION on this Card, if it is not null. Otherwise, the CardDesc.getDescription() field.
    • 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
      An Spellsource.EntityTypeMessage.EntityType
    • getManaCost

      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.

      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.
      The cost.
      See Also:
    • getManaCostModification

      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.
      context - The GameContext to compute the cost modification against.
      player - The Player whose point of view should be considered, i.e. the owner.
      The cost modfication
    • getManaCostModifier

      protected ValueProvider getManaCostModifier()
    • getRarity

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

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

      public boolean hasHeroClass(String heroClass)
      Checks if the hero class specified is in its list of hero classes when this card belongs to multiple hero classes.
      heroClass - The HeroClass to search.
      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.

      True if the card is collectible.
    • play

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

      public boolean hasChoices()
    • toString

      public String toString()
      toString in class 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.
      A CardDesc
    • getNonOverriddenDesc

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

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

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

      public boolean hasPersistentEffects()
      Indicates the card has effects that need to be persisted to a database between matches.
      hasPersistentEffects in class Entity
      true if the card has effects that need to be persisted
      See Also:
    • getDeckTriggers

      public EnchantmentDesc[] getDeckTriggers()
      Returns the triggers that are active when the card is in the deck.
      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.
      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.

      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.
      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
      The play options array of length 2
    • getChooseOneCardIds

      public String[] getChooseOneCardIds()
      Retrieves the card IDs of the choices corresponding to this choose one spell.
      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.
      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
      The action
    • getChooseBothCardId

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

      public boolean hasBothOptions()
      Does this card have both choose one options?
      Specified by:
      hasBothOptions in interface HasChooseOneActions
      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.
      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 Spellsource.CardTypeMessage.CardType.HERO while the card is in the player's hand/deck.

      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.

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

      public boolean isQuest()
      Returns true if this is a quest.
    • 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.

      context -
      player -
      target -
    • getCondition

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

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

      public void markUsed()
      Marks this card as used. Typically intended only for Spellsource.CardTypeMessage.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
      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 String getBattlecryDescription(int index)
    • getBattlecryName

      public 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.
    • isSpell

      public boolean isSpell()
    • isChooseOne

      public boolean isChooseOne()
    • getName

      public String getName()
      Determines how this card should be named.
      getName in class Entity
      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.
      getAttributes in class Entity
      The AttributeMap.
    • isHeroPower

      public boolean isHeroPower()
    • compareTo

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

      public ConditionDesc getTargetSelectionCondition()
    • getTargetSelectionOverride

      public TargetSelection getTargetSelectionOverride()
    • setTargetSelectionCondition

      public void setTargetSelectionCondition(ConditionDesc targetSelectionCondition)
    • setTargetSelectionOverride

      public void setTargetSelectionOverride(TargetSelection targetSelectionOverride)