Jump to content

Deposit Box Class


TheScrub

Recommended Posts

Class 

import java.awt.Point;
import java.awt.Rectangle;

import org.osbot.script.Script;
import org.osbot.script.mouse.RectangleDestination;
import org.osbot.script.rs2.model.Item;
import org.osbot.script.rs2.ui.RS2InterfaceChild;

/*
*Written by TheScrub ~ OSBOT
*/

public class DepositBox {
	private final int START_WIDTH = 135;
	private final int START_HEIGHT = 82;
	// width+ height includes spacing lengths
	private final int WIDTH = 41;
	private final int HEIGHT = 44;
	private Script script;
	private final int PARENTID = 11;
	private final int CHILDID = 61;
	private final int INFOID = 60;

	public DepositBox(Script script) {
		this.script = script;

	}

	public Item[] getItems() {
		if (boxIsOpen()) {
			if (script.client.getInterface(PARENTID) != null) {
				RS2InterfaceChild rc = script.client.getInterface(PARENTID)
						.getChild(CHILDID);
				if (rc != null && rc.isVisible()) {
					return script.client.getInterface(PARENTID).getItems(
							CHILDID);
				}
			}
		}
		return null;
	}

	public int getItemSlot(Item item) {
		Item[] array = getItems();
		if (array != null && array.length > 0) {
			for (int i = 0; i < array.length; i++) {
				if (array[i] != null) {
					if (array[i].equals(item)) {
						return i;
					}
				}
			}
		}

		return -1;
	}

	public int getItemSlot(String item) {
		Item[] array = getItems();
		if (array != null && array.length > 0) {
			for (int i = 0; i < array.length; i++) {
				if (array[i] != null) {
					if (array[i].getName() != null) {
						if (array[i].getName().equalsIgnoreCase(item)) {
							return i;
						}
					}
				}
			}
		}

		return -1;
	}

	public int getItemSlot(int item) {
		Item[] array = getItems();
		if (array != null && array.length > 0) {
			for (int i = 0; i < array.length; i++) {
				if (array[i] != null) {
					if (array[i].getName() != null) {
						if (array[i].getId() == item) {
							return i;
						}
					}
				}
			}
		}

		return -1;
	}

	public boolean contains(String item) {
		if (boxIsOpen()) {
			Item[] array = getItems();
			if (array.length > 0) {
				for (Item i : array) {
					if (i != null) {
						if (i.getName() != null) {
							if (i.getName().equalsIgnoreCase(item)) {
								return true;
							}
						}
					}
				}
			}
		}
		return false;
	}

	public boolean contains(int item) {
		if (boxIsOpen()) {
			Item[] array = getItems();
			if (array.length > 0) {
				for (Item i : array) {
					if (i != null) {
						if (i.getId() == item) {
							return true;
						}

					}
				}
			}
		}
		return false;
	}

	public boolean contains(Item item) {
		if (boxIsOpen()) {
			Item[] array = getItems();
			if (array.length > 0) {
				for (Item i : array) {
					if (i != null) {
						if (i.equals(item)) {
							return true;

						}
					}
				}
			}
		}
		return false;
	}

	private Point getPoint(int slot) {
		int column = slot / 7;
		int row = slot % 7;
		int x = (int) (START_WIDTH + (row * WIDTH));
		int y = START_HEIGHT + (column * HEIGHT);
		return new Point(x, y);
	}

	public Rectangle getRectangle(int slot) {
		Point p = getPoint(slot);
		return new Rectangle(p.x, p.y, 18, 18);
	}

	public boolean boxIsOpen() {
		if (script.client.getInterface(PARENTID) != null) {
			RS2InterfaceChild rc = script.client.getInterface(PARENTID)
					.getChild(CHILDID);
			if (rc != null && rc.isVisible()) {
				return true;
			}
		}
		return false;
	}

	public String getBoxInfo() {
		if (boxIsOpen()) {
			if (script.client.getInterface(PARENTID).getChild(INFOID)
					.getMessage() != null) {
				return script.client.getInterface(PARENTID).getChild(INFOID)
						.getMessage();
			}
		}
		return null;
	}

	public boolean interact(Rectangle rec, String action)
			throws InterruptedException {
		if (rec != null && action != null && !action.isEmpty()) {
			return script.selectOption(null, new RectangleDestination(rec),
					action);
		}
		return false;
	}

}


 

rectangles are abit off but they work fine as it counts as the item still

 

6rBOQ.png

Edited by TheScrub
  • Like 1
Link to comment
Share on other sites

  • 1 month later...
Guest
This topic is now closed to further replies.
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...