Guest User

Untitled

a guest
Jul 22nd, 2018
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.88 KB | None | 0 0
  1. package ej.api;
  2.  
  3. import java.util.LinkedHashSet;
  4. import java.util.Set;
  5.  
  6. import org.powerbot.game.api.methods.Game;
  7. import org.powerbot.game.api.methods.node.Locations;
  8. import org.powerbot.game.api.wrappers.Tile;
  9. import org.powerbot.game.api.wrappers.node.Location;
  10. import org.powerbot.game.client.Client;
  11. import org.powerbot.game.client.RSAnimableNode;
  12.  
  13. public class LocationsApi {
  14.  
  15. public static Location getTopAt(final Tile t, final int mask) {
  16. Location[] objects = getAt(t, mask);
  17. return objects.length > 0 ? objects[0] : null;
  18. }
  19.  
  20. public static Location[] getAt(final Tile t, final int mask) {
  21. Set<Location> objects = getAtLocal(t.getX() - Game.getBaseX(), t.getY()
  22. - Game.getBaseY(), mask);
  23. return objects.toArray(new Location[objects.size()]);
  24. }
  25.  
  26. public static Location getTopAt(Tile tile, int[][] ids) {
  27. for (int[] subIds : ids)
  28. if (getTopAt(tile, subIds) != null)
  29. return getTopAt(tile, subIds);
  30. return null;
  31. }
  32.  
  33. public static Location getTopAt(Tile tile, int... id) {
  34. Location[] objects = getAllAt(tile);
  35. for (Location object : objects) {
  36. for (int doorID : id)
  37. if (object.getId() == doorID)
  38. return object;
  39. }
  40. return null;
  41. }
  42.  
  43. public static Location[] getAllAt(Tile location) {
  44. Set<Location> objects = getAtLocal(location.getX() - Game.getBaseX(),
  45. location.getY() - Game.getBaseY(), -1);
  46. return objects.toArray(new Location[objects.size()]);
  47. }
  48.  
  49. private static Set<Location> getAtLocal(int x, int y, final int mask) {
  50. Client client = methods.client;
  51. Set<Location> objects = new LinkedHashSet<Location>();
  52. if (client.getRSGroundArray() == null) {
  53. return objects;
  54. }
  55.  
  56. try {
  57. int plane = client.getPlane();
  58. RSGround rsGround = client.getRSGroundArray()[plane][x][y];
  59.  
  60. if (rsGround != null) {
  61. Location rsObj;
  62. RSInteractable obj;
  63.  
  64. x += Game.getBaseX();
  65. y += Game.getBaseY();
  66.  
  67. if ((mask & Locations.TYPE_INTERACTIVE) != 0) {
  68. for (RSAnimableNode node = rsGround.getRSAnimableList(); node != null; node = node
  69. .getNext()) {
  70. obj = node.getRSAnimable();
  71. if (obj != null && obj instanceof Location) {
  72. rsObj = (Location) obj;
  73. if (rsObj.getId() != -1) {
  74. objects.add(new Location(methods, rsObj,
  75. Locations.TYPE_INTERACTIVE, plane));
  76. }
  77. }
  78. }
  79. }
  80.  
  81. // Ground Decorations
  82. if ((mask & Locations.TYPE_FLOOR_DECORATION) != 0) {
  83. obj = rsGround.getFloorDecoration();
  84. if (obj != null) {
  85. rsObj = (Location) obj;
  86. if (rsObj.getId() != -1) {
  87. objects.add(new Locations(methods, rsObj,
  88. Locations.TYPE_FLOOR_DECORATION, plane));
  89. }
  90. }
  91. }
  92.  
  93. // Boundaries / Doors / Fences / Walls
  94. if ((mask & Locations.TYPE_BOUNDARY) != 0) {
  95. obj = rsGround.getBoundary1();
  96. if (obj != null) {
  97. rsObj = (Location) obj;
  98. if (rsObj.getId() != -1) {
  99. objects.add(new Location(methods, rsObj,
  100. Locations.TYPE_BOUNDARY, plane));
  101. }
  102. }
  103.  
  104. obj = rsGround.getBoundary2();
  105. if (obj != null) {
  106. rsObj = (Location) obj;
  107. if (rsObj.getId() != -1) {
  108. objects.add(new Location(methods, rsObj,
  109. Locations.TYPE_BOUNDARY, plane));
  110. }
  111. }
  112. }
  113.  
  114. // Wall Decorations
  115. if ((mask & Locations.TYPE_WALL_DECORATION) != 0) {
  116. obj = rsGround.getWallDecoration1();
  117. if (obj != null) {
  118. rsObj = (Location) obj;
  119. if (rsObj.getId() != -1) {
  120. objects.add(new Location(methods, rsObj,
  121. Locations.TYPE_WALL_DECORATION, plane));
  122. }
  123. }
  124.  
  125. obj = rsGround.getWallDecoration2();
  126. if (obj != null) {
  127. rsObj = (Location) obj;
  128. if (rsObj.getId() != -1) {
  129. objects.add(new Location(methods, rsObj,
  130. Locations.TYPE_WALL_DECORATION, plane));
  131. }
  132. }
  133. }
  134. }
  135. } catch (Exception ignored) {
  136. }
  137. return objects;
  138. }
  139.  
  140. }
Add Comment
Please, Sign In to add comment