Class RectArea

  • All Implemented Interfaces:
    Area

    public class RectArea
    extends java.lang.Object
    implements Area
    • Constructor Detail

      • RectArea

        public RectArea​(int x1,
                        int y1,
                        int x2,
                        int y2)
      • RectArea

        public RectArea​(int x1,
                        int y1,
                        int x2,
                        int y2,
                        int plane)
      • RectArea

        public RectArea​(Positionable positionable,
                        int radius)
      • RectArea

        public RectArea​(Positionable positionable,
                        int width,
                        int height)
    • Method Detail

      • fromSize

        public static RectArea fromSize​(int x,
                                        int y,
                                        int width,
                                        int height,
                                        int plane)
      • contains

        public boolean contains​(int x,
                                int y,
                                int plane)
        Specified by:
        contains in interface Area
      • contains2D

        public boolean contains2D​(int x,
                                  int y)
        Specified by:
        contains2D in interface Area
      • isInMeleeDistance

        public boolean isInMeleeDistance​(RectArea 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​(Positionable 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(RectArea)
      • intersectsWith

        public boolean intersectsWith​(RectArea 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​(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(RSWorldView, int, int, Predicate) method.

        Parameters:
        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​(RSWorldView wv,
                                            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(RSWorldView, int, int, Predicate) method.

        Parameters:
        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​(RSWorldView wv,
                                            int dx,
                                            int dy,
                                            java.util.function.Predicate<? super Positionable> 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:
        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​(RSWorldView wv,
                                        RectArea 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:
        other - The other WorldArea to compare with
        Returns:
        Returns true if this WorldArea has line of sight to the other
      • hasLineOfSightTo

        public boolean hasLineOfSightTo​(Positionable 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:
        other - The other WorldTile to compare with
        Returns:
        Returns true if this WorldTile has line of sight to the WorldTile
      • getMinX

        public int getMinX()
        Specified by:
        getMinX in interface Area
      • getMinY

        public int getMinY()
        Specified by:
        getMinY in interface Area
      • getMaxX

        public int getMaxX()
        Specified by:
        getMaxX in interface Area
      • getMaxY

        public int getMaxY()
        Specified by:
        getMaxY in interface Area
      • getPlane

        public int getPlane()
        Specified by:
        getPlane in interface Area
      • equals

        public boolean equals​(java.lang.Object o)
        Overrides:
        equals in class java.lang.Object
      • canEqual

        protected boolean canEqual​(java.lang.Object other)
      • hashCode

        public int hashCode()
        Overrides:
        hashCode in class java.lang.Object