Class Entity
- All Implemented Interfaces:
Serializable,Cloneable,Comparable<Entity>,HasCard
- Direct Known Subclasses:
Actor,Card,Enchantment,Player
Entities are targetable objects in a match. The player, hero, hero power card, minions, cards in hand, cards in deck, cards in graveyard, secrets and certain kinds of triggers are all entities.
Entities are only created, never destroyed. Entities have a EntityLocation; each location (index, zone and
player) can have only one entity occupying it at any time. Destroyed entities go to the Spellsource.ZonesMessage.Zones.GRAVEYARD or
Spellsource.ZonesMessage.Zones.REMOVED_FROM_PLAY zone. EntityZone lists located in the Player objects are reponsible
for making sure entities are in only one place at a time.
Entities all have attributes, which contain their state. As simple maps, entity attributes can be manipulated, copied, etc. Most effects interact with an entity's attributes.
Entities are mutable. Use clone() to create an "immutable" view of an entity. However, for effects that need
copies of entities, typically a getCopy() method is used, like Card.getCopy().
This entity class will contain all the game engine information. It is not suitable to show to clients directly,
because it may contain information that should be secret from an opponent. For example, Secret entities should have their description or card IDs visible
to their opponents.
- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected AttributeMapprotected Entityprotected EntityLocationprotected Stringstatic final intThe value for theownerIndexwhen no owner has been assigned.protected Card -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionclone()Clone an entity, including its ID and location.intbooleanIndicates whether the minion died a natural death (not removed peacefully, not removed by spells, not a permanent) on the battlefield.String[]evaluateDescriptions(GameContext context, Player player) getAttribute(Attribute attribute) Gets the specified attribute.Gets the complete attribute map reference (not a copy).intgetAttributeValue(Attribute attribute) Gets the specified attribute as anIntegervalue or0if the specified attribute is of the wrong type or is not found.intgetAttributeValue(Attribute attribute, int defaultValue) Gets the specified attribute as anIntegervalue, defaulting to the specified value if the value is not an integer.Gets the card's inventory ID (unique instance of the card).abstract EntitygetCopy()Gets a reference to the entity that this entity was potentially copied from.Gets the possibly modified description of the entity to render to the end user.getDescription(GameContext context, Player player) Gets an entity's description applying itsCardDesc.getDynamicDescription()fields and parsing spell damage and health restoration.Gets theEntityLocationof the entity, which includes itsEntityLocation.zone,EntityLocation.playerandEntityLocation.index.abstract com.hiddenswitch.spellsource.rpc.Spellsource.EntityTypeMessage.EntityTypeGets the type of entity this is.Gets a list of triggers that are active as soon as the game starts.intgetId()The entity's ID in the match.intgetIndex()The entity's index in its zone.intgetName()Gets the name of the entity (typically the name of the card that created this entity).intgetOwner()Gets the owner of this entity, orIdFactory.UNASSIGNEDif it has no owner.@NotNull StringgetRace()@NotNull EntityReferenceGets anEntityReferencethat points to this entity.Gets the user ID of the owner of this card.com.hiddenswitch.spellsource.rpc.Spellsource.ZonesMessage.ZonesgetZone()Gets the current zone the entity is located in.booleanhasAttribute(Attribute attribute) booleanEntities with persistent effects need their events to be processed differently in order to record those persistent values to a database.booleanChecks if the entity is destroyed.booleanisInPlay()Indicates that the entity is in play by being in an in-play zone.booleanIs this entity removed peacefully?voidmodifyAttribute(Attribute attribute, int value) voidmodifyHpBonus(int value) Modifies the HP bonus for the given entity.voidmoveOrAddTo(GameContext context, com.hiddenswitch.spellsource.rpc.Spellsource.ZonesMessage.Zones destination) Moves this entity to a new zone (Spellsource.ZonesMessage.Zones) belonging to thePlayerindexed bygetOwner().voidmoveOrAddTo(GameContext context, com.hiddenswitch.spellsource.rpc.Spellsource.ZonesMessage.Zones destination, int index) Moves this entity to a new zone (Spellsource.ZonesMessage.Zones) belonging to thePlayerindexed bygetOwner().voidShould not be called.voidsetAttribute(Attribute attribute) Sets an attribute.voidsetAttribute(Attribute attribute, int value) Sets an attribute to a specific integer value.voidsetAttribute(Attribute attribute, Object value) Sets an attribute to a generic object, like a string.setDescription(String description) Sets the description by setting theAttribute.DESCRIPTIONattribute.setEffectSource(Entity effectSource) voidsetEntityLocation(EntityLocation entityLocation) Should not be called.voidsetId(int id) voidvoidsetOwner(int ownerIndex) setSourceCard(Card sourceCard) protected voidtransformResolved(GameContext context) FollowsAttribute.TRANSFORM_REFERENCEuntil the resolved entity is found.protected EntitytransformResolved(GameContext context, int depth)
-
Field Details
-
NO_OWNER
public static final int NO_OWNERThe value for theownerIndexwhen no owner has been assigned.All entities should have an owner.
- See Also:
-
name
-
attributes
-
sourceCard
-
effectSource
-
entityLocation
- See Also:
-
-
Constructor Details
-
Entity
protected Entity()
-
-
Method Details
-
clone
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.- Overrides:
clonein classCustomCloneable- Returns:
- An exact clone.
-
getAttribute
- Parameters:
attribute- The attribute to look up.- Returns:
- The value of the attribute.
- See Also:
-
getAttributes
Gets the complete attribute map reference (not a copy). This can be mutated like a normalMap.- Returns:
- The
AttributeMap.
-
getAttributeValue
Gets the specified attribute as anIntegervalue or0if the specified attribute is of the wrong type or is not found.- Parameters:
attribute- TheAttributeto look up.- Returns:
- The attribute's value or 0 if it isn't set.
-
getAttributeValue
Gets the specified attribute as anIntegervalue, defaulting to the specified value if the value is not an integer.- Parameters:
attribute- TheAttributeto look up.- Returns:
- The attribute's value or 0 if it isn't set.
-
getEntityType
public abstract com.hiddenswitch.spellsource.rpc.Spellsource.EntityTypeMessage.EntityType getEntityType()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.- Returns:
- An
Spellsource.EntityTypeMessage.EntityType
-
getId
public int getId()The entity's ID in the match.IDs are set by default to
IdFactory.UNASSIGNED. This means entity IDs are mutable; entity IDs must be mutable because entities can be cloned withclone(). In practice, once an entity's ID is set, it is not set again.- Returns:
- The entity's ID, or
IdFactory.UNASSIGNEDif it is unassigned. - See Also:
-
getName
Gets the name of the entity (typically the name of the card that created this entity). Or, overridden by theAttribute.NAMEattribute set in this entity's attributes.- Returns:
- The name.
-
getOwner
public int getOwner()Gets the owner of this entity, orIdFactory.UNASSIGNEDif it has no owner.Owners are mutable because the owner of an entity, especially minions, can change.
The owner should match the
getEntityLocation()'s owner. The minion's location should be changed first, then its owner.- Returns:
GameContext.PLAYER_1,GameContext.PLAYER_2, orIdFactory.UNASSIGNED.
-
getReference
Gets anEntityReferencethat points to this entity. -
hasAttribute
- Parameters:
attribute- TheAttribute.- Returns:
trueif it has the attribute.
-
getMaxNumberOfAttacks
public int getMaxNumberOfAttacks() -
isDestroyed
public boolean isDestroyed()Checks if the entity is destroyed. Overridden to take into account entities with hitpoints.- Returns:
trueif it is destroyed.- See Also:
-
modifyAttribute
- Parameters:
attribute- The attribute.value- The amount to increment or decrement the attribute by.
-
modifyHpBonus
public void modifyHpBonus(int value) Modifies the HP bonus for the given entity.- Parameters:
value- The amount to increment or decrement the HP bonus by.
-
setAttribute
Sets an attribute. This will remove silencing when it is called. Since boolean values are not stored in attributes, attributes that are "boolean" are just set to 1. Setting the value to 0 is not equivalent to not having the attribute.- Parameters:
attribute- The attribute to set.
-
setAttribute
Sets an attribute to a specific integer value. This will remove silencing when it is called. It does not enforce that the attribute is something that only acceptsIntegervalues.- Parameters:
attribute- The attribute to set.value- The value.
-
setAttribute
Sets an attribute to a generic object, like a string. This clears silencing when it is called.- Parameters:
attribute- The attribute to set.value- Its new object value.
-
setId
public void setId(int id) -
setName
-
setOwner
public void setOwner(int ownerIndex) -
hasPersistentEffects
public boolean hasPersistentEffects()Entities with persistent effects need their events to be processed differently in order to record those persistent values to a database.- Returns:
trueif the entity needs to have its persistent effects persisted.- See Also:
-
getUserId
Gets the user ID of the owner of this card.- Returns:
- The user ID.
-
setUserId
-
getCardInventoryId
Gets the card's inventory ID (unique instance of the card).- Returns:
- The card inventory ID.
-
getEntityLocation
Gets theEntityLocationof the entity, which includes itsEntityLocation.zone,EntityLocation.playerandEntityLocation.index.- Returns:
- The entity's location in the match encoded as a
EntityLocation, orEntityLocation.UNASSIGNEDif the entity has not yet been assigned a location or placed into anEntityZone. - See Also:
-
setEntityLocation
Should not be called.Sets the entity location. Typically only called by an
EntityZone.- Parameters:
entityLocation- The new location of the entity.
-
resetEntityLocations
public void resetEntityLocations()Should not be called.Resets the entity's location by setting it to
EntityLocation.UNASSIGNED. Typically only called by anEntityZone. -
getZone
public com.hiddenswitch.spellsource.rpc.Spellsource.ZonesMessage.Zones getZone()Gets the current zone the entity is located in.- Returns:
- The
Spellsource.ZonesMessage.Zoneszone.
-
transformResolved
FollowsAttribute.TRANSFORM_REFERENCEuntil the resolved entity is found.Limits the number of transformations to follow to 14.
- Parameters:
context- AGameContextto perform lookups in.- Returns:
- This entity if no transform is found, otherwise follows the chain of resolved entities until no transformed entity is found.
-
transformResolved
-
getDescription
Gets the possibly modified description of the entity to render to the end user.- Returns:
- The
getSourceCard()'sCard.getDescription()field, or the value specified inAttribute.DESCRIPTION.
-
setDescription
Sets the description by setting theAttribute.DESCRIPTIONattribute.- Parameters:
description-- Returns:
-
getCopy
-
getCopySource
Gets a reference to the entity that this entity was potentially copied from.- Returns:
nullif this entity was not copied from another entity in the game, or anEntityReferenceof another entity.
-
getGameTriggers
Gets a list of triggers that are active as soon as the game starts.- Returns:
- The entity's defined game triggers
- See Also:
-
getDynamicDescription
-
evaluateDescriptions
-
compareTo
- Specified by:
compareToin interfaceComparable<Entity>
-
getRace
-
isInPlay
public boolean isInPlay()Indicates that the entity is in play by being in an in-play zone.- Returns:
- true if the entity is visible to both players
-
getIndex
public int getIndex()The entity's index in its zone.- Returns:
EntityLocation.UNASSIGNED's index if it isn't yet in a zone (typically-1), or the index in thegetZone()this entity is in.
-
isRemovedPeacefully
public boolean isRemovedPeacefully()Is this entity removed peacefully?- Returns:
trueif it's in the graveyard and didn't die violently, otherwise false.
-
getDescription
Gets an entity's description applying itsCardDesc.getDynamicDescription()fields and parsing spell damage and health restoration.- Parameters:
context- The contextplayer- The player whose POV this description should be evaluated- Returns:
- The dynamic description if this entity is a card, otherwise the
getDescription().
-
diedOnBattlefield
public boolean diedOnBattlefield()Indicates whether the minion died a natural death (not removed peacefully, not removed by spells, not a permanent) on the battlefield.- Returns:
trueif this minion died a natural death on the battlefield, is not a permanent, is in the graveyard and is definitely a minion.
-
getSourceCard
- Specified by:
getSourceCardin interfaceHasCard
-
setSourceCard
-
getEffectSource
-
setEffectSource
-