Class Card
- All Implemented Interfaces:
Serializable
,Cloneable
,Comparable<Entity>
,HasChooseOneActions
,HasCard
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 net.demilich.metastone.game.entities.minions.Minion summoned from the hand, this typically corresponds to a Card in the com.hiddenswitch.spellsource.rpc.Spellsource.ZonesMessage.Zones#GRAVEYARD. This saves you from doing many kinds of casts for net.demilich.metastone.game.entities.Actor objects.
for the class that is the base of the serialized representation of cards.
- Serialized Form
-
Field Summary
Modifier and TypeFieldDescriptionFields inherited from class net.demilich.metastone.game.entities.Entity
attributes, effectSource, entityLocation, name, NO_OWNER, sourceCard
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionvoid
Applies the actor'sAttribute.RACE
to the specified instanceboolean
canBeCast
(GameContext context, Player player) Indicates whether this spell can be cast generally, given its target selection.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.clone()
Clones a card's base fields, like name and description, and its current attributes.int
int
getArmor()
int
Gets the complete attribute map reference (not a copy).int
int
int
int
int
The base mana cost of a card.getBattlecryDescription
(int index) getBattlecryName
(int index) int
int
int
int
Gets the card's ID as it corresponds to the card catalogue.Gets the set that the card belongs to.String[]
Gets the sets that this card lists.com.hiddenswitch.spellsource.rpc.Spellsource.CardTypeMessage.CardType
Gets the card type, like Hero, Secret, Spell or Minion.Gets the card ID of the card that executes both choose one effects for this choose one card.Retreives the battlecries of the choices corresponding to this choose one actor.String[]
Retrieves the card IDs of the choices corresponding to this choose one spell.Gets the condition written on this card.getCopy()
Gets a copy of the card with some attributes like its attack or HP bonuses and mana cost modifiers removed.int
Returns the triggers that are active when the card is in the deck.getDesc()
Gets the originalCardDesc
that was used to create this card or the desc of the card described by theCardAttributeMap.getOverrideCardId()
overridden card ID.Gets a cleaned up description of the card.int
com.hiddenswitch.spellsource.rpc.Spellsource.EntityTypeMessage.EntityType
Gets the type of entity this is.getGroup()
getHero()
For aSpellsource.CardTypeMessage.CardType.CLASS
, specifies the default hero (champion).Gets the hero class that this card belongs to.String[]
Some cards have multiple hero classes.int
getHp()
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.int
getManaCostModification
(GameContext context, Player player) Computes the modificatation of this card's built in mana cost modifier for a given context / player.protected ValueProvider
getName()
Determines how this card should be named.Gets the card ID of theCardDesc
that was originally used to create this instance.Retrieves the card's triggers that are active while the card is in theSpellsource.ZonesMessage.Zones.HAND
orSpellsource.ZonesMessage.Zones.HERO_POWER
.@NotNull String
getRace()
Gets the race of a card.com.hiddenswitch.spellsource.rpc.Spellsource.RarityMessage.Rarity
A rarity of the card.The card source of a card is itself.getSpell()
Retrieves the spell effects for this card.Retrieves the card's target requirements.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.boolean
hasAura()
boolean
int
Indicates if this card was used.boolean
Does this card have both choose one options?boolean
boolean
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.boolean
Indicates the card has effects that need to be persisted to a database between matches.boolean
hero()
Creates a hero entity from the text on the card.boolean
isActor()
Indicates this card plays an actor, like a minion, weapon or hero, from the hand.boolean
boolean
Collectible cards can be put into decks.boolean
boolean
isQuest()
Returnstrue
if this is a quest.boolean
isSecret()
Returnstrue
if this card is a secret.boolean
isSpell()
void
markUsed()
Marks this card as used.minion()
Creates a minion from the attributes written on the card.play()
Create an action representing playing the card.@Nullable PlayCardAction
Returns the action that executes both choose ones for this spell or actor card.@NotNull PlayCardAction[]
Retrieves the play options from choose one cards.void
processTargetSelectionOverride
(GameContext context, Player player) Determines if the card's target selection ought to be overrided, and does so via applying or removingAttribute.TARGET_SELECTION
on the card.void
void
setHeroClass
(String heroClass) void
setTargetRequirement
(TargetSelection targetRequirement) void
setTargetSelectionCondition
(ConditionDesc targetSelectionCondition) void
setTargetSelectionOverride
(TargetSelection targetSelectionOverride) void
setUsed
(int used) toString()
weapon()
Gets the weapon equipped by aEquipWeaponSpell
in this hero's battlecry.Methods inherited from class net.demilich.metastone.game.entities.Entity
diedOnBattlefield, evaluateDescriptions, getAttribute, getAttributeValue, getAttributeValue, getCardInventoryId, getCopySource, getDescription, getDynamicDescription, getEffectSource, getEntityLocation, getGameTriggers, getId, getIndex, getMaxNumberOfAttacks, getOwner, getReference, getUserId, getZone, hasAttribute, isDestroyed, isInPlay, isRemovedPeacefully, modifyAttribute, modifyHpBonus, moveOrAddTo, moveOrAddTo, resetEntityLocations, setAttribute, setAttribute, setAttribute, setDescription, setEffectSource, setEntityLocation, setId, setName, setOwner, setSourceCard, setUserId, transformResolved, transformResolved
-
Field Details
-
IGNORED_MINION_ATTRIBUTES
-
HERO_ATTRIBUTES
-
-
Constructor Details
-
Card
protected Card() -
Card
Creates a card from a description of a card.- Parameters:
desc
- The Card description.
-
-
Method Details
-
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. TheAttribute.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
Creates a hero entity from the text on the card. Works similarly tominion()
, except for heroes.- Returns:
- A new hero instance.
-
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. -
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
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
Gets the card ID of theCardDesc
that was originally used to create this instance.- Returns:
-
getHero
For aSpellsource.CardTypeMessage.CardType.CLASS
, specifies the default hero (champion).- Returns:
-
getCardSet
Gets the set that the card belongs to.- Returns:
- The card set
-
getCardSets
Gets the sets that this card lists.- Returns:
- The card sets
-
getCardType
public com.hiddenswitch.spellsource.rpc.Spellsource.CardTypeMessage.CardType getCardType()Gets the card type, like Hero, Secret, Spell or Minion.- Returns:
- The card type
-
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
-
getHeroClasses
Some cards have multiple hero classes. This field stores those multiple classes when they are defined.- Returns:
- The hero classes (the gang)
-
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);
-
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 classEntity
- Returns:
- The value of the
Attribute.DESCRIPTION
on thisCard
, if it is not null. Otherwise, theCardDesc.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 classEntity
- Returns:
- An
Spellsource.EntityTypeMessage.EntityType
-
getManaCost
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
- TheGameContext
to compute the cost against.player
- ThePlayer
whose point of view should be considered for the cost. This is almost always the owner.- Returns:
- The cost.
- See Also:
-
getManaCostModification
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
- TheGameContext
to compute the cost modification against.player
- ThePlayer
whose point of view should be considered, i.e. the owner.- Returns:
- The cost modfication
-
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; andSpellsource.RarityMessage.Rarity.LEGENDARY
cards can only appear once in a deck.- Returns:
- A
Spellsource.RarityMessage.Rarity
-
getRace
Gets the race of a card. Typically only applies toCard
that summon minions when played. -
hasHeroClass
Checks if the hero class specified is in its list of hero classes when this card belongs to multiple hero classes.- Parameters:
heroClass
- TheHeroClass
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
Create an action representing playing the card.- Returns:
- An action that should be evaluated by
GameLogic.performGameAction(int, GameAction)
.
-
hasChoices
public boolean hasChoices() -
toString
-
getDesc
Gets the originalCardDesc
that was used to create this card or the desc of the card described by theCardAttributeMap.getOverrideCardId()
overridden card ID. Modifying this description does not modify the card, and theCardDesc
may be referenced by multiple instances ofCard
.- Returns:
- A
CardDesc
-
getNonOverriddenDesc
- Returns:
-
getSourceCard
The card source of a card is itself.- Specified by:
getSourceCard
in interfaceHasCard
- Overrides:
getSourceCard
in classEntity
- Returns:
- A reference to this instance.
-
getPassiveTriggers
Retrieves the card's triggers that are active while the card is in theSpellsource.ZonesMessage.Zones.HAND
orSpellsource.ZonesMessage.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 classEntity
- Returns:
true
if the card has effects that need to be persisted- See Also:
-
getDeckTriggers
Returns the triggers that are active when the card is in the deck.- Returns:
- A list of
EnchantmentDesc
objects.
-
setDesc
-
getSpell
Retrieves the spell effects for this card. Secrets and quests automatically wrap their effects in aAddSecretSpell
andAddQuestSpell
.- Returns:
- The spell
-
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
Determines if the card's target selection ought to be overrided, and does so via applying or removingAttribute.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
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 interfaceHasChooseOneActions
- Returns:
- The play options array of length 2
-
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
Retreives the battlecries of the choices corresponding to this choose one actor.- Returns:
- The battlecry array of length 2
-
playBothOptions
Returns the action that executes both choose ones for this spell or actor card.- Specified by:
playBothOptions
in interfaceHasChooseOneActions
- Returns:
- The action
-
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 interfaceHasChooseOneActions
- Returns:
true
if this card specified a choose both action.
-
weapon
Gets the weapon equipped by aEquipWeaponSpell
in this hero's battlecry.- Returns:
- A weapon card, or
null
if none was found.
-
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.- Returns:
- The weapon card
-
canBeCast
Indicates whether this spell can be cast generally, given its target selection. Does not provide logical answers for non-spell cards (returnstrue
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()Returnstrue
if this is a quest.- Returns:
-
canBeCastOn
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
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 forSpellsource.CardTypeMessage.CardType.HERO_POWER
cards.- Returns:
-
markUsed
public void markUsed()Marks this card as used. Typically intended only forSpellsource.CardTypeMessage.CardType.HERO_POWER
cards. -
setUsed
public void setUsed(int used) -
applyRace
Applies the actor'sAttribute.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
-
getBattlecryName
-
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
-
setTargetRequirement
-
isSecret
public boolean isSecret()Returnstrue
if this card is a secret.- Returns:
-
isSpell
public boolean isSpell() -
isChooseOne
public boolean isChooseOne() -
getName
Determines how this card should be named.- Overrides:
getName
in classEntity
- Returns:
- The value of the
Attribute.NAME
attribute, or the underlyingCardDesc.getName()
field.
-
getAttributes
Description copied from class:Entity
Gets the complete attribute map reference (not a copy). This can be mutated like a normalMap
.- Overrides:
getAttributes
in classEntity
- Returns:
- The
AttributeMap
.
-
isHeroPower
public boolean isHeroPower() -
compareTo
- Specified by:
compareTo
in interfaceComparable<Entity>
- Overrides:
compareTo
in classEntity
-
getTargetSelectionCondition
-
getTargetSelectionOverride
-
setTargetSelectionCondition
-
setTargetSelectionOverride
-