-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathAA_ArdougneIronMiner.java
More file actions
416 lines (323 loc) · 10.4 KB
/
AA_ArdougneIronMiner.java
File metadata and controls
416 lines (323 loc) · 10.4 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
import java.awt.*;
/**
* Mines iron ore south of Ardougne and banks at the south bank.
* Start script at the mine or at the bank.
* <p>
* Parameters:
* p - enable powermining (no banking)
* l - enable looting iron ore off the ground
* s - use the south spot (3 rocks)
* <p>
*
* @Author Chomp
*/
public class AA_ArdougneIronMiner extends AA_Script {
private static final Coordinate COORDINATE_LOAD = new Coordinate(576, 624);
private static final int[] ITEM_IDS_PICKAXE = new int[]{1262, 1261, 1260, 1259, 1258, 156};
private static final int ITEM_ID_IRON_ORE = 151;
private static final int MAX_FATIGUE = 99;
private static final int MAX_DIST = 12;
private static final int INIT_INV_SIZE = 2;
private RSObject[] rocks;
private Coordinate standCoord;
private RSObject currentRock;
private RSObject previousRock;
private long startTime;
private double initialMiningXp;
private double swingAttempts;
private long mineTimeout;
private long depositTimeout;
private long previousRockTimeout;
private final int[] ironOre = new int[]{-1, -1};
private int playerX;
private int playerY;
private int success;
private int fail;
private boolean idle;
private boolean powerMining;
private boolean looting;
private boolean banking;
public AA_ArdougneIronMiner(final Extension ex) {
super(ex);
}
@Override
public void init(final String parameters) {
if (getInventoryIndex(ITEM_ID_SLEEPING_BAG) != 0) {
throw new IllegalStateException("Sleeping bag missing from inventory slot 1.");
}
if (bot.getInventorySize() < INIT_INV_SIZE || !inArray(ITEM_IDS_PICKAXE, bot.getInventoryId(1))) {
throw new IllegalStateException("Pickaxe missing from inventory slot 2.");
}
if (parameters.contains("s")) {
rocks = SouthRock.values();
standCoord = SouthRock.COORDINATE_STAND;
} else {
rocks = NorthRock.values();
standCoord = NorthRock.COORDINATE_STAND;
}
looting = parameters.contains("l");
banking = !(powerMining = parameters.contains("p")) && isInventoryFull();
initialMiningXp = bot.getExperience(Skill.MINING.getIndex());
startTime = System.currentTimeMillis();
}
@Override
public int main() {
playerX = getX();
playerY = getY();
return banking ? bank() : mine();
}
@Override
public void onServerMessage(final String message) {
if (message.startsWith("swing", 4)) {
swingAttempts++;
} else if (message.startsWith("scratching", 20)) {
fail++;
mineTimeout = 0L;
} else if (message.startsWith("no ore", 19)) {
fail++;
mineTimeout = 0L;
previousRock = currentRock;
previousRockTimeout = System.currentTimeMillis() + TIMEOUT_TWO_SECONDS;
} else if (message.endsWith("ore")) {
success++;
mineTimeout = 0L;
previousRock = currentRock;
previousRockTimeout = System.currentTimeMillis() + TIMEOUT_TWO_SECONDS;
} else if (message.startsWith("found", 9)) {
success++;
mineTimeout = 0L;
} else if (message.endsWith("area")) {
idle = true;
} else {
super.onServerMessage(message);
}
}
private int bank() {
if (Area.BANK.contains(playerX, playerY)) {
if (bot.getInventorySize() == INIT_INV_SIZE) {
banking = false;
return 0;
}
if (!bot.isBankVisible()) {
return openBank();
}
for (final UncutGem uncutGem : UncutGem.VALUES) {
if (!hasInventoryItem(uncutGem.id)) {
continue;
}
if (System.currentTimeMillis() <= uncutGem.depositTimeout) {
return 0;
}
deposit(uncutGem.id, MAX_INV_SIZE);
uncutGem.depositTimeout = System.currentTimeMillis() + TIMEOUT_THREE_SECONDS;
return 0;
}
if (System.currentTimeMillis() <= depositTimeout) {
return 0;
}
deposit(bot.getInventoryId(INIT_INV_SIZE), MAX_INV_SIZE);
depositTimeout = System.currentTimeMillis() + TIMEOUT_THREE_SECONDS;
return 0;
}
if (playerY <= COORDINATE_LOAD.getY()) {
final Coordinate doors = Object.BANK_DOORS.getCoordinate();
if (distanceTo(doors.getX(), doors.getY()) <= MAX_DIST) {
if (isPresent(Object.BANK_DOORS)) {
atObject(doors.getX(), doors.getY());
return SLEEP_ONE_SECOND;
}
walkTo(doors.getX() + 1, doors.getY() + 1);
return SLEEP_ONE_TICK;
}
walkTo(doors.getX(), doors.getY());
return SLEEP_ONE_TICK;
}
walkTo(COORDINATE_LOAD.getX(), COORDINATE_LOAD.getY());
return SLEEP_ONE_TICK;
}
private int mine() {
if (playerY >= COORDINATE_LOAD.getY()) {
if (!powerMining && isInventoryFull()) {
banking = true;
return 0;
}
if (idle) {
return idle();
}
if (looting && !isInventoryFull()) {
updateNearestIronOre();
if (ironOre[0] != -1) {
pickupItem(ITEM_ID_IRON_ORE, ironOre[0], ironOre[1]);
return SLEEP_ONE_TICK;
}
}
if (playerX != standCoord.getX() || playerY != standCoord.getY()) {
walkTo(standCoord.getX(), standCoord.getY());
return SLEEP_ONE_TICK;
}
if (getFatigue() >= MAX_FATIGUE) {
if (bot.isHeadIconVisible(bot.getPlayer())) {
return SLEEP_ONE_TICK;
}
return sleep();
}
if (mineTimeout != 0L && System.currentTimeMillis() <= mineTimeout) {
return 0;
}
for (final RSObject rock : rocks) {
if (!isPresent(rock) || (previousRock == rock && System.currentTimeMillis() <= previousRockTimeout)) {
continue;
}
currentRock = rock;
useObject1(rock.getCoordinate().getX(), rock.getCoordinate().getY());
mineTimeout = System.currentTimeMillis() + TIMEOUT_FIVE_SECONDS;
bot.displayMessage("@dre@Swing ...");
break;
}
return 0;
}
if (Area.BANK.contains(playerX, playerY) && isPresent(Object.BANK_DOORS)) {
atObject(Object.BANK_DOORS.coordinate.getX(), Object.BANK_DOORS.coordinate.getY());
return SLEEP_ONE_SECOND;
}
walkTo(COORDINATE_LOAD.getX(), COORDINATE_LOAD.getY());
return SLEEP_ONE_TICK;
}
private boolean isPresent(final RSObject o) {
return getObjectIdFromCoords(o.getCoordinate().getX(), o.getCoordinate().getY()) == o.getId();
}
private int idle() {
if (playerX != standCoord.getX() || playerY != standCoord.getY()) {
idle = false;
return 0;
}
walkTo(standCoord.getX(), standCoord.getY() - 3);
return SLEEP_ONE_TICK;
}
private void updateNearestIronOre() {
ironOre[0] = -1;
int currentDistance = Integer.MAX_VALUE;
for (int i = 0; i < bot.getGroundItemCount(); i++) {
final int itemId = bot.getGroundItemId(i);
if (itemId != ITEM_ID_IRON_ORE) {
continue;
}
final int x = getItemX(i);
final int y = getItemY(i);
if (!Area.MINE.contains(x, y)) {
continue;
}
final int distance = distanceTo(x, y);
if (currentDistance <= distance) {
continue;
}
currentDistance = distance;
ironOre[0] = x;
ironOre[1] = y;
}
}
@Override
public void paint() {
int y = PAINT_OFFSET_Y;
bot.drawString("@yel@Ardougne Iron Miner", PAINT_OFFSET_X, y, 1, 0);
bot.drawString(String.format("@yel@State: @whi@%s", powerMining ? "Powermining" : banking ? "Banking" : "Mining"),
PAINT_OFFSET_X, y += PAINT_OFFSET_Y_INCREMENT, 1, 0);
bot.drawString(String.format("@yel@Runtime: @whi@%s", toDuration(startTime)),
PAINT_OFFSET_X, y += PAINT_OFFSET_Y_INCREMENT, 1, 0);
bot.drawString("", PAINT_OFFSET_X, y += PAINT_OFFSET_Y_INCREMENT, 1, 0);
final double xpGained = bot.getExperience(Skill.MINING.getIndex()) - initialMiningXp;
bot.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, 1, 0);
bot.drawString(String.format("@yel@Iron ore: @whi@%s @cya@(@whi@%s ores@cya@/ @whi@hr@cya@)",
success, toUnitsPerHour(success, startTime)),
PAINT_OFFSET_X, y += PAINT_OFFSET_Y_INCREMENT, 1, 0);
if (swingAttempts > 0) {
bot.drawString("", PAINT_OFFSET_X, y += PAINT_OFFSET_Y_INCREMENT, 1, 0);
bot.drawString(String.format("@gr1@Success Rate: @whi@%.2f%%", (success / swingAttempts) * 100),
PAINT_OFFSET_X, y += PAINT_OFFSET_Y_INCREMENT, 1, 0);
bot.drawString(String.format("Fail Rate: @whi@%.2f%%", (fail / swingAttempts) * 100),
PAINT_OFFSET_X, y + PAINT_OFFSET_Y_INCREMENT, 1, 0xE0142D);
}
}
private enum Area implements RSArea {
BANK(new Coordinate(551, 609), new Coordinate(554, 616)),
MINE(new Coordinate(615, 654), new Coordinate(620, 659));
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(550, 612));
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;
}
}
private enum NorthRock implements RSObject {
NORTH_WEST(102, new Coordinate(618, 655)),
NORTH(102, new Coordinate(617, 655)),
EAST(102, new Coordinate(616, 656)),
SOUTH_EAST(102, new Coordinate(616, 657));
private static final Coordinate COORDINATE_STAND = new Coordinate(617, 656);
private final int id;
private final Coordinate coordinate;
NorthRock(final int id, final Coordinate coordinate) {
this.id = id;
this.coordinate = coordinate;
}
public int getId() {
return id;
}
public Coordinate getCoordinate() {
return coordinate;
}
}
private enum SouthRock implements RSObject {
WEST(102, new Coordinate(619, 657)),
SOUTH(102, new Coordinate(618, 658)),
SOUTH_EAST(102, new Coordinate(617, 658));
private static final Coordinate COORDINATE_STAND = new Coordinate(618, 657);
private final int id;
private final Coordinate coordinate;
SouthRock(final int id, final Coordinate coordinate) {
this.id = id;
this.coordinate = coordinate;
}
public int getId() {
return id;
}
public Coordinate getCoordinate() {
return coordinate;
}
}
private enum UncutGem {
SAPPHIRE(160),
EMERALD(159),
RUBY(158),
DIAMOND(157);
private static final UncutGem[] VALUES = UncutGem.values();
private final int id;
private long depositTimeout;
UncutGem(final int id) {
this.id = id;
}
}
}