Advertisement
wafflecat

hunt

Feb 26th, 2012
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 20.44 KB | None | 0 0
  1. import java.awt.*;
  2. import java.awt.event.ActionEvent;
  3. import java.awt.event.ActionListener;
  4. import java.util.LinkedList;
  5. import java.util.List;
  6.  
  7. import javax.swing.*;
  8.  
  9. import com.rarebot.event.events.MessageEvent;
  10. import com.rarebot.event.listeners.MessageListener;
  11. import com.rarebot.event.listeners.PaintListener;
  12. import com.rarebot.script.wrappers.RSItem;
  13. import com.rarebot.script.Script;
  14. import com.rarebot.script.ScriptManifest;
  15. import com.rarebot.script.methods.Skills;
  16. import com.rarebot.script.util.Filter;
  17. import com.rarebot.script.wrappers.RSNPC;
  18. import com.rarebot.script.wrappers.RSTile;
  19.  
  20. @ScriptManifest(authors = "UberMouse & TheKoolKat", name = "UberFalconry", keywords = "Hunter", version = 1.5, description = "Catches kebbits at falconry area")
  21. public class UberFalconry extends Script implements MessageListener, PaintListener {
  22. private static List<Strategy> strategies = new LinkedList<Strategy>();
  23.  
  24. //Booleans
  25. private boolean debug = false;
  26. private boolean reGetFalcon = false;
  27. private boolean buryBones = true;
  28. private boolean doBoneWork = false; //Flag that will bury the bones after dropping junk
  29.  
  30. //IDS
  31. public int[] kebbitIDs = { 5098, 5099, 5100 };
  32. private int kebbitID = 5098;
  33. private int[] falconIDs = {5094, 5095, 5096};
  34. private int falconerID = 5093;
  35. private int[] junk = { 526, 10125,10115,10127 };
  36.  
  37. //Tiles
  38. private RSTile falconerTile = new RSTile(2375, 3604);
  39.  
  40. //Statistics
  41. private long startTime;
  42. private int kebbitsCaught = 0;
  43. private int startXPHunter;
  44. private int startXPPrayer;
  45. private int startLevelHunter;
  46. private int startLevelPrayer;
  47.  
  48. public interface Strategy {
  49. public void execute();
  50.  
  51. public boolean isValid();
  52. }
  53.  
  54. public class Debug {
  55. public void debug(Object text, boolean severe)
  56. {
  57. if (debug) {
  58. String className = this.getClass().getName();
  59. if (className.contains("$"))
  60. className = className.split("\\$")[1];
  61. StackTraceElement[] stackTraceElements = Thread.currentThread().getStackTrace();
  62. int stacktraceIndex;
  63. if (stackTraceElements[2].getMethodName() == "debug")
  64. stacktraceIndex = 3;
  65. else
  66. stacktraceIndex = 2;
  67. StackTraceElement stacktrace = stackTraceElements[stacktraceIndex];
  68. String methodName = stacktrace.getMethodName();
  69. if (!severe)
  70. log("[" + className + "] -> [" + methodName + "] -> " + text);
  71. else
  72. log.severe("[" + className + "] -> [" + methodName + "] -> " + text);
  73. }
  74. }
  75.  
  76. public void debug(Object text)
  77. {
  78. debug(text, false);
  79. }
  80. }
  81.  
  82. public boolean onStart()
  83. {
  84. if (!game.isLoggedIn()) {
  85. log.severe("Start script loggedin.");
  86. stopScript();
  87. }
  88. GUI gui = new GUI(this);
  89. gui.setVisible(true);
  90. while (gui.isVisible())
  91. sleep(100);
  92.  
  93. startTime = System.currentTimeMillis();
  94. startXPHunter = skills.getCurrentExp(Skills.HUNTER);
  95. startXPPrayer = skills.getCurrentExp(Skills.PRAYER);
  96. startLevelHunter = skills.getCurrentLevel(Skills.HUNTER);
  97. startLevelPrayer = skills.getCurrentLevel(Skills.PRAYER);
  98.  
  99. //Determine which Kebbit to catch
  100. if (startLevelHunter >= 69)
  101. kebbitID = kebbitIDs[2];
  102. else if (startLevelHunter >= 57)
  103. kebbitID = kebbitIDs[1];
  104. else if (startLevelHunter >= 43)
  105. kebbitID = kebbitIDs[0];
  106. else
  107. {
  108. log("Your hunter level is too low for falconry. You need at least level 43!");
  109. stopScript();
  110. }
  111.  
  112.  
  113. strategies.add(new reGetFalcon());
  114. strategies.add(new dropJunk());
  115. strategies.add(new buryBones());
  116. strategies.add(new catchKebbit());
  117. strategies.add(new takeFalcon());
  118. return true;
  119. }
  120.  
  121. @Override
  122. public int loop()
  123. {
  124. try {
  125. if (interfaces.canContinue())
  126. interfaces.clickContinue();
  127. if (!getMyPlayer().isIdle() || !game.isLoggedIn())
  128. return 400;
  129. mouse.setSpeed(random(4, 7));
  130. for (Strategy strategy : strategies) {
  131. // debug = false;
  132. if (strategy.isValid()) {
  133. // debug = true;
  134. strategy*****cute();
  135. return random(500, 1000);
  136. }
  137. }
  138. }
  139. catch (NullPointerException e) {}
  140. return 10;
  141. }
  142.  
  143. public void turnToNPC(RSNPC npc)
  144. {
  145. if (npc == null)
  146. return;
  147. if (!npc.isOnScreen()) {
  148. //camera.turnToCharacter(npc, random(10,25));
  149. //if (!npc.isOnScreen())
  150. walking.walkTileMM(walking.getClosestTileOnMap(npc.getLocation()));
  151. }
  152. }
  153.  
  154. public class catchKebbit extends Debug implements Strategy {
  155.  
  156. @Override
  157. public void execute()
  158. {
  159. RSNPC kebbit = npcs.getNearest(new Filter<RSNPC>() {
  160.  
  161. @Override
  162. public boolean accept(RSNPC t)
  163. {
  164. if (t.getID() == kebbitID)
  165. return true;
  166. return false;
  167. }
  168. });
  169. turnToNPC(kebbit);
  170. if (kebbit.doAction("Catch")) {
  171. int timeout = 0;
  172. while (npcs.getNearest(falconIDs) == null && ++timeout < 20)
  173. sleep(100);
  174. }
  175. }
  176.  
  177. @Override
  178. public boolean isValid()
  179. {
  180. return (npcs.getNearest(falconIDs) == null);
  181. }
  182. }
  183.  
  184. public class takeFalcon implements Strategy {
  185.  
  186. @Override
  187. public void execute()
  188. {
  189. RSNPC falcon = npcs.getNearest(falconIDs);
  190. turnToNPC(falcon);
  191. if (falcon.doAction("Retrieve")) {
  192. kebbitsCaught++;
  193. int timeout = 0;
  194. while (npcs.getNearest(falconIDs) != null && ++timeout < 25)
  195. sleep(100);
  196. }
  197. }
  198.  
  199. @Override
  200. public boolean isValid()
  201. {
  202. return (npcs.getNearest(falconIDs) != null);
  203. }
  204.  
  205. }
  206.  
  207. public class dropJunk implements Strategy {
  208.  
  209. @Override
  210. public void execute()
  211. {
  212. mouse.setSpeed(4);
  213. for (RSItem item : inventory.getItems()) {
  214. if (arrayContains(junk, item.getID())) {
  215. //Are we dropping bones?
  216. if (buryBones == true && item.getID() == 526)
  217. {
  218. //Do nothing since we don't want to drop the bone
  219. }
  220. else
  221. {
  222. //Drop junk item
  223. mouse.setSpeed(5);
  224. item.doAction("Drop");
  225. sleep(random(300, 500));
  226. //Occasionally sleep extra long for antiban measure
  227. int rndVal = random(1, 30);
  228. if (rndVal == 1) sleep(random(2000,3000));
  229. }
  230. }
  231. }
  232. //When we're done we will set a flag so that we can bury the bones now
  233. doBoneWork = true;
  234. }
  235.  
  236. @Override
  237. public boolean isValid()
  238. {
  239. return inventory.getCount() > 26;
  240. }
  241.  
  242. }
  243.  
  244. public class buryBones implements Strategy {
  245.  
  246. @Override
  247. public void execute()
  248. {
  249. mouse.setSpeed(4);
  250. int[] boneID = {526};
  251. for (RSItem item : inventory.getItems()) {
  252. if (arrayContains(boneID, item.getID())) {
  253. //If this item is a bone, bury it
  254. if (item.getID() == 526)
  255. {
  256. item.doClick(true);
  257. sleep(random(700, 900));
  258. }
  259. }
  260. }
  261. doBoneWork = false; //Stop working with bones, we're done
  262. }
  263.  
  264. @Override
  265. public boolean isValid()
  266. {
  267. return doBoneWork;
  268. }
  269. }
  270.  
  271. public class reGetFalcon implements Strategy {
  272.  
  273. @Override
  274. public void execute()
  275. {
  276. walking.newTilePath(walking.findPath(falconerTile)).traverse();
  277. RSNPC falconer = npcs.getNearest(falconerID);
  278. turnToNPC(falconer);
  279. if (falconer.isOnScreen()) {
  280. if (falconer.doAction("Falconry")) {
  281. int timeout = 0;
  282. while (!interfaces.getComponent(236, 1).isValid() && ++timeout < 20)
  283. sleep(100);
  284. if (interfaces.getComponent(236, 1).doClick()) {
  285. timeout = 0;
  286. while (!interfaces.canContinue() && ++timeout < 20) {
  287. sleep(100);
  288. }
  289. reGetFalcon = false;
  290. }
  291. }
  292. }
  293. }
  294.  
  295. @Override
  296. public boolean isValid()
  297. {
  298. return reGetFalcon;
  299. }
  300.  
  301. }
  302.  
  303. public boolean arrayContains(int[] array, int num)
  304. {
  305. for (int i : array) {
  306. if (i == num)
  307. return true;
  308. }
  309. return false;
  310. }
  311.  
  312. @Override
  313. public void messageReceived(MessageEvent e)
  314. {
  315. String txt = e.getMessage();
  316. if (txt.contains("you see it heading back to the f"))
  317. reGetFalcon = true;
  318.  
  319. }
  320.  
  321. public String getTime(long millis)
  322. {
  323. long time = millis / 1000;
  324. String seconds = Integer.toString((int) (time % 60));
  325. String minutes = Integer.toString((int) ((time % 3600) / 60));
  326. String hours = Integer.toString((int) (time / 3600));
  327. for (int i = 0; i < 2; i++) {
  328. if (seconds.length() < 2) {
  329. seconds = "0" + seconds;
  330. }
  331. if (minutes.length() < 2) {
  332. minutes = "0" + minutes;
  333. }
  334. if (hours.length() < 2) {
  335. hours = "0" + hours;
  336. }
  337. }
  338. String returnThis = hours + ":" + minutes + ":" + seconds;
  339. return returnThis;
  340. }
  341.  
  342. private final Color color1 = new Color(0, 0, 153, 125);
  343. private final Color color2 = new Color(0, 0, 0);
  344. private final Color color3 = new Color(255, 255, 255);
  345. private final Color color4 = new Color(255, 0, 51);
  346. private final Color color5 = new Color(51, 255, 0);
  347.  
  348. private final BasicStroke stroke1 = new BasicStroke(1);
  349.  
  350. private final Font font1 = new Font("Arial", 0, 12);
  351. int xpGainedHunter, xpGainedPrayer, xpPHHunter, xpPHPrayer, kebbitsPH;
  352. long ttlCalcH, ttlCalcP;
  353. String TTLH, TTLP, timeRan;
  354. public void onRepaint(Graphics g)
  355. {
  356. xpGainedHunter = skills.getCurrentExp(Skills.HUNTER) - startXPHunter;
  357. xpGainedPrayer = skills.getCurrentExp(skills.PRAYER) - startXPPrayer;
  358. xpPHHunter = (int) ((xpGainedHunter) * 3600000D / (System.currentTimeMillis() - startTime));
  359. xpPHPrayer = (int) ((xpGainedPrayer) * 3600000D / (System.currentTimeMillis() - startTime));
  360. String TTLH,TTLP;
  361. if(xpPHHunter != 0)
  362. ttlCalcH = (long) (skills.getExpToNextLevel(Skills.HUNTER) * 3600000D) / xpPHHunter;
  363. if(xpPHPrayer != 0)
  364. ttlCalcP = (long) (skills.getExpToNextLevel(Skills.HUNTER) * 3600000D) / xpPHHunter;
  365. kebbitsPH = (int) ((kebbitsCaught) * 3600000D / (System.currentTimeMillis() - startTime));
  366. TTLH = getTime(ttlCalcH);
  367. TTLP = getTime(ttlCalcP);
  368. timeRan = getTime(System.currentTimeMillis() - startTime);
  369.  
  370. Color background = new Color(0,0,0,150);
  371. Color background2 = new Color(180,0,0,100);
  372. Color background3 = new Color(0,0,0,100);
  373.  
  374. if (game.isLoggedIn()) {
  375. //=== Begin drawing the HUD ===
  376.  
  377. int topOfHUD = 25; //Where the top of the HUD is (below the indicator text)
  378. //Draw the title box (200 pixels wide, 20 pixels tall)
  379. g.setColor(background);
  380. g.fillRect(3, topOfHUD, 170, 20);
  381. g.setColor(Color.black);
  382. g.drawRect(3, topOfHUD, 170, 20);
  383. g.setColor(Color.black);
  384. g.drawString(" Uber Falconry", 40, topOfHUD + 16);
  385. g.setColor(Color.red);
  386. g.drawString(" Uber Falconry", 41, topOfHUD + 15);
  387. //Draw the information box (200 pixels wide, 80 pixels tall)
  388. g.setColor(background3);
  389. g.fillRect(3, topOfHUD + 20, 170, 65);
  390. g.setColor(Color.black);
  391. g.drawRect(3, topOfHUD + 20, 170, 65);
  392. //Fill the box with information
  393. int firstListEntry = topOfHUD + 35; //Calculate where the first entry goes
  394. int currentListEntry = 0; //Changes for each entry as the number is incremented
  395. int numberOfListEntries = 0; //Tracks how many items in in this list
  396. g.setFont(new Font("sans serif", Font.PLAIN, 12));
  397. currentListEntry = firstListEntry + (numberOfListEntries * 15);
  398. g.setColor(Color.white);
  399. g.drawString("Time Running: " + timeRan, 8, currentListEntry);
  400. numberOfListEntries++; currentListEntry = firstListEntry + (numberOfListEntries * 15);
  401. g.setColor(Color.green);
  402. g.drawString("Kebbits Caught: " + kebbitsCaught + " (" + kebbitsPH + "/hr)", 8, currentListEntry);
  403. numberOfListEntries++; currentListEntry = firstListEntry + (numberOfListEntries * 15);
  404. g.setColor(Color.green);
  405. g.drawString("Hunter Exp: " + xpGainedHunter + " (" + xpPHHunter + "/hr)", 8, currentListEntry);
  406. numberOfListEntries++; currentListEntry = firstListEntry + (numberOfListEntries * 15);
  407. g.setColor(Color.green);
  408. g.drawString("Prayer Exp: " + xpGainedPrayer + " (" + xpPHPrayer + "/hr)", 8, currentListEntry);
  409.  
  410.  
  411. //Draw progressbar for hunter
  412. String statName = "Hunter level: " + skills.getRealLevel(skills.HUNTER);
  413. int statXPGained = xpGainedHunter;
  414. int statXPToGo = skills.getExpToNextLevel(skills.HUNTER);
  415. int statPercent = skills.getPercentToNextLevel(skills.HUNTER);
  416. int statLevelsGained = skills.getCurrentLevel(Skills.HUNTER) - startLevelHunter;
  417. //Add levels gained to the level indicator if we gained any levels
  418. if (statLevelsGained > 0)
  419. {
  420. statName = statName + " (+" + statLevelsGained + ")";
  421. //Recalculate which Kebbit to catch too
  422. if (startLevelHunter >= 69)
  423. kebbitID = kebbitIDs[2];
  424. else if (startLevelHunter >= 57)
  425. kebbitID = kebbitIDs[1];
  426. else
  427. kebbitID = kebbitIDs[0];
  428. }
  429. double drawPercent = (statPercent * 1.7);
  430.  
  431. g.setColor(background3);
  432. g.fillRect(3, topOfHUD + 85, 170, 25);
  433. g.setColor(Color.black);
  434. g.drawRect(3, topOfHUD + 85, 170, 25);
  435.  
  436. g.setColor(background2);
  437. g.fillRect(4, topOfHUD + 86, (int) drawPercent, 24);
  438. g.setColor(Color.white);
  439. g.setFont(new Font("Verdana", Font.PLAIN, 9));
  440. g.drawString(statName, 8, topOfHUD + 96);
  441. g.drawString("XP Gained " + statXPGained + " | " + statXPToGo + " to lvl", 8, topOfHUD + 106);
  442. g.setColor(Color.black);
  443.  
  444. //Draw progressbar for prayer
  445. if (buryBones == true)
  446. {
  447. statName = "Prayer level: " + skills.getRealLevel(skills.PRAYER);
  448. statXPGained = xpGainedPrayer;
  449. statXPToGo = skills.getExpToNextLevel(skills.PRAYER);
  450. statPercent = skills.getPercentToNextLevel(skills.PRAYER);
  451. statLevelsGained = skills.getCurrentLevel(Skills.PRAYER) - startLevelPrayer;
  452. //Add levels gained to the level indicator if we gained any levels
  453. if (statLevelsGained > 0)
  454. statName = statName + " (+" + statLevelsGained + ")";
  455. drawPercent = (statPercent * 1.7);
  456.  
  457. g.setColor(background3);
  458. g.fillRect(3, topOfHUD + 110, 170, 25);
  459. g.setColor(Color.black);
  460. g.drawRect(3, topOfHUD + 110, 170, 25);
  461.  
  462. g.setColor(background2);
  463. g.fillRect(4, topOfHUD + 111, (int) drawPercent, 24);
  464. g.setColor(Color.white);
  465. g.setFont(new Font("Verdana", Font.PLAIN, 9));
  466. g.drawString(statName, 8, topOfHUD + 121);
  467. g.drawString("XP Gained " + statXPGained + " | " + statXPToGo + " to lvl", 8, topOfHUD + 131);
  468. g.setColor(Color.black);
  469. }
  470. }
  471. }
  472.  
  473. class GUI extends JFrame {
  474. UberFalconry script;
  475.  
  476. public GUI(final UberFalconry script) {
  477. this.script = script;
  478. script.loop();
  479. initComponents();
  480. }
  481.  
  482. private void startBtnActionPerformed(ActionEvent e)
  483. {
  484. if (kebbitSelect.getSelectedIndex() == 0)
  485. script.buryBones = true;
  486. else
  487. script.buryBones = false;
  488. dispose();
  489. }
  490.  
  491. private void initComponents()
  492. {
  493. // JFormDesigner - Component initialization - DO NOT MODIFY //GEN-BEGIN:initComponents
  494. // Generated using JFormDesigner Evaluation license - Taylor Lodge
  495. kebbitLabel = new JLabel();
  496. kebbitSelect = new JComboBox(new Object[] {"Yes", "No"});
  497. startBtn = new JButton();
  498.  
  499. //======== this ========
  500. Container contentPane = getContentPane();
  501. contentPane.setLayout(null);
  502.  
  503. //---- kebbitLabel ----
  504. kebbitLabel.setText("Bury Bones?");
  505. contentPane.add(kebbitLabel);
  506. kebbitLabel.setBounds(new Rectangle(new Point(5, 5), kebbitLabel.getPreferredSize()));
  507. contentPane.add(kebbitSelect);
  508. kebbitSelect.setBounds(5, 25, 110, kebbitSelect.getPreferredSize().height);
  509.  
  510. //---- startBtn ----
  511. startBtn.setText("Start");
  512. startBtn.addActionListener(new ActionListener() {
  513. @Override
  514. public void actionPerformed(ActionEvent e) {
  515. startBtnActionPerformed(e);
  516. }
  517. });
  518. contentPane.add(startBtn);
  519. startBtn.setBounds(new Rectangle(new Point(10, 55), startBtn.getPreferredSize()));
  520.  
  521. { // compute preferred size
  522. Dimension preferredSize = new Dimension();
  523. for(int i = 0; i < contentPane.getComponentCount(); i++) {
  524. Rectangle bounds = contentPane.getComponent(i).getBounds();
  525. preferredSize.width = Math.max(bounds.x + bounds.width, preferredSize.width);
  526. preferredSize.height = Math.max(bounds.y + bounds.height, preferredSize.height);
  527. }
  528. Insets insets = contentPane.getInsets();
  529. preferredSize.width += insets.right;
  530. preferredSize.height += insets.bottom;
  531. contentPane.setMinimumSize(preferredSize);
  532. contentPane.setPreferredSize(preferredSize);
  533. }
  534. pack();
  535. setLocationRelativeTo(getOwner());
  536. // JFormDesigner - End of component initialization //GEN-END:initComponents
  537. }
  538.  
  539. // JFormDesigner - Variables declaration - DO NOT MODIFY //GEN-BEGIN:variables
  540. // Generated using JFormDesigner Evaluation license - Taylor Lodge
  541. private JLabel kebbitLabel;
  542. private JComboBox kebbitSelect;
  543. private JButton startBtn;
  544. // JFormDesigner - End of variables declaration //GEN-END:variables
  545. }
  546. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement