Advertisement
wafflecat

ehjwh

Feb 26th, 2012
52
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 18.36 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", name = "UberFalconry", keywords = "Hunter", version = 1.0, 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.  
  28. //IDS
  29. public int[] kebbitIDs = { 5098, 5099, 5100 };
  30. private int kebbitID = 5098;
  31. private int[] falconIDs = {5094, 5095, 5096};
  32. private int falconerID = 5093;
  33. private int[] junk = { 526, 10125,10115,10127 };
  34.  
  35. //Tiles
  36. private RSTile falconerTile = new RSTile(2375, 3604);
  37.  
  38. //Statistics
  39. private long startTime;
  40. private int kebbitsCaught = 0;
  41. private int startXP;
  42.  
  43. public interface Strategy {
  44. public void execute();
  45.  
  46. public boolean isValid();
  47. }
  48.  
  49. public class Debug {
  50. public void debug(Object text, boolean severe)
  51. {
  52. if (debug) {
  53. String className = this.getClass().getName();
  54. if (className.contains("$"))
  55. className = className.split("\\$")[1];
  56. StackTraceElement[] stackTraceElements = Thread.currentThread().getStackTrace();
  57. int stacktraceIndex;
  58. if (stackTraceElements[2].getMethodName() == "debug")
  59. stacktraceIndex = 3;
  60. else
  61. stacktraceIndex = 2;
  62. StackTraceElement stacktrace = stackTraceElements[stacktraceIndex];
  63. String methodName = stacktrace.getMethodName();
  64. if (!severe)
  65. log("[" + className + "] -> [" + methodName + "] -> " + text);
  66. else
  67. log.severe("[" + className + "] -> [" + methodName + "] -> " + text);
  68. }
  69. }
  70.  
  71. public void debug(Object text)
  72. {
  73. debug(text, false);
  74. }
  75. }
  76.  
  77. public boolean onStart()
  78. {
  79. if (!game.isLoggedIn()) {
  80. log.severe("Start script loggedin.");
  81. stopScript();
  82. }
  83. GUI gui = new GUI(this);
  84. gui.setVisible(true);
  85. while (gui.isVisible())
  86. sleep(100);
  87. startTime = System.currentTimeMillis();
  88. startXP = skills.getCurrentExp(Skills.HUNTER);
  89. strategies.add(new reGetFalcon());
  90. strategies.add(new dropJunk());
  91. strategies.add(new catchKebbit());
  92. strategies.add(new takeFalcon());
  93. return true;
  94. }
  95.  
  96. @Override
  97. public int loop()
  98. {
  99. try {
  100. if (interfaces.canContinue())
  101. interfaces.clickContinue();
  102. if (!getMyPlayer().isIdle() || !game.isLoggedIn())
  103. return 400;
  104. mouse.setSpeed(random(4, 7));
  105. for (Strategy strategy : strategies) {
  106. // debug = false;
  107. if (strategy.isValid()) {
  108. // debug = true;
  109. strategy.execute();
  110. return random(500, 1000);
  111. }
  112. }
  113. }
  114. catch (NullPointerException e) {}
  115. return 10;
  116. }
  117.  
  118. public void turnToNPC(RSNPC npc)
  119. {
  120. if (npc == null)
  121. return;
  122. if (!npc.isOnScreen()) {
  123. camera.turnToCharacter(npc, random(10,25));
  124. if (!npc.isOnScreen())
  125. walking.walkTileMM(walking.getClosestTileOnMap(npc.getLocation()));
  126. }
  127. }
  128.  
  129. public class catchKebbit extends Debug implements Strategy {
  130.  
  131. @Override
  132. public void execute()
  133. {
  134. RSNPC kebbit = npcs.getNearest(new Filter<RSNPC>() {
  135.  
  136. @Override
  137. public boolean accept(RSNPC t)
  138. {
  139. if (t.getID() == kebbitID)
  140. return true;
  141. return false;
  142. }
  143. });
  144. turnToNPC(kebbit);
  145. if (kebbit.doAction("Catch")) {
  146. int timeout = 0;
  147. while (npcs.getNearest(falconIDs) == null && ++timeout < 20)
  148. sleep(100);
  149. }
  150. }
  151.  
  152. @Override
  153. public boolean isValid()
  154. {
  155. return (npcs.getNearest(falconIDs) == null);
  156. }
  157. }
  158.  
  159. public class takeFalcon implements Strategy {
  160.  
  161. @Override
  162. public void execute()
  163. {
  164. RSNPC falcon = npcs.getNearest(falconIDs);
  165. turnToNPC(falcon);
  166. if (falcon.doAction("Retrieve")) {
  167. kebbitsCaught++;
  168. int timeout = 0;
  169. while (npcs.getNearest(falconIDs) != null && ++timeout < 25)
  170. sleep(100);
  171. }
  172. }
  173.  
  174. @Override
  175. public boolean isValid()
  176. {
  177. return (npcs.getNearest(falconIDs) != null);
  178. }
  179.  
  180. }
  181.  
  182. public class dropJunk implements Strategy {
  183.  
  184. @Override
  185. public void execute()
  186. {
  187. for (RSItem item : inventory.getItems()) {
  188. if (arrayContains(junk, item.getID())) {
  189. item.doAction("Drop");
  190. sleep(random(600, 800));
  191. }
  192. }
  193. }
  194.  
  195. @Override
  196. public boolean isValid()
  197. {
  198. return inventory.getCount() > 26;
  199. }
  200.  
  201. }
  202.  
  203. public class reGetFalcon implements Strategy {
  204.  
  205. @Override
  206. public void execute()
  207. {
  208. walking.newTilePath(walking.findPath(falconerTile)).traverse();
  209. RSNPC falconer = npcs.getNearest(falconerID);
  210. turnToNPC(falconer);
  211. if (falconer.isOnScreen()) {
  212. if (falconer.doAction("Falconry")) {
  213. int timeout = 0;
  214. while (!interfaces.getComponent(236, 1).isValid() && ++timeout < 20)
  215. sleep(100);
  216. if (interfaces.getComponent(236, 1).doClick()) {
  217. timeout = 0;
  218. while (!interfaces.canContinue() && ++timeout < 20) {
  219. sleep(100);
  220. }
  221. reGetFalcon = false;
  222. }
  223. }
  224. }
  225. }
  226.  
  227. @Override
  228. public boolean isValid()
  229. {
  230. return reGetFalcon;
  231. }
  232.  
  233. }
  234.  
  235. public boolean arrayContains(int[] array, int num)
  236. {
  237. for (int i : array) {
  238. if (i == num)
  239. return true;
  240. }
  241. return false;
  242. }
  243.  
  244. @Override
  245. public void messageReceived(MessageEvent e)
  246. {
  247. String txt = e.getMessage();
  248. if (txt.contains("you see it heading back to the f"))
  249. reGetFalcon = true;
  250.  
  251. }
  252.  
  253. public String getTime(long millis)
  254. {
  255. long time = millis / 1000;
  256. String seconds = Integer.toString((int) (time % 60));
  257. String minutes = Integer.toString((int) ((time % 3600) / 60));
  258. String hours = Integer.toString((int) (time / 3600));
  259. for (int i = 0; i < 2; i++) {
  260. if (seconds.length() < 2) {
  261. seconds = "0" + seconds;
  262. }
  263. if (minutes.length() < 2) {
  264. minutes = "0" + minutes;
  265. }
  266. if (hours.length() < 2) {
  267. hours = "0" + hours;
  268. }
  269. }
  270. String returnThis = hours + ":" + minutes + ":" + seconds;
  271. return returnThis;
  272. }
  273.  
  274. //START: Code generated using Enfilade's Easel
  275. private final Color color1 = new Color(0, 0, 153, 125);
  276. private final Color color2 = new Color(0, 0, 0);
  277. private final Color color3 = new Color(255, 255, 255);
  278. private final Color color4 = new Color(255, 0, 51);
  279. private final Color color5 = new Color(51, 255, 0);
  280.  
  281. private final BasicStroke stroke1 = new BasicStroke(1);
  282.  
  283. private final Font font1 = new Font("Arial", 0, 12);
  284. int xpGained, xpPH, kebbitsPH;
  285. long ttlCalc;
  286. String TTL, timeRan;
  287. public void onRepaint(Graphics g1)
  288. {
  289. xpGained = skills.getCurrentExp(Skills.HUNTER) - startXP;
  290. xpPH = (int) ((xpGained) * 3600000D / (System.currentTimeMillis() - startTime));
  291. String TTL;
  292. if(xpPH != 0)
  293. ttlCalc = (long) (skills.getExpToNextLevel(Skills.HUNTER) * 3600000D) / xpPH;
  294. kebbitsPH = (int) ((kebbitsCaught) * 3600000D / (System.currentTimeMillis() - startTime));
  295. TTL = getTime(ttlCalc);
  296. timeRan = getTime(System.currentTimeMillis() - startTime);
  297. Graphics2D g = (Graphics2D) g1;
  298. g.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
  299. g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
  300. g.setColor(color1);
  301. g.fillRoundRect(550, 210, 188, 80, 16, 16);
  302. g.setColor(color2);
  303. g.setStroke(stroke1);
  304. g.drawRoundRect(550, 210, 188, 80, 16, 16);
  305. g.setFont(font1);
  306. g.setColor(color3);
  307. g.drawString("Kebbits caught (P/H):" + kebbitsCaught + "(" + kebbitsPH + ")", 555, 225);
  308. g.drawString("Exp gained (P/H):" + xpGained + "(" + xpPH + ")", 555, 240);
  309. g.drawString("Time running: " + getTime(System.currentTimeMillis() - startTime), 555, 255 );
  310. g.setColor(color4);
  311. g.fillRoundRect(555, 260, 175, 21, 16, 16);
  312. g.setColor(color2);
  313. g.drawRoundRect(555, 260, 175, 21, 16, 16);
  314. g.setColor(color5);
  315. g.fillRoundRect(555, 260, (int) (skills.getPercentToNextLevel(Skills.HUNTER) * 1.75), 21, 16, 16);
  316. g.setColor(color3);
  317. g.drawString(skills.getPercentToNextLevel(Skills.HUNTER) + "%/" + TTL, 596, 275);
  318. }
  319.  
  320. //END: Code generated using Enfilade's Easel
  321.  
  322. class GUI extends JFrame {
  323. UberFalconry script;
  324.  
  325. public GUI(final UberFalconry script) {
  326. this.script = script;
  327. script.loop();
  328. initComponents();
  329. }
  330.  
  331. private void startBtnActionPerformed(ActionEvent e)
  332. {
  333. script.kebbitID = script.kebbitIDs[kebbitSelect.getSelectedIndex()];
  334. dispose();
  335. }
  336.  
  337. private void initComponents()
  338. {
  339. // JFormDesigner - Component initialization - DO NOT MODIFY //GEN-BEGIN:initComponents
  340. // Generated using JFormDesigner Evaluation license - Taylor Lodge
  341. kebbitLabel = new JLabel();
  342. kebbitSelect = new JComboBox(new Object[] {"Spotted Kebbit", "Dark Kebbit", "Dashing Kebbit"});
  343. startBtn = new JButton();
  344.  
  345. //======== this ========
  346. Container contentPane = getContentPane();
  347. contentPane.setLayout(null);
  348.  
  349. //---- kebbitLabel ----
  350. kebbitLabel.setText("Select Kebbit:");
  351. contentPane.add(kebbitLabel);
  352. kebbitLabel.setBounds(new Rectangle(new Point(5, 5), kebbitLabel.getPreferredSize()));
  353. contentPane.add(kebbitSelect);
  354. kebbitSelect.setBounds(5, 25, 110, kebbitSelect.getPreferredSize().height);
  355.  
  356. //---- startBtn ----
  357. startBtn.setText("Start");
  358. startBtn.addActionListener(new ActionListener() {
  359. @Override
  360. public void actionPerformed(ActionEvent e) {
  361. startBtnActionPerformed(e);
  362. }
  363. });
  364. contentPane.add(startBtn);
  365. startBtn.setBounds(new Rectangle(new Point(10, 55), startBtn.getPreferredSize()));
  366.  
  367. { // compute preferred size
  368. Dimension preferredSize = new Dimension();
  369. for(int i = 0; i < contentPane.getComponentCount(); i++) {
  370. Rectangle bounds = contentPane.getComponent(i).getBounds();
  371. preferredSize.width = Math.max(bounds.x + bounds.width, preferredSize.width);
  372. preferredSize.height = Math.max(bounds.y + bounds.height, preferredSize.height);
  373. }
  374. Insets insets = contentPane.getInsets();
  375. preferredSize.width += insets.right;
  376. preferredSize.height += insets.bottom;
  377. contentPane.setMinimumSize(preferredSize);
  378. contentPane.setPreferredSize(preferredSize);
  379. }
  380. pack();
  381. setLocationRelativeTo(getOwner());
  382. // JFormDesigner - End of component initialization //GEN-END:initComponents
  383. }
  384.  
  385. // JFormDesigner - Variables declaration - DO NOT MODIFY //GEN-BEGIN:variables
  386. // Generated using JFormDesigner Evaluation license - Taylor Lodge
  387. private JLabel kebbitLabel;
  388. private JComboBox kebbitSelect;
  389. private JButton startBtn;
  390. // JFormDesigner - End of variables declaration //GEN-END:variables
  391. }
  392. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement