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 pathBank.java
More file actions
262 lines (215 loc) · 6.98 KB
/
Bank.java
File metadata and controls
262 lines (215 loc) · 6.98 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
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
package mAPI;
import org.powerbot.game.api.methods.Widgets;
import org.powerbot.game.api.methods.interactive.Npcs;
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.interactive.Npc;
import org.powerbot.game.api.wrappers.node.Item;
import org.powerbot.game.api.wrappers.widget.WidgetChild;
import mAPI.Constants;
import mAPI.Misc;
public class Bank {
public static boolean bankScreen() {
return Widgets.get(Constants.INDEX_BANK).validate();
}
public static boolean depositBoxScreen() {
return Widgets.get(Constants.INDEX_DEPOSIT_BOX).validate();
}
public static void closeBank() {
WidgetChild btn = Widgets.get(Constants.INDEX_BANK, Constants.BANK_CLOSE);
if (btn.validate())
btn.click(true);
}
public static boolean closeBankWait() {
Timer timeout = new Timer(3000);
while (bankScreen()) {
if (timeout.getRemaining() <= 0)
return false;
closeBank();
Time.sleep(Random.nextInt(800, 1000));
}
return !bankScreen();
}
public static WidgetChild[] getBankArray() {
return Widgets.get(Constants.INDEX_BANK, Constants.BANK_ITEM_ARRAY).getChildren();
}
public static BankItem[] getBankItems() {
if (!bankScreen()) return null;
WidgetChild[] bank_items = getBankArray();
int last_index = 0;
for(int i = 0; i<bank_items.length; i++) {
if (bank_items[i].getChildId() != -1)
last_index = i;
else break;
}
BankItem[] barr = new BankItem[last_index+1];
for(int i = 0; i <= last_index; i++)
barr[i] = new BankItem(i);
return barr;
}
public static int getBankCount() {
return getBankItems().length;
}
public static BankItem getBankItem(final Filter<BankItem> filter) {
for(BankItem b:getBankItems())
if (filter.accept(b))
return b;
return null;
}
public static BankItem getBankItem(final String name) {
return getBankItem(new Filter<BankItem>() {
@Override
public boolean accept(BankItem b) {
return (b.getName().equals(name));
}
});
}
public static BankItem getBankItem(final int id) {
return getBankItem(new Filter<BankItem>() {
@Override
public boolean accept(BankItem b) {
return (b.getID() == id);
}
});
}
public static boolean itemInBank(final Filter<BankItem> filter) {
return (getBankItem(filter) != null);
}
public static boolean itemInBank(final String name) {
return itemInBank(new Filter<BankItem>() {
@Override
public boolean accept(BankItem b) {
return (b.getName().equals(name));
}
});
}
public static boolean itemInBank(final int id) {
return itemInBank(new Filter<BankItem>() {
@Override
public boolean accept(BankItem b) {
return (b.getID() == id);
}
});
}
public static boolean withdrawItem(final Filter<BankItem> filter, int amount) {
if(!bankScreen() || !itemInBank(filter) || amount < -1)
return false;
return getBankItem(filter).withdraw(amount);
}
public static boolean withdrawItem(final String name, final int amount) {
return withdrawItem(new Filter<BankItem>() {
@Override
public boolean accept(BankItem b) {
return (b.getName().equals(name));
}
}, amount);
}
public static boolean withdrawItem(final int id, final int amount) {
return withdrawItem(new Filter<BankItem>() {
@Override
public boolean accept(BankItem b) {
return (b.getID() == id);
}
}, amount);
}
public static boolean depositItem(final Filter<Item> filter, int amount) {
return InventoryEx.deposit(InventoryEx.getInvItem(filter), amount);
}
public static boolean depositItem(final int id, int amount) {
return InventoryEx.deposit(InventoryEx.getInvItem(id), amount);
}
public static boolean depositItem(final String name, int amount) {
return InventoryEx.deposit(InventoryEx.getInvItem(name), amount);
}
public static boolean quickDeposit(final int button) {
if(depositBoxScreen())
return Widgets.get(Constants.INDEX_DEPOSIT_BOX, Constants.DEPOSIT_BOX_DEPOSIT_OFFSET + button).click(true);
return Widgets.get(Constants.INDEX_BANK, Constants.BANK_DEPOSIT_OFFSET + button).click(true);
}
public static boolean depositSummon() {
return quickDeposit(Constants.BANK_DEPOSIT_SUMMONING);
}
public static boolean depositEquipped() {
return quickDeposit(Constants.BANK_DEPOSIT_EQUIPPED);
}
public static boolean depositCoins() {
return quickDeposit(Constants.BANK_DEPOSIT_PURSE);
}
public static boolean depositAll() {
return quickDeposit(Constants.BANK_DEPOSIT_ALL);
}
public static boolean depositAll(int...ids) {
if (InventoryEx.getInvItems(ids).length == Inventory.getCount())
return depositAll();
for(Item item: Inventory.getItems())
if (Misc.inIntArr(item.getId(), ids))
InventoryEx.deposit(item, 0);
return true;
}
public static boolean depositAll(String[] names) {
if (InventoryEx.getInvItems(names).length == Inventory.getCount())
return depositAll();
for(Item item: Inventory.getItems())
if (Misc.inStrArr(item.getName(), names))
InventoryEx.deposit(item, 0);
return true;
}
public static boolean depositAll(String name) {
return depositAll(new String[] {name});
}
public static boolean depositAllBut(int...ids) {
if (!InventoryEx.itemsInInv(ids))
return depositAll();
for(Item item: Inventory.getItems())
if (!Misc.inIntArr(item.getId(), ids))
InventoryEx.deposit(item, 0);
return InventoryEx.getInvItems(ids).length == Inventory.getCount();
}
public static boolean depositAllBut(String[] names) {
if (!InventoryEx.itemsInInv(names)) return depositAll();
for(Item item: Inventory.getItems())
if (!Misc.inStrArr(item.getName(), names)) {
InventoryEx.deposit(item, 0);
}
return InventoryEx.getInvItems(names).length == Inventory.getCount();
}
public static boolean depositAllBut(String name) {
return depositAllBut(new String[] {name});
}
public static int getCurrentBankTab() {
if (!bankScreen()) return -1;
for(int i = 0; i<Constants.BANK_TABS.length; i++)
if (Widgets.get(Constants.INDEX_BANK, Constants.BANK_TABS[i] - 1).getTextureId() == Constants.BANK_TAB_SELECTED)
return i;
return -1;
}
public static boolean openBankTab(int tab) {
if (getCurrentBankTab() == tab)
return true;
WidgetChild target = Widgets.get(Constants.INDEX_BANK, Constants.BANK_TABS[tab]);
if (target.getChildId() == -1) return false;
Timer timeout = new Timer(3500);
while(getCurrentBankTab() != tab) {
if (timeout.getRemaining() == 0) break;
target.click(true);
Time.sleep(Random.nextInt(750, 900));
}
return getCurrentBankTab() == tab;
}
public static boolean openBankNPC() {
Npc banker = Npcs.getNearest(new Filter<Npc>() {
@Override
public boolean accept(Npc n) {
String[] act = n.getActions();
for(int i = 0; i<act.length; i++)
if (act[i].contains("Bank"))
return true;
return false;
}
});
return banker.interact("Bank");
}
}