Jump to content

Getting / Setting Bank Quantity (27th Sep Update)


Recommended Posts

Posted (edited)
import org.osbot.rs07.api.ui.RS2Widget;
import org.osbot.rs07.api.util.CachedWidget;
import org.osbot.rs07.script.MethodProvider;
import org.osbot.rs07.utility.ConditionalSleep;

public class BankQuantity extends MethodProvider {

    private static final int CONFIG_ID = 1666;
    private static final int BANK_WIDGET_ROOT_ID = 12;

    private CachedWidget quantityLabelWidget;

    /*
    1666: 0 -> ONE
    1666: 4 -> FIVE
    1666: 8 -> TEN
    1666: 12 -> X
    1666: 16 -> ALL
     */
    public Quantity getQuantity() {
        return Quantity.values()[getConfigs().get(CONFIG_ID) / 4];
    }

    public boolean setQuantity(final Quantity quantity) {
        if (quantity == getQuantity()) {
            return true;
        }

        if (!getWidgets().isVisible(BANK_WIDGET_ROOT_ID)) {
            return false;
        }

        if (quantityLabelWidget == null || !quantityLabelWidget.initialized()) {
            quantityLabelWidget = new CachedWidget(this, w -> w != null && w.getMessage().equals("Quantity:"), BANK_WIDGET_ROOT_ID);
            quantityLabelWidget.cache();
        }

        if (quantityLabelWidget.initialized()) {
            int rootID = quantityLabelWidget.getRootId();
            int secondLevelID = quantityLabelWidget.getSecondLevelId();

            if (quantity == Quantity.ONE) {
                secondLevelID += 1;
            } else {
                secondLevelID += (quantity.ordinal() + 1) * 2;
            }

            RS2Widget quantityWidget = getWidgets().get(rootID, secondLevelID);

            if (quantityWidget != null && quantityWidget.interact()) {
                new ConditionalSleep(1800, 600) {
                    @Override
                    public boolean condition() throws InterruptedException {
                        return getQuantity() == quantity;
                    }
                }.sleep();
                return true;
            }
        }

        return false;
    }

    enum Quantity {
        ONE,
        FIVE,
        TEN,
        X,
        ALL
    }
}

 

Usage:

import org.osbot.rs07.script.Script;
import org.osbot.rs07.script.ScriptManifest;

@ScriptManifest(author = "Explv", name = "Example", version = 0.1, logo = "", info = "")
public class Example extends Script {

    private BankQuantity bankQuantity = new BankQuantity();

    @Override
    public void onStart() {
        bankQuantity.exchangeContext(getBot());
    }

    @Override
    public int onLoop() throws InterruptedException {
        if (!getBank().isOpen()) {
            getBank().open();
        } else if (bankQuantity.getQuantity() != BankQuantity.Quantity.ALL) {
            bankQuantity.setQuantity(BankQuantity.Quantity.ALL);
        } else {
            getBank().withdrawAll("Yew logs");
        }
        return 600;
    }
}



@Alek add to API?

Edited by Explv
  • Like 7
  • Boge 1

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...