-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathAA_ChaosDruidTower.java
More file actions
333 lines (253 loc) · 8.82 KB
/
AA_ChaosDruidTower.java
File metadata and controls
333 lines (253 loc) · 8.82 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
import java.util.HashMap;
import java.util.Map;
import java.util.TreeMap;
/**
* Kills Chaos Druids at the Chaos Druid Tower and banks loot at Ardougne North Bank.
* <p>
* Requirements:
* Start script at the Chaos Druid Tower or Ardougne North Bank with sleeping bag in inventory.
* <p>
* Optional Parameter
* <controlled|attack|strength|defense> (default strength)
* <p>
*
* @Author Chomp
*/
public class AA_ChaosDruidTower extends AA_Script {
private static final Coordinate COORDINATE_LOAD_BANK = new Coordinate(587, 592);
private static final Coordinate COORDINATE_LOAD_TOWER = new Coordinate(600, 591);
private static final int[] ITEM_IDS_LOOT = new int[]{
10, 33, 34, 35, 36, 40, 42,
157, 158, 159, 160, 165,
435, 436, 437, 438, 439, 440, 441, 442, 443, 464, 469,
526, 527, 1092, 1277};
private static final int[] ITEM_IDS_PREMIUM_LOOT = new int[]{438, 439, 441, 442, 443, 469, 526, 527, 1092, 1277};
private static final int NPC_ID_CHAOS_DRUID = 270;
private static final int NPC_XP_CHAOS_DRUID = 58;
private static final int MAXIMUM_FATIGUE = 99;
private static final int MAXIMUM_DISTANCE_FROM_OBJECT = 18;
private static final int MINIMUM_THIEVING = 46;
private final int[] loot = new int[3];
private final Map<Integer, Integer> premiumLoot = new TreeMap<>();
private final Map<Integer, Spawn> spawnMap = new HashMap<>();
private Coordinate nextRespawn;
private long startTime;
private double initialCombatXp;
private long towerDoorTimeout;
private int playerX;
private int playerY;
public AA_ChaosDruidTower(final Extension extension) {
super(extension);
}
@Override
public void init(final String parameters) {
if (getLevel(Skill.THIEVING.getIndex()) < MINIMUM_THIEVING) {
throw new IllegalStateException(String.format("You must have L%d+ thieving to use this script.", MINIMUM_THIEVING));
}
if (!hasInventoryItem(ITEM_ID_SLEEPING_BAG)) {
throw new IllegalStateException("Sleeping bag missing from inventory.");
}
if (!parameters.isEmpty()) combatStyle = CombatStyle.valueOf(parameters.toUpperCase());
setCombatStyle(combatStyle.getIndex());
initialCombatXp = getTotalCombatXp();
startTime = System.currentTimeMillis();
}
@Override
public int main() {
playerX = getX();
playerY = getY();
if (bot.getCombatStyle() != combatStyle.getIndex()) setCombatStyle(combatStyle.getIndex());
if (getInventoryCount() == MAX_INV_SIZE || isBanking()) {
return bank();
}
return kill();
}
@Override
public void onServerMessage(final String message) {
if (message.startsWith("fail", 4) || message.startsWith("go", 4)) {
towerDoorTimeout = 0L;
} else {
super.onServerMessage(message);
}
}
private int bank() {
if (Area.BANK.contains(playerX, playerY)) {
if (!isBanking()) {
return openBank();
}
for (int index = 0; index < getInventoryCount(); index++) {
final int itemId = getInventoryId(index);
if (!inArray(ITEM_IDS_LOOT, itemId)) {
continue;
}
deposit(itemId, getInventoryCount(itemId));
return SLEEP_ONE_TICK;
}
updateBankLoot();
closeBank();
return SLEEP_ONE_SECOND;
}
if (!Area.CHAOS_DRUIDS.contains(playerX, playerY)) {
if (playerY > COORDINATE_LOAD_BANK.getY()) {
walkTo(COORDINATE_LOAD_BANK.getX(), COORDINATE_LOAD_BANK.getY());
} else {
walkTo(Area.BANK.upperBoundingCoordinate.getX(), Area.BANK.lowerBoundingCoordinate.getY());
}
return SLEEP_ONE_TICK;
}
if (System.currentTimeMillis() <= towerDoorTimeout) {
return 0;
}
atWallObject(Object.TOWER_DOOR.coordinate.getX(), Object.TOWER_DOOR.coordinate.getY());
towerDoorTimeout = System.currentTimeMillis() + TIMEOUT_TWO_SECONDS;
return 0;
}
private int kill() {
if (Area.CHAOS_DRUIDS.contains(playerX, playerY)) {
if (inCombat()) {
return 0;
}
if (getFatigue() >= MAXIMUM_FATIGUE) {
return sleep();
}
final int[] druid = getNpcById(NPC_ID_CHAOS_DRUID);
if (druid[0] != -1) {
attackNpc(druid[0]);
return SLEEP_ONE_TICK;
}
updateLoot();
if (loot[0] != -1) {
pickupItem(loot[0], loot[1], loot[2]);
return SLEEP_ONE_TICK;
}
if (nextRespawn != null &&
(playerX != nextRespawn.getX() || playerY != nextRespawn.getY())) {
walkTo(nextRespawn.getX(), nextRespawn.getY());
return SLEEP_ONE_TICK;
}
return 0;
}
if (playerX >= COORDINATE_LOAD_TOWER.getX()) {
if (playerX == Object.TOWER_DOOR.coordinate.getX() && playerY == Object.TOWER_DOOR.coordinate.getY()) {
if (System.currentTimeMillis() <= towerDoorTimeout) {
return 0;
}
atWallObject2(Object.TOWER_DOOR.coordinate.getX(), Object.TOWER_DOOR.coordinate.getY());
towerDoorTimeout = System.currentTimeMillis() + TIMEOUT_TWO_SECONDS;
return 0;
}
walkTo(Object.TOWER_DOOR.coordinate.getX(), Object.TOWER_DOOR.coordinate.getY());
if (getFatigue() != 0 && isWalking()) {
return sleep();
}
return SLEEP_ONE_TICK;
}
walkTo(COORDINATE_LOAD_TOWER.getX(), COORDINATE_LOAD_TOWER.getY());
return SLEEP_ONE_TICK;
}
private void updateBankLoot() {
for (final int itemId : ITEM_IDS_PREMIUM_LOOT) {
final int bankCount = bankCount(itemId);
if (bankCount == 0) {
continue;
}
premiumLoot.put(itemId, bankCount);
}
}
private void updateLoot() {
loot[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 (!Area.CHAOS_DRUIDS.contains(groundItemX, groundItemY)) {
continue;
}
final int distance = distanceTo(groundItemX, groundItemY);
if (distance < currentDistance) {
loot[0] = groundItemId;
loot[1] = groundItemX;
loot[2] = groundItemY;
currentDistance = distance;
}
}
}
@Override
public void paint() {
int y = PAINT_OFFSET_Y;
drawString("@yel@Chaos Druid 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);
final int kills = (int) xpGained / NPC_XP_CHAOS_DRUID;
drawString(String.format("@yel@Kills: @whi@%d @cya@(@whi@%s kills@cya@/@whi@hr@cya@)",
kills, toUnitsPerHour(kills, startTime)),
PAINT_OFFSET_X, y += PAINT_OFFSET_Y_INCREMENT, 1, 0);
if (premiumLoot.isEmpty()) return;
drawString("", PAINT_OFFSET_X, y += PAINT_OFFSET_Y_INCREMENT, 1, 0);
for (final Map.Entry<Integer, Integer> entry : premiumLoot.entrySet()) {
drawString(String.format("@gre@%s: @whi@%d", getItemNameId(entry.getKey()), entry.getValue()),
PAINT_OFFSET_X, y += PAINT_OFFSET_Y_INCREMENT, 1, 0);
}
}
@Override
public void onNpcSpawned(final java.lang.Object npc) {
if (bot.getNpcId(npc) != NPC_ID_CHAOS_DRUID) {
return;
}
final int npcX = bot.getMobLocalX(npc) + bot.getAreaX();
final int npcY = bot.getMobLocalY(npc) + bot.getAreaY();
final int serverIndex = bot.getMobServerIndex(npc);
final Spawn spawn = spawnMap.get(serverIndex);
if (spawn != null) {
spawn.getCoordinate().set(npcX, npcY);
spawn.setTimestamp(System.currentTimeMillis());
} else {
spawnMap.put(serverIndex, new Spawn(new Coordinate(npcX, npcY), System.currentTimeMillis()));
}
nextRespawn = spawnMap.isEmpty() ? null : spawnMap.values().stream().sorted().findFirst().get().getCoordinate();
}
private enum Area implements RSArea {
CHAOS_DRUIDS(new Coordinate(616, 550), new Coordinate(619, 555)) {
@Override
public boolean contains(final int x, final int y) {
return super.contains(x, y) || ((x == 620 || x == 615) && y > 551 && y < 554);
}
},
BANK(new Coordinate(577, 572), new Coordinate(585, 576));
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 {
TOWER_DOOR(96, new Coordinate(617, 556));
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;
}
}
}