Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.merccy.Shop;
- import java.awt.Rectangle;
- import java.util.ArrayList;
- import java.util.List;
- import org.osbot.script.Script;
- import org.osbot.script.mouse.InterfaceDestination;
- import org.osbot.script.mouse.RectangleDestination;
- import org.osbot.script.rs2.model.Item;
- import org.osbot.script.rs2.ui.RS2Interface;
- import org.osbot.script.rs2.ui.RS2InterfaceChild;
- public class Shop {
- private Script scr;
- private int parentID;
- private int childID;
- private String instructions;
- private String shopname;
- public Shop(Script s) {
- this.scr = s;
- this.parentID = 300;
- this.childID = 75;
- }
- public Shop(Script s, int parent, int child) {
- this.scr = s;
- this.parentID = parent;
- this.childID = child;
- this.updateInstructions();
- this.updateShopName();
- }
- public boolean isOpen() {
- RS2Interface pi = this.scr.client.getInterface(this.parentID);
- RS2InterfaceChild ci = pi.getChild(this.childID);
- if (pi != null && ci != null && ci.isVisible()) {
- return true;
- }
- return false;
- }
- public String getShopName(){
- return this.shopname;
- }
- public String getInstructions(){
- return this.instructions;
- }
- public void updateShopName(){
- if(this.isOpen()){
- this.shopname = this.scr.client.getInterface(300).getChild(76).getMessage();
- }
- }
- public void updateInstructions(){
- if(this.isOpen()){
- this.instructions = this.scr.client.getInterface(300).getChild(77).getMessage();
- }
- }
- public boolean close() throws InterruptedException {
- if (!this.isOpen()) {
- return true;
- }
- RS2InterfaceChild closeButton = this.scr.client.getInterface(
- this.parentID).getChild(91);
- this.scr.client.moveMouseTo(new InterfaceDestination(closeButton),
- true, true, false);
- this.scr.sleep(500);
- if (!this.isOpen()) {
- return true;
- }
- return false;
- }
- public ShopItem[] getAllShopItems() {
- if (this.isOpen()) {
- Item[] items = this.scr.client.getInterface(this.parentID)
- .getItems(this.childID);
- if (items == null) {
- return null;
- }
- items = this.removeEmpty(items);
- List<ShopItem> ret = new ArrayList<ShopItem>();
- int denied = 0;
- for (int i = 0; i < items.length; i++) {
- ShopItem x = new ShopItem(this.scr, i + 1);
- if (items[i] != null && items[i].getName() != null
- && items[i].getId() != -1) {
- x.name = items[i].getName();
- x.id = items[i].getId();
- x.amount = items[i].getAmount();
- ret.add(x);
- }
- }
- ShopItem[] buffer = new ShopItem[ret.size()-1];
- buffer = ret.toArray(buffer);
- return buffer;
- }
- return null;
- }
- public ShopItem getShopItem(int slotId) {
- if (this.isOpen()) {
- Item[] items = this.scr.client.getInterface(this.parentID)
- .getItems(this.childID);
- ShopItem ret = new ShopItem(this.scr, slotId);
- ret.name = items[slotId].getName();
- ret.id = items[slotId].getId();
- ret.amount = items[slotId].getAmount();
- return ret;
- }
- return null;
- }
- public ShopItem getShopItemByName(String name) {
- if (this.isOpen()) {
- ShopItem[] allItems = this.getAllShopItems();
- for (ShopItem i : allItems) {
- if (i.name.equalsIgnoreCase(name)) {
- return i;
- }
- }
- }
- return null;
- }
- public ShopItem getShopItemByID(int id) {
- if (this.isOpen()) {
- ShopItem[] allItems = this.getAllShopItems();
- for (ShopItem i : allItems) {
- if (i.id == id) {
- return i;
- }
- }
- }
- return null;
- }
- private Item[] removeEmpty(Item[] all) {
- List<Item> list = new ArrayList<Item>();
- int maxi = 0;
- for (int i = 0; i < all.length; i++) {
- if (all[i] != null && all[i].getName() != null
- && all[i].getId() != -1) {
- maxi = i;
- }
- }
- for (int i = 0; i <= maxi; i++) {
- list.add(all[i]);
- }
- if (list.size() >= 1) {
- Item[] ret = new Item[list.size() - 1];
- ret = list.toArray(ret);
- return ret;
- }
- return null;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement