Guest User

Untitled

a guest
Dec 5th, 2017
111
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 45.01 KB | None | 0 0
  1. import org.rsbot.event.listeners.PaintListener;
  2. import org.rsbot.script.Script;
  3. import org.rsbot.script.ScriptManifest;
  4. import org.rsbot.script.methods.Bank;
  5. import org.rsbot.script.util.Timer;
  6. import org.rsbot.script.wrappers.*;
  7.  
  8. import java.awt.*;
  9. import java.awt.event.KeyEvent;
  10. import java.awt.event.MouseEvent;
  11. import java.awt.event.MouseListener;
  12. import java.awt.event.MouseMotionListener;
  13. import java.util.ArrayList;
  14.  
  15. /**
  16. * Created by IntelliJ IDEA.
  17. * User: Tyler Janca
  18. * Date: Jan 23, 2011
  19. * Time: 5:34:36 PM
  20. */
  21. @ScriptManifest(authors = "Janca", name = "Ash Collector V2", version = 1.666)
  22. public class AshCollector extends Script implements PaintListener, MouseMotionListener, MouseListener {
  23.  
  24. int maxAreaDistance = 30, ashID = 592, fireID = 2732, ashCollected, ashMPrice, flag, invent = 0, failPickup = 0;
  25.  
  26. RSPath walkingPath;
  27. RSTile startingTile;
  28. RSArea startingArea;
  29.  
  30. AshCollectorPaint paint = new AshCollectorPaint();
  31. ScriptMethods methods = new ScriptMethods();
  32.  
  33. Thread p;
  34.  
  35. Point mousePoint = new Point(-1, -1);
  36.  
  37. boolean scriptStopping = false, didClick = false;
  38.  
  39. ArrayList<ColorButton> colorButtons = new ArrayList<ColorButton>();
  40. ArrayList<MouseEffects> effects = new ArrayList<MouseEffects>();
  41.  
  42. RSTile newLocation = null;
  43.  
  44.  
  45. Color colors[];
  46.  
  47. long startTime = -1;
  48.  
  49. public boolean onStart() {
  50. if (!game.isLoggedIn()) {
  51. log.warning("You MUST be fully logged in before starting this script!");
  52. return false;
  53. }
  54.  
  55.  
  56. methods.createColorButtons();
  57.  
  58. p = new Thread(paint);
  59. p.start();
  60.  
  61. startTime = System.currentTimeMillis();
  62. startingTile = getMyPlayer().getLocation();
  63. startingArea = new RSArea(new RSTile(startingTile.getX() - maxAreaDistance, startingTile.getY() - maxAreaDistance),
  64. new RSTile(startingTile.getX() + maxAreaDistance, startingTile.getY() + maxAreaDistance));
  65. return true;
  66. }
  67.  
  68. public int loop() {
  69.  
  70. try {
  71. if (bank.isOpen() && inventory.getCount() == 0) {
  72. if (bank.close()) {
  73. Timer fs = new Timer(5000);
  74. while (fs.isRunning() && bank.isOpen()) sleep(120);
  75. if (bank.isOpen())
  76. return 120;
  77. }
  78. }
  79.  
  80. if (failPickup > 5) {
  81. if (newLocation == null) {
  82. RSGroundItem items[] = groundItems.getAll();
  83. int dist = Integer.MIN_VALUE;
  84. RSTile location = null;
  85. for (RSGroundItem item : items) {
  86. RSTile locationTemp = item.getLocation();
  87. if (calc.distanceTo(locationTemp) > dist && startingArea.contains(locationTemp)) {
  88. dist = calc.distanceTo(locationTemp);
  89. location = locationTemp;
  90. }
  91. }
  92. newLocation = (location == null ? methods.nearestBank() : location);
  93. }
  94.  
  95. if (calc.distanceTo(newLocation) > 4) {
  96. methods.setStatus("Moving to a new location");
  97. walking.walkTo(newLocation);
  98. } else {
  99. newLocation = null;
  100. failPickup = 0;
  101. }
  102. }
  103.  
  104. methods.antibanHandler();
  105. methods.clearInventoryOfUnwantedItems();
  106.  
  107. if (inventory.isFull()) {
  108. if (calc.distanceTo(methods.nearestBank()) >= 4) {
  109. methods.setStatus("Walking to Bank");
  110. if (walkingPath == null) {
  111. walkingPath = walking.getPath(methods.nearestBank());
  112. } else {
  113. walkingPath.traverse();
  114. }
  115. } else {
  116. walkingPath = null;
  117. if (!bank.isOpen()) {
  118. if (methods.openBank())
  119. methods.depositAll();
  120. } else {
  121. methods.depositAll();
  122. }
  123.  
  124. }
  125. } else {
  126. if (!startingArea.contains(getMyPlayer().getLocation())) {
  127. methods.setStatus("Walking to Start Position");
  128. if (walkingPath == null) {
  129. walkingPath = walking.getPath(startingTile);
  130. } else {
  131. walkingPath.traverse();
  132. }
  133. } else {
  134. walkingPath = null;
  135. RSGroundItem temp = methods.getNearestAshPile();
  136. RSGroundItem ash = (startingArea.contains(temp.getLocation()) && methods.pureAsh(temp.getLocation()) ? temp : null);
  137. if (ash == null) {
  138. methods.setStatus("Waiting");
  139. RSObject temp1 = objects.getNearest(fireID);
  140. RSObject fire = (startingArea.contains(temp1.getLocation()) ? temp1 : null);
  141. if (fire == null)
  142. flag++;
  143. if (calc.distanceTo(fire) > 1) {
  144. methods.setStatus("Walking to Fire");
  145. walking.walkTo(objects.getNearest(fireID).getLocation());
  146. if (random(0, 20) < 4)
  147. flag++;
  148. } else {
  149. if (random(0, 16) < 10)
  150. methods.bored();
  151. }
  152. return 100;
  153. }
  154.  
  155. if (getMyPlayer().isMoving()) {
  156. if (ash == null)
  157. return 200;
  158. if (calc.distanceTo(walking.getDestination()) <= 3) {
  159. if (random(0, 20) < 4)
  160. camera.turnTo(ash.getLocation(), random(0, 25));
  161. methods.setStatus("Taking Ashes");
  162. if (random(0, 12) < 8) {
  163. int inventB4 = inventory.getCount();
  164. if (ash.doAction("Take")) {
  165. didClick = true;
  166. Timer fs = new Timer(3200);
  167. do sleep(500);
  168. while (fs.isRunning() && inventB4 == inventory.getCount());
  169. }
  170. } else {
  171. mouse.move(groundItems.getNearest(ashID).getModel().getPoint(), 50, 180);
  172. }
  173. return 20;
  174. }
  175. } else {
  176. if (ash == null)
  177. return 200;
  178. if (ash.isOnScreen()) {
  179. methods.setStatus("Taking Ashes");
  180. int inventB4 = inventory.getCount();
  181. if (ash.doAction("Take")) {
  182. didClick = true;
  183. Timer fs = new Timer(3200);
  184. do sleep(500);
  185. while (fs.isRunning() && inventB4 == inventory.getCount());
  186. }
  187. } else {
  188. if (ash == null)
  189. return 250;
  190. if (walking.walkTo(ash.getLocation())) {
  191. methods.setStatus("Walking to Ash");
  192. Timer fs = new Timer(909);
  193. while (fs.isRunning()) {
  194. if (walking.getDestination() != null) {
  195. if (calc.distanceTo(walking.getDestination()) < 8)
  196. break;
  197. } else if (walking.getDestination() == null) {
  198. break;
  199. }
  200. }
  201. }
  202. }
  203. }
  204. }
  205. }
  206.  
  207. int t = inventory.getCount(ashID);
  208. if (t > invent) {
  209. ashCollected += t - invent;
  210. invent = t;
  211. if ((failPickup - 2) > 0) failPickup -= 2;
  212. else if (failPickup > 0) failPickup++;
  213. } else if (t <= 0) {
  214. invent = 0;
  215. } else if (t == invent) {
  216. if (didClick)
  217. failPickup++;
  218. }
  219.  
  220. didClick = false;
  221.  
  222. } catch (Exception ignore) {}
  223. return random(520, 950);
  224. }
  225.  
  226. public void onFinish() {
  227. scriptStopping = true;
  228. sleep(1200);
  229. env.saveScreenshot(false);
  230. sleep(1200);
  231. }
  232.  
  233. public void onRepaint(Graphics g1) {
  234. Graphics2D g = (Graphics2D) g1;
  235. g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
  236. if (game.isLoggedIn())
  237. paint.paint(g);
  238.  
  239. if (scriptStopping) {
  240. g.setFont(paint.statsBarFont);
  241. g.setColor(new Color(0, 0, 0, 220));
  242. g.fillRect(547, 205, 189, 260);
  243. g.setColor(new Color(0, 0, 0));
  244. g.drawRect(547, 205, 189, 260);
  245.  
  246.  
  247. int y = 226;
  248. g.setColor(paint.themeColor);
  249. drawStringCentered(g, paint.statsBarFont, "Ash Collector :: By Janca", 226);
  250. drawStringCentered(g, paint.statsBarFont, "Running Time: " + paint.getTimeRunning(), y += 16);
  251. drawStringCentered(g, paint.statsBarFont, "Ashes Collected: " + ashCollected, y += 16);
  252. drawStringCentered(g, paint.statsBarFont, "Ashes/Hour: " + (ashCollected > 0
  253. ? (int) ((ashCollected * 3600000D) / (System.currentTimeMillis() - startTime))
  254. : "N/A"), y += 16);
  255. drawStringCentered(g, paint.statsBarFont, "Profit Made: " + (ashCollected * ashMPrice), y += 16);
  256. drawStringCentered(g, paint.statsBarFont, "Profit/Hour: " + (ashCollected > 0
  257. ? (int) (((ashCollected * ashMPrice) * 3600000D) / (System.currentTimeMillis() - startTime))
  258. : "N/A"), y += 16);
  259. }
  260. }
  261.  
  262. private void drawStringCentered(Graphics2D g, Font font, String string, int y) {
  263. FontMetrics metrics = g.getFontMetrics(font);
  264. g.drawString(string, (1285 - metrics.stringWidth(string)) / 2, y);
  265. }
  266.  
  267. public void mouseClicked(MouseEvent e) {
  268. Rectangle rect = new Rectangle(724, 0, 40, 20);
  269. if (rect.contains(e.getPoint())) {
  270. log("You have changed your staring position: " + startingTile.toString());
  271. startingTile = getMyPlayer().getLocation();
  272. startingArea = new RSArea(new RSTile(startingTile.getX() - maxAreaDistance, startingTile.getY() - maxAreaDistance),
  273. new RSTile(startingTile.getX() + maxAreaDistance, startingTile.getY() + maxAreaDistance));
  274.  
  275. }
  276.  
  277. for (ColorButton colorButton1 : colorButtons) {
  278. if (colorButton1.onButton(e.getPoint())) {
  279. for (ColorButton colorButton : colorButtons) {
  280. if (colorButton.onButton(e.getPoint())) {
  281. colorButton.setSelected(true);
  282. paint.themeColor = colorButton.getColor();
  283. } else {
  284. colorButton.setSelected(false);
  285. }
  286. }
  287. }
  288. }
  289. }
  290.  
  291. public void mousePressed(MouseEvent e) {}
  292.  
  293. public void mouseReleased(MouseEvent e) {}
  294.  
  295. public void mouseEntered(MouseEvent e) {}
  296.  
  297. public void mouseExited(MouseEvent e) {}
  298.  
  299. public void mouseDragged(MouseEvent e) {}
  300.  
  301. int currentIdx = 0;
  302. Point origPoint = new Point(-1, -1);
  303.  
  304. public void mouseMoved(MouseEvent e) {
  305. if (distanceBetween(origPoint, e.getPoint()) > 5) {
  306. effects.add(new MouseEffects(e.getX(), e.getY(), currentIdx < colorButtons.size() ? colors[currentIdx++] : colors[(currentIdx = 0)]));
  307.  
  308. origPoint = e.getPoint();
  309. }
  310.  
  311. paint.hoverColor = null;
  312. for (ColorButton colorButton : colorButtons) {
  313. if (colorButton.onButton(e.getPoint())) {
  314. if (paint.themeColor != colorButton.getColor())
  315. paint.hoverColor = colorButton.getColor();
  316. }
  317. }
  318. }
  319.  
  320. public int distanceBetween(Point point1, Point point2) {
  321. return (int) Math.sqrt((point1.getX() - point2.getX()) * (point1.getX() - point2.getX())
  322. + (point1.getY() - point2.getY()) * (point1.getY() - point2.getY()));
  323. }
  324.  
  325. public class ScriptMethods {
  326.  
  327. public void createColorButtons() {
  328. int x = 0;
  329. colorButtons.add(new ColorButton(x, 318, new Color(128, 0, 255), true));
  330. colorButtons.add(new ColorButton(x, 318, new Color(158, 11, 11), false));
  331. colorButtons.add(new ColorButton(x, 318, new Color(255, 0, 0), false));
  332. colorButtons.add(new ColorButton(x, 318, new Color(255, 0, 128), false));
  333. colorButtons.add(new ColorButton(x, 318, new Color(237, 20, 91), false));
  334. colorButtons.add(new ColorButton(x, 318, new Color(0, 84, 166), false));
  335. colorButtons.add(new ColorButton(x, 318, new Color(0, 174, 239), false));
  336. colorButtons.add(new ColorButton(x, 318, new Color(0, 255, 255), false));
  337. colorButtons.add(new ColorButton(x, 318, new Color(100, 255, 0), false));
  338. colorButtons.add(new ColorButton(x, 318, new Color(200, 255, 0), false));
  339. colorButtons.add(new ColorButton(x, 318, new Color(255, 255, 0), false));
  340. colorButtons.add(new ColorButton(x, 318, new Color(230, 125, 0), false));
  341. colorButtons.add(new ColorButton(x, 318, new Color(255, 128, 0), false));
  342.  
  343. x = 516 - (colorButtons.size() * 21) - 24;
  344. colors = new Color[colorButtons.size()];
  345. for (int i = 0; i < colorButtons.size(); i++) {
  346. colorButtons.get(i).setX(x += 21);
  347. colors[i] = colorButtons.get(i).getColor();
  348. }
  349. }
  350.  
  351. public void clearInventoryOfUnwantedItems() {
  352. RSItem inventItems[] = inventory.getItems();
  353. for (RSItem item : inventItems) {
  354. if (item.getID() != ashID && item.getID() != -1 && item != null) {
  355. mouse.setSpeed(random(8, 14));
  356. methods.setStatus("Dropping: " + item.getName());
  357. int inB4 = inventory.getCount();
  358. if (item.doAction("Drop")) {
  359. Timer fs = new Timer(2200);
  360. do sleep(1200);
  361. while (fs.isRunning() && inB4 == inventory.getCount());
  362. if (inventory.contains(item.getID()))
  363. sleep(1200);
  364. }
  365. }
  366. }
  367. }
  368.  
  369. public void antibanHandler() {
  370. if (random(0, 100) <= 60)
  371. mouse.setSpeed(random(2, 8));
  372.  
  373. if (flag > 7 && random(0, 12) < 8) {
  374. antiban(random(0, 15));
  375. flag = 0;
  376. }
  377.  
  378. if (random(0, 30) < 5)
  379. flag++;
  380. }
  381.  
  382. private void bored() {
  383. switch (random(0, 10)) {
  384. case 1:
  385. case 2:
  386. case 3:
  387. setStatus("Being Bored...");
  388. sleep(120);
  389. break;
  390. case 4:
  391. setStatus("Being Bored...");
  392. moveCameraRandomly(random(10, 910));
  393. if (random(0, 12) < 6)
  394. moveCameraRandomly(random(100, 800));
  395. if (random(0, 18) < 5)
  396. moveCameraRandomly(random(10, 800));
  397. break;
  398. case 5:
  399. setStatus("Being Bored...");
  400. mouse.moveRandomly(120, 800);
  401. if (random(0, 17) < 9)
  402. mouse.moveOffScreen();
  403. if (random(0, 20) < 19)
  404. mouse.moveRandomly(120, 1200);
  405. break;
  406. case 6:
  407. case 7:
  408. case 8:
  409. setStatus("Being Bored...");
  410. moveCameraRandomly(random(10, 800));
  411. if (random(0, 12) < 2)
  412. moveCameraRandomly(random(10, 800));
  413. if (random(0, 18) < 9)
  414. moveCameraRandomly(random(500, 1200));
  415. break;
  416. case 9:
  417. setStatus("Being Bored...");
  418. sleep(120);
  419. break;
  420. default:
  421. setStatus("Being Bored...");
  422. sleep(120);
  423. break;
  424.  
  425. }
  426. }
  427.  
  428. private void moveCameraRandomly(int timeOut) {
  429. int lowPosCamAlt = random(75, 100);
  430. int vertical = random(0, 20) < 15 ? KeyEvent.VK_DOWN : KeyEvent.VK_UP;
  431. int horizontal = random(0, 20) < 15 ? KeyEvent.VK_LEFT : KeyEvent.VK_RIGHT;
  432. Timer hold = new Timer(timeOut);
  433. if (random(0, 20) < 14)
  434. keyboard.pressKey((char) vertical);
  435. if (random(0, 20) < 14)
  436. keyboard.pressKey((char) horizontal);
  437. while (hold.isRunning()) {
  438. if (camera.getPitch() < lowPosCamAlt)
  439. keyboard.releaseKey((char) vertical);
  440. sleep(10);
  441. }
  442. keyboard.releaseKey((char) horizontal);
  443. keyboard.releaseKey((char) vertical);
  444. }
  445.  
  446. private void antiban(int switchNumber) {
  447. switch (switchNumber) {
  448. case 0:
  449. setStatus("Mouse Moving Off-Screen");
  450. mouse.moveOffScreen();
  451. break;
  452.  
  453. case 1:
  454. case 2:
  455. case 3:
  456. setStatus("Moving Camera");
  457. camera.setAngle(random(0, 450));
  458. break;
  459.  
  460. case 4:
  461. setStatus("Meddling with Camera");
  462. camera.setPitch(true);
  463. camera.setCompass(random(0, 12) < 6 ? 'n' : 's');
  464. mouse.moveSlightly();
  465. break;
  466.  
  467. case 5:
  468. setStatus("Hovering Nearest Player");
  469. RSPlayer playersAroundUs[] = players.getAll();
  470. RSPlayer nearestPlayer = null;
  471. int nearest = 1000;
  472. for (RSPlayer player : playersAroundUs) {
  473. if (!player.equals(getMyPlayer())) {
  474. if (calc.distanceTo(player) < nearest) {
  475. nearest = calc.distanceTo(player);
  476. nearestPlayer = player;
  477. }
  478. }
  479. }
  480.  
  481. if (nearestPlayer != null) {
  482. if (nearestPlayer.isOnScreen()) {
  483. mouse.click(nearestPlayer.getModel().getPoint(), false);
  484. sleep(500, 2300);
  485. }
  486. }
  487. mouse.moveSlightly();
  488. mouse.moveSlightly();
  489. break;
  490.  
  491. case 6:
  492. setStatus("Adjusting Mouse Speed");
  493. mouse.setSpeed(random(6, 14));
  494. break;
  495.  
  496. case 7:
  497. case 8:
  498. case 9:
  499. case 10:
  500. setStatus("Moving Mouse");
  501. mouse.moveRandomly(120, 510);
  502. break;
  503.  
  504. default:
  505. setStatus("Pausing Briefly");
  506. mouse.moveOffScreen();
  507. sleep(120, 5000);
  508.  
  509. }
  510. if (random(0, 50) < 4)
  511. antiban(random(0, 15));
  512. }
  513.  
  514. public void setStatus(String message) {
  515. paint.mouseStatus = message;
  516. }
  517.  
  518. public boolean pureAsh(RSTile tile) {
  519. RSGroundItem itemsOnTile[] = groundItems.getAllAt(tile);
  520. for (RSGroundItem item : itemsOnTile)
  521. if (item.getItem().getID() != ashID)
  522. return false;
  523. return true;
  524. }
  525.  
  526. public RSTile f2pBankTiles[] = {
  527. new RSTile(3186, 3438), // Varrock West
  528. new RSTile(3253, 3421), //Varrock East
  529. new RSTile(3161, 3488), //Grand Exchange
  530. new RSTile(2944, 3369), //Falador West
  531. new RSTile(3013, 3355), //Falador East
  532. new RSTile(3094, 3243), //Draynor
  533. new RSTile(3270, 3167), //Al Kharid
  534. new RSTile(3093, 3494) //Edgeville
  535. };
  536.  
  537. public RSTile nearestBank() {
  538. int closestDistance = Integer.MAX_VALUE;
  539. RSTile closestTile = null;
  540. for (RSTile tile : f2pBankTiles) {
  541. int distance = calc.distanceTo(tile);
  542. if (distance < closestDistance) {
  543. closestDistance = distance;
  544. closestTile = tile;
  545. }
  546. }
  547. return closestTile;
  548. }
  549.  
  550. public boolean depositAll() {
  551. methods.setStatus("Depositing Inventory");
  552. if (!bank.isOpen())
  553. return false;
  554. if (interfaces.getComponent(Bank.INTERFACE_BANK, Bank.INTERFACE_BANK_BUTTON_DEPOSIT_CARRIED_ITEMS).doClick(true)) {
  555. Timer fs = new Timer(8000);
  556. while (fs.isRunning() && inventory.getCount() > 0) sleep(120);
  557. if (inventory.getCount() == 0)
  558. bank.close();
  559. sleep(1200);
  560. return inventory.getCount() == 0;
  561. }
  562. return false;
  563. }
  564.  
  565. public boolean openBank() {
  566.  
  567. RSNPC banker = npcs.getNearest(Bank.NPC_BANKERS);
  568. if (banker != null) {
  569. if (!banker.isOnScreen()) {
  570. walking.walkTo(banker.getLocation());
  571. } else {
  572. camera.turnTo(banker, random(10, 25));
  573. methods.setStatus("Opening Bank [NPC]");
  574. if (banker.doAction("Bank Banker")) {
  575. Timer fs = new Timer(4000);
  576. while (fs.isRunning() && !bank.isOpen()) sleep(120);
  577. return bank.isOpen();
  578. }
  579. }
  580. } else {
  581. RSObject bankBooth = objects.getNearest(Bank.OBJECT_BANKS);
  582. if (bankBooth != null) {
  583. if (!bankBooth.isOnScreen()) {
  584. walking.walkTo(bankBooth.getLocation());
  585. } else {
  586. camera.turnTo(bankBooth, random(10, 25));
  587. methods.setStatus("Opening Bank [OBJECT]");
  588. if (bankBooth.doAction("Quickly")) {
  589. Timer fs = new Timer(4000);
  590. while (fs.isRunning() && !bank.isOpen()) sleep(120);
  591. return bank.isOpen();
  592. }
  593. }
  594. }
  595. }
  596. return false;
  597. }
  598.  
  599. public RSGroundItem getNearestAshPile() {
  600. RSGroundItem groundItemAU[] = groundItems.getAll();
  601. int min = Integer.MAX_VALUE;
  602. RSGroundItem toReturn = null;
  603.  
  604. for (RSGroundItem item : groundItemAU) {
  605. RSTile tile = item.getLocation();
  606. if (calc.distanceTo(tile) < min && pureAsh(tile)) {
  607. min = calc.distanceTo(tile);
  608. toReturn = item;
  609. }
  610. }
  611.  
  612. return toReturn;
  613. }
  614. }
  615.  
  616. private class AshCollectorPaint implements Runnable {
  617. public boolean stop = false;
  618.  
  619. String message = "Getting Ash Price", mouseStatus = "...";
  620.  
  621. Color toolbarBackground = new Color(0, 0, 0, 220), gloss = new Color(255, 255, 255, 55),
  622. outLine = new Color(0, 0, 0), themeColor = new Color(128, 0, 255, 255), hoverColor = null,
  623. white = new Color(255, 255, 255);
  624.  
  625. Font statsBarFont = new Font("Tahoma", 1, 11);
  626.  
  627. Point origPoint = new Point(-1, -1);
  628.  
  629. public void run() {
  630. while (ashMPrice <= 0) {
  631. ashMPrice = grandExchange.lookup(ashID).getGuidePrice();
  632. sleep(1200);
  633. }
  634.  
  635. int timer = 0;
  636. while (!stop) {
  637. if (timer < 20) {
  638. message = "Ashes Collected: " + numberToKM(ashCollected);
  639. timer++;
  640. } else if (timer < 40) {
  641. message = "Profit Made: " + numberToKM(ashCollected * ashMPrice);
  642. timer++;
  643. } else if (timer < 60) {
  644. message = "Ashes/Hour: " + (ashCollected > 0
  645. ? numberToKM((int) ((ashCollected * 3600000D) / (System.currentTimeMillis() - startTime)))
  646. : "N/A");
  647. timer++;
  648. } else if (timer < 80) {
  649. message = "Profit/Hour: " + (ashCollected > 0
  650. ? numberToKM((int) (((ashCollected * ashMPrice) * 3600000D) / (System.currentTimeMillis() - startTime)))
  651. : "N/A");
  652. timer++;
  653. } else {
  654. timer = 0;
  655. }
  656. sleep(120);
  657. }
  658. }
  659.  
  660. private String numberToKM(int number) {
  661. String s = String.valueOf(number);
  662. for (int k = s.length() - 3; k > 0; k -= 3)
  663. s = s.substring(0, k) + "," + s.substring(k);
  664.  
  665. if (s.length() > 8)
  666. s = s.substring(0, s.length() - 8) + "M";
  667. else if (s.length() > 4)
  668. s = s.substring(0, s.length() - 4) + "K";
  669. return " " + s;
  670. }
  671.  
  672. public String getTimeRunning() {
  673. long hours = 0, minutes = 0, seconds;
  674. seconds = (System.currentTimeMillis() - startTime) / 1000;
  675.  
  676. if (seconds >= 60) {
  677. minutes = seconds / 60;
  678. seconds -= (minutes * 60);
  679. }
  680.  
  681. if (minutes >= 60) {
  682. hours = minutes / 60;
  683. minutes -= (hours * 60);
  684. }
  685.  
  686. return (hours < 10 ? "0" + hours : "" + hours) + ":"
  687. + (minutes < 10 ? "0" + minutes : "" + minutes) + ":"
  688. + (seconds < 10 ? "0" + seconds : "" + seconds);
  689. }
  690.  
  691. public void paint(Graphics2D g) {
  692. if (distanceBetween(origPoint, mouse.getLocation()) > 5) {
  693. effects.add(new MouseEffects((int) mousePoint.getX(), (int) mousePoint.getY(), currentIdx < colorButtons.size() ? colors[currentIdx++] : colors[(currentIdx = 0)]));
  694. origPoint = mousePoint;
  695. }
  696.  
  697. mousePoint = mouse.getLocation();
  698.  
  699.  
  700. //Paint Ash Tiles Invent and Minimap
  701. if (!bank.isOpen())
  702. drawTileOverlay(g, ashID);
  703. paintInventItems(g);
  704.  
  705. //starting tile
  706. g.setColor(new Color(255, 0, 128, 200));
  707. g.fillOval((int) calc.tileToMinimap(startingTile).getX() - 3, (int) calc.tileToMinimap(startingTile).getY() - 2, 5, 5);
  708.  
  709. //Color Button Toolbar
  710. if (!bank.isOpen()) {
  711. paintColorButtons(g);
  712. }
  713.  
  714. //Stats bar
  715. g.setStroke(new BasicStroke(1));
  716. g.setColor(toolbarBackground);
  717. g.fillRect(0, 479, 518, 22); //stats bar
  718. g.fillRect(724, 0, 40, 20); //ST button
  719. g.setColor(outLine);
  720. g.drawRect(0, 479, 518, 22); //stats bar
  721. g.drawRect(724, 0, 40, 20); //ST button
  722. g.setFont(statsBarFont);
  723. g.setColor(hoverColor == null ? themeColor : hoverColor);
  724. drawStringCentered(g, statsBarFont, "Ash Collector :: By Janca", 493, 1);
  725. drawStringCentered(g, statsBarFont, "Time Running: " + getTimeRunning(), 493, 2);
  726. drawStringCentered(g, statsBarFont, message, 493, 3);
  727. g.setColor(gloss);
  728. g.fillRect(1, 480, 516, 9); //stats bar
  729. g.fillRect(725, 1, 38, 9); //ST Button
  730.  
  731. FontMetrics metrics = g.getFontMetrics(statsBarFont);
  732.  
  733. g.setColor(themeColor);
  734. g.drawString("ST", 729 + (metrics.stringWidth("ST") / 2), 13);
  735.  
  736. //Mouse trails
  737. paintMouseTrail(g);
  738.  
  739. //Mouse status
  740. paintMouseStatus(g, statsBarFont);
  741. }
  742.  
  743. int sX = 0;
  744. int cX = 366;
  745.  
  746. private void paintColorButtons(Graphics2D g) {
  747. g.setColor(toolbarBackground);
  748. g.fillRect(516 - (colorButtons.size() * 21) - 12, 312, (colorButtons.size() * 21) + 12, 26);
  749. g.setColor(outLine);
  750. g.drawRect(516 - (colorButtons.size() * 21) - 12, 312, (colorButtons.size() * 21) + 12, 26);
  751. for (ColorButton colorButton : colorButtons) {
  752. if (colorButton.isSelected()) {
  753. sX = colorButton.x;
  754. }
  755. colorButton.paint(g);
  756. }
  757.  
  758. if (cX > sX)
  759. cX -= 3;
  760. else if (cX < sX)
  761. cX += 3;
  762.  
  763. g.setStroke(new BasicStroke(2));
  764. g.setColor(white);
  765. g.drawRect(cX, 318, 15, 15);
  766. g.setStroke(new BasicStroke(1));
  767.  
  768. g.setColor(gloss);
  769. g.fillRect(516 - (colorButtons.size() * 21) - 11, 313, (colorButtons.size() * 21) + 11, 11);
  770. }
  771.  
  772. private void paintMouseTrail(Graphics2D g) {
  773. ArrayList<MouseEffects> temp = effects;
  774. if (temp.size() > 0) {
  775. for (MouseEffects effect : temp) {
  776. if (!effect.effectTimeOver()) {
  777. effect.paint(g);
  778. }
  779. }
  780. }
  781.  
  782. int size = 0;
  783. for (MouseEffects fx : effects) {
  784. if (fx.effectTimeOver())
  785. size++;
  786. }
  787.  
  788. if (size == effects.size() && size != 0) {
  789. effects.clear();
  790. }
  791. }
  792.  
  793. private void paintMouseStatus(Graphics2D g, Font font) {
  794. int width;
  795.  
  796. FontMetrics metrics = g.getFontMetrics(font);
  797. g.setFont(font);
  798.  
  799. if (mouseStatus.equals("")) {
  800. width = 0;
  801. } else {
  802. width = metrics.stringWidth(mouseStatus) + 10;
  803. }
  804.  
  805. if (mousePoint.x > 0 && mousePoint.y > 0) {
  806. if (mousePoint.x < 764 - (width / 2) && mousePoint.x - (width / 2) > 0) {
  807. if (mousePoint.y < 475) {
  808. g.setColor(toolbarBackground);
  809. g.fillRect(mousePoint.x - (width / 2), mousePoint.y + 15, width, 16);
  810. g.setColor(themeColor);
  811. g.drawString(mouseStatus, (mousePoint.x - (width / 2)) + 5, mousePoint.y + 27);
  812. g.setColor(gloss);
  813. g.fillRect(mousePoint.x - (width / 2), mousePoint.y + 15, width, 8);
  814. g.setColor(outLine);
  815. g.setStroke(new BasicStroke(1));
  816. g.drawRect(mousePoint.x - (width / 2), mousePoint.y + 15, width, 16);
  817. } else {
  818. g.setColor(toolbarBackground);
  819. g.fillRect(mousePoint.x - (width / 2), mousePoint.y - 15 - 16, width, 16);
  820. g.setColor(themeColor);
  821. g.drawString(mouseStatus, (mousePoint.x - (width / 2)) + 5, mousePoint.y - 3 - 16);
  822. g.setColor(gloss);
  823. g.fillRect(mousePoint.x - (width / 2), mousePoint.y - 15 - 16, width, 8);
  824. g.setColor(outLine);
  825. g.setStroke(new BasicStroke(1));
  826. g.drawRect(mousePoint.x - (width / 2), mousePoint.y - 15 - 16, width, 16);
  827. }
  828. } else if (mousePoint.x > 764 - (width / 2)) {
  829. if (mousePoint.y < 475) {
  830. g.setColor(toolbarBackground);
  831. g.fillRect(mousePoint.x - width, mousePoint.y + 15, width, 16);
  832. g.setColor(themeColor);
  833. g.drawString(mouseStatus, mousePoint.x - (width - 5), mousePoint.y + 27);
  834. g.setColor(gloss);
  835. g.fillRect(mousePoint.x - width, mousePoint.y + 15, width, 8);
  836. g.setColor(outLine);
  837. g.setStroke(new BasicStroke(1));
  838. g.drawRect(mousePoint.x - width, mousePoint.y + 15, width, 16);
  839. } else {
  840. g.setColor(toolbarBackground);
  841. g.fillRect(mousePoint.x - width, mousePoint.y - 15 - 16, width, 16);
  842. g.setColor(themeColor);
  843. g.drawString(mouseStatus, mousePoint.x - (width - 5), mousePoint.y - 3 - 16);
  844. g.setColor(gloss);
  845. g.fillRect(mousePoint.x - width, mousePoint.y - 15 - 16, width, 8);
  846. g.setColor(outLine);
  847. g.setStroke(new BasicStroke(1));
  848. g.drawRect(mousePoint.x - width, mousePoint.y - 15 - 16, width, 16);
  849. }
  850. } else {
  851. if (mousePoint.y < 475) {
  852. g.setColor(toolbarBackground);
  853. g.fillRect(mousePoint.x, mousePoint.y + 15, width, 16);
  854. g.setColor(themeColor);
  855. g.drawString(mouseStatus, mousePoint.x + 5, mousePoint.y + 27);
  856. g.setColor(gloss);
  857. g.fillRect(mousePoint.x, mousePoint.y + 15, width, 8);
  858. g.setColor(outLine);
  859. g.setStroke(new BasicStroke(1));
  860. g.drawRect(mousePoint.x, mousePoint.y + 15, width, 16);
  861. } else {
  862. g.setColor(toolbarBackground);
  863. g.fillRect(mousePoint.x, mousePoint.y - 15 - 16, width, 16);
  864. g.setColor(themeColor);
  865. g.drawString(mouseStatus, mousePoint.x + 5, mousePoint.y - 3 - 16);
  866. g.setColor(gloss);
  867. g.fillRect(mousePoint.x, mousePoint.y - 15 - 16, width, 8);
  868. g.setColor(outLine);
  869. g.setStroke(new BasicStroke(1));
  870. g.drawRect(mousePoint.x, mousePoint.y - 15 - 16, width, 16);
  871. }
  872. }
  873. }
  874.  
  875. g.setColor(outLine);
  876. g.drawRect(mousePoint.x - 6, mousePoint.y - 6, 12, 12);
  877. g.drawLine(mousePoint.x, mousePoint.y, mousePoint.x, mousePoint.y + 14);
  878. g.drawLine(mousePoint.x, mousePoint.y, mousePoint.x, mousePoint.y - 14);
  879. g.drawLine(mousePoint.x, mousePoint.y, mousePoint.x + 14, mousePoint.y);
  880. g.drawLine(mousePoint.x, mousePoint.y, mousePoint.x - 14, mousePoint.y);
  881. }
  882.  
  883. private void drawStringCentered(Graphics g, Font font, String line, int y, int pos) {
  884. FontMetrics metrics = g.getFontMetrics(font);
  885. g.drawString(line, (((pos == 3 ? 878 : pos == 2 ? 520 : 164) - metrics.stringWidth(line)) / 2), y);
  886. }
  887.  
  888. private boolean pointContainsNegValue(Point point) {
  889. return point.getX() < 0 || point.getY() < 0;
  890. }
  891.  
  892. private void drawTileOverlay(Graphics2D g, int groundItemID) {
  893. RSGroundItem bonePiles[] = groundItems.getAll();
  894. for (RSGroundItem item : bonePiles) {
  895. if (item.getItem().getID() == groundItemID) {
  896. if (item.isOnScreen() && calc.tileOnScreen(item.getLocation())) {
  897. RSTile tile = item.getLocation();
  898. Point southwest = calc.tileToScreen(tile, 0, 0, 0);
  899. Point southeast = calc.tileToScreen(new RSTile(tile.getX() + 1, tile.getY()), 0, 0, 0);
  900. Point northwest = calc.tileToScreen(new RSTile(tile.getX(), tile.getY() + 1), 0, 0, 0);
  901. Point northeast = calc.tileToScreen(new RSTile(tile.getX() + 1, tile.getY() + 1), 0, 0, 0);
  902. if (startingArea.contains(tile)) {
  903. int dist = calc.distanceTo(item.getLocation());
  904. if (dist <= 1)
  905. g.setColor(new Color(128, 255, 0, 180));
  906. else if (dist <= 3)
  907. g.setColor(new Color(200, 252, 0, 180));
  908. else if (dist <= 6)
  909. g.setColor(new Color(230, 252, 3, 180));
  910. else if (dist <= 7)
  911. g.setColor(new Color(250, 200, 5, 180));
  912. else if (dist <= 8)
  913. g.setColor(new Color(250, 85, 2, 180));
  914. else
  915. g.setColor(new Color(240, 20, 15, 180));
  916. } else {
  917. g.setColor(new Color(255, 0, 0, 100));
  918. }
  919. if (!pointContainsNegValue(southeast) && !pointContainsNegValue(southwest)
  920. && !pointContainsNegValue(northeast) && !pointContainsNegValue(northwest)) {
  921. if (!getMyPlayer().getLocation().equals(tile)) {
  922. g.fillPolygon(new int[]{(int) northwest.getX(), (int) northeast.getX(), (int) southeast.getX(),
  923. (int) southwest.getX()}, new int[]{(int) northwest.getY(), (int) northeast.getY(),
  924. (int) southeast.getY(), (int) southwest.getY()}, 4);
  925. }
  926. g.setColor(new Color(0, 0, 0));
  927. g.setStroke(new BasicStroke((float) 1.3));
  928. g.drawPolygon(new int[]{(int) northwest.getX(), (int) northeast.getX(), (int) southeast.getX(),
  929. (int) southwest.getX()}, new int[]{(int) northwest.getY(), (int) northeast.getY(),
  930. (int) southeast.getY(), (int) southwest.getY()}, 4);
  931. }
  932. }
  933. }
  934. }
  935. }
  936.  
  937. private void paintArea(Graphics2D g, RSArea area) {
  938. RSTile areaTiles[] = area.getTileArray();
  939. for (RSTile tile : areaTiles) {
  940. if (calc.tileOnMap(tile)) {
  941. if (tileContains(tile, ashID))
  942. g.setColor(new Color(0, 255, 0, 200));
  943. } else {
  944. if (tileContains(tile, ashID))
  945. g.setColor(new Color(230, 230, 0, 200));
  946. }
  947. if (tileContains(tile, ashID))
  948. g.fillOval((int) calc.tileToMinimap(tile).getX() - 3, (int) calc.tileToMinimap(tile).getY() - 2, 5, 5);
  949. g.setColor(new Color(255, 0, 128, 200));
  950. g.fillOval((int) calc.tileToMinimap(startingTile).getX() - 3, (int) calc.tileToMinimap(startingTile).getY() - 2, 5, 5);
  951. }
  952. }
  953.  
  954. public boolean tileContains(RSTile tile, int groundItemID) {
  955. RSGroundItem items[] = groundItems.getAllAt(tile);
  956. for (RSGroundItem item : items) {
  957. if (item.getItem().getID() == groundItemID)
  958. return true;
  959. }
  960. return false;
  961. }
  962.  
  963. private void paintInventItems(Graphics2D g) {
  964. g.setStroke(new BasicStroke(1));
  965. RSItem itemsInInvent[] = inventory.getItems();
  966. for (RSItem item : itemsInInvent) {
  967. if (item.getID() == ashID && item.getID() > 0) {
  968. paintInventBox2(g, item, new Color(102, 255, 0, 255));
  969. } else if (item.getID() != ashID && item.getID() > 0) {
  970. paintInventBox2(g, item, new Color(255, 0, 0, 255));
  971. }
  972. }
  973. }
  974.  
  975. private void paintInventBox(Graphics2D g, RSItem item, Color color) {
  976. RSComponent invenComp = item.getComponent();
  977. g.setColor(color);
  978. g.fillRoundRect(invenComp.getAbsoluteX(), invenComp.getAbsoluteY(), invenComp.getWidth(), invenComp.getHeight(), 8, 8);
  979. g.setColor(new Color(0, 0, 0));
  980. g.drawRoundRect(invenComp.getAbsoluteX(), invenComp.getAbsoluteY(), invenComp.getWidth(), invenComp.getHeight(), 8, 8);
  981. }
  982.  
  983. private void paintInventBox2(Graphics2D g, RSItem item, Color color) {
  984. RSComponent inventComp = item.getComponent();
  985. int x = inventComp.getAbsoluteX(), y = inventComp.getAbsoluteY(), width = inventComp.getWidth(),
  986. height = inventComp.getHeight();
  987. g.setColor(outLine);
  988. g.drawRect(x, y, width, height);
  989. g.setColor(toolbarBackground);
  990. g.fillRect(x + width - 15, y, 15, 15);
  991. g.setColor(outLine);
  992. g.drawRect(x + width - 15, y, 15, 15);
  993. g.setColor(color);
  994. g.fillRect(x + width - 12, y + 3, 10, 10);
  995. g.setColor(gloss);
  996. g.fillRect(x + width - 14, y + 1, 13, 6);
  997. }
  998. }
  999.  
  1000. private class ColorButton {
  1001. private int x, y;
  1002. private Color color;
  1003. private boolean selected = false;
  1004.  
  1005. private ColorButton(int x, int y, Color color, boolean selected) {
  1006. this.x = x;
  1007. this.y = y;
  1008. this.color = color;
  1009. this.selected = selected;
  1010. }
  1011.  
  1012. public void paint(Graphics2D g) {
  1013. g.setColor(color);
  1014. g.fillRect(x, y, 15, 15);
  1015.  
  1016. g.setColor(paint.outLine);
  1017. g.drawRect(x, y, 15, 15);
  1018.  
  1019. /*if (selected) {
  1020. g.setStroke(new BasicStroke(2));
  1021. g.setColor(white);
  1022. g.drawRect(x, y, 15, 15);
  1023. g.setStroke(new BasicStroke(1));
  1024. }*/
  1025.  
  1026. }
  1027.  
  1028. public void setX(int x) {
  1029. this.x = x;
  1030. }
  1031.  
  1032. public boolean onButton(Point point) {
  1033. Rectangle rect = new Rectangle(x, y, 15, 15);
  1034. return rect.contains(point);
  1035. }
  1036.  
  1037. public boolean isSelected() {
  1038. return selected;
  1039. }
  1040.  
  1041. public Color getColor() {
  1042. return color;
  1043. }
  1044.  
  1045. public void setSelected(boolean selected) {
  1046. this.selected = selected;
  1047. }
  1048. }
  1049.  
  1050. private class MouseEffects {
  1051. int x, y, size;
  1052. Color color, black = new Color(0, 0, 0, 255);
  1053.  
  1054. long startTime, lastOChange;
  1055.  
  1056. public MouseEffects(int x, int y, Color color) {
  1057. this.x = x;
  1058. this.y = y;
  1059. this.color = color;
  1060. this.size = 12;
  1061. this.startTime = System.currentTimeMillis();
  1062. }
  1063.  
  1064. int pass = 0;
  1065.  
  1066. public void paint(Graphics2D g) {
  1067. if (System.currentTimeMillis() - lastOChange > 10 && color.getAlpha() > 0) {
  1068. color = new Color(color.getRed(), color.getGreen(), color.getBlue(), color.getAlpha() - 5);
  1069. black = new Color(0, 0, 0, color.getAlpha());
  1070. if (size > 2 && pass >= 6) {
  1071. size -= 2;
  1072. pass = 0;
  1073. }
  1074. lastOChange = System.currentTimeMillis();
  1075. pass++;
  1076. }
  1077.  
  1078.  
  1079. g.setColor(color);
  1080. //g.setStroke(new BasicStroke(1));
  1081. g.fillOval(x - (size / 2), y - (size / 2), size, size);
  1082.  
  1083. g.setColor(black);
  1084. g.setStroke(new BasicStroke((float) 1.5));
  1085. g.drawOval(x - (size / 2), y - (size / 2), size, size);
  1086. }
  1087.  
  1088. public boolean effectTimeOver() {
  1089. return System.currentTimeMillis() - startTime > 2000 || color.getAlpha() == 0;
  1090. }
  1091. }
  1092. }
Add Comment
Please, Sign In to add comment