Class WorldArea


  • public class WorldArea
    extends Object
    Represents an area on the world.
    • Constructor Detail

      • WorldArea

        public WorldArea​(int x,
                         int y,
                         int width,
                         int height,
                         int plane)
      • WorldArea

        public WorldArea​(WorldPoint location,
                         int width,
                         int height)
    • Method Detail

      • distanceTo

        public int distanceTo​(WorldArea other)
        Computes the shortest distance to another area.
        Parameters:
        other - the passed area
        Returns:
        the distance, or Integer.MAX_VALUE if the planes differ
      • distanceTo

        public int distanceTo​(WorldPoint other)
        Computes the shortest distance to a world coordinate.
        Parameters:
        other - the passed coordinate
        Returns:
        the distance, or Integer.MAX_VALUE if the planes differ
      • distanceTo2D

        public int distanceTo2D​(WorldArea other)
        Computes the shortest distance to another area while ignoring the plane.
        Parameters:
        other - the passed area
        Returns:
        the distance
      • distanceTo2D

        public int distanceTo2D​(WorldPoint other)
        Computes the shortest distance to a world coordinate.
        Parameters:
        other - the passed coordinate
        Returns:
        the distance
      • contains

        public boolean contains​(WorldPoint worldPoint)
        Checks whether a tile is contained within the area and in the same plane.
        Returns:
        true if the tile is contained within the bounds of this area, false otherwise.
      • contains2D

        public boolean contains2D​(WorldPoint worldPoint)
        Checks whether a tile is contained within the area while ignoring the plane.
        Returns:
        true if the tile is contained within the bounds of this area regardless of plane, false otherwise.
      • isInMeleeDistance

        public boolean isInMeleeDistance​(WorldArea other)
        Checks whether this area is within melee distance of another.

        Melee distance is exactly 1 tile, so this method computes and returns whether the shortest distance to the passed area is directly on the outside of this areas edge.

        Parameters:
        other - the other area
        Returns:
        true if in melee distance, false otherwise
      • isInMeleeDistance

        public boolean isInMeleeDistance​(WorldPoint other)
        Checks whether a coordinate is within melee distance of this area.
        Parameters:
        other - the coordinate
        Returns:
        true if in melee distance, false otherwise
        See Also:
        isInMeleeDistance(WorldArea)
      • intersectsWith

        public boolean intersectsWith​(WorldArea other)
        Checks whether this area intersects with another.
        Parameters:
        other - the other area
        Returns:
        true if the areas intersect, false otherwise
      • canTravelInDirection

        public boolean canTravelInDirection​(Client client,
                                            int dx,
                                            int dy)
        Determines if the area can travel in one of the 9 directions by using the standard collision detection algorithm.

        Note that this method does not consider other actors as a collision, but most non-boss NPCs do check for collision with some actors. For actor collision checking, use the canTravelInDirection(Client, int, int, Predicate) method.

        Parameters:
        client - the client to test in
        dx - the x-axis direction to travel (-1, 0, or 1)
        dy - the y-axis direction to travel (-1, 0, or 1)
        Returns:
        true if the area can travel in the specified direction
      • canTravelInDirection

        public boolean canTravelInDirection​(Client client,
                                            int dx,
                                            int dy,
                                            Predicate<? super WorldPoint> extraCondition)
        Determines if the area can travel in one of the 9 directions by using the standard collision detection algorithm.

        The passed x and y axis directions indicate the direction to travel in.

        Note that this method does not normally consider other actors as a collision, but most non-boss NPCs do check for collision with some actors. However, using the extraCondition param it is possible to implement this check manually.

        Parameters:
        client - the client to test in
        dx - the x-axis direction to travel (-1, 0, or 1)
        dy - the y-axis direction to travel (-1, 0, or 1)
        extraCondition - an additional condition to perform when checking valid tiles, such as performing a check for un-passable actors
        Returns:
        true if the area can travel in the specified direction
      • hasLineOfSightTo

        public boolean hasLineOfSightTo​(Client client,
                                        WorldArea other)
        Determine if this WorldArea has line of sight to another WorldArea.

        Note that the reverse isn't necessarily true, meaning this can return true while the other WorldArea does not have line of sight to this WorldArea.

        Parameters:
        client - The client to compare in
        other - The other WorldArea to compare with
        Returns:
        Returns true if this WorldArea has line of sight to the other
      • hasLineOfSightTo

        public boolean hasLineOfSightTo​(Client client,
                                        WorldPoint other)
        Determine if this WorldArea has line of sight to another WorldArea.

        Note that the reverse isn't necessarily true, meaning this can return true while the other WorldArea does not have line of sight to this WorldArea.

        Parameters:
        client - The client to compare in
        other - The other WorldPoint to compare with
        Returns:
        Returns true if this WorldPoint has line of sight to the WorldPoint
      • toWorldPoint

        public WorldPoint toWorldPoint()
        Retrieves the southwestern most point of this WorldArea.
        Returns:
        Returns the southwestern most WorldPoint in the area
      • toWorldPointList

        public List<WorldPoint> toWorldPointList()
        Accumulates all the WorldPoints that this WorldArea contains and returns them as a list
        Returns:
        Returns the WorldPoints in this WorldArea
      • getX

        public int getX()
        The western most point of the area.
      • getY

        public int getY()
        The southern most point of the area.
      • getWidth

        public int getWidth()
        The width of the area.
      • getHeight

        public int getHeight()
        The height of the area.
      • getPlane

        public int getPlane()
        The plane the area is on.