Jump to content

Fishing guild - Swordfish farmer


Vandermooore

Recommended Posts

Hey EpicBot community,

I am fairly new to coding with Java and wanted to post my first successful script. I had an issue with the Pro Fishing script not finding equipped harpoons or anything other than a standard harpoon, so I just decided to write my own script that was tailored to what I wanted (fish for swordfish, drop any tuna I got, and then continue until my inventory was full of swordfish - only at the fishing guild).

I would like to eventually become an official script writer for the community once I am skilled enough, so let me know what you think of this so far.

Any criticism and critiques is greatly appreciated.

image.png.cabe85c103c51625d912e0d61f00e1f4.png

import com.epicbot.api.shared.APIContext;
import com.epicbot.api.shared.GameType;
import com.epicbot.api.shared.entity.NPC;
import com.epicbot.api.shared.entity.WidgetGroup;
import com.epicbot.api.shared.methods.*;
import com.epicbot.api.shared.model.Tile;
import com.epicbot.api.shared.script.LoopScript;
import com.epicbot.api.shared.script.ScriptManifest;
import com.epicbot.api.shared.util.paint.frame.PaintFrame;
import com.epicbot.api.shared.util.time.Time;
import com.epicbot.api.shared.webwalking.model.RSBank;

import java.awt.*;

@ScriptManifest(name = "Fishing Guild - Swordfish Farmer", gameType = GameType.OS)
public class fisher_v2 extends LoopScript {

    /**********************************************************
     *********************VARIABLES/API*******************
     **********************************************************/

    private String status = "";
    private long startTime;
    private NPC fishSpotNPC;
    private int fishingLevel;
    private int xpTNL;
    private int counter = 0;
    private final Tile fishGuild = new Tile(2592, 3415);
    private ISkillsAPI skills() { return getAPIContext().skills(); }
    private INPCsAPI npc() { return getAPIContext().npcs(); }
    private ILocalPlayerAPI player() { return getAPIContext().localPlayer(); }
    private IMouseAPI mouse() { return getAPIContext().mouse(); }
    private IInventoryAPI myInventory() { return getAPIContext().inventory(); }
    private IBankAPI myBank() { return getAPIContext().bank(); }
    private IWebWalkingAPI walk() { return getAPIContext().webWalking(); }

    /**********************************************************
     *********************BANKING METHODS*******************
     **********************************************************/

    private void openBank() {
        setStatus("Banking items");
        System.out.println("Opening bank...");
        myBank().open();
    }

    private void closeBank() {
        setStatus("Banking items");
        System.out.println("Closing bank...");
        myBank().close();
    }

    private void depositItems() {
        setStatus("Banking items");
        System.out.println("Depositing items...");
        myBank().depositAllExcept("Dragon harpoon");
    }

    private void walkToBank() {
        setStatus("Walking to the bank");
        System.out.println("Walking to the bank...");
        walk().walkToBank(RSBank.FISHING_GUILD);
    }

    /**********************************************************
     *********************FISHING METHODS*******************
     **********************************************************/

    private NPC fishSpot() {
        return npc().query().id(1510).reachable().results().nearest();
    }

    private void fish() {
        setStatus("Fishing");
        fishSpotNPC.interact("Harpoon");
        mouse().moveOffScreen();
    }

    private boolean hasTuna() {
        return myInventory().contains("Raw tuna");
    }

    private void dropTuna() {
        myInventory().dropAll("Raw tuna");
    }

    private boolean isInvFull() {
        return myInventory().isFull();
    }

    private int fishCaught() {
        return myInventory().getCount("Raw swordfish");
    }

    private boolean onlySwordFish() {
        return myInventory().onlyContains("Raw swordfish", "Dragon harpoon");
    }

    /**********************************************************
     *********************STATUS METHODS*******************
     **********************************************************/

    public void setStatus(String status) {
        this.status = status;
    }

    @Override
    protected void onPaint(Graphics2D g, APIContext ctx) {
        PaintFrame frame = new PaintFrame();
        frame.setTitle("Swordfish farmer");
        frame.addLine("Status: ", status);
        frame.addLine("Time Running: ", Time.getFormattedRuntime(startTime));
        frame.addLine("Current Fishing level: ", fishingLevel);
        frame.addLine("XP till next Level: ", xpTNL);
        frame.addLine("Swordfish banked: ", counter);
        frame.draw(g, 0, 170, ctx);
    }

    /**********************************************************
     *********************Bot METHODS*******************
     **********************************************************/

    private void levelUp() {
        WidgetGroup LevelUpInterface = getAPIContext().widgets().get(233);
        Time.sleep(500, 1000);
        if (LevelUpInterface.isVisible()) {
            getAPIContext().keyboard().sendKey(32);
        }
    }

    @Override
    public boolean onStart(String... strings) {
        startTime = System.currentTimeMillis();
        System.out.println("Starting Pro Fisher!");
        return true;

    }

    @Override
    protected int loop() {

        // Get and display current fishing level/EXP till next level/get widget for level up chat notification
        fishingLevel = skills().fishing().getCurrentLevel();
        xpTNL = skills().fishing().getTotalExperienceToNextLevel();
        WidgetGroup LevelUpInterface = getAPIContext().widgets().get(233);

        // Check if leveled up message appeared, clear it and continue fishing
        if (LevelUpInterface.isVisible()) {
            levelUp();
        }

        // Check if inventory is not full, find fishing spot, fish
        if (!isInvFull()) {

            // Find fishing spot for swordfish
            if (player().getInteracting() == null) {
                fishSpotNPC = fishSpot();
                System.out.println("Nearest fishing spot found...");

                // Walk to found spot and start fishing
                if (fishSpotNPC != null) {
                    System.out.println("Moving to fishing spot...");
                    walk().walkTo(fishSpotNPC);
                    fish();
                }
            }
        }

        // Check if inventory is full
        if (isInvFull()) {

            // Check if inventory contains raw tuna
            if (hasTuna()) {

                // Drop all raw tuna from inventory
                dropTuna();
            }

            // Check if we only have a full inventory of raw swordfish
            if (isInvFull() && onlySwordFish()) {

                // Walk to bank/open
                walkToBank();
                openBank();

                // When bank is open deposit all but Dragon harpoon, add to fish counter
                if (myBank().open()) {
                    counter = counter + fishCaught();
                    depositItems();
                    closeBank();

                    // To prevent null being return on fishing spots from inside of the bank, walk to edge of the bank for spots to be found
                    walk().walkTo(fishGuild);
                }
            }
        }
        return 400;
    }
}
Link to comment
Share on other sites

15 minutes ago, High Im Joe1 said:

Hello, is there a way you can help me.. I dont know how to get the script into EpicBot.. 

Hey I directly messaged you on this 👍

As I mentioned in the DM, its very direct, does not look for any equipment right now. Dragon Harpoon is the item included in this and should sit in the inventory prior to running the script.

Link to comment
Share on other sites

  • 4 weeks later...
  • 5 months later...

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

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.

×
×
  • Create New...