Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package ej.api;
- import java.util.LinkedHashSet;
- import java.util.Set;
- import org.powerbot.game.api.methods.Game;
- import org.powerbot.game.api.methods.node.Locations;
- import org.powerbot.game.api.wrappers.Tile;
- import org.powerbot.game.api.wrappers.node.Location;
- import org.powerbot.game.client.Client;
- import org.powerbot.game.client.RSAnimableNode;
- public class LocationsApi {
- public static Location getTopAt(final Tile t, final int mask) {
- Location[] objects = getAt(t, mask);
- return objects.length > 0 ? objects[0] : null;
- }
- public static Location[] getAt(final Tile t, final int mask) {
- Set<Location> objects = getAtLocal(t.getX() - Game.getBaseX(), t.getY()
- - Game.getBaseY(), mask);
- return objects.toArray(new Location[objects.size()]);
- }
- public static Location getTopAt(Tile tile, int[][] ids) {
- for (int[] subIds : ids)
- if (getTopAt(tile, subIds) != null)
- return getTopAt(tile, subIds);
- return null;
- }
- public static Location getTopAt(Tile tile, int... id) {
- Location[] objects = getAllAt(tile);
- for (Location object : objects) {
- for (int doorID : id)
- if (object.getId() == doorID)
- return object;
- }
- return null;
- }
- public static Location[] getAllAt(Tile location) {
- Set<Location> objects = getAtLocal(location.getX() - Game.getBaseX(),
- location.getY() - Game.getBaseY(), -1);
- return objects.toArray(new Location[objects.size()]);
- }
- private static Set<Location> getAtLocal(int x, int y, final int mask) {
- Client client = methods.client;
- Set<Location> objects = new LinkedHashSet<Location>();
- if (client.getRSGroundArray() == null) {
- return objects;
- }
- try {
- int plane = client.getPlane();
- RSGround rsGround = client.getRSGroundArray()[plane][x][y];
- if (rsGround != null) {
- Location rsObj;
- RSInteractable obj;
- x += Game.getBaseX();
- y += Game.getBaseY();
- if ((mask & Locations.TYPE_INTERACTIVE) != 0) {
- for (RSAnimableNode node = rsGround.getRSAnimableList(); node != null; node = node
- .getNext()) {
- obj = node.getRSAnimable();
- if (obj != null && obj instanceof Location) {
- rsObj = (Location) obj;
- if (rsObj.getId() != -1) {
- objects.add(new Location(methods, rsObj,
- Locations.TYPE_INTERACTIVE, plane));
- }
- }
- }
- }
- // Ground Decorations
- if ((mask & Locations.TYPE_FLOOR_DECORATION) != 0) {
- obj = rsGround.getFloorDecoration();
- if (obj != null) {
- rsObj = (Location) obj;
- if (rsObj.getId() != -1) {
- objects.add(new Locations(methods, rsObj,
- Locations.TYPE_FLOOR_DECORATION, plane));
- }
- }
- }
- // Boundaries / Doors / Fences / Walls
- if ((mask & Locations.TYPE_BOUNDARY) != 0) {
- obj = rsGround.getBoundary1();
- if (obj != null) {
- rsObj = (Location) obj;
- if (rsObj.getId() != -1) {
- objects.add(new Location(methods, rsObj,
- Locations.TYPE_BOUNDARY, plane));
- }
- }
- obj = rsGround.getBoundary2();
- if (obj != null) {
- rsObj = (Location) obj;
- if (rsObj.getId() != -1) {
- objects.add(new Location(methods, rsObj,
- Locations.TYPE_BOUNDARY, plane));
- }
- }
- }
- // Wall Decorations
- if ((mask & Locations.TYPE_WALL_DECORATION) != 0) {
- obj = rsGround.getWallDecoration1();
- if (obj != null) {
- rsObj = (Location) obj;
- if (rsObj.getId() != -1) {
- objects.add(new Location(methods, rsObj,
- Locations.TYPE_WALL_DECORATION, plane));
- }
- }
- obj = rsGround.getWallDecoration2();
- if (obj != null) {
- rsObj = (Location) obj;
- if (rsObj.getId() != -1) {
- objects.add(new Location(methods, rsObj,
- Locations.TYPE_WALL_DECORATION, plane));
- }
- }
- }
- }
- } catch (Exception ignored) {
- }
- return objects;
- }
- }
Add Comment
Please, Sign In to add comment