Guest User

Untitled

a guest
Jul 22nd, 2018
54
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 34.83 KB | None | 0 0
  1. import java.awt.Color;
  2. import java.awt.Font;
  3. import java.awt.FontMetrics;
  4. import java.awt.Graphics;
  5. import java.awt.Point;
  6. import java.awt.Polygon;
  7. import java.awt.Rectangle;
  8. import java.awt.geom.Rectangle2D;
  9. import java.text.NumberFormat;
  10. import java.util.Map;
  11.  
  12. import org.rsbot.bot.Bot;
  13. import org.rsbot.event.listeners.PaintListener;
  14. import org.rsbot.script.Calculations;
  15. import org.rsbot.script.Methods;
  16. import org.rsbot.script.Script;
  17. import org.rsbot.script.ScriptManifest;
  18. import org.rsbot.script.Skills;
  19. import org.rsbot.script.wrappers.RSNPC;
  20. import org.rsbot.script.wrappers.RSTile;
  21.  
  22. @ScriptManifest(authors = { "Garrett" }, category = "Mining", name = "Garrett's Essence Miner", version = 1.21, description =
  23. "<html><head>" +
  24. "</head><body>" +
  25. "<center><strong><h2>Garrett's Essence Miner</h2></strong></center>" +
  26. "<center>Start the script at Yanille or Varrock</center>" +
  27. "<center>Have your pickaxe equipped or in the inventory</center>" +
  28. "<center>Please sell essence at Mid to Max to keep the prices up</center>" +
  29. "<br />Adjust Mouse Speed: <input name='mouseSpeed' type='text' size='2' maxlength='2' value='0' /><br />(The higher the number, the slower the mouse)" +
  30. "<br /><input name='disablepaint' type='checkbox' value='1'>Disable Paint" +
  31. "<br /><input name='disablemap' type='checkbox' checked='checked' value='1'>Disable Map Paint" +
  32. "</body></html>")
  33.  
  34. public class GarrettsEssenceMiner extends Script implements PaintListener {
  35.  
  36. final ScriptManifest properties = getClass().getAnnotation(ScriptManifest.class);
  37. final TheWalker theWalker = new TheWalker();
  38. final GarrettsPaint thePainter = new GarrettsPaint();
  39.  
  40. int runEnergy = random(40, 95);
  41. int miningCount = -1;
  42. int useX = 0;
  43. int useY = 0;
  44. int failCount = 0;
  45. int sAdj = 0;
  46. int value = 30;
  47. boolean checkPickaxe = false;
  48. boolean setAltitude = false;
  49. boolean foundType = false;
  50. boolean mapPaint = false;
  51. boolean paint = true;
  52.  
  53. final int pickaxe[] = {1265, 1267, 1269, 1296, 1273, 1271, 1275, 15259};
  54.  
  55. final int portal = 2492;
  56.  
  57. final int Aubury = 553;
  58. final int Distentor = 462;
  59.  
  60. final int bankBooth[] = {11402, 2213};
  61.  
  62. final int essenceArea[] = {2950, 4870, 2870, 4790};
  63. final int varrockUpStairsArea[] = {3257, 3423, 3250, 3416};
  64.  
  65. final int varrockBankArea[] = {3257, 3423, 3250, 3420};
  66. final RSTile varrockBank = new RSTile(3254, 3420);
  67. final RSTile varrockPath[] = {new RSTile(3253, 3421), new RSTile(3254, 3427), new RSTile(3262, 3421), new RSTile(3262, 3415), new RSTile(3259, 3411), new RSTile(3257, 3404), new RSTile(3254, 3398), new RSTile(3253, 3401)};
  68. final RSTile varrockDoor = new RSTile(3253, 3399);
  69. final RSTile varrockDoorCheck = new RSTile(3253, 3398);
  70.  
  71. final int yanilleBankArea[] = {2613, 3097, 2609, 3088};
  72. final RSTile yanilleBank = new RSTile(2612, 3093);
  73. final RSTile yanillePath[] = {new RSTile(2611, 3093), new RSTile(2604, 3089), new RSTile(2597, 3088)};
  74. final RSTile yanilleDoor = new RSTile(2597, 3088);
  75.  
  76. final RSTile[] miningTiles = {new RSTile(2927, 4818), new RSTile(2931, 4818), new RSTile(2931, 4814), new RSTile(2927, 4814), new RSTile(2897, 4816), new RSTile(2897, 4812), new RSTile(2893, 4812), new RSTile(2893, 4816), new RSTile(2895, 4847), new RSTile(2891, 4847), new RSTile(2891, 4851), new RSTile(2895, 4851), new RSTile(2925, 4848), new RSTile(2925, 4852), new RSTile(2929, 4852), new RSTile(2929, 4848)};
  77. final int[] tilesX = {1, 0, 0, 1, 0, 0, 1, 1, 0, 1, 1, 0, 1, 1, 0, 0};
  78. final int[] tilesY = {0, 0, 1, 1, 0, 1, 1, 0, 1, 1, 0, 0, 1, 0, 0, 1};
  79.  
  80. final int mageGuildX[] = new int[]{2590,2593,2597,2597,2597,2593,2586,2585,2585,2586,2588};
  81. final int mageGuildY[] = new int[]{3094,3094,3090,3088,3085,3081,3082,3087,3088,3090,3092};
  82. final Polygon mageGuild = new Polygon(mageGuildX, mageGuildY, 11);
  83.  
  84. public enum State { VARwalkTeleport, VARwalkBank, VARdoTeleport, YANwalkTeleport, YANwalkBank, YANdoTeleport, doMining, doBank, exitMines, error; };
  85.  
  86. public int speed = 10;
  87. public void getMouseSpeed(final int speed) {
  88. this.speed = speed;
  89. getMouseSpeed();
  90. }
  91.  
  92. protected int getMouseSpeed() {
  93. return speed;
  94. }
  95.  
  96. public State getState() {
  97. try {
  98. if (playerInArea(essenceArea)) {
  99. if (isInventoryFull()) {
  100. return State.exitMines;
  101. }
  102. return State.doMining;
  103. }
  104. miningCount = -1;
  105. if (distanceTo(varrockBank) < 75) {
  106. if (isInventoryFull()) {
  107. if (playerInArea(varrockBankArea) || (getNearestObjectByID(bankBooth) != null && tileOnScreen(getNearestObjectByID(bankBooth).getLocation())))
  108. return State.doBank;
  109. return State.VARwalkBank;
  110. }
  111. if (getNearestNPCByID(Aubury) != null) {
  112. if (getNearestNPCByID(Aubury).isOnScreen())
  113. return State.VARdoTeleport;
  114. }
  115. return State.VARwalkTeleport;
  116. } else {
  117. if (isInventoryFull()) {
  118. if (playerInArea(yanilleBankArea))
  119. return State.doBank;
  120. return State.YANwalkBank;
  121. }
  122. if (getNearestNPCByID(Distentor) != null) {
  123. if (!playerInArea(mageGuild) && tileOnScreen(yanilleDoor))
  124. return State.YANdoTeleport;
  125. if (getNearestNPCByID(Distentor).isOnScreen())
  126. return State.YANdoTeleport;
  127. }
  128. return State.YANwalkTeleport;
  129. }
  130. } catch(Exception e) { }
  131. return State.error;
  132. }
  133.  
  134. public boolean onStart( Map<String,String> args ) {
  135. sAdj = Integer.parseInt(args.get("mouseSpeed"));
  136. paint = args.get("disablepaint") == null ? true : false;
  137. mapPaint = args.get("disablemap") == null ? true : false;
  138. return true;
  139. }
  140.  
  141. public int loop() {
  142. try {
  143. getMouseSpeed(random(8 + sAdj, 11 + sAdj));
  144.  
  145. if (!isLoggedIn())
  146. return random(50, 100);
  147.  
  148. if(!setAltitude) {
  149. setCameraAltitude(true);
  150. wait(random(250, 500));
  151. setAltitude = true;
  152. return random(50, 100);
  153. }
  154.  
  155. if (!checkPickaxe) {
  156. if (!equipmentContainsOneOf(pickaxe) && !inventoryContainsOneOf(pickaxe)) {
  157. log("Pickaxe was not found.");
  158. return -1;
  159. }
  160. checkPickaxe = true;
  161. return random(50, 100);
  162. }
  163.  
  164. if (!foundType) {
  165. if (inventoryContainsOneOf(1436)) {
  166. value = grandExchange.loadItemInfo(1436).getMarketPrice();
  167. foundType = true;
  168. } else if (inventoryContainsOneOf(7936)) {
  169. value = grandExchange.loadItemInfo(7936).getMarketPrice();
  170. foundType = true;
  171. }
  172. }
  173.  
  174. thePainter.scriptRunning = true;
  175.  
  176. if (!thePainter.savedStats)
  177. thePainter.saveStats();
  178.  
  179. if (getPlane() == 1 && playerInArea(varrockUpStairsArea)) {
  180. if (onTile(new RSTile(3256, 3421), "Climb", 0.5, 0.5, 0)) {
  181. wait(random(1500, 2000));
  182. while (getMyPlayer().isMoving()) {
  183. wait(random(90, 110));
  184. }
  185. wait(random(1500, 2000));
  186. }
  187. return random(50, 100);
  188. }
  189. } catch(Exception e) { }
  190.  
  191. try {
  192. if (getPlane() == 1 && playerInArea(mageGuild)) {
  193. if (onTile(new RSTile(2590, 3091), "Climb", 0.2, 0.5, 0)) {
  194. wait(random(1500, 2000));
  195. while (getMyPlayer().isMoving()) {
  196. wait(random(90, 110));
  197. }
  198. wait(random(1500, 2000));
  199. }
  200. return 100;
  201. }
  202. } catch(Exception e) { }
  203.  
  204. startRunning(runEnergy);
  205.  
  206. try {
  207. switch (getState()) {
  208. case VARwalkTeleport:
  209. walkPath(varrockPath);
  210. return random(50, 100);
  211. case VARwalkBank:
  212. Point checkScreen1 = Calculations.tileToScreen(varrockDoor, 0.5, 0, 50);
  213. if (pointOnScreen(checkScreen1)) {
  214. if (getObjectAt(varrockDoorCheck) != null && distanceTo(new RSTile(3253, 3402)) <= 3) {
  215. if (onTile(varrockDoor, "Open", random(0.39, 0.61), random(0, 0.05), random(20, 50))) {
  216. failCount = 0;
  217. while (getObjectAt(varrockDoor) == null && failCount < 40) {
  218. wait(random(50, 100));
  219. failCount++;
  220. }
  221. }
  222. if (getObjectAt(varrockDoor) == null)
  223. return random(50, 100);
  224. }
  225. }
  226. if (playerInArea(3257, 3419, 3250, 3419)) {
  227. if (getMyPlayer().isMoving())
  228. return random(50, 100);
  229. walkTileMM(varrockBank);
  230. waitToMove(1000);
  231. return random(50, 100);
  232. }
  233. if (!walkPath(reversePath(varrockPath))) {
  234. if (!getMyPlayer().isMoving())
  235. if (theWalker.walkTo(new RSTile[] {varrockBank}, true))
  236. waitToMove(1000);
  237. }
  238. return random(50, 100);
  239. case VARdoTeleport:
  240. Point checkScreen2 = Calculations.tileToScreen(varrockDoor, 0.5, 0, 50);
  241. if (pointOnScreen(checkScreen2)) {
  242. if (getObjectAt(varrockDoorCheck) != null) {
  243. if (onTile(varrockDoor, "Open", random(0.39, 0.61), random(0, 0.05), random(20, 50))) {
  244. failCount = 0;
  245. while (getObjectAt(varrockDoor) == null && failCount < 40) {
  246. wait(random(50, 100));
  247. failCount++;
  248. }
  249. }
  250. if (getObjectAt(varrockDoor) == null)
  251. return random(50, 100);
  252. }
  253. }
  254. failCount = 0;
  255. if (getNearestNPCByID(Aubury).isOnScreen()) {
  256. if (onNPC(getNearestNPCByID(Aubury), "eleport")) {
  257. waitToMove(1000);
  258. wait(random(500, 750));
  259. if (getMyPlayer().getInteracting() == null)
  260. return random(50, 100);
  261. failCount = 0;
  262. while (!playerInArea(essenceArea) && failCount < 50) {
  263. wait(random(90, 110));
  264. if (getMyPlayer().isMoving())
  265. failCount = 0;
  266. failCount++;
  267. }
  268. }
  269. } else theWalker.walkTo(new RSTile[] {getNearestNPCByID(Aubury).getLocation()}, true);
  270. return random(50, 100);
  271. case YANwalkTeleport:
  272. if (walkPath(yanillePath))
  273. waitToMove(1000);
  274. return random(50, 100);
  275. case YANwalkBank:
  276. if (playerInArea(mageGuild)) {
  277. if (onTile(yanilleDoor, "Open", random(0.1, 0.2), random(-0.5, 0.5), random(40, 50))) {
  278. waitToMove(1000);
  279. failCount = 0;
  280. while (playerInArea(mageGuild) && failCount < 20) {
  281. wait(random(90, 110));
  282. if (getMyPlayer().isMoving())
  283. failCount = 0;
  284. failCount++;
  285. }
  286. }
  287. return random(50, 100);
  288. }
  289. if (!walkPath(reversePath(yanillePath))) {
  290. if (!getMyPlayer().isMoving() || distanceTo(getDestination()) <= 5)
  291. if (theWalker.walkTo(new RSTile[] {yanilleBank}, true))
  292. waitToMove(1000);
  293. }
  294. return random(50, 100);
  295. case YANdoTeleport:
  296. failCount = 0;
  297. if (!playerInArea(mageGuild)) {
  298. if (onTile(yanilleDoor, "Open", random(0.1, 0.2), random(-0.5, 0.5), random(40, 50))) {
  299. waitToMove(1000);
  300. failCount = 0;
  301. while (!playerInArea(mageGuild) && failCount < 20) {
  302. wait(random(90, 110));
  303. if (getMyPlayer().isMoving())
  304. failCount = 0;
  305. failCount++;
  306. }
  307. }
  308. return random(50, 100);
  309. }
  310. if (getNearestNPCByID(Distentor).isOnScreen()) {
  311. if (onNPC(getNearestNPCByID(Distentor), "eleport")) {
  312. waitToMove(1000);
  313. wait(random(500, 750));
  314. if (getMyPlayer().getInteracting() == null)
  315. return random(50, 100);
  316. failCount = 0;
  317. while (!playerInArea(essenceArea) && failCount < 50) {
  318. wait(random(90, 110));
  319. if (getMyPlayer().isMoving())
  320. failCount = 0;
  321. failCount++;
  322. }
  323. }
  324. } else theWalker.walkTo(new RSTile[] {getNearestNPCByID(Distentor).getLocation()}, true);
  325. return random(50, 100);
  326. case doMining:
  327. if (miningCount == -1 || miningCount > 20) {
  328. if (onTile(findNearestEssenceTile(), "Mine", useX, useY, 0))
  329. miningCount = 0;
  330. } else {
  331. miningCount++;
  332. if (getMyPlayer().getAnimation() != -1) {
  333. antiBan();
  334. miningCount = 0;
  335. } else wait(random(90, 140));
  336. }
  337. return random(50, 100);
  338. case doBank:
  339. if (playerInArea(3257, 3419, 3250, 3419)) {
  340. if (getMyPlayer().isMoving())
  341. return random(50, 100);
  342. walkTileMM(varrockBank);
  343. waitToMove(1000);
  344. return random(50, 100);
  345. }
  346. doBank();
  347. return random(50, 100);
  348. case exitMines:
  349. if (onTile(getNearestObjectByID(portal).getLocation(), "Enter", 0.5, 0.5, 0)) {
  350. waitToMove(1000);
  351. failCount = 0;
  352. while (playerInArea(essenceArea) && failCount < 30) {
  353. wait(random(90, 110));
  354. if (getMyPlayer().isMoving())
  355. failCount = 0;
  356. failCount++;
  357. }
  358. }
  359. return random(50, 100);
  360. }
  361. } catch(Exception e) { }
  362.  
  363. return random(50, 100);
  364. }
  365.  
  366. public void doBank() {
  367. int failCount = 0;
  368. try {
  369. if (!bank.isOpen()) {
  370. if (onTile(getNearestObjectByID(bankBooth).getLocation(), "Use-quickly", 0.5, 0.5, 0))
  371. waitToMove(1000);
  372. while(!bank.isOpen() && failCount < 10) {
  373. wait(random(90, 110));
  374. if (getMyPlayer().isMoving())
  375. failCount = 0;
  376. failCount++;
  377. }
  378. }
  379. if (bank.isOpen()) {
  380. wait(random(500, 750));
  381. if (inventoryContainsOneOf(pickaxe)) {
  382. if (bank.depositAllExcept(pickaxe))
  383. wait(random(500, 750));
  384. } else {
  385. if (bank.depositAll())
  386. wait(random(500, 750));
  387. }
  388. }
  389. } catch (final Exception e) { }
  390. }
  391.  
  392. public void startRunning(final int energy) {
  393. if (getEnergy() >= energy && !isRunning()) {
  394. runEnergy = random(40, 95);
  395. setRun(true);
  396. wait(random(500, 750));
  397. }
  398. }
  399.  
  400. public double pointDistance(final Point point) {
  401. if (point == null)
  402. return Integer.MAX_VALUE;
  403. final Point mouse = new Point(Bot.getInputManager().getX(), Bot.getInputManager().getY());
  404. return mouse.distance(point);
  405. }
  406.  
  407. public boolean onTile(final RSTile tile, final String action, final double dx, final double dy, final int height) {
  408. if (!tile.isValid())
  409. return false;
  410. Point checkScreen = null;
  411. try {
  412. checkScreen = Calculations.tileToScreen(tile, dx, dy, height);
  413. if (!pointOnScreen(checkScreen)) {
  414. if (distanceTo(tile) <= 8) {
  415. if (getMyPlayer().isMoving())
  416. return false;
  417. walkTileMM(tile);
  418. waitToMove(1000);
  419. return false;
  420. }
  421. if (theWalker.walkTo(new RSTile[] {tile}, true))
  422. waitToMove(1000);
  423. return false;
  424. }
  425. } catch(Exception e) { }
  426. getMouseSpeed(random(8 + sAdj, 10 + sAdj));
  427. try {
  428. boolean stop = false;
  429. for (int i = 0; i <= 50; i++) {
  430. checkScreen = Calculations.tileToScreen(tile, dx, dy, height);
  431. if (!pointOnScreen(checkScreen))
  432. return false;
  433. if (pointDistance(checkScreen) < 150)
  434. getMouseSpeed(random(6 + sAdj, 8 + sAdj));
  435. if (pointDistance(checkScreen) < 50)
  436. getMouseSpeed(random(5 + sAdj, 7 + sAdj));
  437. moveMouse(checkScreen);
  438. final Object[] menuItems = getMenuItems().toArray();
  439. for (int a = 0; a < menuItems.length; a++) {
  440. if (menuItems[a].toString().toLowerCase().contains(action.toLowerCase())) {
  441. stop = true;
  442. break;
  443. }
  444. }
  445. if (stop)
  446. break;
  447. }
  448. } catch(Exception e) { }
  449. try {
  450. return atMenu(action);
  451. } catch(Exception e) { }
  452. return false;
  453. }
  454.  
  455. public boolean onNPC(final RSNPC npc, final String action) {
  456. if (npc == null)
  457. return false;
  458. Point checkScreen = null;
  459. try {
  460. checkScreen = npc.getScreenLocation();
  461. if (!pointOnScreen(checkScreen)) {
  462. if (distanceTo(npc.getLocation()) <= 8) {
  463. if (getMyPlayer().isMoving())
  464. return false;
  465. walkTileMM(npc.getLocation());
  466. waitToMove(1000);
  467. return false;
  468. }
  469. if (theWalker.walkTo(new RSTile[] {npc.getLocation()}, true))
  470. waitToMove(1000);
  471. return false;
  472. }
  473. } catch(Exception e) { }
  474. getMouseSpeed(random(8 + sAdj, 10 + sAdj));
  475. try {
  476. boolean stop = false;
  477. for (int i = 0; i <= 50; i++) {
  478. checkScreen = npc.getScreenLocation();
  479. if (!pointOnScreen(checkScreen))
  480. return false;
  481. if (pointDistance(checkScreen) < 150)
  482. getMouseSpeed(random(6 + sAdj, 8 + sAdj));
  483. if (pointDistance(checkScreen) < 50)
  484. getMouseSpeed(random(5 + sAdj, 7 + sAdj));
  485. moveMouse(checkScreen);
  486. final Object[] menuItems = getMenuItems().toArray();
  487. for (int a = 0; a < menuItems.length; a++) {
  488. if (menuItems[a].toString().toLowerCase().contains(action.toLowerCase())) {
  489. stop = true;
  490. break;
  491. }
  492. }
  493. if (stop)
  494. break;
  495. }
  496. } catch(Exception e) { }
  497. try {
  498. return atMenu(action);
  499. } catch(Exception e) { }
  500. return false;
  501. }
  502.  
  503. public RSTile findNearestEssenceTile() {
  504. RSTile tile = null;
  505. int closest = 999;
  506. for (int i = 0; i < miningTiles.length; i++) {
  507. if(distanceTo(miningTiles[i]) < closest) {
  508. closest = distanceTo(miningTiles[i]);
  509. tile = miningTiles[i];
  510. useX = tilesX[i];
  511. useY = tilesY[i];
  512. }
  513. }
  514. return tile;
  515. }
  516.  
  517. public boolean walkPath(RSTile[] path) {
  518. if(!getMyPlayer().isMoving() || distanceTo(getDestination()) <= 5)
  519. return theWalker.walkTo(path, true);
  520. return false;
  521. }
  522.  
  523. public boolean playerInArea(int maxX, int maxY, int minX, int minY) {
  524. int x = getMyPlayer().getLocation().getX();
  525. int y = getMyPlayer().getLocation().getY();
  526. if (x >= minX && x <= maxX && y >= minY && y <= maxY)
  527. return true;
  528. return false;
  529. }
  530.  
  531. public boolean playerInArea(final int[] area) {
  532. final int x = getMyPlayer().getLocation().getX();
  533. final int y = getMyPlayer().getLocation().getY();
  534. if (x >= area[2] && x <= area[0] && y >= area[3] && y <= area[1])
  535. return true;
  536. return false;
  537. }
  538.  
  539. public boolean playerInArea(Polygon area)
  540. {
  541. return area.contains(new Point(getMyPlayer().getLocation().getX(), getMyPlayer().getLocation().getY()));
  542. }
  543.  
  544. public void antiBan() {
  545. getMouseSpeed(random(9 + sAdj, 12 + sAdj));
  546. int random = random(1, 24);
  547. switch (random) {
  548. case 1:
  549. if (random(1, 10) != 1)
  550. break;
  551. moveMouse(random(10, 750), random(10, 495));
  552. break;
  553. case 2:
  554. if (random(1, 40) != 1)
  555. break;
  556. int angle = getCameraAngle() + random(-90, 90);
  557. if (angle < 0) {
  558. angle = random(0, 10);
  559. }
  560. if (angle > 359) {
  561. angle = random(0, 10);
  562. }
  563. setCameraRotation(angle);
  564. break;
  565. case 3:
  566. if (random(1, 3) != 1)
  567. break;
  568. moveMouseSlightly();
  569. break;
  570. default:
  571. break;
  572. }
  573. getMouseSpeed(random(8 + sAdj, 11 + sAdj));
  574. }
  575.  
  576. public void onFinish() {
  577. Bot.getEventManager().removeListener( PaintListener.class, this );
  578. }
  579.  
  580. public void onRepaint(final Graphics g) {
  581. if (mapPaint) {
  582. theWalker.drawMap(g);
  583. }
  584. if (paint) {
  585. thePainter.paint(g);
  586. }
  587. }
  588.  
  589. //If you use my paint please give credit.
  590. public class GarrettsPaint {
  591.  
  592. final Rectangle r = new Rectangle(7, 345, 408, 114);
  593. final Rectangle r1 = new Rectangle(420, 345, 77, 25);
  594. final Rectangle r2 = new Rectangle(420, 374, 77, 26);
  595. final Rectangle r3 = new Rectangle(420, 404, 77, 26);
  596. final Rectangle r4 = new Rectangle(420, 434, 77, 25);
  597. final Rectangle r2c = new Rectangle(415, 374, 5, 26);
  598. final Rectangle r3c = new Rectangle(415, 404, 5, 26);
  599. final Rectangle r4c = new Rectangle(415, 434, 5, 25);
  600. final Rectangle sb1 = new Rectangle(12, 350, 398, 12);
  601. final Rectangle sb2 = new Rectangle(12, 363, 398, 12);
  602. final Rectangle sb3 = new Rectangle(12, 376, 398, 12);
  603. final Rectangle sb4 = new Rectangle(12, 389, 398, 12);
  604. final Rectangle sb5 = new Rectangle(12, 402, 398, 12);
  605. final Rectangle sb6 = new Rectangle(12, 415, 398, 12);
  606. final Rectangle sb7 = new Rectangle(12, 428, 398, 12);
  607. final Rectangle sb8 = new Rectangle(12, 441, 398, 12);
  608. final Rectangle sb1s = new Rectangle(12, 350, 196, 12);
  609. final Rectangle sb2s = new Rectangle(12, 363, 196, 12);
  610. final Rectangle sb3s = new Rectangle(12, 376, 196, 12);
  611. final Rectangle sb4s = new Rectangle(12, 389, 196, 12);
  612. final Rectangle sb5s = new Rectangle(12, 402, 196, 12);
  613. final Rectangle sb6s = new Rectangle(12, 415, 196, 12);
  614. final Rectangle sb7s = new Rectangle(12, 428, 196, 12);
  615. final Rectangle sb8s = new Rectangle(12, 441, 196, 12);
  616. final Rectangle sb9s = new Rectangle(213, 350, 196, 12);
  617. final Rectangle sb10s = new Rectangle(213, 363, 196, 12);
  618. final Rectangle sb11s = new Rectangle(213, 376, 196, 12);
  619. final Rectangle sb12s = new Rectangle(213, 389, 196, 12);
  620. final Rectangle sb13s = new Rectangle(213, 402, 196, 12);
  621. final Rectangle sb14s = new Rectangle(213, 415, 196, 12);
  622. final Rectangle sb15s = new Rectangle(213, 428, 196, 12);
  623. final Rectangle sb16s = new Rectangle(213, 441, 196, 12);
  624. Rectangle[] skillBars = new Rectangle[] {sb1, sb2, sb3, sb4, sb5, sb6, sb7, sb8};
  625. boolean savedStats = false;
  626. boolean scriptRunning = false;
  627. boolean checkedCount = false;
  628. int currentTab = 0;
  629. int lastTab = 0;
  630. int[] barIndex = new int[16];
  631. int[] start_exp = null;
  632. int[] start_lvl = null;
  633. int[] gained_exp = null;
  634. int[] gained_lvl = null;
  635.  
  636. Thread mouseWatcher = new Thread();
  637. final NumberFormat nf = NumberFormat.getInstance();
  638.  
  639. final long time_ScriptStart = System.currentTimeMillis();
  640. long runTime = System.currentTimeMillis() - time_ScriptStart;
  641.  
  642. int sine = 0;
  643. int sineM = 1;
  644. public void paint(final Graphics g) {
  645. if (!isLoggedIn() || !scriptRunning)
  646. return;
  647.  
  648. //credits to Jacmob for the pulsing
  649. if (sine >= 84) {
  650. sine = 84;
  651. sineM *= -1;
  652. } else if (sine <= 1) {
  653. sine = 1;
  654. sineM *= -1;
  655. }
  656. sine += sineM;
  657.  
  658. runTime = System.currentTimeMillis() - time_ScriptStart;
  659. final String formattedTime = formatTime((int) runTime);
  660.  
  661. currentTab = paintTab();
  662.  
  663. switch(currentTab) {
  664. case -1: //PAINT OFF
  665. g.setColor(new Color(0, 0, 0, 150));
  666. g.fillRect(r1.x, r1.y, r1.width, r1.height);
  667. g.setColor(Color.WHITE);
  668. drawString(g, "Show Paint", r1, 5);
  669. break;
  670. case 0: //DEFAULT TAB - MAIN
  671. drawPaint(g, r2c);
  672. g.setColor(new Color(100, 100, 100, 200));
  673. g.drawLine(r.x + 204, r.y + 22, r.x + 204, r.y + 109);
  674. g.setColor(Color.WHITE);
  675. g.setFont(new Font("sansserif", Font.BOLD, 14));
  676. drawString(g, properties.name(), r, -40);
  677. g.setFont(new Font("sansserif", Font.PLAIN, 12));
  678. drawStringMain(g, "Runtime: ", formattedTime, r, 20, 35, 0, true);
  679. int essPerHour = 0;
  680. int moneyPerHour = 0;
  681. int gainedEXP = skills.getCurrentSkillExp(Skills.getStatIndex("mining")) - start_exp[Skills.getStatIndex("mining")];
  682. final int totalEssence = (gainedEXP / 5);
  683. final int totalMoney = totalEssence * value;
  684. if ((runTime / 1000) > 0) {
  685. essPerHour = (int) ((3600000.0 / (double) runTime) * totalEssence);
  686. moneyPerHour = (int) ((3600000.0 / (double) runTime) * totalMoney);
  687. }
  688. drawStringMain(g, "Essence Mined: ", Integer.toString(totalEssence), r, 20, 35, 2, true);
  689. drawStringMain(g, "Essence / Hour: ", Integer.toString(essPerHour), r, 20, 35, 3, true);
  690.  
  691. drawStringMain(g, "Money Gained: ", Integer.toString(totalMoney), r, 20, 35, 2, false);
  692. drawStringMain(g, "Money / Hour: ", Integer.toString(moneyPerHour), r, 20, 35, 3, false);
  693. break;
  694. case 1: //INFO
  695. drawPaint(g, r3c);
  696. g.setColor(new Color(100, 100, 100, 200));
  697. g.drawLine(r.x + 204, r.y + 22, r.x + 204, r.y + 109);
  698. g.setColor(Color.WHITE);
  699. g.setFont(new Font("sansserif", Font.BOLD, 14));
  700. drawString(g, properties.name(), r, -40);
  701. g.setFont(new Font("sansserif", Font.PLAIN, 12));
  702. drawStringMain(g, "Version: ", Double.toString(properties.version()), r, 20, 35, 0, true);
  703. break;
  704. case 2: //STATS
  705. drawPaint(g, r4c);
  706. drawStats(g);
  707. hoverMenu(g);
  708. break;
  709. }
  710. }
  711.  
  712. public void saveStats() {
  713. nf.setMinimumIntegerDigits(2);
  714. final String[] stats = Skills.statsArray;
  715. start_exp = new int[stats.length];
  716. start_lvl = new int[stats.length];
  717. for (int i = 0; i < stats.length; i++) {
  718. start_exp[i] = skills.getCurrentSkillExp(i);
  719. start_lvl[i] = skills.getCurrentSkillLevel(i);
  720. }
  721. for (int i = 0; i < barIndex.length; i++) {
  722. barIndex[i] = -1;
  723. }
  724. savedStats = true;
  725. }
  726.  
  727. public int paintTab() {
  728. final Point mouse = new Point(Bot.getClient().getMouse().x, Bot.getClient().getMouse().y);
  729. if (mouseWatcher.isAlive())
  730. return currentTab;
  731. if (r1.contains(mouse)) {
  732. mouseWatcher = new Thread(new MouseWatcher(r1));
  733. mouseWatcher.start();
  734. if (currentTab == -1) {
  735. return lastTab;
  736. } else {
  737. lastTab = currentTab;
  738. return -1;
  739. }
  740. }
  741. if (currentTab == -1)
  742. return currentTab;
  743. if (r2.contains(mouse))
  744. return 0;
  745. if (r3.contains(mouse))
  746. return 1;
  747. if (r4.contains(mouse))
  748. return 2;
  749. return currentTab;
  750. }
  751.  
  752. public void drawPaint(final Graphics g, final Rectangle rect) {
  753. g.setColor(new Color(0, 0, 0, 230));
  754. g.fillRect(r1.x, r1.y, r1.width, r1.height);
  755. g.fillRect(r2.x, r2.y, r2.width, r2.height);
  756. g.fillRect(r3.x, r3.y, r3.width, r3.height);
  757. g.fillRect(r4.x, r4.y, r4.width, r4.height);
  758. g.fillRect(rect.x, rect.y, rect.width, rect.height);
  759. g.fillRect(r.x, r.y, r.width, r.height);
  760. g.setColor(Color.WHITE);
  761. drawString(g, "Hide Paint", r1, 5);
  762. drawString(g, "MAIN", r2, 5);
  763. drawString(g, "INFO", r3, 5);
  764. drawString(g, "STATS", r4, 5);
  765. g.setColor(new Color(0, 0, 0, 230));
  766. }
  767.  
  768. public void drawStat(final Graphics g, final int index, final int count) {
  769. if (count >= skillBars.length && !checkedCount) {
  770. skillBars = new Rectangle[] {sb1s, sb2s, sb3s, sb4s, sb5s, sb6s, sb7s, sb8s, sb9s, sb10s, sb11s, sb12s, sb13s, sb14s, sb15s, sb16s};
  771. checkedCount = true;
  772. }
  773. if (count >= skillBars.length)
  774. return;
  775. g.setFont(new Font("serif", Font.PLAIN, 11));
  776. g.setColor(new Color(100, 100, 100, 150));
  777. g.fillRect(skillBars[count].x, skillBars[count].y, skillBars[count].width, skillBars[count].height);
  778. final int percent = skills.getPercentToNextLevel(index);
  779. g.setColor(new Color(255 - 2 * percent, (int) (1.7 * percent + sine), 0, 150));
  780. g.fillRect(skillBars[count].x, skillBars[count].y, (int) (((double) skillBars[count].width / 100.0) * (double) percent), skillBars[count].height);
  781. g.setColor(Color.WHITE);
  782. final String name = Skills.statsArray[index];
  783. final String capitalized = name.substring(0, 1).toUpperCase() + name.substring(1);
  784. g.drawString(capitalized, skillBars[count].x + 2, skillBars[count].y + 10);
  785. drawStringEnd(g, percent + "%", skillBars[count], -2, 4);
  786. barIndex[count] = index;
  787. }
  788.  
  789. public void drawStats(final Graphics g) {
  790. final String[] stats = Skills.statsArray;
  791. int count = 0;
  792. gained_exp = new int[stats.length];
  793. gained_lvl = new int[stats.length];
  794. for (int i = 0; i < stats.length; i++) {
  795. gained_exp[i] = skills.getCurrentSkillExp(i) - start_exp[i];
  796. gained_lvl[i] = skills.getCurrentSkillLevel(i) - start_lvl[i];
  797. if (gained_exp[i] > 0) {
  798. drawStat(g, i, count);
  799. count++;
  800. }
  801. }
  802. }
  803.  
  804. public void hoverMenu(final Graphics g) {
  805. final Point mouse = new Point(Bot.getClient().getMouse().x, Bot.getClient().getMouse().y);
  806. final Rectangle r_main = new Rectangle(mouse.x, mouse.y - 150, 300, 150);
  807. for (int i = 0; i < barIndex.length; i++) {
  808. if (barIndex[i] > -1) {
  809. if (skillBars[i].contains(mouse)) {
  810. final int xpTL = skills.getXPToNextLevel(barIndex[i]);
  811. final int xpHour = ((int) ((3600000.0 / (double) runTime) * gained_exp[barIndex[i]]));
  812. final int TTL = (int) (((double) xpTL / (double) xpHour) * 3600000);
  813. g.setColor(new Color(50, 50, 50, 240));
  814. g.fillRect(r_main.x, r_main.y, r_main.width, r_main.height);
  815. g.setColor(Color.WHITE);
  816. g.setFont(new Font("sansserif", Font.BOLD, 15));
  817. drawString(g, Skills.statsArray[barIndex[i]].toUpperCase(), r_main, -58);
  818. g.setFont(new Font("sansserif", Font.PLAIN, 12));
  819. hoverDrawString(g, "Current Level: ", skills.getCurrentSkillLevel(barIndex[i]) + "", r_main, 40, 0);
  820. hoverDrawString(g, "XP Gained: ", gained_exp[barIndex[i]] + "xp", r_main, 40, 1);
  821. hoverDrawString(g, "XP / Hour: ", xpHour + "xp", r_main, 40, 2);
  822. hoverDrawString(g, "LVL Gained: ", gained_lvl[barIndex[i]] + " lvls", r_main, 40, 3);
  823. hoverDrawString(g, "XPTL: ", xpTL + "xp", r_main, 40, 4);
  824. hoverDrawString(g, "TTL: ", formatTime(TTL), r_main, 40, 5);
  825. }
  826. }
  827. }
  828. }
  829.  
  830. public void hoverDrawString(final Graphics g, final String str, final String val, final Rectangle rect, final int offset, final int index) {
  831. g.setColor(Color.WHITE);
  832. final FontMetrics font = g.getFontMetrics();
  833. final Rectangle2D bounds = font.getStringBounds(val, g);
  834. final int width = (int) bounds.getWidth();
  835. final int y = rect.y + offset + (20 * index);
  836. g.drawString(str, rect.x + 5, y);
  837. g.drawString(val, (rect.x + rect.width) - width - 5, y);
  838. if (index < 5) {
  839. g.setColor(new Color(100, 100, 100, 200));
  840. g.drawLine(rect.x + 5, y + 5, rect.x + rect.width - 5, y + 5);
  841. }
  842. }
  843.  
  844. public void drawString(final Graphics g, final String str, final Rectangle rect, final int offset) {
  845. final FontMetrics font = g.getFontMetrics();
  846. final Rectangle2D bounds = font.getStringBounds(str, g);
  847. final int width = (int) bounds.getWidth();
  848. g.drawString(str, rect.x + ((rect.width - width) / 2), rect.y + ((rect.height / 2) + offset));
  849. }
  850.  
  851. public void drawStringEnd(final Graphics g, final String str, final Rectangle rect, final int xOffset, final int yOffset) {
  852. final FontMetrics font = g.getFontMetrics();
  853. final Rectangle2D bounds = font.getStringBounds(str, g);
  854. final int width = (int) bounds.getWidth();
  855. g.drawString(str, (rect.x + rect.width) - width + xOffset, rect.y + ((rect.height / 2) + yOffset));
  856. }
  857.  
  858. public void drawStringMain(final Graphics g, final String str, final String val, final Rectangle rect, final int xOffset, final int yOffset, final int index, final boolean leftSide) {
  859. final FontMetrics font = g.getFontMetrics();
  860. final Rectangle2D bounds = font.getStringBounds(val, g);
  861. final int indexMult = 17;
  862. final int width = (int) bounds.getWidth();
  863. if (leftSide) {
  864. g.drawString(str, rect.x + xOffset, rect.y + yOffset + (index * indexMult));
  865. g.drawString(val, rect.x + (rect.width / 2) - width - xOffset, rect.y + yOffset + (index * indexMult));
  866. } else {
  867. g.drawString(str, rect.x + (rect.width / 2) + xOffset, rect.y + yOffset + (index * indexMult));
  868. g.drawString(val, rect.x + rect.width - width - xOffset, rect.y + yOffset + (index * indexMult));
  869. }
  870. }
  871.  
  872. public String formatTime(final int milliseconds) {
  873. final long t_seconds = milliseconds / 1000;
  874. final long t_minutes = t_seconds / 60;
  875. final long t_hours = t_minutes / 60;
  876. final int seconds = (int) (t_seconds % 60);
  877. final int minutes = (int) (t_minutes % 60);
  878. final int hours = (int) (t_hours % 60);
  879. return (nf.format(hours) + ":" + nf.format(minutes) + ":" + nf.format(seconds));
  880. }
  881.  
  882. public class MouseWatcher implements Runnable {
  883.  
  884. Rectangle rect = null;
  885.  
  886. MouseWatcher(final Rectangle rect) {
  887. this.rect = rect;
  888. }
  889.  
  890. public void run() {
  891. Point mouse = new Point(Bot.getClient().getMouse().x, Bot.getClient().getMouse().y);
  892. while (rect.contains(mouse)) {
  893. try {
  894. mouse = new Point(Bot.getClient().getMouse().x, Bot.getClient().getMouse().y);
  895. Thread.sleep(50);
  896. } catch(Exception e) { }
  897. }
  898. }
  899.  
  900. }
  901.  
  902. }
  903.  
  904. //Please give credit if you decide to use
  905. public class TheWalker {
  906.  
  907. Methods methods = new Methods();
  908. Thread walker = null;
  909. RSTile[] path = null;
  910.  
  911. public void drawMap(final Graphics g) {
  912. if (walker != null && walker.isAlive()) {
  913. Point myTile = tileToMinimap(getMyPlayer().getLocation());
  914. Point center = new Point(myTile.x + 2, myTile.y + 2);
  915. g.drawOval(center.x - 70, center.y - 70, 140, 140);
  916. if (path == null) return;
  917. for (int i = 0; i < path.length; i++) {
  918. final RSTile tile = path[i];
  919. final Point p = tileToMinimap(tile);
  920. if (p.x != -1 && p.y != -1) {
  921. g.setColor(Color.BLACK);
  922. g.fillRect(p.x + 1, p.y + 1, 3, 3);
  923. if (i > 0) {
  924. final Point p1 = tileToMinimap(path[i - 1]);
  925. g.setColor(Color.ORANGE);
  926. if (p1.x != -1 && p1.y != -1)
  927. g.drawLine(p.x + 2, p.y + 2, p1.x + 2, p1.y + 2);
  928. }
  929. }
  930. }
  931. Point tile = tileToMinimap(nextTile(path));
  932. g.setColor(Color.RED);
  933. if (tile.x != -1 && tile.y != -1) {
  934. g.fillRect(tile.x + 1, tile.y + 1, 3, 3);
  935. }
  936. g.setColor(Color.BLACK);
  937. }
  938. }
  939.  
  940. public boolean walkTo(final RSTile[] path, final boolean waitUntilDest) {
  941. Walker walkto = new Walker(path, 3, 10000);
  942. walker = new Thread(walkto);
  943. walker.start();
  944. waitToMove(random(800, 1200));
  945. if (waitUntilDest) {
  946. while (walker.isAlive()) {
  947. methods.wait(random(300, 600));
  948. }
  949. return walkto.done;
  950. } else return true;
  951. }
  952.  
  953. public Point tileToMM(RSTile tile) {
  954. return new Point(tileToMinimap(tile).x + 2, tileToMinimap(tile).y + 2);
  955. }
  956.  
  957. public boolean tileOnMM(RSTile tile) {
  958. return pointOnMM(tileToMM(tile));
  959. }
  960.  
  961. public boolean pointOnMM(Point point) {
  962. Point myTile = tileToMM(getMyPlayer().getLocation());
  963. Point center = new Point(myTile.x, myTile.y);
  964. return (center.distance(point) < 70) ? true : false;
  965. }
  966.  
  967. public RSTile getClosestTileOnMap(final RSTile tile) {
  968. if (isLoggedIn() && !tileOnMM(tile)) {
  969. try {
  970. final RSTile loc = getMyPlayer().getLocation();
  971. final RSTile walk = new RSTile((loc.getX() + tile.getX()) / 2, (loc.getY() + tile.getY()) / 2);
  972. return tileOnMM(walk) ? walk : getClosestTileOnMap(walk);
  973. } catch (final Exception e) { }
  974. }
  975. return tile;
  976. }
  977.  
  978. public RSTile nextTile(RSTile[] path) {
  979. for (int i = path.length - 1; i >= 0; i--) {
  980. if (tileOnMM(path[i])) {
  981. return path[i];
  982. }
  983. }
  984. return getClosestTileOnMap(path[0]);
  985. }
  986.  
  987. public class Walker implements Runnable {
  988.  
  989. RSTile tile = null;
  990. boolean done = false;
  991. boolean stop = false;
  992. int movementTimer = 10000;
  993. int distanceTo = 3;
  994.  
  995. Walker(final RSTile[] userpath) {
  996. this.tile = userpath[userpath.length - 1];
  997. path = userpath;
  998. }
  999.  
  1000. Walker(final RSTile[] userpath, final int distanceTo, final int movementTimer) {
  1001. this.tile = userpath[userpath.length - 1];
  1002. this.movementTimer = movementTimer;
  1003. this.distanceTo = distanceTo;
  1004. path = userpath;
  1005. }
  1006.  
  1007. public void run() {
  1008. long timer = System.currentTimeMillis();
  1009. RSTile lastTile = getMyPlayer().getLocation();
  1010. int randomReturn = random(5, 8);
  1011. while (distanceTo(tile) > distanceTo && !stop) {
  1012. if (!getMyPlayer().isMoving() || getDestination() == null || distanceTo(getDestination()) < randomReturn) {
  1013. RSTile nextTile = nextTile(path);
  1014. if (getDestination() != null && distanceBetween(getDestination(), nextTile) <= distanceTo) {
  1015. continue;
  1016. }
  1017. getMouseSpeed(random(6 + sAdj, 8 + sAdj));
  1018. walkTileMM(nextTile);
  1019. getMouseSpeed(random(8 + sAdj, 10 + sAdj));
  1020. waitToMove(random(800, 1200));
  1021. randomReturn = random(5, 8);
  1022. }
  1023. final RSTile myLoc = getMyPlayer().getLocation();
  1024. if (myLoc != lastTile) {
  1025. if (distanceBetween(myLoc, lastTile) > 30) {
  1026. log("Teleportation Detected. Stopping The Walking Loop.");
  1027. stop = true;
  1028. }
  1029. timer = System.currentTimeMillis();
  1030. lastTile = myLoc;
  1031. }
  1032. if (System.currentTimeMillis() - timer > movementTimer) {
  1033. stop = true;
  1034. }
  1035. methods.wait(random(20, 40));
  1036. }
  1037. if (distanceTo(tile) <= distanceTo) {
  1038. done = true;
  1039. }
  1040. }
  1041.  
  1042. }
  1043.  
  1044. }
  1045.  
  1046. }
Add Comment
Please, Sign In to add comment