Jump to content

Simple Deadman Mode Safe Deposit Box API (minimal)


LoudPacks

Recommended Posts

Written for lem0n api but you can easily change the imports and TaskScript to Script.

import org.osbot.rs07.api.def.ItemDefinition;
import org.osbot.rs07.api.map.Area;
import org.osbot.rs07.api.model.NPC;
import org.osbot.rs07.api.ui.RS2Widget;
import org.osbot.rs07.utility.ConditionalSleep;

import lemons.api.script.TaskScript;

public class SafeDepositBox {

	private TaskScript script;
	private Area bank;

	public SafeDepositBox(TaskScript script, Area bank) {
		this.script = script;
		this.bank = bank;
	}

	public boolean isOpen() {
		RS2Widget openWidget = script.getWidgets().get(230, 4, 1);
		if (openWidget != null) {
			return true;
		}
		return false;
	}

	public boolean openBox() {
		NPC wizard = script.getNpcs().closest("Financial Wizard");
		if (wizard != null && !isOpen() && bank.contains(script.myPlayer())) {
			wizard.interact("Deposit-box");
			new ConditionalSleep(1500, 2000) {
				public boolean condition() {
					return isOpen();
				}
			}.sleep();
			return true;
		}
		script.log("Not in bank! Unable to interact with financial wizard!");
		return false;
	}

	public boolean closeBox() {
		RS2Widget closeWidget = script.getWidgets().get(230, 4, 13);
		if (closeWidget != null && isOpen()) {
			closeWidget.interact("Close");
			new ConditionalSleep(1500, 2000) {
				public boolean condition() {
					return !isOpen();
				}
			}.sleep();
		}
		return true;
	}

	public boolean depositAll() {
		RS2Widget depositAllWidget = script.getWidgets().get(230, 10);
		long freeInventCount = script.getInventory().getEmptySlots();
		if (depositAllWidget != null) {
			depositAllWidget.interact("Deposit inventory");
			new ConditionalSleep(1500, 2000) {
				public boolean condition() {
					return script.getInventory().getEmptySlots() > freeInventCount;
				}
			}.sleep();
		}
		return true;
	}

	public boolean depositAllWorn() {
		RS2Widget depositAllWornWidget = script.getWidgets().get(230, 11);
		long freeInventCount = script.getInventory().getEmptySlots();
		if (depositAllWornWidget != null) {
			depositAllWornWidget.interact("Deposit worn items");
			new ConditionalSleep(1500, 2000) {
				public boolean condition() {
					return script.getInventory().getEmptySlots() > freeInventCount;
				}
			}.sleep();
		}
		return true;
	}

	public boolean withdrawOne(String itemName) {
		RS2Widget containerParentWidget = script.getWidgets().get(230, 5);
		if (containerParentWidget != null) {
			for (RS2Widget child : containerParentWidget.getChildWidgets()) {
				if (child != null && getName(child.getItemId()).equalsIgnoreCase(itemName)) {
					child.interact("Withdraw-1");
					new ConditionalSleep(950, 1500) {
						public boolean condition() {
							return false;
						}
					}.sleep();
				}
			}
		}
		return true;
	}

	public String getName(int itemID) {
		ItemDefinition itemDef = ItemDefinition.forId(itemID);
		if (itemDef != null) {
			String itemName = itemDef.getName();
			if (itemName != null) {
				return itemName;
			}
		}
		return "";
	}

}

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