Class EntityLocation

java.lang.Object
net.demilich.metastone.game.entities.EntityLocation
All Implemented Interfaces:
Serializable

public final class EntityLocation extends Object implements Serializable
The location of an entity inside a GameContext.

Every entity has an EntityLocation that starts as UNASSIGNED. The creator of the Entity object should add it to an EntityZone, which sets that entity's Entity.entityLocation.

A location has a Player, Spellsource.ZonesMessage.Zones and Integer index tuple that are comparable and exclusive--only one entity can be in a given location at a given time. These locations are used to find entities like GameContext.tryFind(EntityReference), to support effects like AdjacentEffectSpell, and to support networking effects and diffing for game state.

See Also:
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final EntityLocation
    An unassigned location.
  • Constructor Summary

    Constructors
    Constructor
    Description
    EntityLocation(com.hiddenswitch.spellsource.rpc.Spellsource.ZonesMessage.Zones zone, int player, int index)
    Create the location with the specified zone, player and index.
  • Method Summary

    Modifier and Type
    Method
    Description
    boolean
    equals(Object other)
     
    int
    Gets the index in the EntityZone for this location.
    int
    Gets the index of the player for this location, or Entity.NO_OWNER if it has not yet been assigned.
    com.hiddenswitch.spellsource.rpc.Spellsource.ZonesMessage.Zones
    Gets the zone of this location.
    int
     
     

    Methods inherited from class java.lang.Object

    clone, finalize, getClass, notify, notifyAll, wait, wait, wait
  • Field Details

    • UNASSIGNED

      public static final EntityLocation UNASSIGNED
      An unassigned location.
  • Constructor Details

    • EntityLocation

      public EntityLocation(com.hiddenswitch.spellsource.rpc.Spellsource.ZonesMessage.Zones zone, int player, int index)
      Create the location with the specified zone, player and index.
      Parameters:
      zone - The zone in the game.
      player - The player's index, or IdFactory.UNASSIGNED if the owner is not yet known.
      index - The index of the object, or -1 if it is not yet known.
  • Method Details

    • equals

      public boolean equals(Object other)
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • getZone

      public com.hiddenswitch.spellsource.rpc.Spellsource.ZonesMessage.Zones getZone()
      Gets the zone of this location.
      Returns:
      The zone.
      See Also:
      • for a complete description of each zone.
    • getPlayer

      public int getPlayer()
      Gets the index of the player for this location, or Entity.NO_OWNER if it has not yet been assigned. (With the exception of UNASSIGNED, a player fields with a value of Entity.NO_OWNER is an invalid location.
      Returns:
      The player index, or -1 if it has not yet been assigned.
      See Also:
    • getIndex

      public int getIndex()
      Gets the index in the EntityZone for this location.
      Returns:
      The index.
      See Also:
    • toString

      public String toString()
      Overrides:
      toString in class Object