Class Entity

All Implemented Interfaces:
Killer, Cloneable, Iterable<String>, Serializable
Direct Known Subclasses:
ActiveEntity, AreaEntity, ArrestWarrant, Chest, Earning, ExpirationTracker, Fire, Gate, Offer, PassiveEntity, PassiveEntityRespawnPoint, Portal, Sign, UseableEntity, WeatherEntity

public abstract class Entity extends RPObject implements Killer
  • Field Details

  • Constructor Details

    • Entity

      public Entity(RPObject object)
    • Entity

      public Entity()
  • Method Details

    • generateRPClass

      public static void generateRPClass()
    • update

      public void update()
    • hasDescription

      public boolean hasDescription()
    • setDescription

      public void setDescription(String text)
    • getDescription

      public String getDescription()
    • getTitle

      public String getTitle()
      Get the nicely formatted entity title/name.
      Returns:
      The title, or null if unknown.
    • getX

      public int getX()
      Get the entity X coordinate.
      Returns:
      The X coordinate.
    • getY

      public int getY()
      Get the entity Y coordinate.
      Returns:
      The Y coordinate.
    • getZone

      public StendhalRPZone getZone()
      Get the zone this entity is in.
      Returns:
      A zone, or null if not in one.
    • stopped

      public boolean stopped()
      Is this entity not moving?
      Returns:
      true, if it stopped, false if it is moving
    • getResistance

      public int getResistance()
      Get the resistance this has on other entities (0-100).
      Returns:
      The amount of resistance, or 0 if in ghostmode.
    • getResistance

      public int getResistance(Entity entity)
      Get the resistance between this and another entity (0-100).
      Parameters:
      entity - other entity to be evaluated
      Returns:
      The amount of combined resistance.
    • isObstacle

      public boolean isObstacle(Entity entity)
      Determine if this is an obstacle for another entity.
      Parameters:
      entity - The entity to check against.
      Returns:
      true if very high resistance.
    • squaredDistance

      public final double squaredDistance(Entity other)
      This returns square of the distance between this entity and the given one. We're calculating the square because the square root operation would be expensive. As long as we only need to compare distances, it doesn't matter if we compare the distances or the squares of the distances (the square operation is strictly monotonous for positive numbers).
      Parameters:
      other - the entity to which the distance should be calculated
      Returns:
      double representing the squared distance
    • squaredDistance

      public final double squaredDistance(int x, int y)
      This returns square of the distance from this entity to a specific point. We're calculating the square because the square root operation would be expensive. As long as we only need to compare distances, it doesn't matter if we compare the distances or the squares of the distances (the square operation is strictly monotonous for positive numbers).
      Parameters:
      x - The horizontal coordinate of the point
      y - The vertical coordinate of the point
      Returns:
      double representing the squared distance
    • nextTo

      public boolean nextTo(Entity entity)
      Checks whether the given entity is directly next to this entity. This method may be optimized over using nextTo(entity, 0.25).
      Parameters:
      entity - The entity
      Returns:
      true if the entity is next to this.
    • nextTo

      public boolean nextTo(Entity entity, double step)
      Checks whether the given entity is near this entity.
      Parameters:
      entity - the entity
      step - The maximum distance
      Returns:
      true iff the entity is at most step steps away
    • getAdjacentNodes

      public List<Node> getAdjacentNodes()
      Get horizontal & vertical nodes immediately adjacent to entity's current X,Y coordinates. NOTE: This does not compensate for the entity's width & height, it is only meant to get the positions that the entity could potentially move to.
    • getArea

      public Rectangle2D getArea()
      Get the area this object currently occupies.
      Returns:
      A rectangular area.
    • getArea

      public Rectangle2D getArea(double ex, double ey)
      Returns the area used by this entity.
      Parameters:
      ex - x
      ey - y
      Returns:
      rectangle for the used area
    • onAdded

      public void onAdded(StendhalRPZone zone)
      Called when this object is added to a zone.
      Parameters:
      zone - The zone this was added to.
    • onMoved

      protected void onMoved(int oldX, int oldY, int newX, int newY)
      Notification of intra-zone position change.
      Parameters:
      oldX - The old X coordinate.
      oldY - The old Y coordinate.
      newX - The new X coordinate.
      newY - The new Y coordinate.
    • onRemoved

      public void onRemoved(StendhalRPZone zone)
      Called when this object is being removed from a zone.
      Parameters:
      zone - The zone this will be removed from.
    • notifyWorldAboutChanges

      public void notifyWorldAboutChanges()
      Notifies the StendhalRPWorld that this entity's attributes have changed.
    • describe

      public String describe()
      Describes the entity (if a players looks at it).
      Returns:
      description from the players point of view
    • getDescriptionName

      public String getDescriptionName(boolean definite)
      Returns the name or something that can be used to identify the entity for the player.
      Parameters:
      definite - true for "the" and false for "a/an" in case the entity has no name
      Returns:
      name
    • getHeight

      public double getHeight()
      Get the entity height.
      Returns:
      The height (in world units).
    • getWidth

      public double getWidth()
      Get the entity width.
      Returns:
      The width (in world units).
    • setEntityClass

      public final void setEntityClass(String clazz)
      Set the entity class.
      Parameters:
      clazz - The class name.
    • setEntitySubclass

      public final void setEntitySubclass(String subclazz)
      Set the entity sub-class.
      Parameters:
      subclazz - The sub-class name.
    • setPosition

      public final void setPosition(int x, int y)
      Sets the entity position.

      This calls onMoved(). Note: When placing during a zone change, this call should be done after being removed from the old zone, but before adding to the zone to prevent an erroneous position jump in the zone.

      Parameters:
      x - The x position (in world units).
      y - The y position (in world units).
    • getOrigin

      public final Point getOrigin()
      Returns:
      The initial position of the entity
    • setResistance

      public final void setResistance(int resistance)
      Set resistance this has with other entities.
      Parameters:
      resistance - The amount of resistance (0-100).
    • setSize

      public void setSize(int width, int height)
      Set the entity size.
      Parameters:
      width - The width (in world units).
      height - The height (in world units).
    • getCursor

      public String getCursor()
      gets the name of the mouse cursor or null.
      Returns:
      name of the mouse cursor or null.
    • setCursor

      public void setCursor(String cursor)
      sets the name of the mouse cursor
      Parameters:
      cursor - name of cursor
    • setVisibility

      public final void setVisibility(int visibility)
      Set the entity's visibility.
      Parameters:
      visibility - The visibility (0-100).
    • isInSight

      public boolean isInSight(Entity other)
      Check if the other Entity is near enough to be in sight on the client screen.
      Parameters:
      other -
      Returns:
      true if near enough
    • getEntitySlot

      public EntitySlot getEntitySlot(String name)
      gets the named entity slot
      Parameters:
      name - name of entity slot
      Returns:
      EntitySlot or null
    • slotIterator

      public Iterator<RPSlot> slotIterator(Slots slotTypes)
      an iterator over slots
      Parameters:
      slotTypes - slot types to include in the iteration
      Returns:
      Iterator
    • slots

      public Iterable<RPSlot> slots(Slots slotTypes)
      an Iterable over slots
      Parameters:
      slotTypes - slot types to include in the iteration
      Returns:
      Iterable
    • setMenu

      public void setMenu(String menu)
      The menu to display on the client in the format:
          Display Name 1|action1,
          Display Name 2|action2
       
      Parameters:
      menu - menu string
    • getName

      public String getName()
      gets the name of this entity
      Specified by:
      getName in interface Killer
      Returns:
      name