libdo

Untitled

Sep 19th, 2017
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import java.awt.Color;
  2. import java.awt.Graphics;
  3. import java.awt.Point;
  4. import java.awt.Polygon;
  5. import java.util.HashSet;
  6. import java.util.Set;
  7.  
  8. import org.rsbot.event.events.MessageEvent;
  9. import org.rsbot.event.listeners.MessageListener;
  10. import org.rsbot.event.listeners.PaintListener;
  11. import org.rsbot.script.Script;
  12. import org.rsbot.script.ScriptManifest;
  13. import org.rsbot.script.methods.Game;
  14. import org.rsbot.script.methods.Skills;
  15. import org.rsbot.script.util.Filter;
  16. import org.rsbot.script.util.Timer;
  17. import org.rsbot.script.wrappers.RSArea;
  18. import org.rsbot.script.wrappers.RSItem;
  19. import org.rsbot.script.wrappers.RSModel;
  20. import org.rsbot.script.wrappers.RSNPC;
  21. import org.rsbot.script.wrappers.RSObject;
  22. import org.rsbot.script.wrappers.RSPath;
  23. import org.rsbot.script.wrappers.RSTile;
  24. import org.rsbot.script.wrappers.RSTilePath;
  25.  
  26. @ScriptManifest(authors = "Aion, Tak",
  27. name = "Tak's Modified Air Crafter",
  28. version = 0.1,
  29. description = "Modified Aion Air Crafter Supports Pure Essance.")
  30. public class TaksAirCrafter extends Script implements PaintListener, MessageListener {
  31.  
  32. public static interface Constants {
  33.  
  34. int ITEM_AIR_RUNE = 556;
  35.  
  36. int ITEM_AIR_TALISMAN = 1438;
  37.  
  38. int ITEM_RUNE_ESS = 1436;
  39.  
  40. int ITEM_PRUNE_ESS = 7936;
  41.  
  42. int OBJECT_ALTAR = 2478;
  43.  
  44. int OBJECT_PORTAL = 2465;
  45.  
  46. int OBJECT_RUINS = 2452;
  47.  
  48. int NPC_BANKER = 5912;
  49.  
  50. double VERSION = TaksAirCrafter.class.getAnnotation(ScriptManifest.class).version();
  51.  
  52. Filter<RSNPC> FILTER_NPC = new Filter<RSNPC>() {
  53. public boolean accept(RSNPC t) {
  54. return t != null && t.getID() == Constants.NPC_BANKER;
  55. }
  56. };
  57.  
  58. RSTile[] PATH = {
  59. new RSTile(3185, 3434), new RSTile(3173, 3428),
  60. new RSTile(3159, 3423), new RSTile(3147, 3415),
  61. new RSTile(3135, 3407), new RSTile(3129, 3405)
  62. };
  63.  
  64. RSArea AREA_ALTAR = new RSArea(new RSTile(2835, 4823), new RSTile(2851, 4843));
  65.  
  66. RSArea AREA_BANK = new RSArea(new RSTile(3178, 3431), new RSTile(3195, 3447));
  67.  
  68. RSArea AREA_RUINS = new RSArea(new RSTile(3122, 3401), new RSTile(3132, 3409));
  69.  
  70. RSArea AREA_MUSICIAN = new RSArea(new RSTile(3149, 3419), new RSTile(3157, 3424));
  71. }
  72.  
  73. public static abstract class Action {
  74.  
  75. public abstract String getDesc();
  76.  
  77. public abstract boolean isValid();
  78.  
  79. public abstract void process();
  80. }
  81.  
  82. public class BankAction extends Action {
  83.  
  84. public String getDesc() {
  85. if (!bank.isOpen()) {
  86. return "Opening bank.";
  87. } else if (inventory.contains(Constants.ITEM_AIR_RUNE)) {
  88. return "Depositing items.";
  89. }
  90. return "Withdrawing items.";
  91. }
  92.  
  93. public boolean isValid() {
  94. return !canCraft() && inBank();
  95. }
  96.  
  97. public void process() {
  98. if (bank.isOpen()) {
  99. if (inventory.contains(Constants.ITEM_AIR_RUNE)) {
  100. if (inventory.containsOneOf(Constants.ITEM_AIR_TALISMAN, Constants.ITEM_RUNE_ESS, Constants.ITEM_PRUNE_ESS)) {
  101. bank.depositAllExcept(Constants.ITEM_AIR_TALISMAN, Constants.ITEM_RUNE_ESS, Constants.ITEM_PRUNE_ESS);
  102. } else {
  103. bank.depositAll();
  104. }
  105. } else if (!inventory.contains(Constants.ITEM_RUNE_ESS) || !inventory.contains(Constants.ITEM_PRUNE_ESS)) {
  106. int runeCount = bank.getCount(Constants.ITEM_RUNE_ESS);
  107. int pruneCount = bank.getCount(Constants.ITEM_PRUNE_ESS);
  108. if (runeCount < 1) {
  109. log("You are out of rune essences!");
  110. } else {
  111. bank.withdraw(Constants.ITEM_RUNE_ESS, 0);
  112. }
  113.  
  114. if(pruneCount < 1) {
  115. log("You are out of pure rune essences!");
  116. } else {
  117. bank.withdraw(Constants.ITEM_PRUNE_ESS, 0);
  118. }
  119. }
  120. sleep(600, 800);
  121. } else {
  122. RSNPC banker = npcs.getNearest(Constants.FILTER_NPC);
  123. if (banker != null) {
  124. while (!bank.isOpen()) {
  125. camera.setAngle(random(1, 359));
  126.  
  127. mouse.move(banker.getModel().getPoint(), 1, 1);
  128. mouse.click(false);
  129. menu.doAction("Bank banker");
  130. sleep(random(600, 800));
  131.  
  132. if (!bank.isOpen()) {
  133. bank.open();
  134. }
  135. }
  136. }
  137. }
  138. }
  139. }
  140.  
  141. public abstract class ObjectAction extends Action {
  142.  
  143. private String action;
  144. private int id;
  145.  
  146. public ObjectAction(String action, int id) {
  147. this.action = action;
  148. this.id = id;
  149. }
  150.  
  151. public String getDesc() {
  152. return "Interacting with object.";
  153. }
  154.  
  155. public void process() {
  156. RSObject object = objects.getNearest(id);
  157. if (object != null) {
  158. if (object.isOnScreen()) {
  159. object.doAction(action);
  160. if (calc.distanceTo(object) > 1) {
  161. waitToMove(random(600, 900));
  162. }
  163. } else {
  164. camera.turnToObject(object);
  165. if (!object.isOnScreen()) {
  166. walking.getPath(object.getLocation()).traverse();
  167. }
  168. }
  169. }
  170. }
  171. }
  172.  
  173. public abstract class WalkToArea extends Action {
  174.  
  175. private RSPath path;
  176.  
  177. public WalkToArea(RSPath path) {
  178. this.path = path;
  179. }
  180.  
  181. protected abstract boolean canRest();
  182.  
  183. protected abstract boolean isTargetValid();
  184.  
  185. public boolean isValid() {
  186. return isTargetValid();
  187. }
  188.  
  189. public void process() {
  190. if (walking.getEnergy() < 20) {
  191. if (canRest() && inMusician()) {
  192. RSTilePath tilePath = walking.newTilePath(Constants.AREA_MUSICIAN.getTileArray());
  193. if (!tilePath.traverse()) {
  194. walking.newTilePath(new RSTile[]{Constants.AREA_MUSICIAN.getCentralTile()}).traverse();
  195. }
  196. waitToMove(random(600, 900));
  197. walking.rest(100);
  198. }
  199. } else if (!walking.isRunEnabled()) {
  200. walking.setRun(true);
  201. }
  202. path.traverse();
  203. }
  204. }
  205.  
  206. private int runesCrafted;
  207.  
  208. private int startExp;
  209. private int startLvl;
  210.  
  211. private Set<Action> actions;
  212. private Action action;
  213.  
  214. private Timer timer;
  215.  
  216. @Override
  217. public boolean onStart() {
  218. timer = new Timer(0);
  219.  
  220. actions = new HashSet<Action>();
  221.  
  222. actions.add(new BankAction());
  223.  
  224. actions.add(new ObjectAction("Enter", Constants.OBJECT_RUINS) {
  225.  
  226. @Override
  227. public String getDesc() {
  228. return "Entering mysterious ruins.";
  229. }
  230.  
  231. public boolean isValid() {
  232. return canCraft() && inRuins();
  233. }
  234.  
  235. public void process() {
  236. if (inventory.contains(Constants.ITEM_AIR_TALISMAN)) {
  237. if (!inventory.isItemSelected()) {
  238. inventory.getItem(Constants.ITEM_AIR_TALISMAN).doClick(true);
  239. } else {
  240. RSItem selItem = inventory.getSelectedItem();
  241. if (selItem.getID() != Constants.ITEM_AIR_TALISMAN) {
  242. selItem.doClick(true);
  243. return;
  244. }
  245. }
  246. RSObject obj = objects.getNearest(Constants.OBJECT_ALTAR);
  247. if (obj != null) {
  248. Point toClick = getScreenPoint(obj);
  249. if (toClick.x != -1 && toClick.y != -1) {
  250. mouse.click(toClick, true);
  251. if (calc.distanceTo(obj) > 1) {
  252. waitToMove(random(600, 900));
  253. }
  254. return;
  255. } else if (obj.isOnScreen()) {
  256. obj.doClick(true);
  257. if (calc.distanceTo(obj) > 1) {
  258. waitToMove(random(600, 900));
  259. }
  260. } else {
  261. camera.turnToObject(obj);
  262. if (!obj.isOnScreen())
  263. walking.getPath(obj.getLocation()).traverse();
  264. }
  265. }
  266. } else {
  267. super.process();
  268. }
  269. waitToStop();
  270. }
  271. });
  272.  
  273. actions.add(new ObjectAction("Craft-rune", Constants.OBJECT_ALTAR) {
  274.  
  275. @Override
  276. public String getDesc() {
  277. return "Crafting runes.";
  278. }
  279.  
  280. public boolean isValid() {
  281. return canCraft() && inAltar();
  282. }
  283.  
  284. public void process() {
  285. super.process();
  286. sleep(200, 400);
  287. waitForAnim(random(900, 1200));
  288. if (random(1, 6) == 3) {
  289. RSObject portal = objects.getNearest(Constants.OBJECT_PORTAL);
  290. if (portal != null) {
  291. Point toClick = getScreenPoint(portal);
  292. if (toClick.x != -1 && toClick.y != -1) {
  293. mouse.click(toClick, true);
  294. } else {
  295. portal.doClick(false);
  296. }
  297. if (menu.isOpen()) {
  298. if (!menu.contains("Enter")) {
  299. while (menu.isOpen()) {
  300. mouse.moveRandomly(750);
  301. }
  302. }
  303. }
  304. }
  305. }
  306. }
  307. });
  308.  
  309. actions.add(new ObjectAction("Enter", Constants.OBJECT_PORTAL) {
  310.  
  311. public String getDesc() {
  312. return "Leaving mysterious ruins";
  313. }
  314.  
  315. public boolean isValid() {
  316. return !canCraft() && inAltar();
  317. }
  318.  
  319. public void process() {
  320. if (menu.isOpen()) {
  321. if (menu.contains("Enter")) {
  322. menu.doAction("Enter");
  323. waitToMove(random(600, 900));
  324. } else {
  325. mouse.moveSlightly();
  326. }
  327. } else {
  328. super.process();
  329. }
  330. waitToStop();
  331. }
  332. });
  333.  
  334. actions.add(new WalkToArea(walking.newTilePath(Constants.PATH).reverse()) {
  335.  
  336. protected boolean canRest() {
  337. return true;
  338. }
  339.  
  340. protected boolean isTargetValid() {
  341. return !canCraft() && !inAltar() && !inBank();
  342. }
  343.  
  344. public String getDesc() {
  345. return "Heading to bank";
  346. }
  347. });
  348.  
  349. actions.add(new WalkToArea(walking.newTilePath(Constants.PATH)) {
  350.  
  351. protected boolean canRest() {
  352. return true;
  353. }
  354.  
  355. protected boolean isTargetValid() {
  356. return canCraft() && !inRuins() && !inAltar();
  357. }
  358.  
  359. public String getDesc() {
  360. return "Heading to mysterious ruins";
  361. }
  362. });
  363.  
  364. startExp = skills.getCurrentExp(Skills.RUNECRAFTING);
  365. startLvl = skills.getCurrentLevel(Skills.RUNECRAFTING);
  366. return true;
  367. }
  368.  
  369. public int loop() {
  370. if (interfaces.get(741).isValid()) {
  371. interfaces.getComponent(741, 9).doClick();
  372. return random(300, 500);
  373. } else if (interfaces.get(740).isValid()) {
  374. env.saveScreenshot(false);
  375. interfaces.getComponent(740, 3).doClick();
  376. sleep(600, 700);
  377. if (game.getCurrentTab() != Game.TAB_STATS) {
  378. game.openTab(Game.TAB_STATS);
  379. sleep(800, 1200);
  380. }
  381. skills.doHover(Skills.INTERFACE_RUNECRAFTING);
  382. sleep(150, 300);
  383. mouse.click(true);
  384. return random(random(1000, 1300), 2000);
  385. }
  386.  
  387. if (action != null) {
  388. if (action.isValid()) {
  389. action.process();
  390. } else {
  391. action = null;
  392. }
  393. } else {
  394. for (Action a : actions) {
  395. if (a.isValid()) {
  396. action = a;
  397. break;
  398. }
  399. }
  400. }
  401. if (random(1, 10) == random(1, 6)) {
  402. antiban();
  403. }
  404. return random(200, 400);
  405. }
  406.  
  407. public void onRepaint(Graphics g) {
  408. if (game.isLoggedIn() && !game.isLoginScreen()) {
  409. g.setColor(new Color(16, 16, 16, 123));
  410. g.fillRoundRect(8, 179, 243, 153, 15, 15);
  411.  
  412. g.setColor(Color.RED);
  413. g.draw3DRect(13, 291, 231, 15, true);
  414.  
  415. g.setColor(new Color(48, 225, 48, 170));
  416. g.fill3DRect(14, 292, (getPercentToLvl() * 229 / 100), 14, true);
  417.  
  418. g.setColor(Color.WHITE);
  419. g.drawString("Aion's Air Crafter v" + getVersion(), 65, 192);
  420. g.drawString("Runtime: " + getRuntime(), 13, 206);
  421.  
  422. g.drawString("Crafted " + format(getRunesCrafted()) + " air runes", 13, 225);
  423. g.drawString("Gained " + format(getExpGained()) + " exp", 13, 239);
  424. g.drawString("Runes/Hour: " + format((int) getRunesHour()), 140, 225);
  425. g.drawString("Exp/Hour: " + format((int) getExpHour()), 140, 239);
  426.  
  427. int lvlGained = getLvlGained();
  428. String text = lvlGained == 0 ? "runecrafting" : "";
  429. g.drawString("Current " + text + " level: " + getRunecraftLvl(), 13, 258);
  430. if (lvlGained != 0) {
  431. text = lvlGained == 1 ? "" : "s";
  432. g.drawString("Gained " + lvlGained + " level" + text, 140, 258);
  433. }
  434.  
  435. g.drawString("Exp left: " + format(getExpToLvl()), 13, 272);
  436. g.drawString("Runes left: " + format(getRunesLeft()), 140, 272);
  437. g.drawString("Estimated time to level: " + getTimeToLvl(), 13, 286);
  438. g.drawString(getPercentToLvl() + "%", 113, 303);
  439.  
  440. if (action != null) {
  441. g.drawString("Status: " + action.getDesc(), 13, 325);
  442. }
  443.  
  444. }
  445.  
  446. Point mPoint = mouse.getLocation();
  447. Point pPoint = mouse.getPressLocation();
  448. long mpt = System.currentTimeMillis() - mouse.getPressTime();
  449.  
  450. if (mpt < 1000) {
  451. g.setColor(Color.red);
  452. g.drawOval(pPoint.x - 2, pPoint.y - 2, 4, 4);
  453. g.drawOval(pPoint.x - 9, pPoint.y - 9, 18, 18);
  454. }
  455.  
  456. g.setColor(Color.YELLOW);
  457. g.drawOval(mPoint.x - 2, mPoint.y - 2, 4, 4);
  458. g.drawOval(mPoint.x - 9, mPoint.y - 9, 18, 18);
  459. }
  460.  
  461. public void messageReceived(MessageEvent e) {
  462. String message = e.getMessage().toLowerCase();
  463. if (message.contains("bind the temple")) {
  464. runesCrafted += inventory.getCount(Constants.ITEM_RUNE_ESS);
  465. runesCrafted += inventory.getCount(Constants.ITEM_PRUNE_ESS);
  466. } else if (message.contains("you've just")) {
  467. log(message);
  468. }
  469. }
  470.  
  471. private void antiban() {
  472. switch (random(1, 50)) {
  473. case 2:
  474. if (random(1, 5) != 1) {
  475. break;
  476. }
  477. mouse.moveSlightly();
  478. break;
  479. case 6:
  480. if (random(1, 18) != 7) {
  481. break;
  482. }
  483. if (game.getCurrentTab() != Game.TAB_STATS) {
  484. game.openTab(Game.TAB_STATS);
  485. sleep(500, 900);
  486. }
  487. skills.doHover(Skills.INTERFACE_RUNECRAFTING);
  488. sleep(random(1400, 2000), 3000);
  489. if (random(0, 5) != 3) {
  490. break;
  491. }
  492. mouse.moveSlightly();
  493. break;
  494. case 9:
  495. case 14:
  496. case 17:
  497. case 25:
  498. camera.setAngle(random(-360, 360));
  499. break;
  500. case 30:
  501. case 34:
  502. case 37:
  503. case 40:
  504. camera.setPitch(camera.getPitch() >= random(65, 101) ? random(0, 61) : random(61, 101));
  505. }
  506. }
  507.  
  508. private boolean canCraft() {
  509. return inventory.contains(Constants.ITEM_RUNE_ESS) || inventory.contains(Constants.ITEM_PRUNE_ESS);
  510. }
  511.  
  512. private String format(int number) {
  513. return format(String.valueOf(number));
  514. }
  515.  
  516. private String format(String number) {
  517. if (number.length() < 4) {
  518. return number;
  519. }
  520. return format(number.substring(0, number.length() - 3)) + ","
  521. + number.substring(number.length() - 3, number.length());
  522. }
  523.  
  524. private int getExpGained() {
  525. if (startExp == -1) {
  526. if (game.getClientState() == 10) {
  527. startExp = skills.getCurrentExp(Skills.RUNECRAFTING);
  528. }
  529. }
  530. return skills.getCurrentExp(Skills.RUNECRAFTING) - startExp;
  531. }
  532.  
  533. private double getExpHour() {
  534. int xpGained = getExpGained();
  535. long start = System.currentTimeMillis() - timer.getElapsed();
  536. return xpGained * 3600000D / (System.currentTimeMillis() - start);
  537. }
  538.  
  539. private int getExpToLvl() {
  540. return skills.getExpToNextLevel(Skills.RUNECRAFTING);
  541. }
  542.  
  543. private int getLvlGained() {
  544. if (startLvl == -1) {
  545. if (game.getClientState() == 10) {
  546. startLvl = skills.getCurrentLevel(Skills.RUNECRAFTING);
  547. }
  548. }
  549. return skills.getCurrentLevel(Skills.RUNECRAFTING) - startLvl;
  550. }
  551.  
  552. private int getPercentToLvl() {
  553. return skills.getPercentToNextLevel(Skills.RUNECRAFTING);
  554. }
  555.  
  556. private int getRunecraftLvl() {
  557. return skills.getCurrentLevel(Skills.RUNECRAFTING);
  558. }
  559.  
  560. private int getRunesCrafted() {
  561. return runesCrafted;
  562. }
  563.  
  564. private double getRunesHour() {
  565. int runes = getRunesCrafted();
  566. long start = System.currentTimeMillis() - timer.getElapsed();
  567. return runes * 3600000D / (System.currentTimeMillis() - start);
  568. }
  569.  
  570. private int getRunesLeft() {
  571. return getExpToLvl() / 5;
  572. }
  573.  
  574. private String getRuntime() {
  575. return timer.toElapsedString();
  576. }
  577.  
  578. private Point getScreenPoint(RSObject obj) {
  579. if (obj != null) {
  580. RSModel model = obj.getModel();
  581. if (model != null) {
  582. for (Polygon pol : model.getTriangles()) {
  583. for (int i = 0; i < pol.npoints; i++) {
  584. Point p = new Point(pol.xpoints[i], pol.ypoints[i]);
  585. if (calc.pointOnScreen(p)) {
  586. return p;
  587. }
  588. }
  589. }
  590. }
  591. }
  592. return new Point(-1, -1);
  593. }
  594.  
  595. private String getTimeFormat(long time) {
  596. return Timer.format(time);
  597. }
  598.  
  599. private String getTimeToLvl() {
  600. return getTimeFormat((long) (getExpToLvl() / getExpHour() * 3600000D));
  601. }
  602.  
  603. private double getVersion() {
  604. return Constants.VERSION;
  605. }
  606.  
  607. private boolean inAltar() {
  608. return Constants.AREA_ALTAR.contains(getMyPlayer().getLocation());
  609. }
  610.  
  611. private boolean inBank() {
  612. return Constants.AREA_BANK.contains(getMyPlayer().getLocation());
  613. }
  614.  
  615. private boolean inRuins() {
  616. return Constants.AREA_RUINS.contains(getMyPlayer().getLocation());
  617. }
  618.  
  619. private boolean inMusician() {
  620. return Constants.AREA_MUSICIAN.contains(getMyPlayer().getLocation());
  621. }
  622.  
  623. private void waitForAnim(int timeout) {
  624. long endTime = System.currentTimeMillis() + timeout;
  625. while (System.currentTimeMillis() < endTime) {
  626. if (getMyPlayer().getAnimation() != -1) {
  627. break;
  628. }
  629. sleep(5, 15);
  630. }
  631. }
  632.  
  633. private void waitForIface(int iface, int timeout) {
  634. long endTime = System.currentTimeMillis() + timeout;
  635. while (System.currentTimeMillis() < endTime) {
  636. if (interfaces.get(iface).isValid()) {
  637. break;
  638. }
  639. sleep(5, 15);
  640. }
  641. }
  642.  
  643. private boolean waitToMove(int timeout) {
  644. long endTime = System.currentTimeMillis() + timeout;
  645. while (System.currentTimeMillis() < endTime) {
  646. if (getMyPlayer().isMoving()) {
  647. return true;
  648. }
  649. sleep(5, 15);
  650. }
  651. return false;
  652. }
  653.  
  654. private void waitToStop() {
  655. do {
  656. sleep(5, 15);
  657. } while (getMyPlayer().isMoving());
  658. }
Add Comment
Please, Sign In to add comment