-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathAA_VarrockEastMiner.java
More file actions
453 lines (368 loc) · 11.1 KB
/
AA_VarrockEastMiner.java
File metadata and controls
453 lines (368 loc) · 11.1 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
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
/**
* Mines iron, copper, tin at Varrock East Quarry.
* <p>
* Requirements:
* Start at Varrock East with sleeping bag and pickaxe.
* <p>
* Parameters:
* -o,--ore <iron|tin|copper>
* -e,--equal
* -p,--powermine
* <p>
*
* @Author Chomp
*/
public class AA_VarrockEastMiner extends AA_Script {
private static final Coordinate COORDINATE_LOAD_BANK = new Coordinate(77, 544);
private static final Coordinate COORDINATE_LOAD_QUARRY = new Coordinate(75, 536);
private static final int SKILL_MINING_INDEX = 14;
private static final int MAXIMUM_DISTANCE_FROM_OBJECT = 18;
private static final int MAXIMUM_FATIGUE = 99;
private static final int INITIAL_INVENTORY_SIZE = 2;
private long startTime;
private Coordinate adjacentCoordinate;
private RSObject[] rocks;
private RSObject currentRock;
private RSObject previousRock;
private Pickaxe pickaxe;
private Ore ore;
private double initialMiningXp;
private long clickTimeout;
private long previousRockTimeout;
private long closeBankTimeout;
private int playerX;
private int playerY;
private int oresMined;
private boolean idle;
private boolean powermine;
private boolean equal;
public AA_VarrockEastMiner(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 "-o":
case "--ore":
ore = Ore.valueOf(args[++i].toUpperCase());
break;
case "-e":
case "--equal":
equal = true;
break;
case "-p":
case "--power":
case "--powermine":
powermine = true;
break;
default:
throw new IllegalArgumentException("Error: malformed parameters. Try again ...");
}
}
if (ore == Ore.IRON && equal) {
throw new IllegalArgumentException("Error: equal option is invalid with iron ore type.");
}
if (powermine && equal) {
throw new IllegalArgumentException("Error: equal option is invalid with powermining option.");
}
if (!hasInventoryItem(ITEM_ID_SLEEPING_BAG)) {
throw new IllegalStateException("Sleeping bag missing from inventory.");
}
for (final Pickaxe pickaxe : Pickaxe.values()) {
if (hasInventoryItem(pickaxe.id)) {
this.pickaxe = pickaxe;
break;
}
}
if (pickaxe == null) {
throw new IllegalStateException("Pickaxe missing from inventory");
}
switch (ore) {
case TIN:
rocks = TinRock.values();
adjacentCoordinate = TinRock.COORDINATE_ADJACENT;
break;
case COPPER:
rocks = CopperRock.values();
adjacentCoordinate = CopperRock.COORDINATE_ADJACENT;
break;
case IRON:
rocks = IronRock.values();
adjacentCoordinate = IronRock.COORDINATE_ADJACENT;
break;
}
initialMiningXp = getAccurateXpForLevel(SKILL_MINING_INDEX);
startTime = System.currentTimeMillis();
}
@Override
public int main() {
playerX = getX();
playerY = getY();
if (idle) {
return idle();
}
if (isBanking() || (getInventoryCount() == MAX_INV_SIZE && !powermine)) {
return bank();
}
return mine();
}
@Override
public void onServerMessage(final String message) {
if (message.startsWith("You only") || message.startsWith("There is")) {
clickTimeout = 0;
} else if (message.startsWith("You manage") || message.startsWith("You just")) {
oresMined++;
clickTimeout = 0;
previousRock = currentRock;
previousRockTimeout = System.currentTimeMillis() + TIMEOUT_ONE_SECOND;
} else if (message.endsWith("area")) {
idle = true;
} else {
super.onServerMessage(message);
}
}
private int idle() {
switch (ore) {
case TIN:
if (playerX == adjacentCoordinate.getX() &&
playerY == adjacentCoordinate.getY() - 1) {
idle = false;
return 0;
}
walkTo(adjacentCoordinate.getX(), adjacentCoordinate.getY() - 1);
return SLEEP_ONE_TICK;
case COPPER:
if (playerX == adjacentCoordinate.getX() - 1 &&
playerY == adjacentCoordinate.getY()) {
idle = false;
return 0;
}
walkTo(adjacentCoordinate.getX() - 1, adjacentCoordinate.getY());
return SLEEP_ONE_TICK;
case IRON:
if (playerX == adjacentCoordinate.getX() &&
playerY == adjacentCoordinate.getY() + 1) {
idle = false;
return 0;
}
walkTo(adjacentCoordinate.getX(), adjacentCoordinate.getY() + 1);
return SLEEP_ONE_TICK;
default:
throw new IllegalStateException("Invalid ore type");
}
}
private int bank() {
if (Area.BANK.contains(playerX, playerY)) {
if (!isBanking()) {
return openBank();
}
if (getInventoryCount() == INITIAL_INVENTORY_SIZE) {
if (System.currentTimeMillis() <= closeBankTimeout) {
return 0;
}
if (equal) {
switchOres();
}
closeBank();
closeBankTimeout = System.currentTimeMillis() + TIMEOUT_TWO_SECONDS;
return 0;
}
final int itemId = getInventoryId(INITIAL_INVENTORY_SIZE);
deposit(itemId, MAX_INV_SIZE);
return SLEEP_ONE_TICK;
}
if (playerY <= COORDINATE_LOAD_BANK.getY()) {
if (distanceTo(Object.BANK_DOORS.coordinate.getX(), Object.BANK_DOORS.coordinate.getY()) <= MAXIMUM_DISTANCE_FROM_OBJECT) {
if (getObjectIdFromCoords(Object.BANK_DOORS.coordinate.getX(), Object.BANK_DOORS.coordinate.getY()) == Object.BANK_DOORS.id) {
atObject(Object.BANK_DOORS.coordinate.getX(), Object.BANK_DOORS.coordinate.getY());
return SLEEP_ONE_SECOND;
}
walkTo(Object.BANK_DOORS.coordinate.getX(), Object.BANK_DOORS.coordinate.getY() + 1);
return SLEEP_ONE_TICK;
}
walkTo(Object.BANK_DOORS.coordinate.getX(), Object.BANK_DOORS.coordinate.getY());
if (getFatigue() != 0 && isWalking()) {
return sleep();
}
return SLEEP_ONE_TICK;
}
walkTo(COORDINATE_LOAD_BANK.getX(), COORDINATE_LOAD_BANK.getY());
return SLEEP_ONE_TICK;
}
private int mine() {
if (playerY >= COORDINATE_LOAD_QUARRY.getY()) {
if (getFatigue() >= MAXIMUM_FATIGUE) {
return sleep();
}
if (playerX != adjacentCoordinate.getX() || playerY != adjacentCoordinate.getY()) {
walkTo(adjacentCoordinate.getX(), adjacentCoordinate.getY());
return SLEEP_ONE_TICK;
}
if (clickTimeout != 0 && System.currentTimeMillis() <= clickTimeout) {
return 0;
}
for (final RSObject rock : rocks) {
if (getObjectIdFromCoords(rock.getCoordinate().getX(), rock.getCoordinate().getY()) != rock.getId() ||
(previousRock == rock && System.currentTimeMillis() <= previousRockTimeout)) {
continue;
}
currentRock = rock;
final Coordinate coord = rock.getCoordinate();
useObject1(coord.getX(), coord.getY());
clickTimeout = System.currentTimeMillis() + TIMEOUT_FIVE_SECONDS;
break;
}
return 0;
}
if (Area.BANK.contains(playerX, playerY) &&
getObjectIdFromCoords(Object.BANK_DOORS.coordinate.getX(), Object.BANK_DOORS.coordinate.getY()) == Object.BANK_DOORS.id) {
atObject(Object.BANK_DOORS.coordinate.getX(), Object.BANK_DOORS.coordinate.getY());
return SLEEP_ONE_SECOND;
}
walkTo(COORDINATE_LOAD_QUARRY.getX(), COORDINATE_LOAD_QUARRY.getY());
return SLEEP_ONE_TICK;
}
private void switchOres() {
switch (ore) {
case TIN:
ore = Ore.COPPER;
rocks = CopperRock.values();
adjacentCoordinate = CopperRock.COORDINATE_ADJACENT;
break;
case COPPER:
ore = Ore.TIN;
rocks = TinRock.values();
adjacentCoordinate = TinRock.COORDINATE_ADJACENT;
break;
default:
throw new IllegalStateException("Switching ores only supported for tin and copper");
}
}
@Override
public void paint() {
int y = PAINT_OFFSET_Y;
drawString("@yel@Varrock East Miner", 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_MINING_INDEX) - initialMiningXp;
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@%s @cya@(@whi@%s ore@cya@/@whi@hr@cya@)",
ore, oresMined, toUnitsPerHour(oresMined, startTime)),
PAINT_OFFSET_X, y + PAINT_OFFSET_Y_INCREMENT, 1, 0);
}
private enum Pickaxe {
RUNE(1262),
ADAMANTITE(1261),
MITHRIL(1260),
STEEL(1259),
IRON(1258),
BRONZE(156);
private final int id;
Pickaxe(final int id) {
this.id = id;
}
}
private enum Ore {
TIN("Tin"),
COPPER("Copper"),
IRON("Iron");
private final String name;
Ore(final String name) {
this.name = name;
}
@Override
public String toString() {
return name;
}
}
private enum IronRock implements RSObject {
NORTH(102, new Coordinate(75, 543)),
NORTH_WEST(102, new Coordinate(76, 543)),
WEST(103, new Coordinate(76, 544));
private static final Coordinate COORDINATE_ADJACENT = new Coordinate(75, 544);
private final int id;
private final Coordinate coordinate;
IronRock(final int id, final Coordinate coordinate) {
this.id = id;
this.coordinate = coordinate;
}
public int getId() {
return id;
}
public Coordinate getCoordinate() {
return coordinate;
}
}
private enum TinRock implements RSObject {
EAST(105, new Coordinate(78, 545)),
SOUTH_EAST(105, new Coordinate(78, 546)),
SOUTH(105, new Coordinate(79, 546));
private static final Coordinate COORDINATE_ADJACENT = new Coordinate(79, 545);
private final int id;
private final Coordinate coordinate;
TinRock(final int id, final Coordinate coordinate) {
this.id = id;
this.coordinate = coordinate;
}
public int getId() {
return id;
}
public Coordinate getCoordinate() {
return coordinate;
}
}
private enum CopperRock implements RSObject {
NORTH(101, new Coordinate(73, 547)),
EAST(101, new Coordinate(72, 549)),
SOUTH(101, new Coordinate(73, 549)),
WEST(101, new Coordinate(74, 549));
private static final Coordinate COORDINATE_ADJACENT = new Coordinate(73, 548);
private final int id;
private final Coordinate coordinate;
CopperRock(final int id, final Coordinate coordinate) {
this.id = id;
this.coordinate = coordinate;
}
public int getId() {
return id;
}
public Coordinate getCoordinate() {
return coordinate;
}
}
private enum Area implements RSArea {
BANK(new Coordinate(98, 510), new Coordinate(106, 515));
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(102, 509));
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;
}
}
}