Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.merccy.Trade;
- import java.lang.reflect.Field;
- import java.util.ArrayList;
- import java.util.List;
- import org.osbot.accessor.XRS2Interface;
- import org.osbot.script.Script;
- import org.osbot.script.mouse.InterfaceDestination;
- import org.osbot.script.rs2.ui.RS2Interface;
- import org.osbot.script.rs2.ui.RS2InterfaceChild;
- public class Trade {
- private Script s;
- private ClassLoader loader;
- private String error;
- public Trade(Script scr) {
- this.s = scr;
- }
- public boolean isOpen() {
- if (this.s.client.getInterface(335) != null
- && this.s.client.getInterface(335).isValid()) {
- return true;
- }
- return false;
- }
- public void close() throws InterruptedException {
- if (!this.isOpen()) {
- return;
- }
- this.s.client.moveMouseTo(new InterfaceDestination(this.s.client
- .getInterface(335).getChild(7)), true, true, false);
- this.s.sleep(250);
- }
- public void accept() throws InterruptedException {
- this.s.client.moveMouseTo(new InterfaceDestination(this.s.client
- .getInterface(335).getChild(17)), true, true, false);
- }
- public void decline() throws InterruptedException {
- this.s.selectInterfaceOption(334, 20, "Decline");
- this.s.client.moveMouseTo(new InterfaceDestination(this.s.client
- .getInterface(335).getChild(18)), true, true, false);
- }
- public TradeItem getMyTradeItemByID(int id) {
- TradeItem[] all = this.getMyTradeInv();
- for(TradeItem one : all){
- if(one != null){
- if(one.getID() == id){
- return one;
- }
- }
- }
- return null;
- }
- public TradeItem getOtherTradeItemByID(int id) {
- TradeItem[] all = this.getMyTradeInv();
- for(TradeItem one : all){
- if(one != null){
- if(one.getID() == id){
- return one;
- }
- }
- }
- return null;
- }
- public TradeItem[] getMyTradeInv() {
- if (this.isOpen()) {
- XRS2Interface mp = this.s.client.getInterface(335).getChild(48).instance;
- XRS2Interface[] mc = this.findAllChilds(mp);
- List<TradeItem> allItems = new ArrayList<TradeItem>();
- int slots = 1;
- if (mc != null) {
- for (XRS2Interface ic : mc) {
- if (ic != null) {
- int itemId = this.getInterfaceIntData(ic, "dx",
- 1088506441);
- int amount = this.getInterfaceIntData(ic, "do",
- 1790391807);
- if (itemId != -1) {
- TradeItem temp = new TradeItem(this.s, itemId, null, amount,
- slots);
- allItems.add(temp);
- }
- }
- slots += 1;
- }
- TradeItem[] buffer = new TradeItem[allItems.size()];
- buffer = allItems.toArray(buffer);
- return buffer;
- }
- }
- return null;
- }
- public TradeItem[] getOtherTradeInv() {
- if (this.isOpen()) {
- XRS2Interface mp = this.s.client.getInterface(335).getChild(50).instance;
- XRS2Interface[] mc = this.findAllChilds(mp);
- List<TradeItem> allItems = new ArrayList<TradeItem>();
- int slots = 1;
- if (mc != null) {
- for (XRS2Interface ic : mc) {
- if (ic != null) {
- int itemId = this.getInterfaceIntData(ic, "dx",
- 1088506441);
- int amount = this.getInterfaceIntData(ic, "do",
- 1790391807);
- if (itemId != -1) {
- TradeItem temp = new TradeItem(this.s, itemId, null, amount,
- slots);
- allItems.add(temp);
- }
- }
- slots += 1;
- }
- TradeItem[] buffer = new TradeItem[allItems.size()];
- buffer = allItems.toArray(buffer);
- return buffer;
- }
- }
- return null;
- }
- private XRS2Interface[] findAllChilds(XRS2Interface parent) {
- if (this.loader == null) {
- this.loader = parent.getClass().getClassLoader();
- }
- try {
- Class c = Class.forName("fi", false, this.loader);
- Field f = c.getDeclaredField("dg");
- f.setAccessible(true);
- return (XRS2Interface[]) f.get(parent);
- } catch (Exception e) {
- this.error = e.getMessage();
- }
- return null;
- }
- private int getInterfaceIntData(XRS2Interface parent, String f1,
- int multiplier) {
- if (this.loader == null) {
- this.loader = parent.getClass().getClassLoader();
- }
- try {
- Class c = Class.forName("fi", false, this.loader);
- Field f = c.getDeclaredField(f1);
- f.setAccessible(true);
- return (f.getInt(parent) * multiplier);
- } catch (Exception e) {
- this.error = e.getMessage();
- }
- return -1;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment