Jump to content

SimpleFisherman - Effortless 1-99 fishing [Open Source]


Recommended Posts

Posted (edited)

Who is The SimpleFisherman? Some say he's part man, part fish. Some say he's an actual real-life fisherman. All we really know is the man loves to fish.

What the script does: 

  • Fishes Shrimp/Anchovies at Draynor Village until level 20 fishing, then fishes trout/salmon forever
  • Fetches appropriate equipment from the bank if needed
  • Walks to the appropriate fishing area depending on level
  • Fish is dropped to optimise XP/Hour

Future update plans: 

  • Buy feathers from GE when you run out
  • Start going to fishing trawler at level 15 to get full angler (will take some time to implement!) 

Please note: This has not been tested on a low combat account - the dark wizard/jail guard near draynor WILL attack you if you have a low combat level so please use with caution! 

This is the first script that I will upload the source code for, any and all feedback will be greatly appreciated :) I have only started scripting recently so there may be some errors here and there.

Untitled.png

Download link: http://www.mediafire.com/file/0s3rq3q67e4363q/SimpleFisherman.jar

Source code: 

import org.osbot.rs07.api.Skills;
import org.osbot.rs07.api.map.Area;
import org.osbot.rs07.api.map.constants.Banks;
import org.osbot.rs07.api.model.NPC;
import org.osbot.rs07.api.ui.Skill;
import org.osbot.rs07.api.util.ExperienceTracker;
import org.osbot.rs07.script.Script;
import org.osbot.rs07.script.ScriptManifest;

import java.awt.*;
import java.util.concurrent.TimeUnit;

@ScriptManifest(author = "Tommm39", name = "SimpleFisherman", info = "", version = 1.0, logo = "")


public class Main extends Script {

    private Skills s;
    private ExperienceTracker track;

    private String status = "";

    private long timeBegan;
    private long timeRan;

    private final Area shrimpArea = new Area(3092, 3234, 3081, 3226);
    private final Area flyFishingArea = new Area(3102, 3422, 3109, 3434);
    private final Area lumbridgeBankArea = new Area(3208, 3218, 3209, 3219);

    public void onStart() {

        this.track = getExperienceTracker();
        track.start(Skill.FISHING);
        this.s = getSkills();
        this.timeBegan = System.currentTimeMillis();
    }

    public void onExit() {
    }

    public int onLoop() throws InterruptedException {

        if (getInventory().isFull()) {
            drop();
        }
        else if (!getInventory().contains("Small fishing net") && !getInventory().contains("Fly fishing rod")) {
            getFishingEquipment();
        }
        else if ((s.getDynamic(Skill.FISHING) < 20) && (getInventory().contains("Small fishing net"))) {
            fishShrimp();
        }
        else if ((s.getDynamic(Skill.FISHING) >= 20) && (getInventory().contains("Fly fishing rod"))) {
            flyFish();
        }
        else if ((s.getDynamic(Skill.FISHING) < 20) && (!getInventory().contains("Small fishing net"))) {
            getFishingEquipment();
        }
        else if ((s.getDynamic(Skill.FISHING) >= 20) && (!getInventory().contains("Fly fishing rod"))) {
            getFishingEquipment();
        }
        return random(500, 550);
    }

    public void getFishingEquipment() throws InterruptedException {

        status = "Getting equipment";
        Boolean lowLevelEquipment = false;

        if (s.getDynamic(Skill.FISHING) < 20) {
            lowLevelEquipment = true;
        }

        if (getWalking().webWalk(Banks.LUMBRIDGE_UPPER)) {
            Timing.waitCondition(() -> lumbridgeBankArea.contains(myPosition()), 5000);
            sleep(random(100, 500));
        }

        if (getBank().open()) {
            if (getBank().depositAll()) {
                Timing.waitCondition(() -> getInventory().isEmpty(), 5000);
            }
            if (lowLevelEquipment == false) {
                if (getBank().withdraw("Fly fishing rod", 1)) ;
                Timing.waitCondition(() -> getInventory().contains("Fly fishing rod"), 5000);
                sleep(random(100, 500));
            } else {
                if (getBank().withdraw("Small fishing net", 1)) ;
                Timing.waitCondition(() -> getInventory().contains("Fly fishing rod"), 5000);
                sleep(random(100, 500));
            }

        }

        if (lowLevelEquipment == false) {
            if (getBank().withdrawAll("Feather")) {
                Timing.waitCondition(() -> getInventory().contains("Feather"), 5000);
                sleep(random(100, 500));
            }
        }

        if (getBank().close()) {
            Timing.waitCondition(() -> !getBank().isOpen(), 5000);
            sleep(random(100, 500));
        }


    }

    public void drop() throws InterruptedException {

        status = "Dropping inventory";
        if (getInventory().dropAllExcept("Small fishing net", "Fly fishing rod", "Feather")) {
            Timing.waitCondition(() -> getInventory().onlyContains("Small fishing net", "Fly fishing rod", "Feather"), 5000);
            sleep(random(100, 500));
        }
    }

    public void fishShrimp() throws InterruptedException {

        if (!shrimpArea.contains(myPosition())) {
            status = "Walking to shrimp area";
            getWalking().webWalk(shrimpArea);
            Timing.waitCondition(() -> shrimpArea.contains(myPosition()), 5000);
            sleep(random(100, 500));
        } else {
            NPC shrimpSpot = getNpcs().closest(1518);
            status = "Fishing shrimp";
            if (myPlayer().getAnimation() == -1) {
                if (shrimpSpot != null) {
                    if (shrimpSpot.interact()) {
                        Timing.waitCondition(() -> shrimpSpot == null || getDialogues().isPendingContinuation(), 5000);
                        sleep(random(100, 500));
                    }
                }
            }
        }
    }

    public void flyFish() throws InterruptedException {

        if (!flyFishingArea.contains(myPosition())) {
            status = "Walking to fly-fishing area";
            getWalking().webWalk(flyFishingArea);
            Timing.waitCondition(() -> flyFishingArea.contains(myPosition()), 5000);
            sleep(random(100, 500));
        } else {
            NPC flySpot = getNpcs().closest(1526);
            status = "Fishing trout/salmon";
            if (myPlayer().getAnimation() == -1) {
                if (flySpot != null) {
                    if (flySpot.interact("Lure")) {
                        Timing.waitCondition(() -> flySpot == null || getDialogues().isPendingContinuation(), 5000);
                        sleep(random(100, 500));
                    }
                }
            }
        }
    }

    public void onPaint(Graphics2D g) {

        Graphics2D gr = g;
        int fishingExperience = track.getGainedXPPerHour(Skill.FISHING);
        int levelsGained = track.getGainedLevels(Skill.FISHING);
        long timeToLevel = track.getTimeToLevel(Skill.FISHING);
        timeRan = System.currentTimeMillis() - this.timeBegan;

        g.setBackground(Color.WHITE);
        g.drawString("Thanks for using SimpleFisherman by Tommm39", 10, 230);
        g.drawString("Time Running: " + formatTime(timeRan), 10, 250);
        g.drawString("Fishing XP/HR: " + fishingExperience, 10, 270);
        g.drawString("Time to Level: " + formatTime(timeToLevel), 10, 290);
        g.drawString("Levels Gained: " + levelsGained, 10, 310);
        g.drawString("Status: " + status, 10, 330);
    }

    private String formatTime(long duration) {

        String formattedTime = "";
        long days = TimeUnit.MILLISECONDS.toDays(duration);
        long hours = TimeUnit.MILLISECONDS.toHours(duration) - TimeUnit.DAYS.toHours(TimeUnit.MILLISECONDS.toDays(duration));
        long minutes = TimeUnit.MILLISECONDS.toMinutes(duration) - TimeUnit.HOURS.toMinutes(TimeUnit.MILLISECONDS.toHours(duration));
        long seconds = TimeUnit.MILLISECONDS.toSeconds(duration) - TimeUnit.MINUTES.toSeconds(TimeUnit.MILLISECONDS.toMinutes(duration));
        if (days == 0) {
            formattedTime = (hours + ":" + minutes + ":" + seconds);
        } else {
            formattedTime = (days + ":" + hours + ":" + minutes + ":" + seconds);
        }
        return formattedTime;
    }
}

 

Edited by Tommm39
  • Like 1
Posted (edited)

Nice job, although only thing I'd point out for in future.

private String formatTime(long duration) {

        String formattedTime = "";
        long days = TimeUnit.MILLISECONDS.toDays(duration);
        long hours = TimeUnit.MILLISECONDS.toHours(duration) - TimeUnit.DAYS.toHours(TimeUnit.MILLISECONDS.toDays(duration));
        long minutes = TimeUnit.MILLISECONDS.toMinutes(duration) - TimeUnit.HOURS.toMinutes(TimeUnit.MILLISECONDS.toHours(duration));
        long seconds = TimeUnit.MILLISECONDS.toSeconds(duration) - TimeUnit.MINUTES.toSeconds(TimeUnit.MILLISECONDS.toMinutes(duration));
        if (days == 0) {
            formattedTime = (hours + ":" + minutes + ":" + seconds);
        } else {
            formattedTime = (days + ":" + hours + ":" + minutes + ":" + seconds);
        }
        return formattedTime;
    }

Could be:

    private String formatTime(long duration) {

        String formattedTime = "";
        long days = TimeUnit.MILLISECONDS.toDays(duration);
        long hours = TimeUnit.MILLISECONDS.toHours(duration) - TimeUnit.DAYS.toHours(TimeUnit.MILLISECONDS.toDays(duration));
        long minutes = TimeUnit.MILLISECONDS.toMinutes(duration) - TimeUnit.HOURS.toMinutes(TimeUnit.MILLISECONDS.toHours(duration));
        long seconds = TimeUnit.MILLISECONDS.toSeconds(duration) - TimeUnit.MINUTES.toSeconds(TimeUnit.MILLISECONDS.toMinutes(duration));

        formattedTime = days > 0 ? (days + ":" + hours + ":" + minutes + ":" + seconds) : (hours + ":" + minutes + ":" + seconds);

        return formattedTime;
    }

Using ternary operators, 

How it works basically is formattedTime = condition ? true : false;

Well done on the script though looks alright!

Edited by 01053

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

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