63 private final int height;
74 this.height = height < 0 ? 0 : height % 4;
122 public int getRegionX() {
126 public int getRegionY() {
130 public Region getRegion() {
174 return Utility.getDistance(origin, target);
185 if (height != other.height) {
189 final int deltaX = Math.abs(other.x - x);
190 final int deltaY = Math.abs(other.y - y);
191 return deltaX <= radius && deltaY <= radius;
201 if (height != other.height)
return 0;
202 int dx = other.x - x;
203 int dy = other.y - y;
204 return Math.sqrt(dx * dx + dy * dy);
214 return (
int) Math.sqrt(Math.pow(x - other.x, 2) + Math.pow(y - other.y, 2) + Math.pow(height - other.height, 2));
217 public int getChevDistance(
Position other) {
218 return Math.max(Math.abs(other.
getX() -
getX()), Math.abs(other.
getY() -
getY()));
228 final int dx = second.
getX() - first.
getX();
229 final int dy = second.
getY() - first.
getY();
230 return Math.sqrt(dx * dx + dy * dy);
241 if (other ==
null || height != other.height)
return Integer.MAX_VALUE;
242 int dx = Math.abs(other.x - x);
243 int dy = Math.abs(other.y - y);
247 public boolean isViewableFrom(
Position other) {
250 Position p = this.getDelta(
this, other);
251 return p.x <= 14 && p.x >= -15 && p.y <= 14 &&
266 final int dx = Math.abs(second.
getX() - first.
getX());
267 final int dy = Math.abs(second.
getY() - first.
getY());
278 if (height != other.height)
return 0;
279 int deltaX = Math.abs(
getX() - other.
getX());
280 int deltaY = Math.abs(
getY() - other.
getY());
281 return Math.max(deltaX, deltaY);
316 return new Position(x + diffX, y + diffY, height + diffZ);
327 return new Position(x + diffX, y + diffY, height);
331 public boolean inLocation(
Position southWest,
Position northEast,
boolean inclusive) {
332 return !inclusive ? this.x > southWest.
getX() && this.x < northEast.
getX() && this.y > southWest.
getY() && this.y < northEast.
getY() : this.x >= southWest.
getX() && this.x <= northEast.
getX() && this.y >= southWest.
getY() && this.y <= northEast.
getY();
342 if (other ==
null)
return this;
356 public boolean equals(Object obj) {
357 if (obj ==
this)
return true;
361 return x == other.x && y == other.y && height == other.height;
367 public boolean matches(
int x,
int y) {
368 return this.x == x && this.y == y;
371 public boolean matches(
int x,
int y,
int z) {
372 return this.x == x && this.y == y && this.height == z;
376 public int hashCode() {
377 return hash(x, y, height);
381 public String toString() {
382 return String.format(
"pos[x=%d, y=%d, z=%d]", x, y, height);
385 public static int hash(
int x,
int y,
int z) {
386 return (y << 16) | (x << 8) | z;
389 public static boolean isWithinDiagonalDistance(Mob attacker, Mob defender,
int distance) {
390 int attackerSize = 1;
391 int defenderSize = 1;
394 attackerSize = attacker.getNpc().definition.getSize();
396 defenderSize = defender.getNpc().definition.getSize();
398 int e_offset_x = attackerSize - 1 + distance;
399 int e_offset_y = attackerSize - 1 + distance;
401 int o_offset_x = defenderSize - 1 + distance;
402 int o_offset_y = defenderSize - 1 + distance;
404 Position entity_pos = attacker.getPosition().copy();
405 Position other_pos = defender.getPosition().copy();
407 boolean inside_entity =
408 (other_pos.getX() <= entity_pos.getX() + e_offset_x && other_pos.getX() >= (entity_pos.getX() - distance)) &&
409 (other_pos.getY() <= entity_pos.getY() + e_offset_y && other_pos.getY() >= (entity_pos.getY() - distance));
411 boolean inside_other =
412 (entity_pos.getX() <= other_pos.getX() + o_offset_x && entity_pos.getX() >= (other_pos.getX() - distance)) &&
413 (entity_pos.getY() <= other_pos.getY() + o_offset_y && entity_pos.getY() >= (other_pos.getY() - distance));
416 return inside_entity || inside_other;
419 public int getChebyshevDistance(
Position other) {
420 return getChebyshevDistance(
getX(),
getY(), other.getX(), other.getY());
423 public int getChebyshevDistance(
int x1,
int y1,
int x2,
int y2) {
424 return Math.max(Math.abs(x2 - x1), Math.abs(y2 - y1));
427 public int getCoordFaceX(
final int sizeX) {
428 return getCoordFaceX(sizeX, -1, -1);
431 public int getCoordFaceX(
final int sizeX,
final int sizeY,
final int rotation) {
432 return getX() + ((rotation == 1 || rotation == 3 ? sizeY : sizeX) - 1) / 2;
435 public int getCoordFaceY(
final int sizeY) {
436 return getCoordFaceY(-1, sizeY, -1);
439 public int getCoordFaceY(
final int sizeX,
final int sizeY,
final int rotation) {
440 return getY() + ((rotation == 1 || rotation == 3 ? sizeX : sizeY) - 1) / 2;