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
FieldsModifier and TypeFieldDescriptionFields inherited from class net.demilich.metastone.game.entities.Entity
attributes, effectSource, entityLocation, name, NO_OWNER, sourceCard -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidApplies the actor'sAttribute.RACEto the specified instancebooleancanBeCast(GameContext context, Player player) Indicates whether this spell can be cast generally, given its target selection.booleancanBeCastOn(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.intintgetArmor()intGets the complete attribute map reference (not a copy).intintintintintThe base mana cost of a card.getBattlecryDescription(int index) getBattlecryName(int index) intintintintGets 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.CardTypeGets 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.intReturns the triggers that are active when the card is in the deck.getDesc()Gets the originalCardDescthat 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.intcom.hiddenswitch.spellsource.rpc.Spellsource.EntityTypeMessage.EntityTypeGets 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.intgetHp()intgetManaCost(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.intgetManaCostModification(GameContext context, Player player) Computes the modificatation of this card's built in mana cost modifier for a given context / player.protected ValueProvidergetName()Determines how this card should be named.Gets the card ID of theCardDescthat was originally used to create this instance.Retrieves the card's triggers that are active while the card is in theSpellsource.ZonesMessage.Zones.HANDorSpellsource.ZonesMessage.Zones.HERO_POWER.@NotNull StringgetRace()Gets the race of a card.com.hiddenswitch.spellsource.rpc.Spellsource.RarityMessage.RarityA 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.booleanhasAura()booleanintIndicates if this card was used.booleanDoes this card have both choose one options?booleanbooleanbooleanhasHeroClass(String heroClass) Checks if the hero class specified is in its list of hero classes when this card belongs to multiple hero classes.booleanIndicates the card has effects that need to be persisted to a database between matches.booleanhero()Creates a hero entity from the text on the card.booleanisActor()Indicates this card plays an actor, like a minion, weapon or hero, from the hand.booleanbooleanCollectible cards can be put into decks.booleanbooleanisQuest()Returnstrueif this is a quest.booleanisSecret()Returnstrueif this card is a secret.booleanisSpell()voidmarkUsed()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 PlayCardActionReturns the action that executes both choose ones for this spell or actor card.@NotNull PlayCardAction[]Retrieves the play options from choose one cards.voidprocessTargetSelectionOverride(GameContext context, Player player) Determines if the card's target selection ought to be overrided, and does so via applying or removingAttribute.TARGET_SELECTIONon the card.voidvoidsetHeroClass(String heroClass) voidsetTargetRequirement(TargetSelection targetRequirement) voidsetTargetSelectionCondition(ConditionDesc targetSelectionCondition) voidsetTargetSelectionOverride(TargetSelection targetSelectionOverride) voidsetUsed(int used) toString()weapon()Gets the weapon equipped by aEquipWeaponSpellin 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_ATTRIBUTESare copied onto the minion created here. TheAttribute.REMOVES_SELF_AT_END_OF_TURNattribute 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 theCardDescthat 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:
getDescriptionin classEntity- Returns:
- The value of the
Attribute.DESCRIPTIONon thisCard, if it is not null. Otherwise, theCardDesc.getDescription()field.
-
getEntityType
public com.hiddenswitch.spellsource.rpc.Spellsource.EntityTypeMessage.EntityType getEntityType()Description copied from class:EntityGets 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:
getEntityTypein 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- TheGameContextto compute the cost against.player- ThePlayerwhose 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- TheGameContextto compute the cost modification against.player- ThePlayerwhose 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.LEGENDARYcards can only appear once in a deck.- Returns:
- A
Spellsource.RarityMessage.Rarity
-
getRace
Gets the race of a card. Typically only applies toCardthat 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- TheHeroClassto search.- Returns:
Trueif 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
ReturnTargetToHandSpellcan create a card that represents a minion.- Returns:
Trueif 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 originalCardDescthat 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 theCardDescmay be referenced by multiple instances ofCard.- Returns:
- A
CardDesc
-
getNonOverriddenDesc
- Returns:
-
getSourceCard
The card source of a card is itself.- Specified by:
getSourceCardin interfaceHasCard- Overrides:
getSourceCardin classEntity- Returns:
- A reference to this instance.
-
getPassiveTriggers
Retrieves the card's triggers that are active while the card is in theSpellsource.ZonesMessage.Zones.HANDorSpellsource.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:
hasPersistentEffectsin classEntity- Returns:
trueif 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
EnchantmentDescobjects.
-
setDesc
-
getSpell
Retrieves the spell effects for this card. Secrets and quests automatically wrap their effects in aAddSecretSpellandAddQuestSpell.- 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_SELECTIONon the card. -
isActor
public boolean isActor()Indicates this card plays an actor, like a minion, weapon or hero, from the hand.- Returns:
trueif 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:
playOptionsin 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:
playBothOptionsin 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:
hasBothOptionsin interfaceHasChooseOneActions- Returns:
trueif this card specified a choose both action.
-
weapon
Gets the weapon equipped by aEquipWeaponSpellin this hero's battlecry.- Returns:
- A weapon card, or
nullif 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.HEROwhile 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 (returnstruein such cases).Will return
trueeven if the player isn't the owner of this card.- Parameters:
context-player-- Returns:
trueif the card can be cast
-
isQuest
public boolean isQuest()Returnstrueif 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_POWERcards.- Returns:
-
markUsed
public void markUsed()Marks this card as used. Typically intended only forSpellsource.CardTypeMessage.CardType.HERO_POWERcards. -
setUsed
public void setUsed(int used) -
applyRace
Applies the actor'sAttribute.RACEto 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()Returnstrueif this card is a secret.- Returns:
-
isSpell
public boolean isSpell() -
isChooseOne
public boolean isChooseOne() -
getName
Determines how this card should be named.- Overrides:
getNamein classEntity- Returns:
- The value of the
Attribute.NAMEattribute, or the underlyingCardDesc.getName()field.
-
getAttributes
Description copied from class:EntityGets the complete attribute map reference (not a copy). This can be mutated like a normalMap.- Overrides:
getAttributesin classEntity- Returns:
- The
AttributeMap.
-
isHeroPower
public boolean isHeroPower() -
compareTo
- Specified by:
compareToin interfaceComparable<Entity>- Overrides:
compareToin classEntity
-
getTargetSelectionCondition
-
getTargetSelectionOverride
-
setTargetSelectionCondition
-
setTargetSelectionOverride
-