Untitled

mail@pastecode.io avatar
unknown
plain_text
a year ago
3.6 kB
0
Indexable
Never
import org.osbot.rs07.api.model.Item;
import org.osbot.rs07.api.ui.EquipmentSlot;
import org.osbot.rs07.script.Script;
import org.osbot.rs07.utility.ConditionalSleep;

public class MyScript extends Script {

    private int currentStage = 0;

    @Override
    public void onStart() {
        currentStage = 0;
    }

    @Override
    public int onLoop() throws InterruptedException {
        switch (currentStage) {
            case 0:
                // Stage 1: Check inventory
                if (getInventory().contains(27, 14456)) {
                    castLunarSpell();
                } else if (getInventory().contains(25, 14458) || isInventoryEmptyExceptID(14361)) {
                    currentStage++;
                }
                break;
            case 1:
                // Stage 2: Click on the bank and check item 14456 availability
                openBank();
                if (getBank().contains(14456)) {
                    currentStage++;
                }
                break;
            case 2:
                // Stage 3: Deposit all, withdraw item 14456, and close the bank
                depositAll();
                withdrawItem(14456);
                closeBank();
                currentStage++;
                break;
            case 3:
                // Stage 4: End the script
                stop(false);
                break;
        }
        return random(500, 1000); // Set a random delay between iterations
    }

    private void castLunarSpell() {
        // Cast the 'Tan Leather' spell from the Lunar spellbook
        getMagic().castSpell("Tan Leather");
        // Wait until the spell is cast
        new ConditionalSleep(5000) {
            @Override
            public boolean condition() throws InterruptedException {
                return getMagic().isSpellSelected();
            }
        }.sleep();
        currentStage++;
    }

    private boolean isInventoryEmptyExceptID(int itemId) {
        int itemCounter = 0;
        for (Item item : getInventory().getItems()) {
            if (item != null && item.getId() != itemId) {
                itemCounter++;
            }
        }
        return itemCounter == 0;
    }

    private void openBank() {
        // Click on the bank
        getBank().open();
        // Wait until the bank is open
        new ConditionalSleep(5000) {
            @Override
            public boolean condition() throws InterruptedException {
                return getBank().isOpen();
            }
        }.sleep();
    }

    private void depositAll() {
        // Deposit all items
        getBank().depositAll();
        // Wait until all items are deposited
        new ConditionalSleep(5000) {
            @Override
            public boolean condition() throws InterruptedException {
                return getInventory().isEmpty();
            }
        }.sleep();
    }

    private void withdrawItem(int itemId) {
        // Withdraw item with ID 14456
        getBank().withdraw(itemId, EquipmentSlot.MAIN_HAND.getAmount());
        // Wait until the item is withdrawn
        new ConditionalSleep(5000) {
            @Override
            public boolean condition() throws InterruptedException {
                return getInventory().contains(itemId);
            }
        }.sleep();
    }

    private void closeBank() {
        // Close the bank
        getBank().close();
        // Wait until the bank is closed
        new ConditionalSleep(5000) {
            @Override
            public boolean condition() throws InterruptedException {
                return !getBank().isOpen();
            }
        }.sleep();
    }
}