Repository navigation
Expand file tree
/
Copy pathAA_PaladinThiever.java
More file actions
427 lines (333 loc) · 10.6 KB
/
Copy pathAA_PaladinThiever.java
File metadata and controls
427 lines (333 loc) · 10.6 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
import com.aposbot.Constants;
/**
* A script for pickpocketing Paladins at the Ardougne Castle.
* Start script at Paladins with sleeping bag and food in inventory.
* <p>
* Optional Parameter:
* <tuna|lobster|swordfish|bass|shark> (Default shark)
*
* @Author Chomp
*/
public class AA_PaladinThiever extends AA_Script {
private static final Coordinate COORD_BANK = new Coordinate(586, 576);
private static final int ITEM_ID_COINS = 10;
private static final int ITEM_ID_CHAOS_RUNE = 41;
private static final int NPC_ID_PALADIN = 323;
private static final int Y_COORD_DOOR = 1548;
private static final int Y_COORD_CASTLE = 1000;
private static final int MAX_FATIGUE = 100;
private Coordinate prevCoord;
private Food food;
private java.lang.Object paladin;
private double initialThievingXp;
private double totalAttempts;
private long startTime;
private long thieveTimeout;
private long eatTimeout;
private long withdrawFoodTimeout;
private long depositFoodTimeout;
private long depositChaosTimeout;
private long depositCoinsTimeout;
private int eatAt;
private int success;
private int fail;
private int foodCount;
private int cmbRoundCount;
private int playerX;
private int playerY;
private boolean banking;
private boolean flee;
private boolean idle;
public AA_PaladinThiever(final Extension bot) {
super(bot);
combatStyle = CombatStyle.DEFENSE;
}
@Override
public void init(final String parameters) {
food = parameters.isEmpty() ? Food.SHARK : Food.valueOf(parameters.toUpperCase());
if (!hasInventoryItem(ITEM_ID_SLEEPING_BAG)) {
throw new IllegalStateException("Sleeping bag missing from inventory.");
}
setCombatStyle(combatStyle.getIndex());
banking = !hasInventoryItem(food.getId()) || isBankOpen();
eatAt = getBaseHits() - food.getHealAmount();
initialThievingXp = getSkillExperience(Skill.THIEVING.getIndex());
startTime = System.currentTimeMillis();
}
@Override
public int main() {
playerX = getPlayerX();
playerY = getPlayerY();
if (bot.getCombatStyle() != combatStyle.getIndex()) setCombatStyle(combatStyle.getIndex());
return banking ? bank() : thieve();
}
@Override
public void onServerMessage(final String message) {
if (message.startsWith("attempt", 4)) {
totalAttempts++;
thieveTimeout = System.currentTimeMillis() + TIMEOUT_TWO_SECONDS;
} else if (message.startsWith("pick", 4)) {
success++;
thieveTimeout = 0L;
} else if (message.startsWith("fail", 4)) {
fail++;
thieveTimeout = System.currentTimeMillis() + TIMEOUT_ONE_TICK;
} else if (message.endsWith("enough") || message.endsWith("combat")) {
thieveTimeout = 0L;
} else if (message.endsWith("area")) {
idle = true;
prevCoord = new Coordinate(getPlayerX(), getPlayerY());
} else if (message.startsWith("eat", 4)) {
eatTimeout = System.currentTimeMillis() + TIMEOUT_ONE_TICK;
} else if (message.startsWith("advanced", 14)) {
success = 0;
fail = 0;
totalAttempts = 0;
} else {
super.onServerMessage(message);
}
}
private int bank() {
if (playerY <= COORD_BANK.getY()) {
if (getCurrentHits() <= eatAt) {
final int foodIndex = getInventoryItemIndex(food.getId());
if (foodIndex != -1) {
return eat(foodIndex);
}
}
if (!isBankOpen()) {
return openBank();
}
int reqEmptySpaces = 2;
final int chaosIndex = getInventoryItemIndex(ITEM_ID_CHAOS_RUNE);
if (chaosIndex != -1) {
reqEmptySpaces--;
final int chaosCount = getInventoryItemCount(chaosIndex);
if (chaosCount > 1) {
if (System.currentTimeMillis() <= depositChaosTimeout) {
return 0;
}
deposit(ITEM_ID_CHAOS_RUNE, chaosCount - 1);
depositChaosTimeout = System.currentTimeMillis() + TIMEOUT_THREE_SECONDS;
return 0;
}
}
final int coinsIndex = getInventoryItemIndex(ITEM_ID_COINS);
if (coinsIndex != -1) {
reqEmptySpaces--;
final int coinsCount = getInventoryItemCount(coinsIndex);
if (coinsCount > 1) {
if (System.currentTimeMillis() <= depositCoinsTimeout) {
return 0;
}
deposit(ITEM_ID_COINS, coinsCount - 1);
depositCoinsTimeout = System.currentTimeMillis() + TIMEOUT_THREE_SECONDS;
return 0;
}
}
final int emptyCount = getInventoryEmptyCount();
if (emptyCount == reqEmptySpaces) {
banking = false;
return 0;
}
if (emptyCount < reqEmptySpaces) {
if (System.currentTimeMillis() <= depositFoodTimeout) {
return 0;
}
deposit(food.getId(), reqEmptySpaces - emptyCount);
depositFoodTimeout = System.currentTimeMillis() + TIMEOUT_THREE_SECONDS;
return 0;
}
if (System.currentTimeMillis() <= withdrawFoodTimeout) {
return 0;
}
if (!hasBankItem(food.getId())) {
return exit("Out of food.");
}
withdraw(food.getId(), emptyCount - reqEmptySpaces);
withdrawFoodTimeout = System.currentTimeMillis() + TIMEOUT_THREE_SECONDS;
return 0;
}
if (playerY < Y_COORD_CASTLE) {
final Coordinate doors = Object.DOORS.getCoordinate();
if (playerX > doors.getX()) {
if (getObjectId(doors.getX(), doors.getY()) == Object.DOORS.getId()) {
atObject(doors.getX(), doors.getY());
return SLEEP_ONE_SECOND;
}
walkTo(doors.getX(), doors.getY());
return SLEEP_ONE_TICK;
}
final Coordinate gate = Object.GATE.getCoordinate();
if (playerX > gate.getX()) {
if (getObjectId(gate.getX(), gate.getY()) == Object.GATE.getId()) {
atObject(gate.getX(), gate.getY());
return SLEEP_ONE_SECOND;
}
walkTo(gate.getX(), gate.getY());
return SLEEP_ONE_TICK;
}
walkTo(COORD_BANK.getX(), COORD_BANK.getY());
return SLEEP_ONE_TICK;
}
final Coordinate door = Object.DOOR.getCoordinate();
if (playerY >= door.getY()) {
atWallObject(door.getX(), door.getY());
} else {
final Coordinate stairs = Object.STAIRS_DOWN.getCoordinate();
atObject(stairs.getX(), stairs.getY());
}
return SLEEP_ONE_SECOND;
}
private int thieve() {
if (playerY >= Y_COORD_DOOR) {
if (isInCombat()) {
if (flee) {
walkTo(getPlayerX(), getPlayerY());
if (paladin != null && getFatiguePercent() < MAX_FATIGUE && getCurrentHits() > eatAt) {
bot.createPacket(Constants.OP_NPC_ACTION);
bot.put2(bot.getMobServerIndex(paladin));
bot.finishPacket();
}
return SLEEP_ONE_TICK;
}
return 0;
}
if (flee) {
flee = false;
cmbRoundCount = 0;
thieveTimeout = 0L;
}
if (thieveTimeout != 0L && System.currentTimeMillis() <= thieveTimeout) {
return 0;
}
if (idle) {
if (playerX == prevCoord.getX() && playerY == prevCoord.getY()) {
final Coordinate coord = getWalkableCoordinate();
if (coord != null) {
walkTo(coord.getX(), coord.getY());
return SLEEP_ONE_SECOND;
}
}
idle = false;
}
if (getFatiguePercent() >= MAX_FATIGUE) {
return sleep();
}
if (getCurrentHits() <= eatAt) {
final int foodIndex = getInventoryItemIndex(food.getId());
if (foodIndex == -1) {
banking = true;
return 0;
}
return eat(foodIndex);
}
paladin = getNearestNpcNotInCombat(NPC_ID_PALADIN);
if (paladin == null) {
return 0;
}
if (distanceTo(paladin) > 2) {
walkTo(paladin);
} else {
bot.createPacket(Constants.OP_NPC_ACTION);
bot.put2(bot.getMobServerIndex(paladin));
bot.finishPacket();
}
return SLEEP_ONE_TICK;
}
if (playerY > Y_COORD_CASTLE) {
final Coordinate door = Object.DOOR.getCoordinate();
atWallObject2(door.getX(), door.getY());
return SLEEP_ONE_TICK;
}
final Coordinate doors = Object.DOORS.getCoordinate();
if (playerX > doors.getX()) {
final Coordinate stairs = Object.STAIRS_UP.getCoordinate();
if (isInCombat() || playerX != stairs.getX() + 1 || playerY != stairs.getY() - 1) {
walkTo(stairs.getX() + 1, stairs.getY() - 1);
} else {
useObject1(stairs.getX(), stairs.getY());
}
return SLEEP_ONE_TICK;
}
final Coordinate gate = Object.GATE.getCoordinate();
if (playerX > gate.getX()) {
if (getObjectId(doors.getX(), doors.getY()) == Object.DOORS.getId()) {
atObject(doors.getX(), doors.getY());
return SLEEP_ONE_SECOND;
}
walkTo(doors.getX() + 1, doors.getY());
return SLEEP_ONE_TICK;
}
if (distanceTo(gate.getX(), gate.getY()) > 1) {
walkTo(gate.getX(), gate.getY());
return SLEEP_ONE_TICK;
}
if (getObjectId(gate.getX(), gate.getY()) == Object.GATE.getId()) {
atObject(gate.getX(), gate.getY());
return SLEEP_ONE_SECOND;
}
walkTo(gate.getX() + 1, gate.getY());
return SLEEP_ONE_TICK;
}
private int eat(final int inventoryIndex) {
if (System.currentTimeMillis() <= eatTimeout) {
return 0;
}
foodCount++;
useItem(inventoryIndex);
eatTimeout = System.currentTimeMillis() + TIMEOUT_ONE_SECOND;
return 0;
}
@Override
public void paint() {
int y = PAINT_OFFSET_Y;
bot.drawString("@yel@Paladin Thiever", PAINT_OFFSET_X, y, 1, 0);
bot.drawString(String.format("@yel@Runtime: @whi@%s", toDuration(startTime)),
PAINT_OFFSET_X, y += PAINT_OFFSET_Y_INCREMENT, 1, 0);
final double xpGained = getSkillExperience(Skill.THIEVING.getIndex()) - initialThievingXp;
bot.drawString(String.format("@yel@Xp: @whi@%s @cya@(@whi@%s@cya@/@whi@hr@cya@)",
DECIMAL_FORMAT.format(xpGained), toUnitsPerHour((int) xpGained, startTime)),
PAINT_OFFSET_X, y += PAINT_OFFSET_Y_INCREMENT * 2, 1, 0);
bot.drawString(String.format("@yel@Pickpocket: @whi@%s @cya@(@whi@%s@cya@/@whi@hr@cya@)",
DECIMAL_FORMAT.format(totalAttempts), toUnitsPerHour((int) totalAttempts, startTime)),
PAINT_OFFSET_X, y += PAINT_OFFSET_Y_INCREMENT, 1, 0);
if (success > 0) {
bot.drawString(String.format("@gr1@Success Rate: @whi@%.2f%%", (success / totalAttempts) * 100),
PAINT_OFFSET_X, y += PAINT_OFFSET_Y_INCREMENT * 2, 1, 0);
bot.drawString(String.format("Fail Rate: @whi@%.2f%%", (fail / totalAttempts) * 100),
PAINT_OFFSET_X, y + PAINT_OFFSET_Y_INCREMENT, 1, 0xE0142D);
}
}
@Override
public void onPlayerDamaged(final java.lang.Object player) {
if (player == bot.getPlayer()) {
cmbRoundCount++;
}
}
@Override
public void onNpcDamaged(final java.lang.Object npc) {
if (cmbRoundCount >= 2) {
flee = true;
}
}
private enum Object implements RSObject {
GATE(57, new Coordinate(598, 603)),
DOORS(64, new Coordinate(607, 603)),
STAIRS_UP(342, new Coordinate(611, 601)),
STAIRS_DOWN(44, new Coordinate(611, 1545)),
DOOR(97, new Coordinate(609, 1548));
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;
}
}
}