Advertisement
Guest User

Untitled

a guest
Sep 19th, 2017
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 9.55 KB | None | 0 0
  1. import java.awt.Color;
  2. import java.awt.Graphics;
  3. import java.awt.Point;
  4. import java.util.Vector;
  5.  
  6. import org.rsbot.event.listeners.PaintListener;
  7. import org.rsbot.script.Script;
  8. import org.rsbot.script.ScriptManifest;
  9. import org.rsbot.script.methods.Skills;
  10. import org.rsbot.script.wrappers.RSObject;
  11. import org.rsbot.script.wrappers.RSTile;
  12.  
  13. /**
  14. * AIO fire maker that generates lanes at any spot so no need to be at a specific spot to run
  15. */
  16. @ScriptManifest(authors = { "Battleguard" }, version = 0.01, keywords = { "AIO Firemaker 3" }, description = "AIO Firemaker 3, by Battleguard", name = "AIO firemaker 3")
  17. public class firemaker3 extends Script implements PaintListener {
  18.  
  19. // SCRIPT GOALS
  20. // -- NO GLOBAL VARIABLES
  21. // -- LOOK VERY SIMILAR TO RSBOTS SOURCE CODE METHODS
  22. //
  23.  
  24. Vector<fireLane> allLanes = new Vector<fireLane>();
  25. Vector<fireLane> goodLanes = new Vector<fireLane>();
  26. fireLane bestLane = null;
  27. RSTile startLocation;
  28. boolean atLane = false;
  29. boolean newRow = true;
  30. public static final int TINDERBOX_ID = 590, WILLOW_ID = 1519;
  31.  
  32. public boolean onStart() {
  33. log("Calculating all lanes please give it 30 seconds");
  34. startLocation = getMyPlayer().getLocation();
  35. allLanes = getAllLanes(45, 27, startLocation);
  36. allLanes = getAllGoodLanes(allLanes, startLocation);
  37. log("All " + allLanes.size() + " lanes have been calculated StartUp complete");
  38. return true;
  39. }
  40.  
  41. @Override
  42. public int loop() {
  43. if (inventory.getCount(WILLOW_ID) > 0) {
  44. if (!atLane) {
  45. walkToFireSpot();
  46. } else {
  47. lightFires();
  48. }
  49. } else {
  50. bank();
  51. }
  52.  
  53. return 50;
  54. }
  55.  
  56. void bank() {
  57. log("banking");
  58. if (atBank()) {
  59. log("we are at bank");
  60. doBank();
  61. } else {
  62. log("we are not at bank");
  63. walking.walkTo(startLocation);
  64. sleep(1000);
  65. }
  66. }
  67.  
  68. private final boolean atBank() {
  69. RSObject bank = objects.getNearest(11758);
  70. if (bank != null && bank.isOnScreen()) {
  71.  
  72. return true;
  73. }
  74. return false;
  75. }
  76.  
  77. private final void doBank() {
  78. if (bank.isOpen()) {
  79. bank.depositAllExcept(TINDERBOX_ID);
  80. bank.withdraw(WILLOW_ID, 0);
  81. sleep(800, 1200);
  82. bank.close();
  83. sleep(800, 1200);
  84. // SET STARTING VARIABLES FOR LIGHTING FIRES PART
  85. bestLane = null;
  86. atLane = false;
  87. newRow = true;
  88. } else {
  89. bank.open();
  90. sleep(1800, 2200);
  91. }
  92. }
  93.  
  94. /**
  95. * walk to starting position of fireLane
  96. */
  97. void walkToFireSpot() {
  98. try {
  99. if (bestLane == null) {
  100. // CALCULATE BEST LANE
  101. Vector<fireLane> goodLanes = new Vector<fireLane>();
  102. goodLanes = noFiresOnTop(allLanes);
  103. bestLane = this.bestLane(goodLanes);
  104. } else {
  105. // WALK TO FIRELANE
  106. if (!players.getMyPlayer().getLocation().equals(bestLane.getStart())) {
  107. walking.walkTileOnScreen(bestLane.getStart());
  108. log("walking to tile");
  109. sleep(1000);
  110. } else {
  111. atLane = true;
  112. newRow = true;
  113. }
  114. }
  115. } catch (Exception e) {
  116. log("error walking to start location");
  117. }
  118. }
  119.  
  120. private RSTile oldLoc;
  121.  
  122. /**
  123. * lights fires till out of logs
  124. */
  125. private void lightFires() {
  126. log("lighting fires now");
  127. if (newRow) {
  128. oldXP = skills.getCurrentExp(Skills.FIREMAKING);
  129. timer = System.currentTimeMillis();
  130. }
  131.  
  132. if ((inventory.contains(WILLOW_ID) && !getMyPlayer().getLocation().equals(oldLoc)) || newRow) {
  133. newRow = false;
  134. oldLoc = players.getMyPlayer().getLocation();
  135. if (!inventory.isItemSelected()) {
  136. inventory.getItem(WILLOW_ID).doClick(true);
  137. log("preClick");
  138. sleep(500);
  139. }
  140. int numOfLogs = inventory.getCount(WILLOW_ID);
  141. inventory.getItem(TINDERBOX_ID).doClick(true);
  142. while (numOfLogs == inventory.getCount(WILLOW_ID)) {
  143. sleep(50);
  144. }
  145. if (inventory.contains(WILLOW_ID)) {
  146. inventory.getItem(WILLOW_ID).doClick(true);
  147. mouse.move(inventory.getItem(TINDERBOX_ID).getPoint());
  148. }
  149. sleep(100);
  150. }
  151. checkXP();
  152. }
  153.  
  154. // CHECK TO MAKE SURE THAT NOTHING HAS INTERUPTED LIGHTING FIRES
  155. // IF SOMETHING WRONG HAPPENS FIND A NEW LANE AND RESTART
  156. private int oldXP = 0;
  157. private long timer = 0;
  158.  
  159. private void checkXP() {
  160. int currentXP = skills.getCurrentExp(Skills.FIREMAKING);
  161. if (currentXP != oldXP) {
  162. oldXP = currentXP;
  163. timer = System.currentTimeMillis();
  164. return;
  165. }
  166. if (currentXP == oldXP && (timer + 10000) < System.currentTimeMillis()) {
  167. bestLane = null;
  168. atLane = false;
  169. newRow = true;
  170. }
  171. }
  172.  
  173. /**
  174. * Makes a vector of all good RSTiles around person and returns vector
  175. * @param rad radius of the square we will be making around centLoc
  176. * @param laneSize size of lanes that we want to make
  177. * @param centLoc location of the square
  178. * @return Vector of all possible starting lane positions
  179. */
  180. private Vector<fireLane> getAllLanes(int rad, int laneSize, RSTile centLoc) {
  181. Vector<fireLane> allPossibleLanes = new Vector<fireLane>();
  182. for (int y = -rad; y <= rad; y++) {
  183. for (int x = -rad + (laneSize - 1); x <= rad; x++)
  184. allPossibleLanes.add(new fireLane(new RSTile(centLoc.getX() + x, centLoc.getY() + y), laneSize));
  185. }
  186. return allPossibleLanes;
  187. }
  188.  
  189. /**
  190. * get all fire lanes that are reachable
  191. * @param allLanes AllLanes that we need to check
  192. * @param startT Tile that we are starting from
  193. * @return all good fire lanes
  194. */
  195. private Vector<fireLane> getAllGoodLanes(Vector<fireLane> lanes, RSTile startT) {
  196. Vector<fireLane> goodLanes = new Vector<fireLane>();
  197. for (int i = 0; i < lanes.size(); i++) {
  198. if (lanes.get(i).isLanePossible(startT))
  199. goodLanes.add(lanes.get(i));
  200. }
  201. return goodLanes;
  202. }
  203.  
  204. /**
  205. * gets all lanes that do not currently have a burning fire in them
  206. * @param allLanes: all fire lanes to check for fires
  207. * @returns all lanes that do not have fires on them
  208. */
  209. private Vector<fireLane> noFiresOnTop(Vector<fireLane> lanes) {
  210. Vector<fireLane> goodLanes = new Vector<fireLane>();
  211. for (int i = 0; i < lanes.size(); i++) {
  212. if (lanes.get(i).noFires()) {
  213. goodLanes.add(lanes.get(i));
  214. }
  215. }
  216. return goodLanes;
  217. }
  218.  
  219. /**
  220. * gets the fire lane that has the closest walking distance
  221. * @param lanes: lanes to check for closest distance
  222. * @returns closest fire lane
  223. */
  224. private fireLane bestLane(Vector<fireLane> lanes) {
  225. fireLane bestLane = null;
  226. double dist = 10000;
  227. for (int i = 0; i < lanes.size(); i++) {
  228. if (lanes.get(i).getDist() < dist) {
  229. bestLane = lanes.get(i);
  230. dist = bestLane.getDist();
  231. }
  232. }
  233. return bestLane;
  234. }
  235.  
  236. /**
  237. * fireLane class that stores all tiles in a fire lane and dist from starting location
  238. */
  239. class fireLane {
  240. private Vector<RSTile> fireLaneTiles = new Vector<RSTile>();
  241. private double dist = 10000;
  242.  
  243. /**
  244. * Constructor that makes a fire lane
  245. * @param startT: tile that a player would start lighting fires at
  246. * @param laneSize: size of fire lane (typically 27)
  247. */
  248. fireLane(RSTile startT, int laneSize) {
  249. for (int shift = 0; shift < laneSize; shift++) {
  250. fireLaneTiles.add(new RSTile(startT.getX() - shift, startT.getY()));
  251. }
  252. }
  253.  
  254. /**
  255. * Checks to see if lane has any objects on top of it and is of no father walking distance than 20 tiles
  256. * @param curLoc: Location of player
  257. * @returns true is goodLane false if badLane
  258. */
  259. boolean isLanePossible(RSTile curLoc) {
  260. for (int i = 0; i < fireLaneTiles.size(); i++) {
  261. double tempDist = calc.pathLengthBetween(curLoc, fireLaneTiles.get(i), false);
  262. if (tempDist == -1) {
  263. return false;
  264. } else {
  265. if (tempDist < dist)
  266. dist = tempDist;
  267. }
  268. }
  269. if (dist > 20)
  270. return false;
  271. return true;
  272. }
  273.  
  274. /**
  275. * checks to see if the lane is currently clear of fires
  276. * @returns true if no fires in lane
  277. */
  278. boolean noFires() {
  279. try {
  280. for (int i = 0; i < fireLaneTiles.size(); i++) {
  281. if (objects.getTopAt(fireLaneTiles.get(i)) != null)
  282. return false;
  283. }
  284. } catch (Exception e) {
  285. log("error in doing objects.getTopAt");
  286. return false;
  287. }
  288. return true;
  289. }
  290.  
  291. /**
  292. * @returns start position of fireLane
  293. */
  294. RSTile getStart() {
  295. return fireLaneTiles.get(0);
  296. }
  297.  
  298. /**
  299. * @returns distance to fireLane
  300. */
  301. double getDist() {
  302. return dist;
  303. }
  304. }
  305.  
  306. // DRAW TILE ON SCREEN
  307. public void drawTile(Graphics g, RSTile tile, Color color) {
  308. if (isTileOnScreen(tile)) {
  309. final Point pn = calc.tileToScreen(tile, 0, 0, 0);
  310. final Point px = calc.tileToScreen(new RSTile(tile.getX() + 1, tile.getY()), 0, 0, 0);
  311. final Point py = calc.tileToScreen(new RSTile(tile.getX(), tile.getY() + 1), 0, 0, 0);
  312. final Point pxy = calc.tileToScreen(new RSTile(tile.getX() + 1, tile.getY() + 1), 0, 0, 0);
  313. g.setColor(Color.black);
  314. g.drawPolygon(new int[] { py.x, pxy.x, px.x, pn.x }, new int[] { py.y, pxy.y, px.y, pn.y }, 4);
  315. g.setColor(color);
  316. g.fillPolygon(new int[] { py.x, pxy.x, px.x, pn.x }, new int[] { py.y, pxy.y, px.y, pn.y }, 4);
  317. }
  318. }
  319.  
  320. // CHECKS TO SEE IF TILE IS ON SCREEN
  321. public boolean isTileOnScreen(RSTile tile) {
  322. return calc.pointOnScreen(new Point(calc.tileToScreen(tile)))
  323. && calc.pointOnScreen(new Point(calc.tileToScreen(new RSTile(tile.getX() + 1, tile.getY()))))
  324. && calc.pointOnScreen(new Point(calc.tileToScreen(new RSTile(tile.getX(), tile.getY() + 1))))
  325. && calc.pointOnScreen(new Point(calc.tileToScreen(new RSTile(tile.getX() + 1, tile.getY() + 1))));
  326. }
  327.  
  328. @Override
  329. public void onRepaint(Graphics g) {
  330. if (this.bestLane != null) {
  331. for (int i = 0; i < bestLane.fireLaneTiles.size(); i++) {
  332. this.drawTile(g, bestLane.fireLaneTiles.get(i), Color.BLUE);
  333. }
  334.  
  335. }
  336. }
  337. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement