Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import com.rsbuddy.event.events.MessageEvent;
- import com.rsbuddy.event.listeners.MessageListener;
- import com.rsbuddy.event.listeners.PaintListener;
- import com.rsbuddy.script.ActiveScript;
- import com.rsbuddy.script.Manifest;
- import com.rsbuddy.script.methods.*;
- import com.rsbuddy.script.util.Random;
- import com.rsbuddy.script.wrappers.*;
- import com.rsbuddy.script.wrappers.Component;
- import javax.swing.*;
- import java.awt.*;
- import java.awt.event.ActionEvent;
- import java.awt.event.ActionListener;
- import java.util.LinkedHashMap;
- /**
- * Created by IntelliJ IDEA.
- * User: Other
- * Date: 3/5/11
- * Time: 11:52 PM
- * To change this template use File | Settings | File Templates.
- */
- @Manifest(authors = "Drew", name = "Catherby Fisher/Cooker", version = 1.0, description = "Ethereal presents: A Catherby Fisher/Cooker")
- public class CatherbyFisherOriginal extends ActiveScript implements PaintListener, MessageListener, EtherealPaint.EtherealPaintInfo {
- // Gui
- private boolean fish = true;
- private boolean cook = true;
- private boolean startScript = false;
- // Fishing equipment
- private final int LOBSTER_CAGE = 301;
- // Fishing spot ID
- private final int FISHING_SPOT = 331;
- // Animations
- private final int FISHING_ANIMATION = 619;
- // Object IDs
- private final int BANK_BOOTH = 2213;
- private final int COOKING_DOOR = 1530;
- private final int RANGE = 2772;
- // Lobster IDs
- private final int COOKED_LOBSTER = 379;
- private final int RAW_LOBSTER = 377;
- private final int BURNT_LOBSTER = 381;
- // Cooking widgets
- private final int COOKING_WIDGET = 905;
- private final int COOKING_COMPONENT = 14;
- private Component c;
- // Walking locations
- private final Tile LOC_1 = new Tile(2836, 3434);
- private final Tile LOC_2 = new Tile(2844, 3432);
- private final Tile LOC_3 = new Tile(2856, 3425);
- private final Tile BANK_LOC = new Tile(2809, 3440);
- // Fishing spots
- private final Tile SPOT_1 = new Tile(2836, 3431);
- private final Tile SPOT_2 = new Tile(2837, 3431);
- private final Tile SPOT_3 = new Tile(2838, 3431);
- private final Tile SPOT_4 = new Tile(2844, 3429);
- private final Tile SPOT_5 = new Tile(2845, 3429);
- private final Tile SPOT_6 = new Tile(2846, 3429);
- private final Tile SPOT_7 = new Tile(2853, 3423);
- private final Tile SPOT_8 = new Tile(2354, 3423);
- private final Tile SPOT_9 = new Tile(2355, 3423);
- private final Tile SPOT_10 = new Tile(2859, 3426);
- private final Tile SPOT_11 = new Tile(2860, 3426);
- private final Tile RANGE_TILE = new Tile(2816, 3442);
- private final Area RANGE_AREA = new Area(new Tile(2815, 3439), new Tile(2818, 3444));
- private final Tile TILE_AT_RANGE_1 = new Tile(2817, 3443), TILE_AT_RANGE_2 = new Tile(2818, 3443);
- // Test stuff
- boolean click = true;
- // Paint vars
- int count = 0;
- int expHour = 0;
- long startTime;
- String status = "Starting";
- EtherealPaint paint;
- public void messageReceived(MessageEvent messageEvent) {
- if(messageEvent.getMessage().contains("catch a lobster"))
- count++;
- }
- public void onRepaint(Graphics graphics) {
- paint.onRepaint(graphics);
- }
- public LinkedHashMap<String, Boolean> getPaintStrings(LinkedHashMap<String, Boolean> strings) {
- long runTime = System.currentTimeMillis() - startTime;
- int seconds = (int) ((runTime / 1000) % 60);
- int minutes = (int) ((runTime / (1000 * 60)) % 60);
- long hours = ((runTime / (1000 * 60 * 60)));
- int experience = count * 40;
- if(runTime > 0)
- expHour = (int) (experience * 3600000 / runTime);
- strings.put("Information", true);
- strings.put("Run Time: " + hours + " h:" + minutes + " m:" + seconds + " s", false);
- strings.put("Status: " + status, false);
- if(cook && !fish) {
- strings.put("Cooking", true);
- strings.put("Cooked: " + count, false);
- strings.put("Experience Gained: " + experience, false);
- strings.put("Experience / Hour: " + expHour, false);
- }
- else if(!cook && fish) {
- }
- else {
- }
- strings.put("Skills", true);
- strings.put("Cooking percent: " + Skills.getPercentToNextLevel(Skills.COOKING), false);
- strings.put("Lobster Count: " + count, false);
- strings.put("Experience Gained: " + experience, false);
- strings.put("Experience / Hour: " + expHour, false);
- return strings;
- }
- public int getPaintPercent() {
- return Skills.getPercentToNextLevel(Skills.FISHING);
- }
- public char getPaintStringSplitCharacter() {
- return ':';
- }
- private enum States { // Declare main States
- FISHING, COOKING, BANKING
- }
- private enum Fishing { // States specific to Fishing
- WALKING, FISHING, ANTIBAN
- }
- private enum Cooking { // States specific to Cooking
- WALKING, COOKING, ANTIBAN
- }
- private enum Banking { // States specific to Banking
- WALKING, BANKING, OPENING
- }
- @Override
- public boolean onStart() {
- Camera.setPitch(100); // Adjust camera to max altitude
- EventQueue.invokeLater(new Runnable() { // The following code allows GUI to appear
- public void run() {
- new SelectionGUI();
- }
- });
- startTime = System.currentTimeMillis(); // Declares time script started
- paint = new EtherealPaint(this);
- return true;
- }
- @Override
- public int loop() { // Loop - think of it like an instruction manual: Tells the script what to do in specific situations
- if(!startScript) // boolean changed when the GUI is closed
- return 250;
- if(Widgets.canContinue())
- Widgets.clickContinue();
- switch(getCurrentState()) {
- case COOKING: // Handles everything related to cooking
- switch(getCookingState()) {
- case ANTIBAN: // No actual antiban implemented, just waits until the state changes
- status = "Cooking/Antiban";
- while(!Widgets.canContinue() && Inventory.getCount(RAW_LOBSTER) > 0) {
- // Do Antiban
- if(!(RANGE_AREA.contains(Players.getLocal().getLocation())))
- break;
- else
- sleep(500, 700);
- }
- break;
- case COOKING: // Uses fish on the range and begins cooking
- status = "Starting to cook";
- c = Widgets.get(COOKING_WIDGET).getComponent(COOKING_COMPONENT);
- if(c.isVisible())
- c.click();
- else {
- Inventory.useItem(Inventory.getItem(RAW_LOBSTER), Objects.getNearest(RANGE));
- waitForWidget(c.getWidget());
- }
- sleep(1200, 1600);
- break;
- case WALKING:// Walks to the range to cook
- status = "Locating range";
- if(Bank.isOpen()) {
- Bank.close();
- break;
- }
- GameObject door = Objects.getNearest(COOKING_DOOR);
- // Checks position of the door to determine if the correct door is open or closed in order to enter the
- if(door != null && door.isOnScreen() && door.getLocation().getY() < RANGE_TILE.getY() && !RANGE_AREA.contains(Players.getLocal().getLocation())) {
- door.interact("Open ");
- sleep(850, 1100);
- Camera.setCompass('N');
- break;
- }
- if(Calculations.isTileOnScreen(RANGE_TILE)) { // Walks on screen to the range building if applicable
- long start = System.currentTimeMillis();
- Tile[] t = new Tile[] { TILE_AT_RANGE_1, TILE_AT_RANGE_2 };
- Mouse.click(Calculations.tileToScreen(t[Random.nextInt(0, 2)]), true);
- sleep(250, 400);
- while(System.currentTimeMillis() - start < 3500) {
- if(RANGE_AREA.contains(Players.getLocal().getLocation())) break;
- if(!Players.getLocal().isMoving()) break;
- sleep(100, 200);
- }
- }
- else
- Mouse.click(Calculations.tileToMap(Walking.getTileOnMap(RANGE_TILE)), true); // Walks with minimap to the range
- sleep(600, 850); // Sleep to slow down the "thinking" of the script
- break;
- }
- break;
- case FISHING: // Handles everything related to Fishing
- switch(getFishingState()) {
- case ANTIBAN: // Only implemented antiban is moving locations if the spot gets "fished out" and player is still fishing
- status = "Fishing/Antiban";
- if(Players.getLocal().getInteracting() == null && nearestFishingSpot() != null) {
- if(nearestFishingSpot().isOnScreen())
- nearestFishingSpot().interact("Cage ");
- else
- walkTo(nearestFishingSpot().getLocation(), 2, 2);
- }
- break;
- case FISHING: // Clicks fishing psot
- status = "Clicking fishing spot";
- Player p = Players.getLocal();
- if(p.getInteracting() == null)
- nearestFishingSpot().interact("Cage ");
- waitForFishing();
- break;
- case WALKING: // Walks to the next fishing spot, backtracking when reaching the last spot
- status = "Finding fishing spot";
- int x = Players.getLocal().getLocation().getX();
- if(x < LOC_1.getX())
- walkTo(LOC_1, 2, 2);
- else if(x < LOC_2.getX())
- walkTo(LOC_2, 2, 2);
- else if(x < LOC_3.getX())
- walkTo(LOC_3, 2, 2);
- else
- walkTo(LOC_1, 2, 2);
- break;
- }
- break;
- case BANKING: // Handles all things related to Banking
- switch(getBankingState()) {
- case BANKING: // Simply handles banking the appropriate way
- status = "Banking fish";
- if(cook && !fish) {
- Bank.depositAll();
- if(Bank.getCount(RAW_LOBSTER) > 0)
- Bank.withdraw(RAW_LOBSTER, 0);
- else {
- log("Out of raw lobsters!");
- return -1;
- }
- }
- else if(fish) {
- Bank.depositAllExcept(LOBSTER_CAGE);
- if(!Inventory.contains(LOBSTER_CAGE) && Bank.getCount(LOBSTER_CAGE) > 0)
- Bank.withdraw(LOBSTER_CAGE, 1);
- }
- sleep(150); // Sleep to slow down the "thinking" speed of the script
- break;
- case OPENING: // Opens up bank booth and waits for the bank to open (with a timeout)
- status = "Opening bank";
- if(Objects.getNearest(BANK_BOOTH).interact("Use-qu")) {
- long start = System.currentTimeMillis();
- while(System.currentTimeMillis() - start < 1800) { // timeout
- if(Bank.isOpen()) break;
- if(Players.getLocal().isMoving()) start = System.currentTimeMillis();
- sleep(50);
- }
- }
- break;
- case WALKING: // Handles walking to the bank
- status = "Finding bank";
- GameObject door = Objects.getNearest(COOKING_DOOR);
- // If player is within the range building and the door is closed open the door
- if(door != null && door.getLocation().getY() < RANGE_TILE.getY() && RANGE_AREA.contains(Players.getLocal().getLocation())) {
- if(door.isOnScreen()) {
- door.interact("Open ");
- sleep(850, 1000);
- break;
- }
- else
- Camera.turnTo(door);
- }
- walkTo(BANK_LOC, 2, 2);
- break;
- }
- break;
- }
- return 250;
- }
- private States getCurrentState() { // Logically determines the main state
- if(Inventory.isFull() && Inventory.contains(RAW_LOBSTER) && cook)
- return States.COOKING;
- else if(!Inventory.isFull() && !Inventory.contains(COOKED_LOBSTER) && Inventory.contains(LOBSTER_CAGE) && fish)
- return States.FISHING;
- else
- return States.BANKING;
- }
- private Fishing getFishingState() { // Logically determines the current fishing state (if applicable)
- if(Players.getLocal().getInteracting() != null && ((Npc)Players.getLocal().getInteracting()).getId() == FISHING_SPOT)
- return Fishing.ANTIBAN;
- else if(nearestFishingSpot() != null && nearestFishingSpot().isOnScreen())
- return Fishing.FISHING;
- else
- return Fishing.WALKING;
- }
- private Banking getBankingState() { // Logically determines the current banking state (if applicable)
- GameObject o = Objects.getNearest(BANK_BOOTH);
- if(Bank.isOpen())
- return Banking.BANKING;
- // the isReachable is used to determine if the door is closed or not
- else if(o != null && o.isOnScreen() && Calculations.isReachable(BANK_LOC, false)) // method is deprecated, but no better solution available
- return Banking.OPENING;
- else
- return Banking.WALKING; // Handles opening the door if applicable
- }
- private Cooking getCookingState() {
- GameObject o = Objects.getNearest(RANGE);
- if(Players.getLocal().getAnimation() != -1)
- return Cooking.ANTIBAN;
- // the isReachable is used, again, to see if the door is open or closed.
- else if(o != null && o.isOnScreen() && Calculations.isReachable(TILE_AT_RANGE_1, false) && !Bank.isOpen())
- return Cooking.COOKING;
- else
- return Cooking.WALKING; // Handles opening the door if applicable
- }
- private Npc nearestFishingSpot() { // Nothing fancy, planned on expanding but never did.
- return Npcs.getNearest(321);
- }
- private boolean waitForFishing() { // A simple while loop to wait to enter fishing with a timeout
- long start = System.currentTimeMillis();
- while(System.currentTimeMillis() - start < 1500) {
- if(Players.getLocal().getAnimation() != -1) return true;
- }
- return false;
- }
- private void waitForWidget(Widget w) { // A while loop to wait for the cooking widget to open
- long start = System.currentTimeMillis();
- while(System.currentTimeMillis() - start < 1500) {
- if(w.isValid()) return;
- if(Players.getLocal().isMoving()) start = System.currentTimeMillis();
- sleep(150);
- }
- }
- private void walkTo(Tile t, int randX, int randY) { // Walks to a given tile with a given randomness
- if(!Players.getLocal().isMoving() || Walking.getDestination() == null)
- Walking.stepTowards(t); // Simple call to start walking to create the destination flag used in the next part
- else if(Calculations.distanceBetween(Walking.getDestination(), t) > 3)
- Walking.stepTowards(t.randomize(randX, randY));
- }
- class SelectionGUI extends JFrame { // Simple hand-written GUI
- // Allows user to choose if they want to fish/cook/both
- // Won't be discussing Swing, sorry :\
- public SelectionGUI() {
- c = getContentPane();
- buttonPanel = new JPanel();
- fishButton = new JRadioButton("Fish");
- cookButton = new JRadioButton("Cook");
- both = new JRadioButton("Both");
- buttons = new ButtonGroup();
- start = new JButton("Start");
- setTitle("Ethereal Catherby Lobs");
- setPreferredSize(new Dimension(85, 150));
- buttons.add(fishButton);
- buttons.add(cookButton);
- buttons.add(both);
- c.setLayout(new BorderLayout());
- c.add(buttonPanel, BorderLayout.NORTH);
- c.add(start, BorderLayout.SOUTH);
- buttonPanel.setLayout(new BoxLayout(buttonPanel, BoxLayout.Y_AXIS));
- buttonPanel.add(fishButton);
- buttonPanel.add(cookButton);
- buttonPanel.add(both);
- start.addActionListener(new ActionListener() {
- public void actionPerformed(ActionEvent e) {
- if(fishButton.isSelected())
- cook = false;
- else if(cookButton.isSelected())
- fish = false;
- setVisible(false);
- dispose();
- startScript = true;
- }
- });
- setLocationRelativeTo(getOwner());
- setVisible(true);
- pack();
- }
- private Container c;
- private JPanel buttonPanel;
- private JRadioButton fishButton;
- private JRadioButton cookButton;
- private JRadioButton both;
- private ButtonGroup buttons;
- private JButton start;
- }
- }
Add Comment
Please, Sign In to add comment