Guest User

Untitled

a guest
Jul 21st, 2018
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 36.44 KB | None | 0 0
  1. import org.rsbot.bot.Bot;
  2. import org.rsbot.bot.input.CanvasWrapper;
  3. import org.rsbot.bot.input.Mouse;
  4. import org.rsbot.event.listeners.PaintListener;
  5. import org.rsbot.script.Calculations;
  6. import org.rsbot.script.Methods;
  7. import org.rsbot.script.Script;
  8. import org.rsbot.script.ScriptManifest;
  9. import org.rsbot.script.wrappers.*;
  10.  
  11. import java.applet.Applet;
  12. import java.awt.*;
  13. import java.awt.event.MouseEvent;
  14. import java.awt.event.MouseWheelEvent;
  15. import java.util.ArrayList;
  16. import java.util.Map;
  17.  
  18. /**
  19. * Created by IntelliJ IDEA.
  20. * User: Raven
  21. * Date: 2-jan-2010
  22. * Time: 23:52:27
  23. * To change this template use File | Settings | File Templates.
  24. */
  25.  
  26. @ScriptManifest(authors = "Bool", name = "BRuneMiner")
  27. public class BRuneMiner extends Script implements PaintListener {
  28. Pathfinder pf = new Pathfinder();
  29. int COMPONENTS = -1;
  30. public final int ROCKID = 14859, GATEID = 21505, bridge1 = 21314, bridge2 = 21315, RUNEID = 451;
  31. WorldSwitcher ws = new WorldSwitcher();
  32. RSTile bankLoc = new RSTile(2336, 3807), gateLoc = new RSTile(2326, 3805), rockLoc = new RSTile(2376, 3850);
  33. RSTile ropeloc = new RSTile(2378, 3839);
  34. RSTile bridge2loc = new RSTile(2343, 3829);
  35. int oldcount, currentcount, total;
  36. Timer running;
  37.  
  38. public boolean painting = false;
  39. public int paintx = 20, painty = 70, xoff = -1, yoff = -1;
  40. public int paintwidth = -1, paintheight = -1;
  41. int price = 1;
  42. int startexp = 0;
  43. int FOODID = 379;
  44.  
  45. public boolean onStart(Map<String, String> args) {
  46. price = grandExchange.loadItemInfo(RUNEID).getMarketPrice();
  47. oldcount = getInventoryCount(RUNEID);
  48. currentcount = getInventoryCount(RUNEID);
  49. running = new Timer();
  50. startexp = skills.getCurrentSkillExp(STAT_MINING);
  51. return true;
  52. }
  53.  
  54. @Override
  55. public int loop() {
  56. if (!isLoggedIn())
  57. return random(100, 600);
  58. currentcount = getInventoryCount(RUNEID);
  59. if (oldcount < currentcount) {
  60. total++;
  61. oldcount = currentcount;
  62. }
  63. if (isInventoryFull()) {
  64. if (getMyPlayer().getLocation().getY() > 3847) {
  65. RSObject bridge = getNearestObjectByID(bridge2);
  66. if (bridge != null) {
  67. log("clicking bridge 1");
  68. while (getMyPlayer().getLocation().getY() > 3847) {
  69. if (!tileOnScreen(bridge.getLocation())) {
  70. walkTileMM(bridge.getLocation());
  71. waitToMove(2000);
  72. while (getMyPlayer().isMoving())
  73. sleep(200, 600);
  74. } else {
  75. if (atTile(bridge.getLocation(), "across")) {
  76. sleep(900, 1200);
  77. while (getMyPlayer().getLocation().getY() < 3848 && getMyPlayer().getLocation().getY() > 3839 && getLocation().getX() == 2378) {
  78. log("Walking on bridge");
  79. sleep(200, 500);
  80. }
  81. }
  82. }
  83. }
  84. return random(100, 300);
  85. }
  86. }
  87. if (getMyPlayer().getLocation().getY() > 3828) {
  88. log("walking to bridge");
  89. walkPath(bridge2loc);
  90. RSObject bridge = getNearestObjectByID(21309);
  91. if (bridge != null) {
  92. log("clicking bridge");
  93. while (getMyPlayer().getLocation().getY() > 3828) {
  94. if (!tileOnScreen(bridge.getLocation())) {
  95. walkTileMM(bridge.getLocation());
  96. waitToMove(2000);
  97. while (getMyPlayer().isMoving())
  98. sleep(200, 600);
  99. } else {
  100. if (atTile(bridge.getLocation(), "across")) {
  101. sleep(900, 1200);
  102. while (getMyPlayer().getLocation().getY() > 3820 && getMyPlayer().getLocation().getY() < 3829 && getLocation().getX() == 2343) {
  103. log("Walking on bridge");
  104. sleep(200, 500);
  105. }
  106. }
  107. }
  108. }
  109. }
  110. return random(100, 300);
  111. }
  112. if (!pf.validTile(bankLoc)) {
  113. log("walking to gate");
  114. walkPath(gateLoc);
  115. RSObject gate = getNearestObjectByID(GATEID);
  116. if (gate != null) {
  117. RSTile tile1 = new RSTile(2328,3804);
  118. RSTile tile2 = new RSTile(2329,3804);
  119. log("opening door");
  120. atDoorTiles(tile1,tile2);
  121. return random(100,700);
  122. }
  123. }
  124. if (distanceTo(bankLoc) > 5) {
  125. log("walking to bank");
  126. walkPath(bankLoc);
  127. return random(100, 400);
  128. } else {
  129. RSObject BANK = getNearestObjectByID(21301);
  130. if (BANK != null) {
  131. if (tileOnScreen(BANK.getLocation())) {
  132. if (bank.isOpen() || atTile(BANK.getLocation(), "Use")) {
  133. long start = System.currentTimeMillis();
  134. while (!bank.isOpen()) {
  135. if ((System.currentTimeMillis() - start) > 2000)
  136. break;
  137. if (getMyPlayer().isMoving())
  138. start = System.currentTimeMillis();
  139. }
  140. if (bank.isOpen()) {
  141. bank.depositAll();
  142. start = System.currentTimeMillis();
  143. while (getInventoryCount() > 0) {
  144. if ((System.currentTimeMillis() - start) > 2000)
  145. break;
  146. sleep(40, 500);
  147. }
  148. if (getInventoryCount() == 0) {
  149. int food = getNeededLobsters();
  150. log("we need " + food + " food");
  151. if (food > 0) {
  152. bank.withdraw(FOODID, food);
  153. start = System.currentTimeMillis();
  154. while (getInventoryCount() == 0) {
  155. if ((System.currentTimeMillis() - start) > 2000)
  156. break;
  157. sleep(100, 300);
  158. }
  159. }
  160. }
  161. }
  162. }
  163. } else if (tileOnMap(BANK.getLocation())) {
  164. walkTileMM(BANK.getLocation());
  165. waitToMove(1200);
  166. while (getMyPlayer().isMoving())
  167. sleep(100, 600);
  168. }
  169. }
  170. }
  171. return random(100, 400);
  172. }
  173. if (!pf.validTile(rockLoc) && !isInventoryFull()) {
  174. if(pf.validTile(bankLoc) && !pf.validTile(new RSTile(2342, 3819))){
  175. RSObject gate = getNearestObjectByID(GATEID);
  176. if (gate != null) {
  177. RSTile tile1 = new RSTile(2328,3804);
  178. RSTile tile2 = new RSTile(2329,3804);
  179. atDoorTiles(tile1,tile2);
  180. return random(100,700);
  181. }
  182. }
  183. if (getMyPlayer().getLocation().getY() < 3829) {
  184. log("walking to bridge");
  185. walkPath(new RSTile(2342, 3819));
  186. RSObject bridge = getNearestObjectByID(21308);
  187. if (bridge != null) {
  188. log("clicking bridge");
  189. while (getMyPlayer().getLocation().getY() < 3829) {
  190. if (!tileOnScreen(bridge.getLocation())) {
  191. walkTileMM(bridge.getLocation());
  192. waitToMove(2000);
  193. while (getMyPlayer().isMoving())
  194. sleep(200, 600);
  195. } else {
  196. if (atTile(bridge.getLocation(), "across")) {
  197. sleep(900, 1200);
  198. while (getMyPlayer().getLocation().getY() > 3820 && getMyPlayer().getLocation().getY() < 3829 && getLocation().getX() == 2343) {
  199. log("Walking on bridge");
  200. sleep(200, 500);
  201. }
  202. }
  203. }
  204. }
  205. }
  206. return random(100, 300);
  207. }
  208. if (getMyPlayer().getLocation().getY() < 3847) {
  209. walkPath(ropeloc);
  210. RSObject bridge = getNearestObjectByID(bridge1);
  211. if (bridge != null) {
  212. while (getMyPlayer().getLocation().getY() < 3847) {
  213. if (!tileOnScreen(bridge.getLocation())) {
  214. walkTileMM(bridge.getLocation());
  215. waitToMove(2000);
  216. while (getMyPlayer().isMoving())
  217. sleep(200, 600);
  218. } else {
  219. if (atTile(bridge.getLocation(), "Cross")) {
  220. sleep(900, 1200);
  221. while (getMyPlayer().getLocation().getY() < 3848 && getMyPlayer().getLocation().getY() > 3839 && getLocation().getX() == 2378) {
  222. log("Walking on bridge");
  223. sleep(200, 500);
  224. }
  225. }
  226. }
  227. }
  228. }
  229. return random(100, 300);
  230. }
  231. } else {
  232. RSObject rock = getNearestObjectByID(ROCKID);
  233. if (rock != null) {
  234. if (!isMining()) {
  235. atTile(rock.getLocation(), "Mine");
  236. waitForAnim(1200);
  237. }
  238. } else {
  239. ws.changeWorld();
  240. return random(300, 800);
  241. }
  242. }
  243. return random(300, 700);
  244. }
  245.  
  246. public int getNeededLobsters() {
  247. return (skills.getRealSkillLevel(STAT_HITPOINTS) - skills.getCurrentSkillLevel(STAT_HITPOINTS)) / 12;
  248. }
  249.  
  250. public void onRepaint(Graphics g) {
  251. if (running == null)
  252. return;
  253. Mouse m = Bot.getClient().getMouse();
  254. int x = m.x, y = m.y;
  255. if (running.getTimeElapsed() > 1) {
  256. int expgained = (skills.getCurrentSkillExp(STAT_MINING) - startexp);
  257. int expph = expgained > 0 ? (int) ((expgained * 60 * 60) / (running.getTimeElapsed() / 1000)) : 0;
  258. int logsph = total > 0 ? (int) ((total * 60 * 60) / (running.getTimeElapsed() / 1000)) : 0;
  259. int moneyph = logsph * price;
  260. java.awt.geom.Rectangle2D r = g.getFontMetrics().getStringBounds("Show paint", g);
  261. r.setRect(paintx, painty, r.getWidth() + 5, r.getHeight() + 3);
  262. if (m.pressed) {
  263. if (xoff == -1) {
  264. xoff = m.x - (int) r.getX();
  265. yoff = m.y - (int) r.getY();
  266. }
  267. //painting = false;
  268. }
  269. if (painting || (paintheight > r.getHeight() || paintwidth > r.getWidth())) {
  270. if (m.pressed) {
  271. if (new Rectangle(paintx, painty, paintwidth, paintheight).contains(m.x, m.y)) {
  272. paintx = m.x - xoff;
  273. painty = m.y - yoff;
  274. }
  275. } else {
  276. if (!pointValid(new Point(paintx, painty))) {
  277. paintx = 20;
  278. painty = 70;
  279. }
  280. xoff = -1;
  281. }
  282. String[] strings = {"BRuneMiner by bool", "Time running : " + running.toString(), "", "Rocks mined : " + total, "Rocks p/h : " + logsph, "", "Money p/h : " + moneyph, "Made : " + (total * price), "", "Exp gained : " + expgained, "Exp p/h : " + expph};
  283. int width = 0, height = 5;
  284. for (String s : strings) {
  285. if (s.length() > 2) {
  286. height += 15;
  287. } else {
  288. height += 1;
  289. }
  290. java.awt.geom.Rectangle2D rect = g.getFontMetrics().getStringBounds(s, g);
  291. if (width < rect.getWidth())
  292. width = (int) rect.getWidth();
  293. }
  294. width += 5;
  295. if (paintwidth == -1) {
  296. paintwidth = (int) r.getWidth();
  297. paintheight = (int) r.getHeight();
  298. }
  299. g.setColor(Color.black);
  300. if (painting) {
  301. if (paintwidth < width)
  302. paintwidth += 4;
  303. else
  304. paintwidth = width;
  305. if (paintheight < height)
  306. paintheight += 4;
  307. else
  308. paintheight = height;
  309. } else {
  310. if (paintheight > r.getHeight()) {
  311. paintheight -= 4;
  312. } else {
  313. paintheight = (int) r.getHeight();
  314. }
  315. if (paintwidth > r.getWidth()) {
  316. paintwidth -= 4;
  317. } else {
  318. paintwidth = (int) r.getWidth();
  319. }
  320. }
  321. g.drawRoundRect(paintx, painty, paintwidth, paintheight, 3, 3);
  322. g.setColor(new Color(51, 204, 102, 50));
  323. g.fillRoundRect(paintx, painty, paintwidth, paintheight, 3, 3);
  324. g.setColor(Color.black);
  325. int lines = 0;
  326. for (int i = 0; i < strings.length; i++) {
  327. String s = strings[i];
  328. boolean fit = s.length() < 2;
  329. while (!fit) {
  330. if (paintheight == height) {
  331. fit = true;
  332. break;
  333. }
  334. if ((painty + paintheight) < (painty + 2 + (i * 15) + 14))
  335. break;
  336. java.awt.geom.Rectangle2D temp = g.getFontMetrics().getStringBounds(s, g);
  337. if (new Rectangle(paintx, painty, paintwidth, paintheight).contains(paintx + 2, painty + 2 + (i * 15) + 14, temp.getWidth(), temp.getHeight())) {
  338. fit = true;
  339. break;
  340. }
  341. if (s.length() > 0) {
  342. s = s.substring(0, s.length() - 1);
  343. } else {
  344. break;
  345. }
  346. }
  347. if (fit) {
  348. if (s.length() < 2) {
  349. if (lines == 3)
  350. continue;
  351. if ((painty + paintheight) > painty + 2 + ((i - lines) * 15))
  352. g.drawLine(paintx, painty + 4 + ((i - lines) * 15), paintx + paintwidth, painty + 4 + ((i - lines) * 15));
  353. lines++;
  354. } else {
  355. drawShadow(s, paintx + 2, painty + 2 + ((i - lines) * 15) + 14, g);
  356. }
  357. }
  358. }
  359. if (!new Rectangle(paintx, painty, paintwidth, paintheight).contains(x, y))
  360. painting = false;
  361. } else {
  362. if (m.pressed) {
  363. if (r.contains(m.x, m.y)) {
  364. paintx = m.x - xoff;
  365. painty = m.y - yoff;
  366. }
  367. } else {
  368. if (!pointValid(new Point(paintx, painty))) {
  369. paintx = 20;
  370. painty = 70;
  371. }
  372. xoff = -1;
  373. }
  374. g.setColor(Color.black);
  375. g.drawRoundRect((int) r.getX(), (int) r.getY(), (int) r.getWidth(), (int) r.getHeight(), 3, 3);
  376. g.setColor(new Color(51, 204, 102, 50));
  377. g.fillRoundRect((int) r.getX(), (int) r.getY(), (int) r.getWidth(), (int) r.getHeight(), 3, 3);
  378. g.setColor(Color.black);
  379.  
  380. drawShadow("Show paint", (int) (r.getX() + 2), (int) (r.getY() + r.getHeight()) - 3, g);
  381. if (r.contains(x, y)) {
  382. painting = true;
  383. }
  384. }
  385. }
  386. }
  387.  
  388. public void drawShadow(String text, int x, int y, Graphics g) {
  389. Color c = g.getColor();
  390. g.setColor(c.brighter());
  391. g.drawString(text, x + 1, y);
  392. g.setColor(c);
  393. g.drawString(text, x, y);
  394. }
  395.  
  396. public boolean pointValid(final Point check) {
  397. final int x = check.x, y = check.y;
  398. return x > 0 && x < CanvasWrapper.getGameWidth() && y > 0
  399. && y < CanvasWrapper.getGameHeight();
  400. }
  401.  
  402. public void walkPath(RSTile tile) {
  403. while (distanceTo(tile) > 5) {
  404. RSTile valid = getValidTile(tile);
  405. RSTile[] path = pf.findPath(valid);
  406. while (!walkNext(path, 4)) {
  407. sleep(10, 30);
  408. }
  409. }
  410. }
  411.  
  412. private boolean walkNext(final RSTile[] path, int dist) {
  413. final char left = 37;
  414. final char right = 39;
  415. RSTile tile = getNext(path);
  416. /*if (distanceTo(path[path.length - 1]) < 10)
  417. return true;*/
  418. if (getDestination() != null) {
  419. if (distanceBetween(tile, getDestination()) < 4) {
  420. return false;
  421. }
  422. }
  423. moveMouse(Calculations.worldToMinimap(tile.getX(), tile.getY()));
  424. try {
  425. if (getMenuItems().get(0).contains("ancel")) {
  426. char dir = random(0, 3) == 2 ? left : right;
  427. Bot.getInputManager().pressKey(dir);
  428. wait(random(800, 1200));
  429. Bot.getInputManager().releaseKey(dir);
  430. return false;
  431. }
  432. } catch (Exception e) {
  433. wait(random(600, 800));
  434. return walkNext(path, dist);
  435. }
  436. try {
  437. walkTileMM(getNext(path));
  438. wait(random(200, 500));
  439. while (getMyPlayer().isMoving() && distanceTo(getDestination()) > 7) {
  440. wait(random(600, 800));
  441. }
  442. } catch (final Exception ignored) {
  443. }
  444. return distanceTo(path[path.length - 1]) < 4;
  445. }
  446.  
  447. private RSTile getNext(final RSTile[] path) {
  448. RSTile nearest = path[0];
  449. for (final RSTile element : path) {
  450. if (distanceBetween(element, path[path.length - 1]) < distanceBetween(nearest, path[path.length - 1])) {
  451. if (tileOnMap(element)) {
  452. nearest = element;
  453. }
  454. }
  455. }
  456. return nearest;
  457. }
  458.  
  459. public boolean isMining() {
  460. return getMyPlayer().getAnimation() != -1;
  461. }
  462.  
  463. public void sleep(int min, int max) {
  464. wait(random(min, max));
  465. }
  466.  
  467. public RSTile getValidTile(RSTile tile) {
  468. while (!pf.validTile(tile))
  469. tile = new RSTile((getLocation().getX() + tile.getX()) / 2, (getLocation().getY() + tile.getY()) / 2);
  470. return tile;
  471. }
  472.  
  473. class WorldSwitcher {
  474. public World[] worlds = null;
  475. private final int WORLD_INTERFACE = 744;
  476.  
  477. public RSInterfaceComponent[] getComponents() {
  478. if (COMPONENTS == -1) {
  479. COMPONENTS = getComponentIndex();
  480. return getComponents();
  481. }
  482. return RSInterface.getChildInterface(WORLD_INTERFACE, COMPONENTS).getComponents();
  483. }
  484.  
  485. public void changeWorld() {
  486. try {
  487. while (isLoggedIn()) {
  488. logout();
  489. sleep(200, 600);
  490. }
  491. int x9 = random(345, 415);
  492. int y9 = random(242, 250);
  493. clickMouse(x9, y9, true);
  494. sleep(1000, 2000);
  495. if (worlds == null)
  496. loadWorlds();
  497. Rectangle theRect = new Rectangle(79, 148, 608, 229);
  498. Rectangle a = null;
  499. World world = null;
  500. while (world == null || !world.canSwitch()) {
  501. world = worlds[random(0, worlds.length)];
  502. //log("getting world");
  503. }
  504. while (!theRect.contains((a = world.getArea()))) {
  505. if (!theRect.contains(getMouseLocation())) {
  506. moveMouse(theRect.x + Bot.getInputManager().random(0, world.getArea().width), theRect.y + Bot.getInputManager().random(0, world.getArea().height));
  507. }
  508. if (new Point(a.x, a.y).distance(new Point(100, 132)) < new Point(
  509. a.x, a.y).distance(new Point(104, 455))) {
  510. scroll(false);
  511. try {
  512. Thread.sleep(20);
  513. } catch (InterruptedException e) {
  514. e.printStackTrace();
  515. }
  516. } else {
  517. scroll(true);
  518. try {
  519. Thread.sleep(20);
  520. } catch (InterruptedException e) {
  521. e.printStackTrace();
  522. }
  523. }
  524. }
  525. try {
  526. Thread.sleep(1000);
  527. } catch (InterruptedException e) {
  528. // TODO Auto-generated catch block
  529. e.printStackTrace();
  530. }
  531. clickMouse(world.getArea().x + Bot.getInputManager().random(0, world.getArea().width), world.getArea().y + Bot.getInputManager().random(0, world.getArea().height), true);
  532. world.reset();
  533. } catch (Exception e) {
  534. changeWorld();
  535. }
  536. }
  537.  
  538. public int getComponentIndex() {
  539. RSInterface inter = RSInterface.getInterface(744);
  540. for (RSInterfaceChild child : inter.getChildren()) {
  541. for (RSInterfaceComponent com : child.getComponents()) {
  542. if (com.getText().contains("World")) {
  543. return child.getIndex();
  544. }
  545. }
  546. }
  547. return -1;
  548. }
  549.  
  550. public void scroll(boolean up) {
  551. int x = getMouseLocation().x;
  552. int y = getMouseLocation().y;
  553. MouseWheelEvent event = new MouseWheelEvent(((Applet) Bot.getClient()),
  554. MouseEvent.MOUSE_WHEEL, System.currentTimeMillis(), 0, x,
  555. y, 0, false, MouseWheelEvent.WHEEL_UNIT_SCROLL, 3, (up ? 1 : -1));
  556. Bot.getClient().getMouseWheel()._mouseWheelMoved(event);
  557. }
  558.  
  559. public void loadWorlds() {
  560. ArrayList<World> result = new ArrayList<World>();
  561. RSInterfaceComponent[] coms = getComponents();
  562. int index = 0;
  563. try {
  564.  
  565. for (RSInterfaceComponent i : coms) {
  566. index++;
  567. if (i != null && i.isValid()) {
  568. if (i.getText() != null && !i.getText().contains("Bounty")
  569. && i.getText().contains("World") && !coms[index].getText().isEmpty()) {
  570. int pop = coms[index].getText().equals("FULL")
  571. || coms[index].getText().equals("OFFLINE") ? 2000
  572. : Integer.parseInt(coms[index].getText().trim());
  573. boolean mem = coms[index + 6].getText()
  574. .contains("bers");
  575. String worldNam = i.getText();
  576. int worldNum = Integer.parseInt(worldNam.replace(
  577. "World ", ""));
  578. result.add(new World(i.getText(), worldNum, pop, mem,
  579. index - 1));
  580. }
  581. }
  582. }
  583. } catch (Exception e) {
  584. loadWorlds();
  585. }
  586. worlds = result.toArray(new World[result.size()]);
  587. }
  588. }
  589.  
  590. class World {
  591. private String worldName;
  592. private int worldNumber = -1;
  593. private int index = 0;
  594. private int worldPopulation = -1;
  595. private boolean members = false;
  596. private final int WORLD_INTERFACE = 744;
  597. Timer canswitch = null;
  598.  
  599. public World(String worldName, int worldNumber,
  600. int worldPopulation, boolean members, int i) {
  601. this.index = i;
  602. this.worldName = worldName;
  603. this.worldNumber = worldNumber;
  604. this.worldPopulation = worldPopulation;
  605. this.members = members;
  606. }
  607.  
  608. public boolean canSwitch() {
  609. if (!isMembers() || worldNumber == 26 || worldNumber == 72 || worldNumber == 86 || worldNumber == 18 || worldNumber == 65 || worldNumber == 137 || worldNumber == 124) {
  610. return false;
  611. }
  612. if (canswitch == null)
  613. return true;
  614. int pop = getWorldPopulation();
  615. if (pop > 0 && pop < 400) {
  616. return canswitch.getminutes() > 27;
  617. } else if (pop >= 400 && pop <= 800) {
  618. return canswitch.getminutes() > 24;
  619. } else if (pop >= 800 && pop <= 1200) {
  620. return canswitch.getminutes() > 21;
  621. } else if (pop >= 1200 && pop <= 1600) {
  622. return canswitch.getminutes() > 19;
  623. } else if (pop >= 1600 && pop <= 2000) {
  624. return canswitch.getminutes() > 16;
  625. } else if (pop == 2000) {
  626. return canswitch.getminutes() > 13;
  627. }
  628. return false;
  629. }
  630.  
  631. public void reset() {
  632. canswitch = new Timer();
  633. }
  634.  
  635. public RSInterfaceComponent toInterface() {
  636. try {
  637. return getComponents()[index];
  638. } catch (Exception e) {
  639. return toInterface();
  640. }
  641. }
  642.  
  643. private RSInterfaceComponent[] getComponents() {
  644. return RSInterface.getChildInterface(WORLD_INTERFACE, COMPONENTS).getComponents();
  645. }
  646.  
  647. public boolean isMembers() {
  648. return members;
  649. }
  650.  
  651. public int getWorldNumber() {
  652. return worldNumber;
  653. }
  654.  
  655. public String getWorldName() {
  656. return worldName;
  657. }
  658.  
  659. public int getWorldPopulation() {
  660. return worldPopulation;
  661. }
  662.  
  663. public Rectangle getArea() {
  664. RSInterfaceComponent com = toInterface();
  665. Rectangle r = com.getArea();
  666. r.y -= RSInterface.getChildInterface(WORLD_INTERFACE, COMPONENTS).getVerticalScrollBarPosition();
  667. r.width = 608;
  668. r.x = 79;
  669. return r;
  670. }
  671. }
  672.  
  673. class Timer {
  674.  
  675. private long start;
  676. private int time;
  677.  
  678. public Timer(int time) {
  679. start = System.currentTimeMillis();
  680. this.time = time;
  681. }
  682.  
  683. public long getTimeElapsed() {
  684. return (System.currentTimeMillis() - start);
  685. }
  686.  
  687. public Timer() {
  688. this(0);
  689. }
  690.  
  691. public boolean isDone() {
  692. return (System.currentTimeMillis() - start) > time;
  693. }
  694.  
  695. public void reset() {
  696. start = System.currentTimeMillis();
  697. }
  698.  
  699. public void resest(int newtime) {
  700. time = newtime;
  701. reset();
  702. }
  703.  
  704. public long gethours() {
  705. return (System.currentTimeMillis() - start) / (1000 * 60 * 60);
  706. }
  707.  
  708. public long getminutes() {
  709. return ((System.currentTimeMillis() - start) - gethours() * 1000 * 60 * 60) / (1000 * 60);
  710. }
  711.  
  712. public long getseconds() {
  713. return ((System.currentTimeMillis() - start) - getminutes() * 1000 * 60 * 60) / (1000);
  714. }
  715.  
  716. @Override
  717. public String toString() {
  718. return timeToString((System.currentTimeMillis() - start));
  719. }
  720. }
  721.  
  722. public String timeToString(long time) {
  723. final long hours = time / (1000 * 60 * 60);
  724. time -= hours * 1000 * 60 * 60;
  725. final long minutes = time / (1000 * 60);
  726. time -= minutes * 1000 * 60;
  727. final long seconds = time / 1000;
  728. String str = "";
  729. if (hours < 10)
  730. str += "0";
  731. str += hours + ":";
  732. if (minutes < 10)
  733. str += "0";
  734. str += minutes + ":";
  735. if (seconds < 10)
  736. str += "0";
  737. str += seconds;
  738. return str;
  739. }
  740.  
  741. class Pathfinder {
  742.  
  743. public int basex, basey;
  744. public int[][] blocks;
  745.  
  746. public Pathfinder() {
  747. reload();
  748. }
  749.  
  750. public void reload() {
  751. basex = Bot.getClient().getBaseX();
  752. basey = Bot.getClient().getBaseY();
  753. blocks = Bot.getClient().getRSGroundDataArray()[Bot.getClient()
  754. .getPlane()].getBlocks();
  755. }
  756.  
  757. public RSTile[] findPath(RSTile dest) {
  758. if (!isValid())
  759. reload();
  760. return findPath(getLocation(), dest);
  761. }
  762.  
  763. public RSTile[] findPath(RSTile start, RSTile dest) {
  764. if (!isValid())
  765. reload();
  766. return findPath(
  767. new Node(start.getX() - basex, start.getY() - basey),
  768. new Node(dest.getX() - basex, dest.getY() - basey));
  769. }
  770.  
  771. public RSTile[] findPath(Node start, Node dest) {
  772. if (!isValid())
  773. reload();
  774. if (!canReach(new RSTile(dest.x + basex, dest.y + basey), false)) {
  775. return null;
  776. }
  777. ArrayList<Node> closed = new ArrayList<Node>();
  778. ArrayList<Node> open = new ArrayList<Node>();
  779.  
  780. Node current = start;
  781. open.add(current);
  782. while (open.size() != 0) {
  783. current = getBestNode(open);
  784. closed.add(current);
  785. open.remove(current);
  786. for (Node node : getNodesAround(current)) {
  787. if (!closed.contains(node)) {
  788. if (!open.contains(node)) {
  789. node.parent = current;
  790. node.cost = current.cost
  791. + getMovementCost(node, current);
  792. node.heuristic = node.cost
  793. + getHeuristicCost(node, dest);
  794. open.add(node);
  795. } else {
  796. if (current.cost + getMovementCost(node, current) < node.cost) {
  797. node.parent = current;
  798. node.cost = current.cost
  799. + getMovementCost(node, current);
  800. node.heuristic = node.cost
  801. + getHeuristicCost(node, dest);
  802. }
  803. }
  804. }
  805. }
  806. if (closed.contains(dest)) {
  807. final ArrayList<RSTile> path = new ArrayList<RSTile>();
  808. Node node = closed.get(closed.size() - 1);
  809. while (node.parent != null) {
  810. path.add(new RSTile(node.x + basex, node.y + basey));
  811. node = node.parent;
  812. }
  813. return reversePath(path.toArray(new RSTile[path.size()]));
  814. }
  815. }
  816. return null;
  817. }
  818.  
  819. public Node getBestNode(ArrayList<Node> nodes) {
  820. Node winner = null;
  821. for (Node node : nodes) {
  822. if (winner == null || node.cost < winner.cost) {
  823. winner = node;
  824. }
  825. }
  826. return winner;
  827. }
  828.  
  829. public double getHeuristicCost(Node current, Node dest) {
  830. float dx = dest.x - current.x;
  831. float dy = dest.y - current.y;
  832. return (double) (Math.sqrt((dx * dx) + (dy * dy)));
  833. }
  834.  
  835. public double getMovementCost(Node current, Node dest) {
  836. return (double) Math.hypot(dest.x - current.x, dest.y - current.y);
  837. }
  838.  
  839. /**
  840. * credits to jacmob
  841. */
  842. public ArrayList<Node> getNodesAround(Node node) {
  843. final ArrayList<Node> tiles = new ArrayList<Node>();
  844. final int curX = node.x, curY = node.y;
  845. if (curX > 0 && curY < 103
  846. && (blocks[curX - 1][curY + 1] & 0x1280138) == 0
  847. && (blocks[curX - 1][curY] & 0x1280108) == 0
  848. && (blocks[curX][curY + 1] & 0x1280120) == 0) {
  849. tiles.add(new Node(curX - 1, curY + 1));
  850. }
  851. if (curY < 103 && (blocks[curX][curY + 1] & 0x1280120) == 0) {
  852. tiles.add(new Node(curX, curY + 1));
  853. }
  854. if (curX > 0 && curY < 103
  855. && (blocks[curX - 1][curY + 1] & 0x1280138) == 0
  856. && (blocks[curX - 1][curY] & 0x1280108) == 0
  857. && (blocks[curX][curY + 1] & 0x1280120) == 0) {
  858. tiles.add(new Node(curX + 1, curY + 1));
  859. }
  860. if (curX > 0 && (blocks[curX - 1][curY] & 0x1280108) == 0) {
  861. tiles.add(new Node(curX - 1, curY));
  862. }
  863. if (curX < 103 && (blocks[curX + 1][curY] & 0x1280180) == 0) {
  864. tiles.add(new Node(curX + 1, curY));
  865. }
  866. if (curX > 0 && curY > 0
  867. && (blocks[curX - 1][curY - 1] & 0x128010e) == 0
  868. && (blocks[curX - 1][curY] & 0x1280108) == 0
  869. && (blocks[curX][curY - 1] & 0x1280102) == 0) {
  870. tiles.add(new Node(curX - 1, curY - 1));
  871. }
  872. if (curY > 0 && (blocks[curX][curY - 1] & 0x1280102) == 0) {
  873. tiles.add(new Node(curX, curY - 1));
  874. }
  875. if (curX < 103 && curY > 0
  876. && (blocks[curX + 1][curY - 1] & 0x1280183) == 0
  877. && (blocks[curX + 1][curY] & 0x1280180) == 0
  878. && (blocks[curX][curY - 1] & 0x1280102) == 0) {
  879. tiles.add(new Node(curX + 1, curY - 1));
  880. }
  881. return tiles;
  882.  
  883. }
  884.  
  885. public boolean validTile(RSTile tile) {
  886. return canReach(tile, false);
  887. }
  888.  
  889. public boolean isValid() {
  890. return basex == Bot.getClient().getBaseX()
  891. && basey == Bot.getClient().getBaseY();
  892. }
  893.  
  894. class Node {
  895.  
  896. public final int x, y;
  897. public double cost = 0, heuristic = 0;
  898. public Node parent;
  899.  
  900. public Node(int x, int y) {
  901. this.x = x;
  902. this.y = y;
  903. }
  904.  
  905. public boolean equals(Object other) {
  906. if (other instanceof Node) {
  907. Node o = (Node) other;
  908. return x == o.x && y == o.y;
  909. }
  910. return false;
  911. }
  912. }
  913. }
  914. }
Add Comment
Please, Sign In to add comment