Advertisement
OSBotMerccy

Untitled

Jul 6th, 2013
123
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 4.00 KB | None | 0 0
  1. package com.merccy.Shop;
  2.  
  3. import java.awt.Rectangle;
  4. import java.util.ArrayList;
  5. import java.util.List;
  6.  
  7. import org.osbot.script.Script;
  8. import org.osbot.script.mouse.InterfaceDestination;
  9. import org.osbot.script.mouse.RectangleDestination;
  10. import org.osbot.script.rs2.model.Item;
  11. import org.osbot.script.rs2.ui.RS2Interface;
  12. import org.osbot.script.rs2.ui.RS2InterfaceChild;
  13.  
  14. public class Shop {
  15.  
  16.     private Script scr;
  17.     private int parentID;
  18.     private int childID;
  19.     private String instructions;
  20.     private String shopname;
  21.  
  22.     public Shop(Script s) {
  23.     this.scr = s;
  24.     this.parentID = 300;
  25.     this.childID = 75;
  26.     }
  27.  
  28.     public Shop(Script s, int parent, int child) {
  29.     this.scr = s;
  30.     this.parentID = parent;
  31.     this.childID = child;
  32.     this.updateInstructions();
  33.     this.updateShopName();
  34.     }
  35.  
  36.     public boolean isOpen() {
  37.     RS2Interface pi = this.scr.client.getInterface(this.parentID);
  38.     RS2InterfaceChild ci = pi.getChild(this.childID);
  39.     if (pi != null && ci != null && ci.isVisible()) {
  40.         return true;
  41.     }
  42.     return false;
  43.     }
  44.  
  45.     public String getShopName(){
  46.     return this.shopname;
  47.     }
  48.    
  49.     public String getInstructions(){
  50.     return this.instructions;
  51.     }
  52.    
  53.     public void updateShopName(){
  54.     if(this.isOpen()){
  55.         this.shopname = this.scr.client.getInterface(300).getChild(76).getMessage();
  56.     }
  57.     }
  58.    
  59.     public void updateInstructions(){
  60.     if(this.isOpen()){
  61.         this.instructions = this.scr.client.getInterface(300).getChild(77).getMessage();
  62.     }
  63.     }
  64.    
  65.     public boolean close() throws InterruptedException {
  66.     if (!this.isOpen()) {
  67.         return true;
  68.     }
  69.     RS2InterfaceChild closeButton = this.scr.client.getInterface(
  70.         this.parentID).getChild(91);
  71.     this.scr.client.moveMouseTo(new InterfaceDestination(closeButton),
  72.         true, true, false);
  73.     this.scr.sleep(500);
  74.     if (!this.isOpen()) {
  75.         return true;
  76.     }
  77.     return false;
  78.     }
  79.  
  80.     public ShopItem[] getAllShopItems() {
  81.     if (this.isOpen()) {
  82.         Item[] items = this.scr.client.getInterface(this.parentID)
  83.             .getItems(this.childID);
  84.         if (items == null) {
  85.         return null;
  86.         }
  87.         items = this.removeEmpty(items);
  88.         List<ShopItem> ret = new ArrayList<ShopItem>();
  89.         int denied = 0;
  90.         for (int i = 0; i < items.length; i++) {
  91.         ShopItem x = new ShopItem(this.scr, i + 1);
  92.         if (items[i] != null && items[i].getName() != null
  93.             && items[i].getId() != -1) {
  94.             x.name = items[i].getName();
  95.             x.id = items[i].getId();
  96.             x.amount = items[i].getAmount();
  97.             ret.add(x);
  98.         }
  99.         }
  100.         ShopItem[] buffer = new ShopItem[ret.size()-1];
  101.         buffer = ret.toArray(buffer);
  102.         return buffer;
  103.     }
  104.     return null;
  105.     }
  106.  
  107.     public ShopItem getShopItem(int slotId) {
  108.     if (this.isOpen()) {
  109.         Item[] items = this.scr.client.getInterface(this.parentID)
  110.             .getItems(this.childID);
  111.         ShopItem ret = new ShopItem(this.scr, slotId);
  112.         ret.name = items[slotId].getName();
  113.         ret.id = items[slotId].getId();
  114.         ret.amount = items[slotId].getAmount();
  115.         return ret;
  116.     }
  117.     return null;
  118.     }
  119.  
  120.     public ShopItem getShopItemByName(String name) {
  121.     if (this.isOpen()) {
  122.         ShopItem[] allItems = this.getAllShopItems();
  123.         for (ShopItem i : allItems) {
  124.         if (i.name.equalsIgnoreCase(name)) {
  125.             return i;
  126.         }
  127.         }
  128.     }
  129.     return null;
  130.     }
  131.  
  132.     public ShopItem getShopItemByID(int id) {
  133.     if (this.isOpen()) {
  134.         ShopItem[] allItems = this.getAllShopItems();
  135.         for (ShopItem i : allItems) {
  136.         if (i.id == id) {
  137.             return i;
  138.         }
  139.         }
  140.     }
  141.     return null;
  142.     }
  143.  
  144.     private Item[] removeEmpty(Item[] all) {
  145.     List<Item> list = new ArrayList<Item>();
  146.     int maxi = 0;
  147.     for (int i = 0; i < all.length; i++) {
  148.         if (all[i] != null && all[i].getName() != null
  149.             && all[i].getId() != -1) {
  150.         maxi = i;
  151.         }
  152.     }
  153.     for (int i = 0; i <= maxi; i++) {
  154.         list.add(all[i]);
  155.     }
  156.     if (list.size() >= 1) {
  157.         Item[] ret = new Item[list.size() - 1];
  158.         ret = list.toArray(ret);
  159.         return ret;
  160.     }
  161.     return null;
  162.     }
  163. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement