Jump to content

Progressive Mining (from copper->iron ore)


Recommended Posts

Start the script in varrock south east mine.

it will mine the copper / iron ore automatically and drop the ores on the ground when inventory is full.

does not drop gems/geodes.

demo:

image.png.e5faee82662a856f8a8c63dd3ecb9660.png

glhf 🙂

 

import com.epicbot.api.shared.APIContext;
import com.epicbot.api.shared.GameType;
import com.epicbot.api.shared.entity.details.Locatable;
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 com.epicbot.api.shared.webwalking.model.WebPath;

import java.awt.Graphics2D;

@ScriptManifest(name = "VarrockEastMine", gameType = GameType.OS)
public class VarrockEastMine extends LoopScript {
    // constants
    private final int DELAY_BETWEEN_ORE_CLICKS = 900;
    private final Tile TILE_MINE_AREA = new Tile(3287,3364); // varrock east mine
    private final int[] COPPER_ROCKS = {11161,10943};
    private final int[] IRON_ROCKS = {11364,11365};
    // global variables
    private String status = "Starting";
    private int[] currentRocks = {};
    boolean settedOres = false;
    String currentOre = "Copper";
    private int invtSpace = 28;
    @Override
    public boolean onStart(String... strings) {
        Time.sleep(20000);
        return true;//getAPIContext().client().isLoggedIn() ;
    }
    @Override
    protected int loop() {
        setOres();
        if ( isInvtFull()) {
            dropOres();
        }else{
            doMine();
        }
        return 1337; // delay for 1.337 seconds
    }
    // tasks
    private void doMine(){
        status = "Mining "+currentOre;
        while (!isInvtFull() && isRunning() && !isPaused() && !isStopping()){
            if ( !getAPIContext().localPlayer().isAnimating() && !getAPIContext().localPlayer().isMoving() ) {
                getAPIContext().objects().query().id(currentRocks).results().nearest().interact("Mine");
                Time.sleep(1800);
                //System.out.println("Mining. Free invt="+(28-getAPIContext().inventory().getCount()));
            }
            Time.sleep(DELAY_BETWEEN_ORE_CLICKS);
        }
        //if (isInvtFull()) {
        //    System.out.println("Full invt");
        //}
    };
    private void dropOres(){
        status = "Dropping ores";
        getAPIContext().inventory().dropAll(436,440); // copper and iron ores
    }
    private void setOres(){
        if (settedOres) return;

        if (getAPIContext().skills().mining().getCurrentLevel()>14){
            currentRocks = IRON_ROCKS;
            settedOres = true;
            currentOre ="Iron";
        }else{
            currentRocks = COPPER_ROCKS;
        }
    }
    // checks
    private boolean isInvtFull(){
        invtSpace = 28-getAPIContext().inventory().getCount();
        return invtSpace ==0;
    };
    //todo worldHopIfCrowded
    //todo dismissRandomEvent
    @Override
    protected void onPaint(Graphics2D g, APIContext ctx) {
        PaintFrame frame = new PaintFrame("VarrockE mine");
        frame.addLine("Status", status);
        frame.addLine("Free space", invtSpace);
        frame.draw(g, 0, 170, ctx);
    }
}

 

Link to comment
Share on other sites

now with added banking ability & ore per hr tracking!
image.png.c58429f522b0904bb30d4c10c5fac201.png

import com.epicbot.api.shared.APIContext;
import com.epicbot.api.shared.GameType;
import com.epicbot.api.shared.entity.details.Locatable;
import com.epicbot.api.shared.model.Area;
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.util.time.Timer;
import com.epicbot.api.shared.webwalking.model.RSBank;
import com.epicbot.api.shared.webwalking.model.WalkState;
import com.epicbot.api.shared.webwalking.model.WebPath;

import java.awt.Graphics2D;

@ScriptManifest(name = "VarrockEastMine", gameType = GameType.OS)
public class VarrockEastMine extends LoopScript {
    // constants
    private final int[] f2pworlds = {380,382,383,394,397,398,399,417,418,430,433,434,435,436,437,451,452,453,454,455,456,470,
            471,472,473,475,476,483,498,499,500,501,536,537,542,543,544,545,546,547,552,553,554,555,556,557,562,563,564,565,
            566,567,571,573,574,575,576
    };
    private final int DELAY_BETWEEN_ORE_CLICKS = 900;
    //private final Tile TILE_MINE_AREA = new Tile(3287,3364); // varrock east mine
    private final Area AREA_MINE = new Area(new Tile(3280,3360),new Tile(3290,3370));
    private final int[] COPPER_ROCKS = {11161,10943};
    private final int[] IRON_ROCKS = {11364,11365};
    private final Timer runTimer = new Timer(0);
    // global variables
    private String status = "Starting";
    private int[] currentRocks = {};
    boolean settedOres = false;
    String currentOre = "Copper";
    private int invtSpace = 28;
    private int prevInvtSpace = 28;
    private int minedOres = 0;
    @Override
    public boolean onStart(String... strings) {
        if (!getAPIContext().client().isLoggedIn()){
            Time.sleep(15000);
        }
        Time.sleep(5000);
        return true;// ;
    }
    @Override
    protected int loop() {
        setOres();
        setInvtSpace();
        if ( isInvtFull()){
            System.out.println("bag is full");
            goBanknDesposit();
        } else if (isNearMine()){
            System.out.println("start mining");
            doMine();
        } else {
            System.out.println("head to mine");
            goNearMine();

        }
        return 1337; // delay for 1.337 seconds
    }
    // tasks
    private void doMine(){
        status = "Mining "+currentOre;
        while (!isInvtFull() && isRunning() && !isPaused() && !isStopping()){
            if ( !getAPIContext().localPlayer().isAnimating() && !getAPIContext().localPlayer().isMoving() ) {
                getAPIContext().objects().query().id(currentRocks).results().nearest().interact("Mine");
                Time.sleep(1800);
            }
            Time.sleep(DELAY_BETWEEN_ORE_CLICKS);
        }
    };
    private void dropOres(){
        status = "Dropping ores";
        getAPIContext().inventory().dropAll(436,440); // copper and iron ores
    }
    private void goBanknDesposit(){
        status = "Going to bank";
        if ( !getAPIContext().localPlayer().isAnimating() && !getAPIContext().localPlayer().isMoving() ) {
            getAPIContext().webWalking().walkToBank(RSBank.VARROCK_EAST);
        }
        // deposit ores n gems
        status = "Despositing";
        if ( !getAPIContext().localPlayer().isAnimating() && !getAPIContext().localPlayer().isMoving() ) {
            if (getAPIContext().bank().isReachable()) {
                getAPIContext().bank().open();
                Time.sleep(2000);
                getAPIContext().bank().depositAllExcept("Bronze Pickaxe", "Iron Pickaxe", "Steel Pickaxe", "Black Pickaxe", "Mithril Pickaxe", "Adamant Pickaxe", "Rune Pickaxe");
                Time.sleep(2000);
            }
        }
        // close bank
        if (getAPIContext().bank().isOpen()){
            getAPIContext().bank().close();
        }
        setInvtSpace();
    };
    private void goNearMine(){
        System.out.println("starting go near mine");
        status = "Going to mine";
        if ( getAPIContext().localPlayer().isAnimating() || getAPIContext().localPlayer().isMoving() ) {
            System.out.println("exiting goNearMine with failure, sleep for 14secs");
            Time.sleep(14000);
            return;
        }
        WebPath path = getAPIContext().webWalking().getPath(AREA_MINE.getCentralTile());
        System.out.println("path status "+path.getPathStatus().toString());
        WalkState ws = getAPIContext().webWalking().walkPath(path);
        System.out.println("walk state "+ws.toString());
        if(ws == WalkState.SUCCESS){
            System.out.println("exiting goNearMine with success");
        }else {
            System.out.println("exiting goNearMine with failure, sleep for 15secs");
            Time.sleep(15000);
        }
        //Time.sleep(5000, () -> AREA_MINE.contains(getAPIContext().localPlayer().getLocation()));
    };
    private void setOres(){
        if (settedOres) return;
        if (getAPIContext().skills().mining().getCurrentLevel()>14){
            currentRocks = IRON_ROCKS;
            settedOres = true;
            currentOre ="Iron";
        }else{
            currentRocks = COPPER_ROCKS;
        }
    }
    private void setInvtSpace(){
        prevInvtSpace = getAPIContext().inventory().getEmptySlotCount();
        invtSpace = prevInvtSpace;
    }
    // checks
    private boolean isNearMine(){
        Locatable playerLocation = getAPIContext().localPlayer().get().getLocation();
        boolean nearmine = AREA_MINE.contains( playerLocation );
        System.out.println("near mine boolean"+nearmine);
        return nearmine;
    };
    private boolean isInvtFull(){
        invtSpace = 28-getAPIContext().inventory().getCount();
        if (invtSpace!=prevInvtSpace){
            minedOres++;
            prevInvtSpace=invtSpace;
        }
        return invtSpace ==0;
    };
    //todo worldHopIfCrowded
    //todo dismissRandomEvent
    @Override
    protected void onPaint(Graphics2D g, APIContext ctx) {
        PaintFrame frame = new PaintFrame("VarrockE mine");
        frame.addLine("Time",runTimer.toElapsedString());
        frame.addLine("Mined ores",minedOres);
        frame.addLine("Ores/h",getHourlyRate(minedOres));
        frame.addLine("Status", status);
        frame.addLine("Free space", invtSpace);
        frame.draw(g, 0, 170, ctx);
    }
    private int getHourlyRate(int i) {
        return (int) (i / (runTimer.getElapsed() / 3600000.0D));
    }
}

 

Link to comment
Share on other sites

  • 2 weeks 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.

 Share

×
×
  • Create New...