Class OccupantArea

All Implemented Interfaces:
MovementListener, TurnListener, Killer, Cloneable, Iterable<String>, Serializable
Direct Known Subclasses:
DamagingArea, LifeDrainArea

public class OccupantArea extends AreaEntity implements MovementListener, TurnListener
An base area that performs actions on RPEntity's that are entering, leaving, moving in, or standing in it's space.
  • Field Details

    • interval

      protected int interval
      How often an action is done while stationary (in turns).
    • playersOnly

      protected boolean playersOnly
      Applies only to players.
    • targets

      protected List<RPObject.ID> targets
      A list of entities [potentially] occupying this area.
  • Constructor Details

    • OccupantArea

      public OccupantArea(int width, int height, int interval)
      Create an occupant area.
      Parameters:
      width - Width of this area
      height - Height of this area
      interval - Standing action interval.
  • Method Details

    • addTarget

      protected void addTarget(RPEntity entity)
      Add an entity to the target list.
      Parameters:
      entity - The RPEntity to add.
    • isOccupant

      public boolean isOccupant(RPEntity entity)
      Check if an entity is an [acknowledged] occupant of this area.
      Parameters:
      entity - to be tested
      Returns:
      true if is occupant
    • handleAdded

      protected boolean handleAdded(RPEntity entity)
      An entity has entered the area. This should not apply any actions that handleMovement() does.
      Parameters:
      entity - The RPEntity that was added.
      Returns:
      false if this entity should not be processed, true otherwise.
    • handleInterval

      protected boolean handleInterval(RPEntity entity)
      Apply actions done at regular intervals.
      Parameters:
      entity - The RPEntity occupant.
      Returns:
      false if this entity should be removed from further processing, true otherwise.
    • handleMovement

      protected boolean handleMovement(RPEntity entity)
      Apply actions done while moving.
      Parameters:
      entity - The RPEntity that moved.
      Returns:
      false if this entity should be removed from further processing, true otherwise.
    • handleRemoved

      protected void handleRemoved(RPEntity entity)
      An entity has left the area. This should not apply any actions that handleMovement() does.
      Parameters:
      entity - The RPEntity that was added.
    • removeTarget

      protected void removeTarget(RPEntity entity)
      Remove an entity from the target list.
      Parameters:
      entity - The RPEntity to remove.
    • setPlayersOnly

      public void setPlayersOnly(boolean playersOnly)
      Set whether only players get affected.
      Parameters:
      playersOnly - Whether to only affect players.
    • onAdded

      public void onAdded(StendhalRPZone zone)
      Called when this object is added to a zone.
      Overrides:
      onAdded in class AreaEntity
      Parameters:
      zone - The zone this was added to.
    • onRemoved

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

      public void update()
      Handle object attribute change(s).
      Overrides:
      update in class Entity
    • onEntered

      public void onEntered(ActiveEntity entity, StendhalRPZone zone, int newX, int newY)
      Invoked when an entity enters the object area.
      Specified by:
      onEntered in interface MovementListener
      Parameters:
      entity - The entity that moved.
      zone - The new zone.
      newX - The new X coordinate.
      newY - The new Y coordinate.
    • onExited

      public void onExited(ActiveEntity entity, StendhalRPZone zone, int oldX, int oldY)
      Invoked when an entity leaves the object area.
      Specified by:
      onExited in interface MovementListener
      Parameters:
      entity - The entity that entered.
      zone - The old zone.
      oldX - The old X coordinate.
      oldY - The old Y coordinate.
    • onMoved

      public void onMoved(ActiveEntity entity, StendhalRPZone zone, int oldX, int oldY, int newX, int newY)
      Invoked when an entity moves while over the object area.
      Specified by:
      onMoved in interface MovementListener
      Parameters:
      entity - The entity that left.
      zone - The zone.
      oldX - The old X coordinate.
      oldY - The old Y coordinate.
      newX - The new X coordinate.
      newY - The new Y coordinate.
    • onTurnReached

      public void onTurnReached(int currentTurn)
      This method is called when the turn number is reached.
      Specified by:
      onTurnReached in interface TurnListener
      Parameters:
      currentTurn - Current turn number.
    • beforeMove

      public void beforeMove(ActiveEntity entity, StendhalRPZone zone, int oldX, int oldY, int newX, int newY)
      Description copied from interface: MovementListener
      Invoked before an entity moves while over the object area.
      Specified by:
      beforeMove in interface MovementListener
      Parameters:
      entity - The entity that left.
      zone - The zone.
      oldX - The old X coordinate.
      oldY - The old Y coordinate.
      newX - The new X coordinate.
      newY - The new Y coordinate.