Object distance validation / check
I remember someone (think it might've been professor oak?) that released this but not complete (iirc it only had a check for 1 type). Eitherway, this is directly from the client :)
Code:
public boolean isWithinDistance(GameObject object) {
int type = object.getType();
int rotation = object.getRotation();
if (type == 10 || type == 11 || type == 22) {
int width;
int height;
if (rotation == 0 || rotation == 2) {
width = object.getDefinition().getWidth();
height = object.getDefinition().getLength();
} else {
width = object.getDefinition().getLength();
height = object.getDefinition().getWidth();
}
int surroundings = object.getDefinition().getSurroundings();
if (rotation != 0) {
surroundings = (surroundings << rotation & 0xf) + (surroundings >> 4 - rotation);
}
return isWithinDistance(object, width, height, 0, 0, surroundings);
}
return isWithinDistance(object, 0, 0, type + 1, rotation, 0);
}
public boolean isWithinDistance(GameObject object, int width, int height, int type, int rotation, int surroundings) {
if (type != 0) {
if ((type <= 5 || type == 10) && reachedWall(object.getPosition().getX(), object.getPosition().getY(), rotation, type - 1)) {
return true;
}
if (type < 10 && reachedDecoration(object.getPosition().getX(), object.getPosition().getY(), type - 1, rotation)) {
return true;
}
}
if (width != 0 && height != 0) {
return reachedObject(object.getPosition().getX(), object.getPosition().getY(), height, surroundings, width);
}
return false;
}
private static final int WALL_EAST = 0x8;
private static final int WALL_NORTH = 0x2;
private static final int WALL_NORTHEAST = 0x4;
private static final int WALL_NORTHWEST = 0x1;
private static final int WALL_SOUTH = 0x20;
private static final int WALL_SOUTHEAST = 0x10;
private static final int WALL_SOUTHWEST = 0x40;
private static final int WALL_WEST = 0x80;
private class Orientation {
public static final int NORTH = 0;
public static final int EAST = 1;
public static final int SOUTH = 2;
public static final int WEST = 3;
}
public boolean reachedDecoration(int finalX, int finalY, int type, int orientation) {
if (x == finalX && y == finalY) {
return true;
}
if (type == 6 || type == 7) {
if (type == 7) {
orientation = orientation + 2 & 3;
}
if (orientation == Orientation.NORTH) {
if (x == finalX + 1 && y == finalY && (MapRegion.getClipping(x, y, z) & WALL_WEST) == 0) {
return true;
} else if (x == finalX && y == finalY - 1 && (MapRegion.getClipping(x, y, z) & WALL_NORTH) == 0) {
return true;
}
} else if (orientation == Orientation.EAST) {
if (x == finalX - 1 && y == finalY && (MapRegion.getClipping(x, y, z) & WALL_EAST) == 0) {
return true;
} else if (x == finalX && y == finalY - 1 && (MapRegion.getClipping(x, y, z) & WALL_NORTH) == 0) {
return true;
}
} else if (orientation == Orientation.SOUTH) {
if (x == finalX - 1 && y == finalY && (MapRegion.getClipping(x, y, z) & WALL_EAST) == 0) {
return true;
} else if (x == finalX && y == finalY + 1 && (MapRegion.getClipping(x, y, z) & WALL_SOUTH) == 0) {
return true;
}
} else if (orientation == Orientation.WEST) {
if (x == finalX + 1 && y == finalY && (MapRegion.getClipping(x, y, z) & WALL_WEST) == 0) {
return true;
} else if (x == finalX && y == finalY + 1 && (MapRegion.getClipping(x, y, z) & WALL_SOUTH) == 0) {
return true;
}
}
}
if (type == 8) {
if (x == finalX && y == finalY + 1 && (MapRegion.getClipping(x, y, z) & WALL_SOUTH) == 0) {
return true;
} else if (x == finalX && y == finalY - 1 && (MapRegion.getClipping(x, y, z) & WALL_NORTH) == 0) {
return true;
} else if (x == finalX - 1 && y == finalY && (MapRegion.getClipping(x, y, z) & WALL_EAST) == 0) {
return true;
} else if (x == finalX + 1 && y == finalY && (MapRegion.getClipping(x, y, z) & WALL_WEST) == 0) {
return true;
}
}
return false;
}
public boolean reachedWall(int finalX, int finalY, int orientation, int type) {
System.out.println("type: " + type + " orientation: " + orientation + " finalX: " + finalX + " finalY: " + finalY);
if (x == finalX && y == finalY) {
return true;
}
if (type == 0) {
if (orientation == Orientation.NORTH) {
if (x == finalX - 1 && y == finalY) {
return true;
} else if (x == finalX && y == finalY + 1 && (MapRegion.getClipping(x, y, z) & 0x1280120) == 0) {
return true;
} else if (x == finalX && y == finalY - 1 && (MapRegion.getClipping(x, y, z) & 0x1280102) == 0) {
return true;
}
} else if (orientation == Orientation.EAST) {
if (x == finalX && y == finalY + 1) {
return true;
} else if (x == finalX - 1 && y == finalY && (MapRegion.getClipping(x, y, z) & 0x1280108) == 0) {
return true;
} else if (x == finalX + 1 && y == finalY && (MapRegion.getClipping(x, y, z) & 0x1280180) == 0) {
return true;
}
} else if (orientation == Orientation.SOUTH) {
if (x == finalX + 1 && y == finalY) {
return true;
} else if (x == finalX && y == finalY + 1 && (MapRegion.getClipping(x, y, z) & 0x1280120) == 0) {
return true;
} else if (x == finalX && y == finalY - 1 && (MapRegion.getClipping(x, y, z) & 0x1280102) == 0) {
return true;
}
} else if (orientation == Orientation.WEST) {
if (x == finalX && y == finalY - 1) {
return true;
} else if (x == finalX - 1 && y == finalY && (MapRegion.getClipping(x, y, z) & 0x1280108) == 0) {
return true;
} else if (x == finalX + 1 && y == finalY && (MapRegion.getClipping(x, y, z) & 0x1280180) == 0) {
return true;
}
}
}
if (type == 2) {
if (orientation == Orientation.NORTH) {
if (x == finalX - 1 && y == finalY) {
return true;
} else if (x == finalX && y == finalY + 1) {
return true;
} else if (x == finalX + 1 && y == finalY && (MapRegion.getClipping(x, y, z) & 0x1280180) == 0) {
return true;
} else if (x == finalX && y == finalY - 1 && (MapRegion.getClipping(x, y, z) & 0x1280102) == 0) {
return true;
}
} else if (orientation == Orientation.EAST) {
// UNLOADED_TILE | BLOCKED_TILE | UNKNOWN | OBJECT_TILE | WALL_EAST
if (x == finalX - 1 && y == finalY && (MapRegion.getClipping(x, y, z) & 0x1280108) == 0) {
return true;
} else if (x == finalX && y == finalY + 1) {
return true;
} else if (x == finalX + 1 && y == finalY) {
return true;
} else if (x == finalX && y == finalY - 1 && (MapRegion.getClipping(x, y, z) & 0x1280102) == 0) {
return true;
}
} else if (orientation == Orientation.SOUTH) {
if (x == finalX - 1 && y == finalY && (MapRegion.getClipping(x, y, z) & 0x1280108) == 0) {
return true;
} else if (x == finalX && y == finalY + 1 && (MapRegion.getClipping(x, y, z) & 0x1280120) == 0) {
return true;
} else if (x == finalX + 1 && y == finalY) {
return true;
} else if (x == finalX && y == finalY - 1) {
return true;
}
} else if (orientation == Orientation.WEST) {
if (x == finalX - 1 && y == finalY) {
return true;
} else if (x == finalX && y == finalY + 1 && (MapRegion.getClipping(x, y, z) & 0x1280120) == 0) {
return true;
} else if (x == finalX + 1 && y == finalY && (MapRegion.getClipping(x, y, z) & 0x1280180) == 0) {
return true;
} else if (x == finalX && y == finalY - 1) {
return true;
}
}
}
if (type == 9) {
if (x == finalX && y == finalY + 1 && (MapRegion.getClipping(x, y, z) & WALL_SOUTH) == 0) {
return true;
} else if (x == finalX && y == finalY - 1 && (MapRegion.getClipping(x, y, z) & WALL_NORTH) == 0) {
return true;
} else if (x == finalX - 1 && y == finalY && (MapRegion.getClipping(x, y, z) & WALL_EAST) == 0) {
return true;
} else if (x == finalX + 1 && y == finalY && (MapRegion.getClipping(x, y, z) & WALL_WEST) == 0) {
return true;
}
}
return false;
}
public boolean reachedObject(int finalX, int finalY, int height, int surroundings, int width) {
int maxX = finalX + width;
int maxY = finalY + height;
if (x >= finalX && x <= maxX && y >= finalY && y <= maxY) {
return true;
} else if (x == finalX - 1 && y >= finalY && y <= maxY && (MapRegion.getClipping(x, y, z) & WALL_EAST) == 0
&& (surroundings & WALL_EAST) == 0) {
return true;
} else if (x == maxX + 1 && y >= finalY && y <= maxY && (MapRegion.getClipping(x, y, z) & WALL_WEST) == 0
&& (surroundings & WALL_NORTH) == 0) {
return true;
} else if (y == finalY - 1 && x >= finalX && x <= maxX && (MapRegion.getClipping(x, y, z) & WALL_NORTH) == 0
&& (surroundings & WALL_NORTHEAST) == 0) {
return true;
}
return y == maxY + 1 && x >= finalX && x <= maxX && (MapRegion.getClipping(x, y, height) & WALL_SOUTH) == 0
&& (surroundings & WALL_NORTHWEST) == 0;
}
[Only registered and activated users can see links. Click Here To Register...]