Jump to content

Master / Slave Runecrafting Script [WIP]


Lol_marcus

Recommended Posts

Hi :)

I made this to train RCing in F2P; in short, you have 1 account that's the "master" account that sits at the air altar and waits for trades to come in, and the "slave" accounts run back and forth between the altar and the bank and trade pure essence to the master account. You choose this when you start the script (master or slave).

It prompts you to put a username in, so it'll know to always trade the master account. I don't have it set up to trade accounts with a space in the name (it's fairly simple to do, I just never have usernames with spaces xD) so you'll have to change that yourself if you want to.

Other than that, just start with the air tiara equipped and the script'll do the rest for you. :)

It's a work in progress, but works fine at the moment!

 

Spoiler
package Osbot;

import org.osbot.rs07.api.map.Area;
import org.osbot.rs07.api.map.constants.Banks;
import org.osbot.rs07.api.model.RS2Object;
import org.osbot.rs07.api.model.Player;
import org.osbot.rs07.api.ui.Message;
import org.osbot.rs07.api.ui.Message.MessageType;
import org.osbot.rs07.api.ui.Skill;
import org.osbot.rs07.script.Script;
import org.osbot.rs07.script.ScriptManifest;
import org.osbot.rs07.utility.ConditionalSleep;


import javax.swing.*;
import java.awt.*;

@ScriptManifest(info = "Master & Slave air runecrafter", logo = "", name = "M/S Runecrafter", author = "Marcus", version = 1.3)
public class testScript extends Script {

    private final Area altarArea = new Area(2841, 4828, 2851, 4838);
    private final Area mysteriousRuinsArea = new Area(2982, 3291, 2988, 3295);
    private final String AIR_TIARA = "Air tiara";
    private final String PURE_ESSENCE = "Pure essence";
    private final String BANK_BOOTH = "Bank booth";
    private final String ALTAR = "Altar";
    private boolean tradeRequested = false;
    private String mode = "";
    private String tradeUsername;
    private long startTime;
    private int startXP;
    private int currentXP;
    private int xpGained;
    private int xpPerHour;
    private String currentTaskDescription = "";

    @Override
    public void onStart() {
        startTime = System.currentTimeMillis();
        startXP = getSkills().getExperience(Skill.RUNECRAFTING);

        SwingUtilities.invokeLater(() -> {
            JFrame frame = new JFrame("Select Mode");
            JPanel panel = new JPanel();
            JButton masterButton = new JButton("Master");
            JButton slaveButton = new JButton("Slave");

            masterButton.addActionListener(e -> {
                mode = "Master";
                frame.dispose();
            });

            slaveButton.addActionListener(e -> {
                mode = "Slave";
                tradeUsername = JOptionPane.showInputDialog("Enter the username to trade with:");
                if (tradeUsername == null || tradeUsername.isEmpty()) {
                    log("No username entered, stopping script.");
                    stop();
                } else {
                    frame.dispose();
                }
            });

            panel.add(masterButton);
            panel.add(slaveButton);
            frame.add(panel);
            frame.pack();
            frame.setVisible(true);
        });

        new ConditionalSleep(30000) {
            @Override
            public boolean condition() {
                return !mode.isEmpty();
            }
        }.sleep();
    }

    @Override
    public int onLoop() throws InterruptedException {
    	currentTaskDescription ="Starting script in " + mode + " mode";
        handleLevelUp();

        if (mode.equals("Master")) {
            if (hasPureEssence()) {
                currentTaskDescription = "Crafting runes";
                craftRunes();
            } else if (tradeRequested) {
                currentTaskDescription = "Handling trade";
                handleTrade();
            } else {
                currentTaskDescription = "Waiting for trade request";
                checkForTradeRequest();
            }
        } else if (mode.equals("Slave")) {
            toggleRunEnergy();

            if (hasPureEssence()) {
                if (!altarArea.contains(myPosition())) {
                    enterRuins();
                } else {
                    tradePureEssence();
                }
            } else {
                withdrawEssence();
            }
        }
        return 700;
    }

    private boolean hasPureEssence() {
        boolean hasEssence = getInventory().contains(PURE_ESSENCE);
        currentTaskDescription = "Checking for pure essence: " + hasEssence;
        return hasEssence;
    }

    private void checkForTradeRequest() {
        Player tradePlayer = getTrade().getLastRequestingPlayer();
        if (tradePlayer != null) {
            currentTaskDescription = "Trade request from: " + tradePlayer.getName();
            if (tradePlayer.interact("Trade with")) {
                tradeRequested = true;
                new ConditionalSleep(5000) {
                    @Override
                    public boolean condition() {
                        return getTrade().isCurrentlyTrading();
                    }
                }.sleep();
            }
        }
    }

    private void handleTrade() throws InterruptedException {
        if (!getTrade().isCurrentlyTrading()) {
            currentTaskDescription = "Not currently trading. Resetting trade request flag.";
            tradeRequested = false;
            return;
        }

        currentTaskDescription = "Waiting for first trade interface to open.";
        new ConditionalSleep(10000) {
            @Override
            public boolean condition() {
                return getTrade().isFirstInterfaceOpen();
            }
        }.sleep();

        if (getTrade().isFirstInterfaceOpen()) {
            currentTaskDescription = "First trade interface open. Waiting for 27 pure essence.";
            new ConditionalSleep(30000) {
                @Override
                public boolean condition() {
                    return getTrade().getTheirOffers().contains(PURE_ESSENCE) && getTrade().getTheirOffers().getAmount(PURE_ESSENCE) == 27;
                }
            }.sleep();
            if (getTrade().getTheirOffers().contains(PURE_ESSENCE) && getTrade().getTheirOffers().getAmount(PURE_ESSENCE) == 27) {
                currentTaskDescription = "27 pure essence detected. Accepting trade.";
                getTrade().acceptTrade();

                new ConditionalSleep(5000) {
                    @Override
                    public boolean condition() {
                        return getTrade().isSecondInterfaceOpen();
                    }
                }.sleep();

                if (getTrade().isSecondInterfaceOpen()) {
                    currentTaskDescription = "Second trade interface open. Accepting trade.";
                    getTrade().acceptTrade();
                    new ConditionalSleep(5000) {
                        @Override
                        public boolean condition() {
                            return !getTrade().isCurrentlyTrading();
                        }
                    }.sleep();
                }
            }
        }
    }

    private void craftRunes() throws InterruptedException {
        if (!altarArea.contains(myPosition())) {
            currentTaskDescription = "Walking to altar area.";
            getWalking().webWalk(altarArea);
        } else {
            currentTaskDescription = "In altar area. Looking for the altar.";
            RS2Object altar = getObjects().closest(ALTAR);
            if (altar != null && altar.interact("Craft-rune")) {
                currentTaskDescription = "Crafting runes at the altar.";
                new ConditionalSleep(5000) {
                    @Override
                    public boolean condition() {
                        return !getInventory().contains(PURE_ESSENCE) && !myPlayer().isAnimating();
                    }
                }.sleep();
                currentTaskDescription = "Runes crafted.";
            }
        }
    }

    private void toggleRunEnergy() {
        if (!getSettings().isRunning() && getSettings().getRunEnergy() > 30) {
            currentTaskDescription = "Toggling run energy.";
            getSettings().setRunning(true);
        }
    }

    private void withdrawEssence() throws InterruptedException {
        if (!Banks.FALADOR_EAST.contains(myPosition())) {
            currentTaskDescription = "Walking to the bank area.";
            getWalking().webWalk(Banks.FALADOR_EAST);
        } else {
            RS2Object bankBooth = getObjects().closest(BANK_BOOTH);
            if (bankBooth != null && bankBooth.interact("Bank")) {
                currentTaskDescription = "Interacting with the bank booth.";
                new ConditionalSleep(5000) {
                    @Override
                    public boolean condition() {
                        return getBank().isOpen();
                    }
                }.sleep();

                if (getBank().isOpen()) {
                    currentTaskDescription = "Withdrawing 27 pure essence.";
                    getBank().depositAll();
                    new ConditionalSleep(3000) {
                        @Override
                        public boolean condition() {
                            return getInventory().isEmpty();
                        }
                    }.sleep();
                    getBank().withdraw(PURE_ESSENCE, 27);
                    new ConditionalSleep(3000) {
                        @Override
                        public boolean condition() {
                            return getInventory().contains(PURE_ESSENCE) && getInventory().getAmount(PURE_ESSENCE) == 27;
                        }
                    }.sleep();
                    getBank().close();
                }
            }
        }
    }

    private void enterRuins() throws InterruptedException {
        if (!mysteriousRuinsArea.contains(myPosition())) {
            currentTaskDescription = "Walking to mysterious ruins area.";
            getWalking().webWalk(mysteriousRuinsArea);
        } else {
            RS2Object mysteriousRuins = getObjects().closest("Mysterious ruins");
            if (mysteriousRuins != null && mysteriousRuins.interact("Enter")) {
                currentTaskDescription = "Entering mysterious ruins.";
                new ConditionalSleep(5000) {
                    @Override
                    public boolean condition() {
                        return altarArea.contains(myPosition());
                    }
                }.sleep();
            }
        }
    }

    private void tradePureEssence() throws InterruptedException {
        Player tradePlayer = getPlayers().closest(tradeUsername);
        if (tradePlayer != null && tradePlayer.isVisible()) {
            if (tradePlayer.interact("Trade with")) {
                currentTaskDescription = "Trading with " + tradeUsername;
                new ConditionalSleep(10000) {
                    @Override
                    public boolean condition() {
                        return getTrade().isFirstInterfaceOpen();
                    }
                }.sleep();

                if (getTrade().isFirstInterfaceOpen()) {
                    getTrade().offer(PURE_ESSENCE, 27);
                    new ConditionalSleep(5000) {
                        @Override
                        public boolean condition() {
                            return getTrade().getOurOffers().contains(PURE_ESSENCE);
                        }
                    }.sleep();
                    getTrade().acceptTrade();

                    new ConditionalSleep(5000) {
                        @Override
                        public boolean condition() {
                            return getTrade().isSecondInterfaceOpen();
                        }
                    }.sleep();

                    if (getTrade().isSecondInterfaceOpen()) {
                        getTrade().acceptTrade();
                        new ConditionalSleep(5000) {
                            @Override
                            public boolean condition() {
                                return !getTrade().isCurrentlyTrading();
                            }
                        }.sleep();
                    }
                }
            }
        } else {
            currentTaskDescription = "Walking to altar area.";
            getWalking().webWalk(altarArea);
        }
    }

    private void handleLevelUp() throws InterruptedException {
        if (getWidgets().getWidgetContainingText("Click here to continue") != null) {
            currentTaskDescription = "Level up message detected. Clicking to continue.";
            while (getWidgets().getWidgetContainingText("Click here to continue") != null) {
                getWidgets().getWidgetContainingText("Click here to continue").interact("Continue");
                sleep(1000);
            }
            currentTaskDescription = "Level up message cleared.";
        }
    }

    @Override
    public void onMessage(Message message) throws InterruptedException {
        if (message.getType() == MessageType.GAME) {
            if (message.getMessage().contains("You craft the runes.")) {
                currentTaskDescription = "Runes crafted.";
            } else if (message.getMessage().contains("Congratulations, you just advanced")) {
                currentTaskDescription = "Level up detected.";
                handleLevelUp();
            } else if (message.getMessage().contains("wishes to trade with you")) {
                currentTaskDescription = "Trade request detected.";
                tradeRequested = true;
            } else if (message.getMessage().contains("Accepted trade")) {
                currentTaskDescription = "Trade completed.";
            }
        }
    }

    @Override
    public void onPaint(Graphics2D g) {
        long runTime = System.currentTimeMillis() - startTime;
        currentXP = getSkills().getExperience(Skill.RUNECRAFTING);
        xpGained = currentXP - startXP;
        xpPerHour = (int) ((xpGained) * 3600000D / runTime);


        g.setColor(Color.WHITE);
        g.drawString("Mode: " + mode, 10, 40);
        g.drawString("Time running: " + formatTime(runTime), 10, 60);
        g.drawString("XP Gained: " + xpGained, 10, 80);
        g.drawString("XP per hour: " + xpPerHour, 10, 100);
        g.drawString("Current Action: " + currentTaskDescription, 10, 120);
    }

    private String formatTime(long time) {
        long s = (time / 1000) % 60;
        long m = (time / (1000 * 60)) % 60;
        long h = (time / (1000 * 60 * 60)) % 24;
        return String.format("%02d:%02d:%02d", h, m, s);
    }
}

 

 

  • Like 4
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...