Repository navigation
Expand file tree
/
Copy pathAA_VarrockWestSmither.java
More file actions
399 lines (325 loc) · 11.5 KB
/
Copy pathAA_VarrockWestSmither.java
File metadata and controls
399 lines (325 loc) · 11.5 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
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
/**
* Smiths items at the Varrock West anvils.
* <p>
* Requirements:
* Start at Varrock West with sleeping bag and hammer in inventory.
* <p>
* Required Parameters:
* -b,--bar <bronze|iron|steel|mithril|adamantite|runite>
* -p,--product <plate_mail_body|kite_shield|two_handed_sword|...>
* <p>
* Products:
* dagger
* throwing_knife
* short_sword
* long_sword
* scimitar
* two_handed_sword
* hatchet
* battle_axe
* mace
* medium_helmet
* large_helmet
* square_shield
* kite_shield
* chain_mail_body
* plate_mail_body
* plate_mail_legs
* plated_skirt
* arrow_heads
* bronze_wire
* nails
* <p>
*
* @Author Chomp
*/
public class AA_VarrockWestSmither extends AA_Script {
private static final long HAMMERING_DELAY = 600L; // +- based on latency
private static final int ITEM_ID_HAMMER = 168;
private static final int INITIAL_INVENTORY_SIZE = 2;
private static final int MAXIMUM_FATIGUE = 99;
private Bar bar;
private Product product;
private long startTime;
private double initialSmithingXp;
private long bankDepositTimeout;
private long bankWithdrawTimeout;
private long doorOpenTimeout;
private long optionMenuTimeout;
private int playerX;
private int playerY;
private int barWithdrawCount;
private int barsSmithed;
private int barsRemaining;
public AA_VarrockWestSmither(final Extension extension) {
super(extension);
}
@Override
public void init(final String parameters) {
if (parameters.isEmpty()) printInstructions();
final String[] args = parameters.split(" ");
for (int i = 0; i < args.length; i++) {
switch (args[i].toLowerCase()) {
case "-b":
case "--bar":
bar = Bar.valueOf(args[++i].toUpperCase());
break;
case "-p":
case "--product":
product = Product.valueOf(args[++i].toUpperCase());
break;
default:
throw new IllegalArgumentException("Error: malformed parameters. Try again ...");
}
}
if (bar == null) {
throw new IllegalArgumentException("Missing bar type parameter.");
}
if (product == null) {
throw new IllegalArgumentException("Missing product parameter.");
}
if (!hasInventoryItem(ITEM_ID_SLEEPING_BAG)) {
throw new IllegalStateException("Sleeping bag missing from inventory.");
}
if (!hasInventoryItem(ITEM_ID_HAMMER)) {
throw new IllegalStateException("Hammer missing from inventory.");
}
final int inventorySize = MAX_INV_SIZE - INITIAL_INVENTORY_SIZE;
barWithdrawCount = inventorySize - (inventorySize % product.getBarCount());
initialSmithingXp = getAccurateXpForLevel(Skill.SMITHING.getIndex());
startTime = System.currentTimeMillis();
}
@Override
public int main() {
playerX = getX();
playerY = getY();
if (getInventoryCount(bar.id) < product.barCount) {
return bank();
}
return smith();
}
@Override
public void onServerMessage(final String message) {
if (message.startsWith("hammer", 4)) {
barsSmithed += product.barCount;
if (barsRemaining >= product.barCount) {
barsRemaining -= product.barCount;
}
optionMenuTimeout = System.currentTimeMillis() + HAMMERING_DELAY;
} else if (message.endsWith("shut") || message.endsWith("open")) {
doorOpenTimeout = System.currentTimeMillis() + TIMEOUT_ONE_TICK;
} else {
super.onServerMessage(message);
}
}
private int bank() {
if (Area.BANK.contains(playerX, playerY)) {
if (!isBanking()) {
return openBank();
}
if (System.currentTimeMillis() <= bankWithdrawTimeout) {
return 0;
}
if (getInventoryCount() == INITIAL_INVENTORY_SIZE) {
if (bankCount(bar.id) < product.barCount) {
return exit("Out of bars.");
}
barsRemaining = bankCount(bar.id);
withdraw(bar.id, barWithdrawCount);
bankWithdrawTimeout = System.currentTimeMillis() + TIMEOUT_THREE_SECONDS;
return 0;
}
if (System.currentTimeMillis() <= bankDepositTimeout) {
return 0;
}
final int itemId = getInventoryId(INITIAL_INVENTORY_SIZE);
final int itemCount = getInventoryCount(itemId);
deposit(itemId, itemCount);
bankDepositTimeout = System.currentTimeMillis() + TIMEOUT_THREE_SECONDS;
return 0;
}
if (Area.ANVIL_HOUSE.contains(playerX, playerY)) {
if (getWallObjectIdFromCoords(Object.ANVIL_DOOR.coordinate.getX(), Object.ANVIL_DOOR.coordinate.getY()) == Object.ANVIL_DOOR.id) {
if (System.currentTimeMillis() <= doorOpenTimeout) {
return 0;
}
atWallObject(Object.ANVIL_DOOR.coordinate.getX(), Object.ANVIL_DOOR.coordinate.getY());
doorOpenTimeout = System.currentTimeMillis() + TIMEOUT_ONE_SECOND;
return 0;
}
walkTo(Object.BANK_DOORS.coordinate.getX(), Object.BANK_DOORS.coordinate.getY());
return SLEEP_ONE_TICK;
}
if (getObjectIdFromCoords(Object.BANK_DOORS.coordinate.getX(), Object.BANK_DOORS.coordinate.getY()) == Object.BANK_DOORS.id) {
if (System.currentTimeMillis() <= doorOpenTimeout) {
return 0;
}
atObject(Object.BANK_DOORS.coordinate.getX(), Object.BANK_DOORS.coordinate.getY());
doorOpenTimeout = System.currentTimeMillis() + TIMEOUT_ONE_SECOND;
return 0;
}
walkTo(Object.BANK_DOORS.coordinate.getX(), Object.BANK_DOORS.coordinate.getY() - 1);
return SLEEP_ONE_TICK;
}
private int smith() {
if (Area.ANVIL_HOUSE.contains(playerX, playerY)) {
if (getFatigue() >= MAXIMUM_FATIGUE) {
return sleep();
}
if (isQuestMenu()) {
int index;
for (final String menuOption : product.getMenuOptions()) {
index = getMenuIndex(menuOption);
if (index != -1) {
answer(index);
optionMenuTimeout = System.currentTimeMillis() + TIMEOUT_TWO_SECONDS;
return 0;
}
}
return SLEEP_ONE_SECOND;
}
if (System.currentTimeMillis() <= optionMenuTimeout) {
return 0;
}
if (playerX != Object.ANVIL.coordinate.getX() ||
playerY != Object.ANVIL.coordinate.getY() - 1) {
walkTo(Object.ANVIL.coordinate.getX(), Object.ANVIL.coordinate.getY() - 1);
return SLEEP_ONE_TICK;
}
bot.displayMessage("@gre@Hammering...");
final Coordinate anvil = Object.ANVIL.getCoordinate();
useWithObject(INITIAL_INVENTORY_SIZE, anvil.getX(), anvil.getY());
optionMenuTimeout = System.currentTimeMillis() + TIMEOUT_TWO_SECONDS;
return 0;
}
if (Area.BANK.contains(playerX, playerY)) {
if (getObjectIdFromCoords(Object.BANK_DOORS.coordinate.getX(), Object.BANK_DOORS.coordinate.getY()) == Object.BANK_DOORS.id) {
if (System.currentTimeMillis() <= doorOpenTimeout) {
return 0;
}
atObject(Object.BANK_DOORS.coordinate.getX(), Object.BANK_DOORS.coordinate.getY());
doorOpenTimeout = System.currentTimeMillis() + TIMEOUT_ONE_SECOND;
return 0;
}
walkTo(Object.ANVIL_DOOR.coordinate.getX(), Object.ANVIL_DOOR.coordinate.getY());
return SLEEP_ONE_TICK;
}
if (getWallObjectIdFromCoords(Object.ANVIL_DOOR.coordinate.getX(), Object.ANVIL_DOOR.coordinate.getY()) == Object.ANVIL_DOOR.id) {
if (System.currentTimeMillis() <= doorOpenTimeout) {
return 0;
}
atWallObject(Object.ANVIL_DOOR.coordinate.getX(), Object.ANVIL_DOOR.coordinate.getY());
doorOpenTimeout = System.currentTimeMillis() + TIMEOUT_ONE_SECOND;
return 0;
}
walkTo(Object.ANVIL_DOOR.coordinate.getX() - 1, Object.ANVIL_DOOR.coordinate.getY());
return SLEEP_ONE_TICK;
}
@Override
public void paint() {
int y = PAINT_OFFSET_Y;
drawString("@yel@Varrock West Smither", PAINT_OFFSET_X, y, 1, 0);
drawString(String.format("@yel@Runtime: @whi@%s", toDuration(startTime)),
PAINT_OFFSET_X, y += PAINT_OFFSET_Y_INCREMENT, 1, 0);
final double xpGained = getAccurateXpForLevel(Skill.SMITHING.getIndex()) - initialSmithingXp;
drawString(String.format("@yel@Xp: @whi@%s @cya@(@whi@%s xp@cya@/@whi@hr@cya@)",
DECIMAL_FORMAT.format(xpGained), toUnitsPerHour((int) xpGained, startTime)),
PAINT_OFFSET_X, y += PAINT_OFFSET_Y_INCREMENT * 2, 1, 0);
drawString(String.format("@yel@%s: @whi@%d @cya@(@whi@%s bars@cya@/@whi@hr@cya@)",
bar, barsSmithed, toUnitsPerHour(barsSmithed, startTime)),
PAINT_OFFSET_X, y += PAINT_OFFSET_Y_INCREMENT, 1, 0);
drawString(String.format("@yel@Remaining: @whi@%d", barsRemaining),
PAINT_OFFSET_X, y += PAINT_OFFSET_Y_INCREMENT * 2, 1, 0);
drawString(String.format("@yel@Time remaining: @whi@%s",
toTimeToCompletion(barsSmithed, barsRemaining, startTime)),
PAINT_OFFSET_X, y + PAINT_OFFSET_Y_INCREMENT, 1, 0);
}
private enum Bar {
BRONZE(169, "Bronze"),
IRON(170, "Iron"),
STEEL(171, "Steel"),
MITHRIL(173, "Mithril"),
ADAMANTITE(174, "Adamantite"),
RUNITE(408, "Runite");
private final int id;
private final String name;
Bar(final int id, final String name) {
this.id = id;
this.name = name;
}
public int getId() {
return id;
}
@Override
public String toString() {
return name;
}
}
private enum Product {
DAGGER(1, new String[]{"Make Weapon", "Dagger"}),
THROWING_KNIFE(1, new String[]{"Make Weapon", "Throwing Knife"}),
SHORT_SWORD(1, new String[]{"Make Weapon", "Sword", "Short sword"}),
LONG_SWORD(2, new String[]{"Make Weapon", "Sword", "Long sword (2 bars)"}),
SCIMITAR(2, new String[]{"Make Weapon", "Sword", "Scimitar (2 bars)"}),
TWO_HANDED_SWORD(3, new String[]{"Make Weapon", "Sword", "2-handed sword (3 bars)"}),
HATCHET(1, new String[]{"Make Weapon", "Axe", "Hatchet"}),
BATTLE_AXE(3, new String[]{"Make Weapon", "Axe", "Battle Axe (3 bars)"}),
MACE(1, new String[]{"Make Weapon", "Mace"}),
MEDIUM_HELMET(1, new String[]{"Make Armour", "Helmet", "Medium Helmet"}),
LARGE_HELMET(2, new String[]{"Make Armour", "Helmet", "Large Helmet (2 bars)"}),
SQUARE_SHIELD(2, new String[]{"Make Armour", "Shield", "Square Shield (2 bars)"}),
KITE_SHIELD(3, new String[]{"Make Armour", "Shield", "Kite Shield (3 bars)"}),
CHAIN_MAIL_BODY(3, new String[]{"Make Armour", "Armour", "Chain mail body (3 bars)"}),
PLATE_MAIL_BODY(5, new String[]{"Make Armour", "Armour", "Plate mail body (5 bars)"}),
PLATE_MAIL_LEGS(3, new String[]{"Make Armour", "Armour", "Plate mail legs (3 bars)"}),
PLATED_SKIRT(3, new String[]{"Make Armour", "Armour", "Plated Skirt (3 bars)"}),
ARROW_HEADS(1, new String[]{"Make Missile Heads", "Make Arrow Heads."}),
BRONZE_WIRE(1, new String[]{"Make Craft Item", "Bronze Wire(1 bar)"}),
NAILS(1, new String[]{"Make Nails"});
private final int barCount;
private final String[] menuOptions;
Product(final int barCount, final String[] menuOptions) {
this.barCount = barCount;
this.menuOptions = menuOptions;
}
public int getBarCount() {
return barCount;
}
public String[] getMenuOptions() {
return menuOptions;
}
}
private enum Area implements RSArea {
BANK(new Coordinate(147, 498), new Coordinate(153, 506)),
ANVIL_HOUSE(new Coordinate(145, 510), new Coordinate(148, 516));
private final Coordinate lowerBoundingCoordinate;
private final Coordinate upperBoundingCoordinate;
Area(final Coordinate lowerBoundingCoordinate, final Coordinate upperBoundingCoordinate) {
this.lowerBoundingCoordinate = lowerBoundingCoordinate;
this.upperBoundingCoordinate = upperBoundingCoordinate;
}
public Coordinate getLowerBoundingCoordinate() {
return lowerBoundingCoordinate;
}
public Coordinate getUpperBoundingCoordinate() {
return upperBoundingCoordinate;
}
}
private enum Object implements RSObject {
BANK_DOORS(64, new Coordinate(150, 507)),
ANVIL_DOOR(2, new Coordinate(149, 512)),
ANVIL(50, new Coordinate(148, 513));
private final int id;
private final Coordinate coordinate;
Object(final int id, final Coordinate coordinate) {
this.id = id;
this.coordinate = coordinate;
}
public int getId() {
return id;
}
public Coordinate getCoordinate() {
return coordinate;
}
}
}