Advertisement
Guest User

agility

a guest
Feb 26th, 2012
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 16.36 KB | None | 0 0
  1. import java.awt.BasicStroke;
  2. import java.awt.Color;
  3. import java.awt.Font;
  4. import java.awt.Graphics;
  5. import java.awt.Graphics2D;
  6. import java.awt.Image;
  7. import java.awt.Point;
  8. import java.awt.RenderingHints;
  9. import java.io.BufferedReader;
  10. import java.io.IOException;
  11. import java.io.InputStreamReader;
  12. import java.net.MalformedURLException;
  13. import java.net.URL;
  14. import java.text.NumberFormat;
  15. import java.util.concurrent.TimeUnit;
  16.  
  17. import javax.imageio.ImageIO;
  18.  
  19. import com.rarebot.event.listeners.PaintListener;
  20. import com.rarebot.script.Script;
  21. import com.rarebot.script.ScriptManifest;
  22. import com.rarebot.script.methods.Skills;
  23. import com.rarebot.script.util.Timer;
  24. import com.rarebot.script.wrappers.RSArea;
  25. import com.rarebot.script.wrappers.RSComponent;
  26. import com.rarebot.script.wrappers.RSItem;
  27. import com.rarebot.script.wrappers.RSObject;
  28. import com.rarebot.script.wrappers.RSTile;
  29.  
  30. @ScriptManifest(authors = { "Robert G" }, name = "ApeAgility", version = 1.4)
  31. public class ApeAgility extends Script implements PaintListener {
  32.  
  33. private static final int pineapplePlant = 4827;
  34. private static final int pineapple = 2114;
  35. private static final int pineappleRing = 2118;
  36. private static final int tropicalTree = 12570;
  37. private static final int monkeyBars = 12573;
  38. private static final int skullSlope = 12576;
  39. private static final int ropeSwing = 12578;
  40. private static final int upperTropicalTree = 12618;
  41. private static final RSArea steppingStoneArea = new RSArea(2755, 2742, 2779, 2754);
  42. private static final RSArea tropicalTreeArea = new RSArea(2752, 2742, 2753, 2742);
  43. private static final RSArea monkeyBarsArea = new RSArea(2752, 2741, 2754, 2742);
  44. private static final RSTile skullSlopeTile = new RSTile(2747, 2741, 0);
  45. private static final RSTile[] ropeSwingArea = { new RSTile(2741, 2740),
  46. new RSTile(2741, 2739), new RSTile(2741, 2738),
  47. new RSTile(2741, 2733), new RSTile(2741, 2732),
  48. new RSTile(2742, 2741), new RSTile(2742, 2740),
  49. new RSTile(2742, 2739), new RSTile(2742, 2738),
  50. new RSTile(2742, 2737), new RSTile(2742, 2736),
  51. new RSTile(2742, 2734), new RSTile(2742, 2732),
  52. new RSTile(2742, 2731), new RSTile(2743, 2741),
  53. new RSTile(2743, 2740), new RSTile(2743, 2739),
  54. new RSTile(2743, 2738), new RSTile(2743, 2737),
  55. new RSTile(2743, 2736), new RSTile(2743, 2735),
  56. new RSTile(2743, 2734), new RSTile(2743, 2732),
  57. new RSTile(2743, 2731), new RSTile(2743, 2730),
  58. new RSTile(2744, 2741), new RSTile(2744, 2740),
  59. new RSTile(2744, 2739), new RSTile(2744, 2738),
  60. new RSTile(2744, 2737), new RSTile(2744, 2736),
  61. new RSTile(2744, 2735), new RSTile(2744, 2734),
  62. new RSTile(2744, 2732), new RSTile(2744, 2731),
  63. new RSTile(2744, 2730), new RSTile(2745, 2741),
  64. new RSTile(2745, 2739), new RSTile(2745, 2737),
  65. new RSTile(2745, 2736), new RSTile(2745, 2735),
  66. new RSTile(2745, 2734), new RSTile(2745, 2733),
  67. new RSTile(2745, 2732), new RSTile(2745, 2731),
  68. new RSTile(2745, 2730), new RSTile(2745, 2729),
  69. new RSTile(2746, 2738), new RSTile(2746, 2737),
  70. new RSTile(2746, 2736), new RSTile(2746, 2735),
  71. new RSTile(2746, 2734), new RSTile(2746, 2733),
  72. new RSTile(2746, 2732), new RSTile(2746, 2731),
  73. new RSTile(2746, 2730), new RSTile(2746, 2729),
  74. new RSTile(2747, 2736), new RSTile(2747, 2735),
  75. new RSTile(2747, 2734), new RSTile(2747, 2733),
  76. new RSTile(2747, 2732), new RSTile(2747, 2729),
  77. new RSTile(2748, 2735), new RSTile(2748, 2734),
  78. new RSTile(2748, 2733), new RSTile(2748, 2732),
  79. new RSTile(2748, 2729), new RSTile(2748, 2728),
  80. new RSTile(2749, 2734), new RSTile(2749, 2733),
  81. new RSTile(2749, 2730), new RSTile(2749, 2729),
  82. new RSTile(2749, 2727), new RSTile(2750, 2734),
  83. new RSTile(2750, 2733), new RSTile(2750, 2730),
  84. new RSTile(2750, 2729), new RSTile(2750, 2728),
  85. new RSTile(2750, 2727), new RSTile(2750, 2726),
  86. new RSTile(2751, 2733), new RSTile(2751, 2732),
  87. new RSTile(2751, 2731), new RSTile(2751, 2730),
  88. new RSTile(2751, 2729), new RSTile(2751, 2728),
  89. new RSTile(2751, 2727), new RSTile(2751, 2726),
  90. new RSTile(2751, 2725), new RSTile(2752, 2730),
  91. new RSTile(2752, 2729) };
  92. private static final RSArea upperTropicalTreeArea = new RSArea(2756, 2731, 2760, 2736);
  93. private static int startLVL, curLVL, startXP, curXP;
  94. private static long startTime, runTime;;
  95. private static String status = "Loading...";
  96. private final Color color1 = new Color(0, 0, 0);
  97. private final Color color2 = new Color(51, 204, 0);
  98. private final Color color3 = new Color(255, 255, 255, 90);
  99. private final BasicStroke stroke1 = new BasicStroke(1);
  100. private final Font font1 = new Font("Cambria", 1, 15);
  101. private Image img1;
  102. private Image img2;
  103. private boolean eat = false;
  104. private static final NumberFormat nf = NumberFormat.getInstance();
  105. private static final String versionUrl = "http://pastebin.com/raw.php?i=vGfspk34";
  106. private static final String scriptUrl = "http://pastebin.com/raw.php?i=WepLnaHm";
  107. ScriptManifest props = getClass().getAnnotation(ScriptManifest.class);
  108. private final RenderingHints antialiasing = new RenderingHints(
  109. RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
  110.  
  111. private boolean checkVersion(double currentVersion, double latestVersion) {
  112. return (currentVersion >= latestVersion);
  113. }
  114.  
  115. private double getCurrentVersion(String webUrl, String search) {
  116. try {
  117. URL url = new URL(webUrl);
  118. BufferedReader x = new BufferedReader(new InputStreamReader(url.openStream()));
  119. String inputLine;
  120. while ((inputLine = x.readLine()) != null) {
  121. if (inputLine.contains(search)) {
  122. return Double.parseDouble(x.readLine());
  123. }
  124. }
  125. x.close();
  126. } catch (MalformedURLException e) {
  127. e.printStackTrace();
  128. } catch (IOException e) {
  129. e.printStackTrace();
  130. }
  131. return -1D;
  132. }
  133.  
  134. @Override
  135. public boolean onStart() {
  136. log("Welcome to ApeAgility by Robert G");
  137. log("Checking version...");
  138. if (checkVersion(props.version(), getCurrentVersion(versionUrl, props.name()))) {
  139. log("You have the lates version, starting up.");
  140. } else {
  141. log.severe("New version available!, please update.");
  142. log.severe("Download the new version from here: " + scriptUrl);
  143. return false;
  144. }
  145. if (getText().toLowerCase().contains("eat")) {
  146. log("Eating enabled.");
  147. eat = true;
  148. }
  149. new imageLoader();
  150. startLVL = skills.getRealLevel(Skills.AGILITY);
  151. if (startLVL < 48) {
  152. log.severe("This script requires 48 agility to run!");
  153. return false;
  154. }
  155. startXP = skills.getCurrentExp(Skills.AGILITY);
  156. startTime = System.currentTimeMillis();
  157. return true;
  158. }
  159.  
  160. public class imageLoader extends Thread {
  161.  
  162. private imageLoader() {
  163. Thread t = new Thread(this);
  164. t.start();
  165. }
  166.  
  167. @Override
  168. public void run() {
  169. log("Downloading paint images...");
  170. img1 = getImage("http://desmond.imageshack.us/Himg821/scaled.php?server=821&filename=cooltext643981409.png&res=medium");
  171. img2 = getImage("http://img845.imageshack.us/img845/6471/cooltext643985568.png");
  172. log("Finished downloading paint images.");
  173. }
  174.  
  175. }
  176.  
  177. private RSComponent getComp() {
  178. return interfaces.getComponent(137, 55);
  179. }
  180.  
  181. private String getText() {
  182. return getComp().getText().trim();
  183. }
  184.  
  185. private boolean canPick() {
  186. final RSObject pine = objects.getNearest(pineapplePlant);
  187. return pine != null && steppingStoneArea.contains(pine.getLocation());
  188. }
  189.  
  190. private boolean canCut() {
  191. return inventory.contains(pineapple);
  192.  
  193. }
  194.  
  195. private RSComponent getPInt() {
  196. return interfaces.getComponent(905, 14);
  197. }
  198.  
  199. private boolean inArea(RSArea area) {
  200. return area.contains(myTile());
  201. }
  202.  
  203. private boolean atSlope() {
  204. return myTile().equals(skullSlopeTile);
  205. }
  206.  
  207. private boolean atSwing() {
  208. for (RSTile t : ropeSwingArea) {
  209. if (myTile().equals(t)) {
  210. return true;
  211. }
  212. }
  213. return false;
  214. }
  215.  
  216. private boolean idle() {
  217. return getMyPlayer().isIdle();
  218. }
  219.  
  220. private RSTile myTile() {
  221. return new RSTile(getMyPlayer().getLocation().getX(), getMyPlayer().getLocation().getY());
  222. }
  223.  
  224. private boolean chop() {
  225. final RSItem p = inventory.getItem(pineapple);
  226. if (p != null) {
  227. if (p.interact("slice")) {
  228. waitFor();
  229. }
  230. if (getPInt().isValid()) {
  231. return getPInt().doClick();
  232. }
  233. }
  234. return false;
  235. }
  236.  
  237. private boolean eat() {
  238. final RSItem p = inventory.getItem(pineappleRing);
  239. if (p != null) {
  240. return p.interact("eat");
  241. }
  242. return false;
  243. }
  244.  
  245. private boolean hasFood() {
  246. return inventory.contains(pineappleRing);
  247. }
  248.  
  249. private void waitFor() {
  250. final long start = System.currentTimeMillis();
  251. while (System.currentTimeMillis() - start < 2000) {
  252. sleep(50);
  253. if (getPInt().isValid())break;
  254. }
  255. }
  256.  
  257. private boolean walk(RSTile dest) {
  258. final Point p = calc.tileToMinimap(dest);
  259. if (eat) {
  260. return walking.walkTileMM(dest);
  261. } else {
  262. if (p.x != -1 && p.y != -1) {
  263. if (!mouse.getLocation().equals(p)) {
  264. mouse.hop(p);
  265. mouse.click(true);
  266. mouse.moveSlightly();
  267. return true;
  268. }
  269. }
  270. }
  271. return false;
  272. }
  273.  
  274. private boolean doObstacle(int id, String action) {
  275. final RSObject obj = objects.getNearest(id);
  276. if (obj != null) {
  277. if (obj.isOnScreen()) {
  278. mouse.hop(obj.getPoint());
  279. return obj.interact(action);
  280. } else {
  281. if (walk(obj.getLocation())) {
  282. camera.turnTo(obj);
  283. return true;
  284. }
  285. }
  286. }
  287. return false;
  288. }
  289.  
  290. private boolean steppingStone() {
  291. final RSTile tile = new RSTile(2754, 2742);
  292. final RSObject stone = objects.getTopAt(tile);
  293. if (stone != null) {
  294. if (stone.isOnScreen()) {
  295. return tiles.interact(tile, "Jump");
  296. } else {
  297. if (walk(new RSTile(2755, 2742))) {
  298. camera.turnTo(stone);
  299. }
  300.  
  301. }
  302. }
  303. return false;
  304. }
  305.  
  306. private boolean ropeSwing() {
  307. final RSObject swing = objects.getNearest(ropeSwing);
  308. if (swing != null) {
  309. if (swing.isOnScreen()) {
  310. mouse.hop(swing.getPoint());
  311. return swing.interact("Swing");
  312. } else {
  313. return walk(swing.getLocation());
  314. }
  315. }
  316. return false;
  317. }
  318.  
  319. private enum State {
  320. SETRUN, STEPPING_STONE, TROPICAL_TREE, MONKEYBARS, SKULL_SLOPE, ROPE_SWING, UPPER_TROPICAL_TREE, SLEEP, CROSSING_OBSTACLE, EAT, GET_PINEAPPLE, SLICE
  321. }
  322.  
  323. private boolean hasSpace() {
  324. return inventory.getCount() <= 20;
  325. }
  326.  
  327. private State getState() {
  328. if (!game.isLoggedIn() || game.isWelcomeScreen()) {
  329. return State.SLEEP;
  330. } else {
  331. if (walking.getEnergy() > 20 && !walking.isRunEnabled()) {
  332. return State.SETRUN;
  333. }
  334. if (eat) {
  335. if (hasSpace() && inArea(steppingStoneArea)) {
  336. if (canPick()) {
  337. return State.GET_PINEAPPLE;
  338. }
  339. }
  340. if (combat.getHealth() < 50 && hasFood()) {
  341. return State.EAT;
  342. }
  343. if (canCut()) {
  344. return State.SLICE;
  345. }
  346. }
  347. if (idle()) {
  348. if (inArea(steppingStoneArea) && game.getPlane() == 0) {
  349. return State.STEPPING_STONE;
  350. } else if (inArea(tropicalTreeArea) && game.getPlane() == 0) {
  351. return State.TROPICAL_TREE;
  352. } else if (inArea(monkeyBarsArea) && game.getPlane() == 2) {
  353. return State.MONKEYBARS;
  354. } else if (atSlope() && game.getPlane() == 0) {
  355. return State.SKULL_SLOPE;
  356. } else if (atSwing() && game.getPlane() == 0) {
  357. return State.ROPE_SWING;
  358. } else if (inArea(upperTropicalTreeArea)
  359. && game.getPlane() == 0) {
  360. return State.UPPER_TROPICAL_TREE;
  361. } else {
  362. return State.CROSSING_OBSTACLE;
  363. }
  364. }
  365. }
  366. return State.CROSSING_OBSTACLE;
  367. }
  368.  
  369. @Override
  370. public int loop() {
  371. mouse.setSpeed(random(3, 5));
  372. switch (getState()) {
  373. case SLEEP:
  374. status = ("Waiting for client.");
  375. return random(1000, 1200);
  376. case CROSSING_OBSTACLE:
  377. status = ("Moving.");
  378. return 400;
  379. case SETRUN:
  380. status = "Turning run on";
  381. walking.setRun(true);
  382. return random(1200, 1400);
  383. case GET_PINEAPPLE:
  384. status = ("Picking pineapple.");
  385. if (doObstacle(pineapplePlant, "Pick")) {
  386. return random(1000, 1200);
  387. }
  388. break;
  389. case SLICE:
  390. status = ("Slicing pineapple.");
  391. if (chop()) {
  392. return random(1000, 1200);
  393. }
  394. break;
  395. case EAT:
  396. status = ("Eating food.");
  397. if (eat()) {
  398. return random(1000, 1200);
  399. }
  400. break;
  401. case STEPPING_STONE:
  402. status = ("Stepping stone.");
  403. if (steppingStone()) {
  404. return random(1200, 1400);
  405. }
  406. break;
  407. case TROPICAL_TREE:
  408. status = ("Tropical tree.");
  409. if (doObstacle(tropicalTree, "Climb")) {
  410. return random(1200, 1400);
  411. }
  412. break;
  413. case MONKEYBARS:
  414. status = ("Monkey bars.");
  415. if (doObstacle(monkeyBars, "Swing")) {
  416. camera.setCompass('w');
  417. return random(1200, 1400);
  418. }
  419. break;
  420. case SKULL_SLOPE:
  421. status = ("Skull slope.");
  422. if (doObstacle(skullSlope, "Climb")) {
  423. camera.setCompass('e');
  424. camera.setPitch(false);
  425. return random(1200, 1400);
  426. }
  427. break;
  428. case ROPE_SWING:
  429. status = ("Rope swing.");
  430. if (ropeSwing()) {
  431. return random(1200, 1400);
  432. }
  433. break;
  434. case UPPER_TROPICAL_TREE:
  435. status = ("Tropical tree");
  436. if (doObstacle(upperTropicalTree, "Climb")) {
  437. camera.setPitch(true);
  438. return random(1200, 1400);
  439. }
  440. break;
  441. }
  442. return 0;
  443. }
  444.  
  445. private Image getImage(String url) {
  446. try {
  447. return ImageIO.read(new URL(url));
  448. } catch (IOException e) {
  449. return null;
  450. }
  451. }
  452.  
  453. private int PH(int arg0) {
  454. int PH = (int) (3600000.0 / runTime * arg0);
  455. return PH;
  456. }
  457.  
  458. private String nf(int number) {
  459. return nf.format(number);
  460. }
  461.  
  462. private RSComponent get() {
  463. return interfaces.getComponent(261, 8);
  464. }
  465.  
  466. private RSComponent getMain() {
  467. return interfaces.getComponent(548, 0);
  468. }
  469.  
  470. private String ft(long duration) {
  471. String res = "";
  472. long days = TimeUnit.MILLISECONDS.toDays(duration);
  473. long hours = TimeUnit.MILLISECONDS.toHours(duration)
  474. - TimeUnit.DAYS.toHours(TimeUnit.MILLISECONDS.toDays(duration));
  475. long minutes = TimeUnit.MILLISECONDS.toMinutes(duration)
  476. - TimeUnit.HOURS.toMinutes(TimeUnit.MILLISECONDS
  477. .toHours(duration));
  478. long seconds = TimeUnit.MILLISECONDS.toSeconds(duration)
  479. - TimeUnit.MINUTES.toSeconds(TimeUnit.MILLISECONDS
  480. .toMinutes(duration));
  481. if (days == 0) {
  482. res = (hours + ":" + minutes + ":" + seconds);
  483. } else {
  484. res = (days + ":" + hours + ":" + minutes + ":" + seconds);
  485. }
  486. return res;
  487. }
  488.  
  489. public void onRepaint(Graphics g1) {
  490. Graphics2D g = (Graphics2D) g1;
  491. g.setRenderingHints(antialiasing);
  492. runTime = System.currentTimeMillis() - startTime;
  493. curLVL = skills.getRealLevel(Skills.AGILITY);
  494. curXP = skills.getCurrentExp(Skills.AGILITY);
  495. int x = get().getAbsoluteX();
  496. int y = get().getAbsoluteY();
  497. int mX = getMain().getAbsoluteX();
  498. int mY = getMain().getAbsoluteY();
  499. int gainedLVL = curLVL - startLVL;
  500. int gainedXP = curXP - startXP;
  501. int tnl = skills.getExpToNextLevel(Skills.AGILITY);
  502. int till99 = skills.getExpToMaxLevel(Skills.AGILITY);
  503. long timeTNL = (long) ((double) tnl / (double) PH(gainedXP) * 3600000);
  504. long timeTo99 = (long) ((double) till99 / (double) PH(gainedXP) * 3600000);
  505. g.drawImage(img1, mX + 60, mY - 15, null);
  506. g.drawImage(img2, x, y, null);
  507. x += 15;
  508. y += 30;
  509. g.setFont(font1);
  510. g.setColor(color1);
  511. g.drawString("Run Time: " + Timer.format(runTime), x, y);
  512. y += 20;
  513. g.drawString("Start Level: " + startLVL, x, y);
  514. y += 20;
  515. g.drawString("Current Level: " + curLVL, x, y);
  516. y += 20;
  517. g.drawString("Levels Gained: " + gainedLVL, x, y);
  518. y += 20;
  519. g.drawString("Xp Gained: " + nf(gainedXP), x, y);
  520. y += 20;
  521. g.drawString("Xp Ph: " + nf(PH(gainedXP)), x, y);
  522. y += 20;
  523. g.drawString("Xp Tnl: " + nf(tnl), x, y);
  524. y += 20;
  525. if (gainedXP > 0) {
  526. g.drawString("TTnl: " + ft(timeTNL), x, y);
  527. y += 20;
  528. g.drawString("TT 99: " + ft(timeTo99), x, y);
  529. y += 20;
  530. } else {
  531. g.drawString("TTnl: Calculating", x, y);
  532. y += 20;
  533. g.drawString("TT 99: Calculating", x, y);
  534. y += 20;
  535. }
  536. g.drawString("Status: " + status, x, y);
  537. y += 10;
  538. int percent = skills.getPercentToNextLevel(Skills.AGILITY);
  539. int length = percent * 156 / 100;
  540. g.setColor(color1);
  541. g.setStroke(stroke1);
  542. g.drawRect(x, y, 156, 25);
  543. g.setColor(color2);
  544. g.fillRect(x, y, length, 25);
  545. g.setColor(color1);
  546. g.setStroke(stroke1);
  547. g.drawRect(x, y, length, 25);
  548. g.setColor(color3);
  549. g.fillRect(x, y, length, 13);
  550. g.setColor(color1);
  551. y += 20;
  552. x += 70;
  553. g.drawString(percent + "%", x, y);
  554. }
  555.  
  556. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement