Jump to content

DexCooker


Dextrell

Recommended Posts

This script supports many fish such as shrimp, sharks, anglerfish etc.

Start at canafis bank make sure you have the raw fish selected in your bank and it will make runs in between cooking them.

 

package com.dexcooker;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.SwingUtilities;

import org.osbot.rs07.api.map.Area;
import org.osbot.rs07.api.model.RS2Object;
import org.osbot.rs07.api.ui.RS2Widget;
import org.osbot.rs07.api.ui.Tab;
import org.osbot.rs07.script.Script;
import org.osbot.rs07.script.ScriptManifest;
import org.osbot.rs07.utility.ConditionalSleep;

@ScriptManifest(author = "Dextrell", info = "Cooking Script", name = "DexCooker", version = 1.1, logo = "")
public class DexCooker extends Script {

    private String selectedFish = null;
    private boolean guiComplete = false;

    private final Area BANK_AREA = new Area(2806, 3438, 2812, 3441);  // Canifis Bank
    private final Area RANGE_AREA = new Area(2815, 3439, 2817, 3444); // Canifis Range

    @Override
    public void onStart() {
        // Create GUI to select fish
        SwingUtilities.invokeLater(this::createGUI);
    }

    /**
     * Creates the GUI for selecting the type of fish to cook.
     */
    private void createGUI() {
        JFrame frame = new JFrame("DexCooker");
        JPanel panel = new JPanel();

        String[] fishOptions = {
                "Raw shrimps", "Raw sardine", "Raw herring", "Raw anchovies",
                "Raw trout", "Raw salmon", "Raw tuna", "Raw lobster",
                "Raw swordfish", "Raw monkfish", "Raw shark", "Raw anglerfish"
        };
        JComboBox<String> fishSelection = new JComboBox<>(fishOptions);

        JButton startButton = new JButton("Start Cooking");

        startButton.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                selectedFish = (String) fishSelection.getSelectedItem();
                guiComplete = true;
                frame.dispose();  // Close the GUI after fish is selected
            }
        });

        panel.add(new JLabel("Select fish to cook:"));
        panel.add(fishSelection);
        panel.add(startButton);

        frame.add(panel);
        frame.pack();
        frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
        frame.setLocationRelativeTo(null); // Center the frame
        frame.setVisible(true);
    }

    @Override
    public int onLoop() throws InterruptedException {
        if (!guiComplete) {
            return 100;  // Wait until GUI is completed
        }

        // If the player is in the bank area and doesn't have fish to cook
        if (BANK_AREA.contains(myPlayer()) && !inventoryContainsRawFish()) {
            if (!getBank().isOpen()) {
                getBank().open();
                
                if(getInventory().isFull())
                	getBank().depositAll();
                sleep(1000);
            } else {
                if (getBank().contains(getRawFishID())) {
                    getBank().withdrawAll(getRawFishID());
                    sleep(1000);
                } else {
                    log("No more fish to cook. Stopping script.");
                    stop();
                }
                getBank().close();
            }
        }

        // If player is at the range and has raw fish to cook
        if (RANGE_AREA.contains(myPlayer()) && inventoryContainsRawFish()) {
            if (!getTabs().isOpen(Tab.INVENTORY)) {
                getTabs().open(Tab.INVENTORY);
                sleep(500);
            }

            // Ensure the range is available
            RS2Object range = getObjects().closest("Range");
            if (range != null) {
                if (!range.isVisible()) {
                    getWalking().webWalk(RANGE_AREA);
                    return 600; // Wait a bit after walking
                }

                // Interact with the range to start cooking
                if (range.interact("Cook")) {
                    log("Interacting with the range to cook.");
                    sleep(2000);  // Wait for cooking animation to start
                    RS2Widget cookingWidget = getWidgets().get(270, 14, 38);
                    
                    
                    // Wait for the cooking widget to appear
                    if (new ConditionalSleep(500, 1000) {
                        @Override
                        public boolean condition() throws InterruptedException {
                            return cookingWidget != null && cookingWidget.isVisible();
                        }
                    }.sleep()) {
                        // Interact with the "Cook All" option in the widget
                    	
                        if (cookingWidget != null) { // Widget 270, Child 14 is "Cook All"
                        	
                        	if(!cookingWidget.isVisible()) {
                        		range.interact("Cook");
                        	}
                        	if (cookingWidget.interact("Cook")) {
                                log("Selected 'Cook All' option.");
                                // Wait until cooking starts (player animates)
                                new ConditionalSleep(8000, 15000) {
                                    @Override
                                    public boolean condition() throws InterruptedException {
                                        return myPlayer().isAnimating();
                                    }
                                }.sleep();
                            }
                        } else {
                            log("Cook option not found.");
                        }
                    }

                    // Wait until cooking is finished
                    new ConditionalSleep(15000, 20000) {
                        @Override
                        public boolean condition() throws InterruptedException {
                            return !myPlayer().isAnimating();
                        }
                    }.sleep();
                }
            }
        }

        // Walk to the bank if inventory is empty
        if (!inventoryContainsRawFish() && !BANK_AREA.contains(myPlayer())) {
            getWalking().webWalk(BANK_AREA);
        }

        // Walk to the range if the inventory contains raw fish
        if (inventoryContainsRawFish() && !RANGE_AREA.contains(myPlayer())) {
            getWalking().webWalk(RANGE_AREA);
        }

        return 300;  // Delay for script loop
    }

    /**
     * Checks if the inventory contains the selected raw fish.
     *
     * @return true if inventory contains raw fish, false otherwise
     */
    private boolean inventoryContainsRawFish() {
        return getInventory().contains(getRawFishID());
    }

    /**
     * Maps the selected fish to its raw item ID.
     *
     * @return the raw fish item ID
     */
    private int getRawFishID() {
        switch (selectedFish) {
            case "Raw shrimps":
                return 317;
            case "Raw sardine":
                return 327;
            case "Raw herring":
                return 345;
            case "Raw anchovies":
                return 321;
            case "Raw trout":
                return 335;
            case "Raw salmon":
                return 331;
            case "Raw tuna":
                return 359;
            case "Raw lobster":
                return 377;
            case "Raw swordfish":
                return 371;
            case "Raw monkfish":
                return 7944;
            case "Raw shark":
                return 383;
            case "Raw anglerfish":
                return 13439;
            default:
                return -1;
        }
    }

    @Override
    public void onExit() {
        log("Thank you for using DexCooker!");
    }
}

 

  • Like 1
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...