Class EntityReference

All Implemented Interfaces:

public final class EntityReference
extends java.lang.Object
An entity reference identifies a specific game entity, like a card or minion; or, it is interpreted as a group of entities, possibly always of length 1 (like FRIENDLY_HERO) or 0 or more (FRIENDLY_MINIONS). These references are called group references, and their isTargetGroup() will return true.

Group references are appropriate to put into SpellArg.TARGET. If SpellArg.RANDOM_TARGET is specified along with a group reference, a random entity from the group will be chosen.

When Entity.getReference() is called, a specific (non-group) reference is always returned. Thus, calling Entity.getReference() will never return FRIENDLY_HERO.

When the target has been transformed, group reference resolution will always return the transformed targets using Entity.transformResolved(GameContext). Resolving a target using GameContext.resolveSingleTarget(EntityReference) will also always return the transformed target, regardless if it is a group reference or not.


Friendly versus enemy references are evaluated with respect to the calling/casting player. This includes triggers that are put on the opponent by effects cast by the player. In other words, regardless of "where" the source is, the player from whose point of view the reference is being resolved is always the caster.

This can be confusing in a situation like Loatheb, who puts a CardCostModifier on the caster's Player entity whose CardCostModifierArg.TARGET is FRIENDLY_HAND but whose CardCostModifierArg.TARGET_PLAYER is TargetPlayer.OPPONENT. In card cost modifiers, target player is used to determine if a modifier affects a card by comparing the trigger's owner to the card's owner; opponent indicates that the card's owner must not equal the trigger's owner. However, FRIENDLY_HAND is evaluated from each player's point of view separately, because card cost modifiers (GameLogic.getModifiedManaCost(Player, Card)) are evaluated by both players, always (this allows opponents to see card cost changes).

Or, for example, Temporus causes a spell to be cast during the turn of the opponent of the owner of Temporus. The source of the spell that modifies the Attribute.EXTRA_TURN of both players is cast during the opponent's turn and in an event whose TargetPlayer is the opponent. But, EnchantmentDesc.spell is always cast by the enchantment's owner, which was the caster who originally put the enchantment into play. Therefore, the source will be the same as the player who put Temporus onto the battlefield, and that's from whose point of view the FRIENDLY_PLAYER and ENEMY_PLAYER will be evaluated.

See Also:
to see how references are interpreted., to see more about how group references are used in the casting of spells., Serialized Form