This repository was archived by the owner on Aug 19, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathInventoryEx.java
More file actions
219 lines (189 loc) · 5.46 KB
/
InventoryEx.java
File metadata and controls
219 lines (189 loc) · 5.46 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
package mAPI;
import java.util.ArrayList;
import org.powerbot.game.api.methods.Tabs;
import org.powerbot.game.api.methods.Widgets;
import org.powerbot.game.api.methods.input.Keyboard;
import org.powerbot.game.api.methods.tab.Inventory;
import org.powerbot.game.api.util.Filter;
import org.powerbot.game.api.util.Random;
import org.powerbot.game.api.util.Time;
import org.powerbot.game.api.util.Timer;
import org.powerbot.game.api.wrappers.node.Item;
public class InventoryEx {
public static boolean bankAction(Item item, String prefix, int amount) {
if(!Bank.bankScreen())
return false;
switch(amount) {
case -1:
return item.getWidgetChild().interact(prefix + "-All but one");
case 0:
if (countItems(item.getId()) > 1)
return item.getWidgetChild().interact(prefix + "-All");
else
return item.getWidgetChild().interact(prefix);
case 1:
return item.getWidgetChild().click(true);
default:
String[] actions = item.getWidgetChild().getActions();
for(String str:actions)
if (str.equals(prefix + "-" + amount))
return item.getWidgetChild().interact(prefix + "-" + amount);
Timer timeout = new Timer(3500);
//TO-DO: Solid method for detection of box!!!
while (!Widgets.get(Constants.BANK_AMOUNT_INDEX, Constants.BANK_AMOUNT_VISIBLE).isVisible()) {
if (timeout.getRemaining() == 0) return false;
item.getWidgetChild().interact(prefix + "-X");
Time.sleep(Random.nextInt(1200, 1600));
}
Keyboard.sendText("" + amount, true);
return true;
}
}
public static boolean deposit(Item item, int amount) {
int c = Inventory.getCount();
Timer timeout = new Timer(2000);
while (timeout.getRemaining() > 0) {
if (c > Inventory.getCount() ||
countItems(item.getId()) == 0) break;
if (bankAction(item, "Deposit", amount))
Time.sleep(Random.nextInt(750, 1000));
else
Time.sleep(Random.nextInt(250, 350));
}
return (c > Inventory.getCount());
}
public static boolean invTab() {
return Bank.bankScreen() || Tabs.INVENTORY.open();
}
public static boolean isFull() {
invTab();
return Inventory.getCount() >= 28;
}
public static boolean isEmpty() {
invTab();
return Inventory.getCount() == 0;
}
public static Item[] getInvItems(final Filter<Item> filter) {
invTab();
ArrayList<Item> list = new ArrayList<Item>();
for(Item b:Inventory.getItems())
if (filter.accept(b))
list.add(b);
Item[] result = new Item[list.size()];
list.toArray(result);
return result;
}
public static Item[] getInvItems(final String[] names) {
invTab();
return getInvItems(new Filter<Item>() {
@Override
public boolean accept(Item i) {
return Misc.inStrArr(i.getName(), names);
}
});
}
public static Item[] getInvItems(final String name) {
invTab();
return getInvItems(new String[] {name});
}
public static Item[] getInvItems(final int...ids) {
invTab();
return getInvItems(new Filter<Item>() {
@Override
public boolean accept(Item i) {
return Misc.inIntArr(i.getId(), ids);
}
});
}
public static Item getInvItem(final Filter<Item> filter) {
invTab();
for(Item b:Inventory.getItems())
if (filter.accept(b))
return b;
return null;
}
public static Item getInvItem(final int id) {
invTab();
return getInvItem(new Filter<Item>() {
@Override
public boolean accept(Item b) {
return (b.getId() == id);
}});
}
public static Item getInvItem(final String name) {
invTab();
return getInvItem(new Filter<Item>() {
@Override
public boolean accept(Item b) {
return (b.getName().toLowerCase().contains(name.toLowerCase()));
}});
}
public static boolean itemsInInv(final Filter<Item> filter) {
invTab();
return getInvItems(filter).length > 0;
}
public static boolean itemsInInv(final int...ids) {
invTab();
return getInvItems(ids).length > 0;
}
public static boolean itemsInInv(final String[] names) {
invTab();
return getInvItems(names).length > 0;
}
public static boolean itemsInInv(final String name) {
invTab();
return getInvItems(new String[] {name}).length > 0;
}
public static boolean itemInInv(final Filter<Item> filter) {
invTab();
return getInvItem(filter) != null;
}
public static boolean itemInInv(final int id) {
invTab();
return getInvItem(id) != null;
}
public static boolean itemInInv(final String name) {
invTab();
return getInvItem(name) != null;
}
public static int countItems(final String[] names) {
invTab();
return Inventory.getCount(new Filter<Item>() {
@Override
public boolean accept(Item b) {
return Misc.inStrArr(b.getName(), names);
}});
}
public static int countItems(final int...ids) {
invTab();
return Inventory.getCount(new Filter<Item>() {
@Override
public boolean accept(Item b) {
return Misc.inIntArr(b.getId(), ids);
}});
}
public static int countItemsExcept(final Filter<Item> filter) {
invTab();
return Inventory.getCount() - getInvItems(filter).length;
}
public static int countItemsExcept(final String[] names) {
invTab();
return countItemsExcept(new Filter<Item>() {
@Override
public boolean accept(Item b) {
return Misc.inStrArr(b.getName(), names);
}});
}
public static int countItemsExcept(final int...ids) {
invTab();
return countItemsExcept(new Filter<Item>() {
@Override
public boolean accept(Item b) {
return Misc.inIntArr(b.getId(), ids);
}});
}
public static int countItemsExcept(final String name) {
invTab();
return countItemsExcept(new String[] {name});
}
}