1package com.runehive.game.world.position;
3import com.runehive.game.world.Interactable;
4import com.runehive.game.world.World;
5import com.runehive.game.world.entity.mob.Mob;
6import com.runehive.game.world.region.Region;
7import com.runehive.util.Utility;
152 final int deltaX = Math.abs(other.
x -
x);
153 final int deltaY = Math.abs(other.
y -
y);
154 return deltaX <= radius && deltaY <= radius;
165 int dx = other.x -
x;
166 int dy = other.y -
y;
167 return Math.sqrt(dx * dx + dy * dy);
177 return (
int) Math.sqrt(Math.pow(
x - other.
x, 2) + Math.pow(
y - other.
y, 2) + Math.pow(
height - other.
height, 2));
181 return Math.max(Math.abs(other.
getX() -
getX()), Math.abs(other.
getY() -
getY()));
191 final int dx = second.
getX() - first.
getX();
192 final int dy = second.
getY() - first.
getY();
193 return Math.sqrt(dx * dx + dy * dy);
204 if (other ==
null ||
height != other.
height)
return Integer.MAX_VALUE;
205 int dx = Math.abs(other.
x -
x);
206 int dy = Math.abs(other.
y -
y);
214 return p.x <= 14 && p.x >= -15 && p.y <= 14 &&
229 final int dx = Math.abs(second.
getX() - first.
getX());
230 final int dy = Math.abs(second.
getY() - first.
getY());
242 int deltaX = Math.abs(
getX() - other.
getX());
243 int deltaY = Math.abs(
getY() - other.
getY());
244 return Math.max(deltaX, deltaY);
305 if (other ==
null)
return this;
320 if (obj ==
this)
return true;
331 return this.x ==
x && this.y ==
y;
335 return this.x ==
x && this.y ==
y && this.height == z;
345 return String.format(
"pos[x=%d, y=%d, z=%d]",
x,
y,
height);
348 public static int hash(
int x,
int y,
int z) {
349 return (
y << 16) | (
x << 8) | z;
353 int attackerSize = 1;
354 int defenderSize = 1;
361 int e_offset_x = attackerSize - 1 + distance;
362 int e_offset_y = attackerSize - 1 + distance;
364 int o_offset_x = defenderSize - 1 + distance;
365 int o_offset_y = defenderSize - 1 + distance;
370 boolean inside_entity =
371 (other_pos.
getX() <= entity_pos.
getX() + e_offset_x && other_pos.
getX() >= (entity_pos.
getX() - distance)) &&
372 (other_pos.
getY() <= entity_pos.
getY() + e_offset_y && other_pos.
getY() >= (entity_pos.
getY() - distance));
374 boolean inside_other =
375 (entity_pos.
getX() <= other_pos.
getX() + o_offset_x && entity_pos.
getX() >= (other_pos.
getX() - distance)) &&
376 (entity_pos.
getY() <= other_pos.
getY() + o_offset_y && entity_pos.
getY() >= (other_pos.
getY() - distance));
379 return inside_entity || inside_other;
387 return Math.max(Math.abs(x2 - x1), Math.abs(y2 - y1));
394 public int getCoordFaceX(
final int sizeX,
final int sizeY,
final int rotation) {
395 return getX() + ((rotation == 1 || rotation == 3 ? sizeY : sizeX) - 1) / 2;
402 public int getCoordFaceY(
final int sizeX,
final int sizeY,
final int rotation) {
403 return getY() + ((rotation == 1 || rotation == 3 ? sizeX : sizeY) - 1) / 2;
Represents the game world.
static RegionManager getRegions()
final boolean isNpc()
Check if an entity is an npc.
Position transform(Position other)
Creates a new location based on this location.
Position(int x, int y, int height)
Creates a location.
int getLongestDelta(Position other)
Gets the longest horizontal or vertical delta between the two positions.
static int getManhattanDistance(Interactable origin, Interactable target)
Gets the manhattan distance between two interactable object.
Position getDelta(Position location, Position other)
boolean inLocation(Position southWest, Position northEast, boolean inclusive)
boolean isWithinDistance(Position other, int radius)
Checks if this location is within range of another.
final int height
The height coordinate.
static boolean isWithinDiagonalDistance(Mob attacker, Mob defender, int distance)
int getHeight()
Gets the height coordinate, or height.
int getLocalX(Position origin)
Gets the local x coordinate relative to a specific region.
Position transform(int diffX, int diffY)
Creates a new location based on this location.
int getY()
Gets the absolute y coordinate.
int getCoordFaceY(final int sizeY)
static int hash(int x, int y, int z)
boolean isViewableFrom(Position other)
final int x
The x coordinate.
int getLocalY(Position origin)
Gets the local y coordinate relative to a specific region.
Position(int x, int y)
Creates a location with a default height of 0.
int getX()
Gets the absolute x coordinate.
int getDistances(Position other)
Absolute distance between this Coordiante and another.
int getCoordFaceX(final int sizeX)
Position transform(int diffX, int diffY, int diffZ)
Creates a new location based on this location.
static final int HEIGHT_LEVELS
The maximum amount of height-planes.
int getManhattanDistance(Position other)
Gets the distance between this location and another location without diagonals.
int getCoordFaceX(final int sizeX, final int sizeY, final int rotation)
int getLocalY()
Gets the local y coordinate relative to this region.
boolean equals(Object obj)
static int getManhattanDistance(Position first, Position second)
Gets the Euclidean (straight-line) distance between two Position s.
int getChevDistance(Position other)
static Position create(int x, int y, int z)
Creates a location.
int getChebyshevDistance(Position other)
boolean matches(int x, int y)
int getChunkX()
Gets the chunk x coordinate.
int getLocalX()
Gets the local x coordinate relative to this region.
int getChebyshevDistance(int x1, int y1, int x2, int y2)
int getCoordFaceY(final int sizeX, final int sizeY, final int rotation)
static double getDistance(Position first, Position second)
Gets the Euclidean (straight-line) distance between two Position s.
double getDistance(Position other)
Gets the distance between this location and another location.
static Position create(int x, int y)
Creates a location.
int getChunkY()
Gets the chunk y coordinate.
final int y
The y coordinate.
Position copy()
Creates a deep copy of this location.
boolean matches(int x, int y, int z)
Represents a single region.
Region getRegion(Position position)
Gets a region by position.
Handles miscellaneous methods.
static int getDistance(Interactable source, Position target)
An object implementing Interactable has uses.