OSBotMerccy

Untitled

Jul 10th, 2013
145
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 4.26 KB | None | 0 0
  1. package com.merccy.Trade;
  2.  
  3. import java.lang.reflect.Field;
  4. import java.util.ArrayList;
  5. import java.util.List;
  6.  
  7. import org.osbot.accessor.XRS2Interface;
  8. import org.osbot.script.Script;
  9. import org.osbot.script.mouse.InterfaceDestination;
  10. import org.osbot.script.rs2.ui.RS2Interface;
  11. import org.osbot.script.rs2.ui.RS2InterfaceChild;
  12.  
  13. public class Trade {
  14.     private Script s;
  15.     private ClassLoader loader;
  16.     private String error;
  17.  
  18.     public Trade(Script scr) {
  19.     this.s = scr;
  20.     }
  21.  
  22.     public boolean isOpen() {
  23.     if (this.s.client.getInterface(335) != null
  24.         && this.s.client.getInterface(335).isValid()) {
  25.         return true;
  26.     }
  27.     return false;
  28.     }
  29.  
  30.     public void close() throws InterruptedException {
  31.     if (!this.isOpen()) {
  32.         return;
  33.     }
  34.     this.s.client.moveMouseTo(new InterfaceDestination(this.s.client
  35.         .getInterface(335).getChild(7)), true, true, false);
  36.     this.s.sleep(250);
  37.     }
  38.  
  39.     public void accept() throws InterruptedException {
  40.     this.s.client.moveMouseTo(new InterfaceDestination(this.s.client
  41.         .getInterface(335).getChild(17)), true, true, false);
  42.     }
  43.  
  44.     public void decline() throws InterruptedException {
  45.     this.s.selectInterfaceOption(334, 20, "Decline");
  46.     this.s.client.moveMouseTo(new InterfaceDestination(this.s.client
  47.         .getInterface(335).getChild(18)), true, true, false);
  48.     }
  49.  
  50.     public TradeItem getMyTradeItemByID(int id) {
  51.     TradeItem[] all = this.getMyTradeInv();
  52.     for(TradeItem one : all){
  53.         if(one != null){
  54.         if(one.getID() == id){
  55.             return one;
  56.         }
  57.         }
  58.     }
  59.     return null;
  60.     }
  61.    
  62.     public TradeItem getOtherTradeItemByID(int id) {
  63.     TradeItem[] all = this.getMyTradeInv();
  64.     for(TradeItem one : all){
  65.         if(one != null){
  66.         if(one.getID() == id){
  67.             return one;
  68.         }
  69.         }
  70.     }
  71.     return null;
  72.     }
  73.  
  74.     public TradeItem[] getMyTradeInv() {
  75.     if (this.isOpen()) {
  76.         XRS2Interface mp = this.s.client.getInterface(335).getChild(48).instance;
  77.         XRS2Interface[] mc = this.findAllChilds(mp);
  78.         List<TradeItem> allItems = new ArrayList<TradeItem>();
  79.         int slots = 1;
  80.         if (mc != null) {
  81.         for (XRS2Interface ic : mc) {
  82.             if (ic != null) {
  83.             int itemId = this.getInterfaceIntData(ic, "dx",
  84.                 1088506441);
  85.             int amount = this.getInterfaceIntData(ic, "do",
  86.                 1790391807);
  87.             if (itemId != -1) {
  88.                 TradeItem temp = new TradeItem(this.s, itemId, null, amount,
  89.                     slots);
  90.                 allItems.add(temp);
  91.             }
  92.             }
  93.             slots += 1;
  94.         }
  95.         TradeItem[] buffer = new TradeItem[allItems.size()];
  96.         buffer = allItems.toArray(buffer);
  97.         return buffer;
  98.         }
  99.     }
  100.     return null;
  101.     }
  102.  
  103.     public TradeItem[] getOtherTradeInv() {
  104.     if (this.isOpen()) {
  105.         XRS2Interface mp = this.s.client.getInterface(335).getChild(50).instance;
  106.         XRS2Interface[] mc = this.findAllChilds(mp);
  107.         List<TradeItem> allItems = new ArrayList<TradeItem>();
  108.         int slots = 1;
  109.         if (mc != null) {
  110.         for (XRS2Interface ic : mc) {
  111.             if (ic != null) {
  112.             int itemId = this.getInterfaceIntData(ic, "dx",
  113.                 1088506441);
  114.             int amount = this.getInterfaceIntData(ic, "do",
  115.                 1790391807);
  116.             if (itemId != -1) {
  117.                 TradeItem temp = new TradeItem(this.s, itemId, null, amount,
  118.                     slots);
  119.                 allItems.add(temp);
  120.             }
  121.             }
  122.             slots += 1;
  123.         }
  124.         TradeItem[] buffer = new TradeItem[allItems.size()];
  125.         buffer = allItems.toArray(buffer);
  126.         return buffer;
  127.         }
  128.     }
  129.     return null;
  130.     }
  131.  
  132.     private XRS2Interface[] findAllChilds(XRS2Interface parent) {
  133.     if (this.loader == null) {
  134.         this.loader = parent.getClass().getClassLoader();
  135.     }
  136.     try {
  137.         Class c = Class.forName("fi", false, this.loader);
  138.         Field f = c.getDeclaredField("dg");
  139.         f.setAccessible(true);
  140.         return (XRS2Interface[]) f.get(parent);
  141.     } catch (Exception e) {
  142.         this.error = e.getMessage();
  143.     }
  144.     return null;
  145.     }
  146.  
  147.     private int getInterfaceIntData(XRS2Interface parent, String f1,
  148.         int multiplier) {
  149.     if (this.loader == null) {
  150.         this.loader = parent.getClass().getClassLoader();
  151.     }
  152.     try {
  153.         Class c = Class.forName("fi", false, this.loader);
  154.         Field f = c.getDeclaredField(f1);
  155.         f.setAccessible(true);
  156.         return (f.getInt(parent) * multiplier);
  157.     } catch (Exception e) {
  158.         this.error = e.getMessage();
  159.     }
  160.     return -1;
  161.     }
  162. }
Advertisement
Add Comment
Please, Sign In to add comment