-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathAA_DarkWizardTower.java
More file actions
365 lines (283 loc) Β· 8.92 KB
/
AA_DarkWizardTower.java
File metadata and controls
365 lines (283 loc) Β· 8.92 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
/**
* Kills Darkwizards and collects runes/coins at the Dark Wizard Tower.
* Start at the tower with sleeping bag in inventory.
* <p>
* Optional Parameter:
* --no-doors (Disables closing doors)
* -f,--fightmode <controlled|strength|attack|defense>
* <p>
*
* @Author Chomp
*/
public class AA_DarkWizardTower extends AA_Script {
private static final int[] NPC_IDS_DARK_WIZARD = new int[]{57, 60};
private static final int[] ITEM_IDS_LOOT = new int[]{10, 31, 32, 33, 34, 35, 36, 38, 40, 41, 42, 46, 619};
private static final int MAXIMUM_FATIGUE = 99;
private final int[] groundItem = new int[4];
private long startTime;
private double initialCombatXp;
private long doorTimeout;
private long ladderTimeout;
private int playerX;
private int playerY;
private boolean checkTopFloor;
private boolean doors = true;
public AA_DarkWizardTower(final Extension extension) {
super(extension);
}
@Override
public void init(final String parameters) {
if (!parameters.isEmpty()) {
final String[] args = parameters.split(" ");
for (int i = 0; i < args.length; i++) {
switch (args[i].toLowerCase()) {
case "-f":
case "--fightmode":
combatStyle = CombatStyle.valueOf(args[++i].toUpperCase());
break;
case "--no-doors":
doors = false;
break;
default:
throw new IllegalArgumentException("Error: malformed parameters. Try again ...");
}
}
}
if (!hasInventoryItem(ITEM_ID_SLEEPING_BAG)) {
throw new IllegalStateException("Sleeping bag missing from inventory.");
}
setCombatStyle(combatStyle.getIndex());
initialCombatXp = getTotalCombatXp();
startTime = System.currentTimeMillis();
}
@Override
public int main() {
if (bot.getCombatStyle() != combatStyle.getIndex()) setCombatStyle(combatStyle.getIndex());
if (inCombat()) {
return 0;
}
if (getFatigue() >= MAXIMUM_FATIGUE) {
return sleep();
}
playerX = getX();
playerY = getY();
return Floor.F2.contains(playerX, playerY) || Floor.F3.contains(playerX, playerY) ?
handleF2F3() :
handleF1();
}
@Override
public void onServerMessage(final String message) {
if (message.endsWith("ladder")) {
ladderTimeout = System.currentTimeMillis() + TIMEOUT_ONE_TICK;
} else if (message.endsWith("open") || message.endsWith("shut")) {
doorTimeout = System.currentTimeMillis() + TIMEOUT_ONE_TICK;
} else {
super.onServerMessage(message);
}
}
private int handleF2F3() {
final int[] wizard = getNpcById(NPC_IDS_DARK_WIZARD);
if (wizard[0] != -1) {
attackNpc(wizard[0]);
return SLEEP_ONE_TICK;
}
updateGroundItem(false);
if (groundItem[0] != -1) {
pickupItem(groundItem[3], groundItem[1], groundItem[2]);
return SLEEP_ONE_TICK;
}
return nextFloor();
}
private int handleF1() {
final int[] wizard = getNpcById(NPC_IDS_DARK_WIZARD);
if (wizard[0] != -1) {
if (Floor.F1.contains(playerX, playerY) != Floor.F1.contains(wizard[1], wizard[2])) {
final Door door = getNearestDoorTo(wizard[1], wizard[2]);
final int doorX = door.coordinate.getX();
final int doorY = door.coordinate.getY();
if (getWallObjectIdFromCoords(doorX, doorY) == door.id) {
if (System.currentTimeMillis() <= doorTimeout) {
return 0;
}
atWallObject(doorX, doorY);
doorTimeout = System.currentTimeMillis() + TIMEOUT_FIVE_SECONDS;
return 0;
}
}
attackNpc(wizard[0]);
return SLEEP_ONE_TICK;
}
updateGroundItem(true);
if (groundItem[0] != -1) {
pickupItem(groundItem[3], groundItem[1], groundItem[2]);
return SLEEP_ONE_TICK;
}
if (!Floor.F1.contains(playerX, playerY)) {
return enterF1();
}
if (doors) {
for (final Door door : Door.DOORS) {
final int doorX = door.coordinate.getX();
final int doorY = door.coordinate.getY();
if (getWallObjectIdFromCoords(doorX, doorY) != door.id) {
if (System.currentTimeMillis() <= doorTimeout) {
return 0;
}
atWallObject2(doorX, doorY);
doorTimeout = System.currentTimeMillis() + TIMEOUT_FIVE_SECONDS;
return 0;
}
}
}
return nextFloor();
}
private void updateGroundItem(final boolean bottomFloor) {
groundItem[0] = -1;
int currentDistance = Integer.MAX_VALUE;
for (int index = 0; index < getGroundItemCount(); index++) {
final int groundItemId = getGroundItemId(index);
if (!inArray(ITEM_IDS_LOOT, groundItemId)) {
continue;
}
final int groundItemX = getItemX(index);
final int groundItemY = getItemY(index);
if (bottomFloor && !Floor.F1.contains(groundItemX, groundItemY)) {
continue;
}
final int distance = distanceTo(groundItemX, groundItemY);
if (distance < currentDistance) {
groundItem[0] = index;
groundItem[1] = groundItemX;
groundItem[2] = groundItemY;
groundItem[3] = groundItemId;
currentDistance = distance;
}
}
}
private int nextFloor() {
if (System.currentTimeMillis() <= ladderTimeout) {
return 0;
}
if (Floor.F1.contains(playerX, playerY)) {
checkTopFloor = true;
atObject(Ladder.F1_UP.coordinate.getX(),
Ladder.F1_UP.coordinate.getY());
} else if (Floor.F2.contains(playerX, playerY)) {
if (checkTopFloor) {
atObject(Ladder.F2_UP.coordinate.getX(),
Ladder.F2_UP.coordinate.getY());
} else {
atObject(Ladder.F2_DOWN.coordinate.getX(),
Ladder.F2_DOWN.coordinate.getY());
}
} else if (Floor.F3.contains(playerX, playerY)) {
checkTopFloor = false;
atObject(Ladder.F3_DOWN.coordinate.getX(),
Ladder.F3_DOWN.coordinate.getY());
} else {
return SLEEP_ONE_TICK;
}
ladderTimeout = System.currentTimeMillis() + TIMEOUT_TWO_SECONDS;
return 0;
}
private Door getNearestDoorTo(final int x, final int y) {
Door closestDoor = null;
int currentDistance = Integer.MAX_VALUE;
for (final Door door : Door.DOORS) {
final int distance = distanceTo(x, y, door.coordinate.getX(), door.coordinate.getY());
if (distance < currentDistance) {
currentDistance = distance;
closestDoor = door;
}
}
return closestDoor;
}
private int enterF1() {
final Door door = getNearestDoorTo(playerX, playerY);
final int doorX = door.coordinate.getX();
final int doorY = door.coordinate.getY();
if (getWallObjectIdFromCoords(doorX, doorY) != door.id) {
walkTo(doorX, doorY);
return SLEEP_ONE_TICK;
}
if (System.currentTimeMillis() <= doorTimeout) {
return 0;
}
atWallObject(doorX, doorY);
doorTimeout = System.currentTimeMillis() + TIMEOUT_FIVE_SECONDS;
return 0;
}
@Override
public void paint() {
int y = PAINT_OFFSET_Y;
drawString("@yel@Dark Wizard Tower", 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 = getTotalCombatXp() - initialCombatXp;
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);
}
private enum Floor implements RSArea {
F1(new Coordinate(360, 568), new Coordinate(363, 573)) {
public boolean contains(final int x, final int y) {
return super.contains(x, y) || ((x == 364 || x == 359) && y > 568 && y < 573);
}
},
F2(new Coordinate(360, 1512), new Coordinate(363, 1517)) {
public boolean contains(final int x, final int y) {
return super.contains(x, y) || ((x == 359 || x == 364) && y > 1513 && y < 1516);
}
},
F3(new Coordinate(360, 2457), new Coordinate(364, 2460));
private final Coordinate lowerBoundingCoordinate;
private final Coordinate upperBoundingCoordinate;
Floor(final Coordinate lowerBoundingCoordinate, final Coordinate upperBoundingCoordinate) {
this.lowerBoundingCoordinate = lowerBoundingCoordinate;
this.upperBoundingCoordinate = upperBoundingCoordinate;
}
public Coordinate getLowerBoundingCoordinate() {
return lowerBoundingCoordinate;
}
public Coordinate getUpperBoundingCoordinate() {
return upperBoundingCoordinate;
}
}
private enum Ladder implements RSObject {
F1_UP(5, new Coordinate(360, 570)),
F2_DOWN(6, new Coordinate(360, 1514)),
F2_UP(5, new Coordinate(363, 1514)),
F3_DOWN(6, new Coordinate(363, 2458));
private final int id;
private final Coordinate coordinate;
Ladder(final int id, final Coordinate coordinate) {
this.id = id;
this.coordinate = coordinate;
}
public int getId() {
return id;
}
public Coordinate getCoordinate() {
return coordinate;
}
}
private enum Door implements RSObject {
NE(2, new Coordinate(360, 568)),
NW(2, new Coordinate(364, 569)),
SE(2, new Coordinate(359, 572)),
SW(2, new Coordinate(363, 573));
private static final Door[] DOORS = Door.values();
private final int id;
private final Coordinate coordinate;
Door(final int id, final Coordinate coordinate) {
this.id = id;
this.coordinate = coordinate;
}
public int getId() {
return id;
}
public Coordinate getCoordinate() {
return coordinate;
}
}
}