Guest User

Untitled

a guest
Nov 24th, 2017
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 18.75 KB | None | 0 0
  1. import com.rsbuddy.event.events.MessageEvent;
  2. import com.rsbuddy.event.listeners.MessageListener;
  3. import com.rsbuddy.event.listeners.PaintListener;
  4. import com.rsbuddy.script.ActiveScript;
  5. import com.rsbuddy.script.Manifest;
  6. import com.rsbuddy.script.methods.*;
  7. import com.rsbuddy.script.util.Random;
  8. import com.rsbuddy.script.wrappers.*;
  9. import com.rsbuddy.script.wrappers.Component;
  10.  
  11. import javax.swing.*;
  12. import java.awt.*;
  13. import java.awt.event.ActionEvent;
  14. import java.awt.event.ActionListener;
  15. import java.util.LinkedHashMap;
  16.  
  17. /**
  18. * Created by IntelliJ IDEA.
  19. * User: Other
  20. * Date: 3/5/11
  21. * Time: 11:52 PM
  22. * To change this template use File | Settings | File Templates.
  23. */
  24. @Manifest(authors = "Drew", name = "Catherby Fisher/Cooker", version = 1.0, description = "Ethereal presents: A Catherby Fisher/Cooker")
  25. public class CatherbyFisherOriginal extends ActiveScript implements PaintListener, MessageListener, EtherealPaint.EtherealPaintInfo {
  26.  
  27. // Gui
  28. private boolean fish = true;
  29. private boolean cook = true;
  30. private boolean startScript = false;
  31.  
  32. // Fishing equipment
  33. private final int LOBSTER_CAGE = 301;
  34.  
  35. // Fishing spot ID
  36. private final int FISHING_SPOT = 331;
  37.  
  38. // Animations
  39. private final int FISHING_ANIMATION = 619;
  40.  
  41. // Object IDs
  42. private final int BANK_BOOTH = 2213;
  43. private final int COOKING_DOOR = 1530;
  44. private final int RANGE = 2772;
  45.  
  46. // Lobster IDs
  47. private final int COOKED_LOBSTER = 379;
  48. private final int RAW_LOBSTER = 377;
  49. private final int BURNT_LOBSTER = 381;
  50.  
  51. // Cooking widgets
  52. private final int COOKING_WIDGET = 905;
  53. private final int COOKING_COMPONENT = 14;
  54. private Component c;
  55.  
  56. // Walking locations
  57. private final Tile LOC_1 = new Tile(2836, 3434);
  58. private final Tile LOC_2 = new Tile(2844, 3432);
  59. private final Tile LOC_3 = new Tile(2856, 3425);
  60. private final Tile BANK_LOC = new Tile(2809, 3440);
  61.  
  62. // Fishing spots
  63. private final Tile SPOT_1 = new Tile(2836, 3431);
  64. private final Tile SPOT_2 = new Tile(2837, 3431);
  65. private final Tile SPOT_3 = new Tile(2838, 3431);
  66. private final Tile SPOT_4 = new Tile(2844, 3429);
  67. private final Tile SPOT_5 = new Tile(2845, 3429);
  68. private final Tile SPOT_6 = new Tile(2846, 3429);
  69. private final Tile SPOT_7 = new Tile(2853, 3423);
  70. private final Tile SPOT_8 = new Tile(2354, 3423);
  71. private final Tile SPOT_9 = new Tile(2355, 3423);
  72. private final Tile SPOT_10 = new Tile(2859, 3426);
  73. private final Tile SPOT_11 = new Tile(2860, 3426);
  74.  
  75. private final Tile RANGE_TILE = new Tile(2816, 3442);
  76.  
  77. private final Area RANGE_AREA = new Area(new Tile(2815, 3439), new Tile(2818, 3444));
  78.  
  79. private final Tile TILE_AT_RANGE_1 = new Tile(2817, 3443), TILE_AT_RANGE_2 = new Tile(2818, 3443);
  80.  
  81. // Test stuff
  82. boolean click = true;
  83.  
  84. // Paint vars
  85. int count = 0;
  86. int expHour = 0;
  87. long startTime;
  88. String status = "Starting";
  89. EtherealPaint paint;
  90.  
  91.  
  92. public void messageReceived(MessageEvent messageEvent) {
  93. if(messageEvent.getMessage().contains("catch a lobster"))
  94. count++;
  95. }
  96.  
  97. public void onRepaint(Graphics graphics) {
  98. paint.onRepaint(graphics);
  99. }
  100.  
  101. public LinkedHashMap<String, Boolean> getPaintStrings(LinkedHashMap<String, Boolean> strings) {
  102.  
  103. long runTime = System.currentTimeMillis() - startTime;
  104. int seconds = (int) ((runTime / 1000) % 60);
  105. int minutes = (int) ((runTime / (1000 * 60)) % 60);
  106. long hours = ((runTime / (1000 * 60 * 60)));
  107.  
  108. int experience = count * 40;
  109. if(runTime > 0)
  110. expHour = (int) (experience * 3600000 / runTime);
  111.  
  112. strings.put("Information", true);
  113. strings.put("Run Time: " + hours + " h:" + minutes + " m:" + seconds + " s", false);
  114. strings.put("Status: " + status, false);
  115.  
  116. if(cook && !fish) {
  117. strings.put("Cooking", true);
  118. strings.put("Cooked: " + count, false);
  119. strings.put("Experience Gained: " + experience, false);
  120. strings.put("Experience / Hour: " + expHour, false);
  121. }
  122. else if(!cook && fish) {
  123.  
  124. }
  125. else {
  126.  
  127. }
  128. strings.put("Skills", true);
  129. strings.put("Cooking percent: " + Skills.getPercentToNextLevel(Skills.COOKING), false);
  130. strings.put("Lobster Count: " + count, false);
  131. strings.put("Experience Gained: " + experience, false);
  132. strings.put("Experience / Hour: " + expHour, false);
  133.  
  134. return strings;
  135.  
  136. }
  137.  
  138. public int getPaintPercent() {
  139. return Skills.getPercentToNextLevel(Skills.FISHING);
  140. }
  141.  
  142. public char getPaintStringSplitCharacter() {
  143. return ':';
  144. }
  145.  
  146. private enum States { // Declare main States
  147. FISHING, COOKING, BANKING
  148. }
  149.  
  150. private enum Fishing { // States specific to Fishing
  151. WALKING, FISHING, ANTIBAN
  152. }
  153.  
  154. private enum Cooking { // States specific to Cooking
  155. WALKING, COOKING, ANTIBAN
  156. }
  157.  
  158. private enum Banking { // States specific to Banking
  159. WALKING, BANKING, OPENING
  160. }
  161.  
  162. @Override
  163. public boolean onStart() {
  164. Camera.setPitch(100); // Adjust camera to max altitude
  165.  
  166. EventQueue.invokeLater(new Runnable() { // The following code allows GUI to appear
  167. public void run() {
  168. new SelectionGUI();
  169. }
  170. });
  171.  
  172. startTime = System.currentTimeMillis(); // Declares time script started
  173. paint = new EtherealPaint(this);
  174. return true;
  175. }
  176.  
  177. @Override
  178. public int loop() { // Loop - think of it like an instruction manual: Tells the script what to do in specific situations
  179.  
  180. if(!startScript) // boolean changed when the GUI is closed
  181. return 250;
  182.  
  183. if(Widgets.canContinue())
  184. Widgets.clickContinue();
  185.  
  186. switch(getCurrentState()) {
  187. case COOKING: // Handles everything related to cooking
  188. switch(getCookingState()) {
  189. case ANTIBAN: // No actual antiban implemented, just waits until the state changes
  190. status = "Cooking/Antiban";
  191. while(!Widgets.canContinue() && Inventory.getCount(RAW_LOBSTER) > 0) {
  192. // Do Antiban
  193. if(!(RANGE_AREA.contains(Players.getLocal().getLocation())))
  194. break;
  195. else
  196. sleep(500, 700);
  197. }
  198. break;
  199. case COOKING: // Uses fish on the range and begins cooking
  200. status = "Starting to cook";
  201. c = Widgets.get(COOKING_WIDGET).getComponent(COOKING_COMPONENT);
  202. if(c.isVisible())
  203. c.click();
  204. else {
  205. Inventory.useItem(Inventory.getItem(RAW_LOBSTER), Objects.getNearest(RANGE));
  206. waitForWidget(c.getWidget());
  207. }
  208. sleep(1200, 1600);
  209. break;
  210. case WALKING:// Walks to the range to cook
  211. status = "Locating range";
  212. if(Bank.isOpen()) {
  213. Bank.close();
  214. break;
  215. }
  216. GameObject door = Objects.getNearest(COOKING_DOOR);
  217. // Checks position of the door to determine if the correct door is open or closed in order to enter the
  218. if(door != null && door.isOnScreen() && door.getLocation().getY() < RANGE_TILE.getY() && !RANGE_AREA.contains(Players.getLocal().getLocation())) {
  219. door.interact("Open ");
  220. sleep(850, 1100);
  221. Camera.setCompass('N');
  222. break;
  223. }
  224.  
  225. if(Calculations.isTileOnScreen(RANGE_TILE)) { // Walks on screen to the range building if applicable
  226. long start = System.currentTimeMillis();
  227. Tile[] t = new Tile[] { TILE_AT_RANGE_1, TILE_AT_RANGE_2 };
  228. Mouse.click(Calculations.tileToScreen(t[Random.nextInt(0, 2)]), true);
  229. sleep(250, 400);
  230. while(System.currentTimeMillis() - start < 3500) {
  231. if(RANGE_AREA.contains(Players.getLocal().getLocation())) break;
  232. if(!Players.getLocal().isMoving()) break;
  233. sleep(100, 200);
  234. }
  235. }
  236. else
  237. Mouse.click(Calculations.tileToMap(Walking.getTileOnMap(RANGE_TILE)), true); // Walks with minimap to the range
  238.  
  239. sleep(600, 850); // Sleep to slow down the "thinking" of the script
  240.  
  241. break;
  242. }
  243. break;
  244. case FISHING: // Handles everything related to Fishing
  245. switch(getFishingState()) {
  246. case ANTIBAN: // Only implemented antiban is moving locations if the spot gets "fished out" and player is still fishing
  247. status = "Fishing/Antiban";
  248. if(Players.getLocal().getInteracting() == null && nearestFishingSpot() != null) {
  249. if(nearestFishingSpot().isOnScreen())
  250. nearestFishingSpot().interact("Cage ");
  251. else
  252. walkTo(nearestFishingSpot().getLocation(), 2, 2);
  253. }
  254. break;
  255. case FISHING: // Clicks fishing psot
  256. status = "Clicking fishing spot";
  257. Player p = Players.getLocal();
  258. if(p.getInteracting() == null)
  259. nearestFishingSpot().interact("Cage ");
  260. waitForFishing();
  261. break;
  262. case WALKING: // Walks to the next fishing spot, backtracking when reaching the last spot
  263. status = "Finding fishing spot";
  264. int x = Players.getLocal().getLocation().getX();
  265. if(x < LOC_1.getX())
  266. walkTo(LOC_1, 2, 2);
  267. else if(x < LOC_2.getX())
  268. walkTo(LOC_2, 2, 2);
  269. else if(x < LOC_3.getX())
  270. walkTo(LOC_3, 2, 2);
  271. else
  272. walkTo(LOC_1, 2, 2);
  273. break;
  274. }
  275. break;
  276. case BANKING: // Handles all things related to Banking
  277. switch(getBankingState()) {
  278. case BANKING: // Simply handles banking the appropriate way
  279. status = "Banking fish";
  280. if(cook && !fish) {
  281. Bank.depositAll();
  282. if(Bank.getCount(RAW_LOBSTER) > 0)
  283. Bank.withdraw(RAW_LOBSTER, 0);
  284. else {
  285. log("Out of raw lobsters!");
  286. return -1;
  287. }
  288. }
  289. else if(fish) {
  290. Bank.depositAllExcept(LOBSTER_CAGE);
  291. if(!Inventory.contains(LOBSTER_CAGE) && Bank.getCount(LOBSTER_CAGE) > 0)
  292. Bank.withdraw(LOBSTER_CAGE, 1);
  293. }
  294. sleep(150); // Sleep to slow down the "thinking" speed of the script
  295. break;
  296. case OPENING: // Opens up bank booth and waits for the bank to open (with a timeout)
  297. status = "Opening bank";
  298. if(Objects.getNearest(BANK_BOOTH).interact("Use-qu")) {
  299. long start = System.currentTimeMillis();
  300. while(System.currentTimeMillis() - start < 1800) { // timeout
  301. if(Bank.isOpen()) break;
  302. if(Players.getLocal().isMoving()) start = System.currentTimeMillis();
  303. sleep(50);
  304. }
  305. }
  306. break;
  307. case WALKING: // Handles walking to the bank
  308. status = "Finding bank";
  309. GameObject door = Objects.getNearest(COOKING_DOOR);
  310. // If player is within the range building and the door is closed open the door
  311. if(door != null && door.getLocation().getY() < RANGE_TILE.getY() && RANGE_AREA.contains(Players.getLocal().getLocation())) {
  312. if(door.isOnScreen()) {
  313. door.interact("Open ");
  314. sleep(850, 1000);
  315. break;
  316. }
  317. else
  318. Camera.turnTo(door);
  319. }
  320. walkTo(BANK_LOC, 2, 2);
  321. break;
  322. }
  323. break;
  324. }
  325.  
  326. return 250;
  327. }
  328.  
  329. private States getCurrentState() { // Logically determines the main state
  330. if(Inventory.isFull() && Inventory.contains(RAW_LOBSTER) && cook)
  331. return States.COOKING;
  332. else if(!Inventory.isFull() && !Inventory.contains(COOKED_LOBSTER) && Inventory.contains(LOBSTER_CAGE) && fish)
  333. return States.FISHING;
  334. else
  335. return States.BANKING;
  336. }
  337.  
  338. private Fishing getFishingState() { // Logically determines the current fishing state (if applicable)
  339. if(Players.getLocal().getInteracting() != null && ((Npc)Players.getLocal().getInteracting()).getId() == FISHING_SPOT)
  340. return Fishing.ANTIBAN;
  341. else if(nearestFishingSpot() != null && nearestFishingSpot().isOnScreen())
  342. return Fishing.FISHING;
  343. else
  344. return Fishing.WALKING;
  345. }
  346.  
  347. private Banking getBankingState() { // Logically determines the current banking state (if applicable)
  348. GameObject o = Objects.getNearest(BANK_BOOTH);
  349. if(Bank.isOpen())
  350. return Banking.BANKING;
  351. // the isReachable is used to determine if the door is closed or not
  352. else if(o != null && o.isOnScreen() && Calculations.isReachable(BANK_LOC, false)) // method is deprecated, but no better solution available
  353. return Banking.OPENING;
  354. else
  355. return Banking.WALKING; // Handles opening the door if applicable
  356.  
  357. }
  358.  
  359. private Cooking getCookingState() {
  360. GameObject o = Objects.getNearest(RANGE);
  361. if(Players.getLocal().getAnimation() != -1)
  362. return Cooking.ANTIBAN;
  363. // the isReachable is used, again, to see if the door is open or closed.
  364. else if(o != null && o.isOnScreen() && Calculations.isReachable(TILE_AT_RANGE_1, false) && !Bank.isOpen())
  365. return Cooking.COOKING;
  366. else
  367. return Cooking.WALKING; // Handles opening the door if applicable
  368. }
  369.  
  370. private Npc nearestFishingSpot() { // Nothing fancy, planned on expanding but never did.
  371. return Npcs.getNearest(321);
  372. }
  373.  
  374. private boolean waitForFishing() { // A simple while loop to wait to enter fishing with a timeout
  375. long start = System.currentTimeMillis();
  376. while(System.currentTimeMillis() - start < 1500) {
  377. if(Players.getLocal().getAnimation() != -1) return true;
  378. }
  379. return false;
  380. }
  381.  
  382. private void waitForWidget(Widget w) { // A while loop to wait for the cooking widget to open
  383. long start = System.currentTimeMillis();
  384. while(System.currentTimeMillis() - start < 1500) {
  385. if(w.isValid()) return;
  386. if(Players.getLocal().isMoving()) start = System.currentTimeMillis();
  387. sleep(150);
  388. }
  389. }
  390.  
  391. private void walkTo(Tile t, int randX, int randY) { // Walks to a given tile with a given randomness
  392. if(!Players.getLocal().isMoving() || Walking.getDestination() == null)
  393. Walking.stepTowards(t); // Simple call to start walking to create the destination flag used in the next part
  394. else if(Calculations.distanceBetween(Walking.getDestination(), t) > 3)
  395. Walking.stepTowards(t.randomize(randX, randY));
  396. }
  397.  
  398. class SelectionGUI extends JFrame { // Simple hand-written GUI
  399. // Allows user to choose if they want to fish/cook/both
  400. // Won't be discussing Swing, sorry :\
  401. public SelectionGUI() {
  402. c = getContentPane();
  403. buttonPanel = new JPanel();
  404. fishButton = new JRadioButton("Fish");
  405. cookButton = new JRadioButton("Cook");
  406. both = new JRadioButton("Both");
  407. buttons = new ButtonGroup();
  408. start = new JButton("Start");
  409.  
  410. setTitle("Ethereal Catherby Lobs");
  411. setPreferredSize(new Dimension(85, 150));
  412.  
  413. buttons.add(fishButton);
  414. buttons.add(cookButton);
  415. buttons.add(both);
  416.  
  417. c.setLayout(new BorderLayout());
  418. c.add(buttonPanel, BorderLayout.NORTH);
  419. c.add(start, BorderLayout.SOUTH);
  420.  
  421. buttonPanel.setLayout(new BoxLayout(buttonPanel, BoxLayout.Y_AXIS));
  422.  
  423. buttonPanel.add(fishButton);
  424. buttonPanel.add(cookButton);
  425. buttonPanel.add(both);
  426.  
  427. start.addActionListener(new ActionListener() {
  428. public void actionPerformed(ActionEvent e) {
  429. if(fishButton.isSelected())
  430. cook = false;
  431. else if(cookButton.isSelected())
  432. fish = false;
  433.  
  434. setVisible(false);
  435. dispose();
  436.  
  437. startScript = true;
  438.  
  439. }
  440. });
  441.  
  442. setLocationRelativeTo(getOwner());
  443. setVisible(true);
  444. pack();
  445.  
  446. }
  447.  
  448. private Container c;
  449. private JPanel buttonPanel;
  450. private JRadioButton fishButton;
  451. private JRadioButton cookButton;
  452. private JRadioButton both;
  453. private ButtonGroup buttons;
  454. private JButton start;
  455.  
  456. }
  457.  
  458. }
Add Comment
Please, Sign In to add comment