Added Trading#getMyOffer

This commit is contained in:
JKetelaar
2015-04-10 17:45:17 +02:00
parent df4ae0b8e2
commit f92d6fab4b
+23 -9
View File
@@ -20,7 +20,7 @@ public class Trading {
TODO Get the player its offer and implement its features TODO Get the player its offer and implement its features
*/ */
public static int OPPONENT_OFFER_INTERFACE_ID = 3416; public static int OPPONENT_OFFER_INTERFACE_ID = 3416;
public static int YOUR_OFFER_INTERFACE_ID = -1; public static int MY_OFFER_INTERFACE_ID = 3415;
public static int FIRST_TRADE_INTERFACE_ID = 3323; public static int FIRST_TRADE_INTERFACE_ID = 3323;
public static int SECOND_TRADE_INTERFACE_ID = 3443; public static int SECOND_TRADE_INTERFACE_ID = 3443;
@@ -30,6 +30,9 @@ public class Trading {
if (p.containsKey("opponentInterface")) { if (p.containsKey("opponentInterface")) {
OPPONENT_OFFER_INTERFACE_ID = Integer.parseInt(p.getProperty("opponentInterface")); OPPONENT_OFFER_INTERFACE_ID = Integer.parseInt(p.getProperty("opponentInterface"));
} }
if (p.containsKey("myInterface")) {
OPPONENT_OFFER_INTERFACE_ID = Integer.parseInt(p.getProperty("myInterface"));
}
if (p.containsKey("firstTradeInterface")) { if (p.containsKey("firstTradeInterface")) {
FIRST_TRADE_INTERFACE_ID = Integer.parseInt(p.getProperty("firstTradeInterface")); FIRST_TRADE_INTERFACE_ID = Integer.parseInt(p.getProperty("firstTradeInterface"));
} }
@@ -69,10 +72,10 @@ public class Trading {
}, 2500); }, 2500);
} }
public static Item[] getOpponentsOffer() { public static Item[] getMyOffer() {
ArrayList<Item> items = new ArrayList<>(); ArrayList<Item> items = new ArrayList<>();
int[] ids = getItemIDs(); int[] ids = getItemIDs(MY_OFFER_INTERFACE_ID);
int[] stacks = getItemStacks(); int[] stacks = getItemStacks(MY_OFFER_INTERFACE_ID);
for (int i = 0; i < ids.length; i++) { for (int i = 0; i < ids.length; i++) {
if (ids[i] > 0) { if (ids[i] > 0) {
items.add(new Item(ids[i], stacks[i], i)); items.add(new Item(ids[i], stacks[i], i));
@@ -81,10 +84,21 @@ public class Trading {
return items.toArray(new Item[items.size()]); return items.toArray(new Item[items.size()]);
} }
private static int[] getItemIDs() { public static Item[] getOpponentsOffer() {
Interface i; ArrayList<Item> items = new ArrayList<>();
int[] ids = getItemIDs(OPPONENT_OFFER_INTERFACE_ID);
int[] stacks = getItemStacks(OPPONENT_OFFER_INTERFACE_ID);
for (int i = 0; i < ids.length; i++) {
if (ids[i] > 0) {
items.add(new Item(ids[i], stacks[i], i));
}
}
return items.toArray(new Item[items.size()]);
}
if ((i = Loader.getClient().getInterfaceCache()[OPPONENT_OFFER_INTERFACE_ID]) != null) { private static int[] getItemIDs(int interfaceID) {
Interface i;
if ((i = Loader.getClient().getInterfaceCache()[interfaceID]) != null) {
int[] items; int[] items;
if ((items = i.getItems()) != null && items.length > 0) { if ((items = i.getItems()) != null && items.length > 0) {
return items; return items;
@@ -93,10 +107,10 @@ public class Trading {
return new int[0]; return new int[0];
} }
private static int[] getItemStacks() { private static int[] getItemStacks(int interfaceID) {
Interface i; Interface i;
if ((i = Loader.getClient().getInterfaceCache()[OPPONENT_OFFER_INTERFACE_ID]) != null) { if ((i = Loader.getClient().getInterfaceCache()[interfaceID]) != null) {
int[] stacks; int[] stacks;
if ((stacks = i.getStackSizes()) != null && stacks.length > 0) { if ((stacks = i.getStackSizes()) != null && stacks.length > 0) {
return stacks; return stacks;