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
Modifier and TypeFieldDescriptionprotected AttributeMap
protected Entity
protected EntityLocation
protected String
static final int
The value for theownerIndex
when no owner has been assigned.protected Card
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionclone()
Clone an entity, including its ID and location.int
boolean
Indicates 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).int
getAttributeValue
(Attribute attribute) Gets the specified attribute as anInteger
value or0
if the specified attribute is of the wrong type or is not found.int
getAttributeValue
(Attribute attribute, int defaultValue) Gets the specified attribute as anInteger
value, defaulting to the specified value if the value is not an integer.Gets the card's inventory ID (unique instance of the card).abstract Entity
getCopy()
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 theEntityLocation
of the entity, which includes itsEntityLocation.zone
,EntityLocation.player
andEntityLocation.index
.abstract com.hiddenswitch.spellsource.rpc.Spellsource.EntityTypeMessage.EntityType
Gets the type of entity this is.Gets a list of triggers that are active as soon as the game starts.int
getId()
The entity's ID in the match.int
getIndex()
The entity's index in its zone.int
getName()
Gets the name of the entity (typically the name of the card that created this entity).int
getOwner()
Gets the owner of this entity, orIdFactory.UNASSIGNED
if it has no owner.@NotNull String
getRace()
@NotNull EntityReference
Gets anEntityReference
that points to this entity.Gets the user ID of the owner of this card.com.hiddenswitch.spellsource.rpc.Spellsource.ZonesMessage.Zones
getZone()
Gets the current zone the entity is located in.boolean
hasAttribute
(Attribute attribute) boolean
Entities with persistent effects need their events to be processed differently in order to record those persistent values to a database.boolean
Checks if the entity is destroyed.boolean
isInPlay()
Indicates that the entity is in play by being in an in-play zone.boolean
Is this entity removed peacefully?void
modifyAttribute
(Attribute attribute, int value) void
modifyHpBonus
(int value) Modifies the HP bonus for the given entity.void
moveOrAddTo
(GameContext context, com.hiddenswitch.spellsource.rpc.Spellsource.ZonesMessage.Zones destination) Moves this entity to a new zone (Spellsource.ZonesMessage.Zones
) belonging to thePlayer
indexed bygetOwner()
.void
moveOrAddTo
(GameContext context, com.hiddenswitch.spellsource.rpc.Spellsource.ZonesMessage.Zones destination, int index) Moves this entity to a new zone (Spellsource.ZonesMessage.Zones
) belonging to thePlayer
indexed bygetOwner()
.void
Should not be called.void
setAttribute
(Attribute attribute) Sets an attribute.void
setAttribute
(Attribute attribute, int value) Sets an attribute to a specific integer value.void
setAttribute
(Attribute attribute, Object value) Sets an attribute to a generic object, like a string.setDescription
(String description) Sets the description by setting theAttribute.DESCRIPTION
attribute.setEffectSource
(Entity effectSource) void
setEntityLocation
(EntityLocation entityLocation) Should not be called.void
setId
(int id) void
void
setOwner
(int ownerIndex) setSourceCard
(Card sourceCard) protected void
transformResolved
(GameContext context) FollowsAttribute.TRANSFORM_REFERENCE
until the resolved entity is found.protected Entity
transformResolved
(GameContext context, int depth)
-
Field Details
-
NO_OWNER
public static final int NO_OWNERThe value for theownerIndex
when 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:
clone
in 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 anInteger
value or0
if the specified attribute is of the wrong type or is not found.- Parameters:
attribute
- TheAttribute
to look up.- Returns:
- The attribute's value or 0 if it isn't set.
-
getAttributeValue
Gets the specified attribute as anInteger
value, defaulting to the specified value if the value is not an integer.- Parameters:
attribute
- TheAttribute
to 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.UNASSIGNED
if 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.NAME
attribute set in this entity's attributes.- Returns:
- The name.
-
getOwner
public int getOwner()Gets the owner of this entity, orIdFactory.UNASSIGNED
if 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 anEntityReference
that points to this entity. -
hasAttribute
- Parameters:
attribute
- TheAttribute
.- Returns:
true
if 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:
true
if 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 acceptsInteger
values.- 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:
true
if 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 theEntityLocation
of the entity, which includes itsEntityLocation.zone
,EntityLocation.player
andEntityLocation.index
.- Returns:
- The entity's location in the match encoded as a
EntityLocation
, orEntityLocation.UNASSIGNED
if 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.Zones
zone.
-
transformResolved
FollowsAttribute.TRANSFORM_REFERENCE
until the resolved entity is found.Limits the number of transformations to follow to 14.
- Parameters:
context
- AGameContext
to 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.DESCRIPTION
attribute.- Parameters:
description
-- Returns:
-
getCopy
-
getCopySource
Gets a reference to the entity that this entity was potentially copied from.- Returns:
null
if this entity was not copied from another entity in the game, or anEntityReference
of 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:
compareTo
in 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:
true
if 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:
true
if 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:
getSourceCard
in interfaceHasCard
-
setSourceCard
-
getEffectSource
-
setEffectSource
-