Jump to content

Getting / Setting Bank Quantity (27th Sep Update)


Explv

Recommended Posts

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