-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathAA_Script.java
More file actions
1197 lines (948 loc) · 27.7 KB
/
AA_Script.java
File metadata and controls
1197 lines (948 loc) · 27.7 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
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
import com.aposbot.Constants;
import java.text.DecimalFormat;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.time.temporal.ChronoUnit;
import java.util.Objects;
public abstract class AA_Script extends Script {
public static final DecimalFormat DECIMAL_FORMAT = new DecimalFormat("#,##0");
public static final int[] NPC_IDS_BANKER = new int[]{95, 224, 268, 485, 540, 617, 792};
public static final int[] OBJECT_IDS_BED = new int[]{14, 15, 1035, 1162, 1171};
public static final long TIMEOUT_ONE_TICK = 650L;
public static final long TIMEOUT_ONE_SECOND = 1000L;
public static final long TIMEOUT_TWO_SECONDS = 2000L;
public static final long TIMEOUT_THREE_SECONDS = 3000L;
public static final long TIMEOUT_FIVE_SECONDS = 5000L;
public static final long TIMEOUT_TEN_SECONDS = 10000L;
public static final int SLEEP_ONE_TICK = 650;
public static final int SLEEP_ONE_SECOND = 1000;
public static final int SLEEP_TWO_SECONDS = 2000;
public static final int SLEEP_THREE_SECONDS = 3000;
public static final int SLEEP_FIVE_SECONDS = 5000;
public static final int SLEEP_TEN_SECONDS = 10000;
public static final int PAINT_OFFSET_X = 312;
public static final int PAINT_OFFSET_X_LOOT = 140;
public static final int PAINT_OFFSET_Y = 48;
public static final int PAINT_OFFSET_Y_INCREMENT = 14;
public static final int MAX_INVENTORY_SIZE = 30;
public static final int MAX_TRADE_SIZE = 12;
public static final int ITEM_ID_SLEEPING_BAG = 1263;
private static final DateTimeFormatter DATE_TIME_FORMATTER = DateTimeFormatter.ofPattern("HH:mm:ss");
protected final Extension bot;
protected CombatStyle combatStyle = CombatStyle.STRENGTH;
private long optionMenuTimeout;
public AA_Script(final Extension bot) {
super(bot);
this.bot = bot;
}
public static String toUnitsPerHour(final int processed, final long time) {
if (processed == 0) {
return "0";
}
final double amount = processed * 60.0 * 60.0;
final double seconds = (System.currentTimeMillis() - time) / 1000.0;
return DECIMAL_FORMAT.format(amount / seconds);
}
public static String toTimeToCompletion(final int processed, final int remaining, final long time) {
if (processed == 0) {
return "0:00:00";
}
final double seconds = (System.currentTimeMillis() - time) / 1000.0;
final double secondsPerItem = seconds / processed;
final long ttl = (long) (secondsPerItem * remaining);
return String.format("%d:%02d:%02d", ttl / 3600, (ttl % 3600) / 60, (ttl % 60));
}
public static String toDuration(final long time) {
final long seconds = (System.currentTimeMillis() - time) / 1000;
return String.format("%d:%02d:%02d", seconds / 3600, (seconds % 3600) / 60, (seconds % 60));
}
public static String getLocalDateTime() {
return LocalDateTime.now().truncatedTo(ChronoUnit.SECONDS).format(DATE_TIME_FORMATTER);
}
@Override
public abstract void init(final String parameters);
@Override
public abstract int main();
@Override
public void onServerMessage(final String message) {
if (message.endsWith("moment")) {
optionMenuTimeout = 0L;
}
}
@Override
public void onDeath() {
setAutoLogin(false);
stopScript();
System.out.println("Oh dear, you are dead.");
}
/**
* Overrides walkTo and walks to the given tile.
*
* @param x the x coordinate to walk to
* @param y the y coordinate to walk to
*/
@Override
public void walkTo(final int x, final int y) {
bot.walkDirectly(x - bot.getAreaX(), y - bot.getAreaY(), false);
bot.setActionInd(24);
}
@Override
public void useItemOnObject(final int inventoryIndex, final int x, final int y) {
final int localX = x - bot.getAreaX();
final int localY = y - bot.getAreaY();
int objectId = -1;
int objectDirection = -1;
for (int index = 0; index < bot.getObjectCount(); index++) {
if (bot.getObjectLocalX(index) == localX && bot.getObjectLocalY(index) == localY) {
objectId = bot.getObjectId(index);
objectDirection = bot.getObjectDir(index);
break;
}
}
if (objectId == -1 || objectDirection == -1) {
return;
}
bot.walkToObject(localX, localY, objectDirection, objectId);
bot.createPacket(Constants.OP_OBJECT_USEWITH);
bot.put2(x);
bot.put2(y);
bot.put2(inventoryIndex);
bot.finishPacket();
}
@Override
public void atObject(final int x, final int y) {
final int index = getObjectIndex(x, y);
if (index == -1) {
return;
}
bot.walkToObject(x - bot.getAreaX(), y - bot.getAreaY(), bot.getObjectDir(index),
bot.getObjectId(index));
bot.createPacket(Constants.OP_OBJECT_ACTION1);
bot.put2(x);
bot.put2(y);
bot.finishPacket();
}
@Override
public void atObject2(final int x, final int y) {
final int index = getObjectIndex(x, y);
if (index == -1) {
return;
}
bot.walkToObject(x - bot.getAreaX(), y - bot.getAreaY(), bot.getObjectDir(index),
bot.getObjectId(index));
bot.createPacket(Constants.OP_OBJECT_ACTION2);
bot.put2(x);
bot.put2(y);
bot.finishPacket();
}
@Override
public void atWallObject(final int x, final int y) {
final int wallObjectIndex = getWallObjectIndex(x, y);
if (wallObjectIndex == -1) {
return;
}
final int dir = bot.getBoundDir(wallObjectIndex);
bot.walkToBound(x - bot.getAreaX(), y - bot.getAreaY(), dir);
bot.createPacket(Constants.OP_BOUND_ACTION1);
bot.put2(x);
bot.put2(y);
bot.put1(dir);
bot.finishPacket();
}
@Override
public void atWallObject2(final int x, final int y) {
final int wallObjectIndex = getWallObjectIndex(x, y);
if (wallObjectIndex == -1) {
return;
}
final int dir = bot.getBoundDir(wallObjectIndex);
bot.walkToBound(x - bot.getAreaX(), y - bot.getAreaY(), dir);
bot.createPacket(Constants.OP_BOUND_ACTION2);
bot.put2(x);
bot.put2(y);
bot.put1(dir);
bot.finishPacket();
}
@Override
public void deposit(final int itemId, final int amount) {
bot.createPacket(Constants.OP_BANK_DEPOSIT);
bot.put2(itemId);
bot.put4(amount);
bot.put4(-2023406815);
bot.finishPacket();
}
@Override
public void withdraw(final int itemId, final int amount) {
bot.createPacket(Constants.OP_BANK_WITHDRAW);
bot.put2(itemId);
bot.put4(amount);
bot.put4(305419896);
bot.finishPacket();
}
@Override
public boolean hasBankItem(final int itemId) {
for (int index = 0; index < bot.getBankSize(); index++) {
if (bot.getBankId(index) == itemId && bot.getBankStack(index) > 0) {
return true;
}
}
return false;
}
@Override
public void closeBank() {
bot.createPacket(Constants.OP_BANK_CLOSE);
bot.finishPacket();
bot.setBankVisible(false);
}
@Override
public void buyShopItem(final int shopIndex, final int amount) {
bot.createPacket(Constants.OP_SHOP_BUY);
bot.put2(bot.getShopId(shopIndex));
bot.put2(bot.getShopStack(shopIndex));
bot.put2(amount);
bot.finishPacket();
}
@Override
public void sellShopItem(final int shopIndex, final int amount) {
bot.createPacket(Constants.OP_SHOP_SELL);
bot.put2(bot.getShopId(shopIndex));
bot.put2(bot.getShopStack(shopIndex));
bot.put2(amount);
bot.finishPacket();
}
@Override
public void acceptTrade() {
bot.createPacket(Constants.OP_TRADE_ACCEPT);
bot.finishPacket();
bot.Mi = true;
}
@Override
public void confirmTrade() {
bot.createPacket(Constants.OP_TRADE_CONFIRM);
bot.finishPacket();
bot.Vi = true;
}
@Override
public void declineTrade() {
bot.createPacket(Constants.OP_TRADE_DECLINE);
bot.finishPacket();
}
@Override
public String getItemName(final int itemId) {
return getItemNameId(itemId);
}
protected int getWallObjectIndex(final int x, final int y) {
for (int index = 0; index < bot.getBoundCount(); index++) {
if (bot.getBoundLocalX(index) == (x - bot.getAreaX()) && bot.getBoundLocalY(index) == (y - bot.getAreaY())) {
return index;
}
}
return -1;
}
protected int getObjectIndex(final int x, final int y) {
for (int index = 0; index < bot.getObjectCount(); index++) {
if (bot.getObjectLocalX(index) == (x - bot.getAreaX()) && bot.getObjectLocalY(index) == (y - bot.getAreaY())) {
return index;
}
}
return -1;
}
protected boolean isOnFriendList(final String playerName) {
for (int index = 0; index < getFriendCount(); ++index) {
if (getFriendName(index).equalsIgnoreCase(playerName)) return true;
}
return false;
}
protected void addToFriendList(String playerName) {
playerName = playerName.replace(' ', (char) 160);
bot.Bj = 0;
bot.e = "";
bot.Cb = "";
bot.b(114, playerName);
}
protected void offerTradeItem(final int inventoryIndex, final int amount) {
bot.offerItemTrade(inventoryIndex, amount);
}
protected boolean isTradeOpen() {
return bot.isInTradeOffer() || bot.isInTradeConfirm();
}
protected boolean isTradeConfirmOpen() {
return bot.isInTradeConfirm();
}
protected boolean isTradeAcceptOpen() {
return bot.isInTradeOffer();
}
protected boolean isTradeRecipientAccepted() {
return bot.hasRemoteAcceptedTrade();
}
protected boolean isTradeAccepted() {
return bot.hasLocalAcceptedTrade();
}
public void setCombatStyle(final int combatStyle) {
bot.setCombatStyle(combatStyle);
bot.createPacket(Constants.OP_SET_COMBAT_STYLE);
bot.put1(combatStyle);
bot.finishPacket();
}
protected void printInstructions() {
throw new IllegalArgumentException(String.format("Please see the %s.java file for instructions!%n", this));
}
@Override
public final String toString() {
return getClass().getSimpleName();
}
protected boolean isAtCoordinate(final Coordinate coordinate) {
return getPlayerX() == coordinate.getX() && getPlayerY() == coordinate.getY();
}
protected int getPlayerX() {
return bot.getLocalX() + bot.getAreaX();
}
protected int getPlayerY() {
return bot.getLocalY() + bot.getAreaY();
}
protected int getServerIndex(final java.lang.Object mob) {
return bot.getMobServerIndex(mob);
}
protected boolean isDead() {
return bot.isDeathScreen() ||
bot.getLocalX() < 0 || bot.getLocalX() > 96 ||
bot.getLocalY() < 0 || bot.getLocalY() > 96;
}
protected double getTotalCombatXp() {
int total = 0;
for (int i = 0; i < 4; i++) {
total += bot.getExperience(i);
}
return total;
}
protected boolean isInventoryFull() {
return bot.getInventorySize() == MAX_INV_SIZE;
}
protected boolean isInventoryEmpty() {
return bot.getInventorySize() == 0;
}
protected int getInventoryEmptyCount() {
return MAX_INV_SIZE - bot.getInventorySize();
}
protected boolean hasInventoryItem(final int[] itemIds) {
for (final int itemId : itemIds) {
for (int index = 0; index < bot.getInventorySize(); index++) {
if (bot.getInventoryId(index) == itemId) {
return true;
}
}
}
return false;
}
protected boolean isItemIdEquipped(final int itemId) {
for (int index = 0; index < bot.getInventorySize(); index++) {
if (bot.getInventoryId(index) == itemId) {
return bot.isEquipped(index);
}
}
return false;
}
protected void equipItem(final int inventoryIndex) {
bot.createPacket(Constants.OP_INV_EQUIP);
bot.put2(inventoryIndex);
bot.finishPacket();
}
protected int openBank() {
return openInterface(0, NPC_IDS_BANKER);
}
private int openInterface(final int optionIndex, final int[] npcs) {
if (bot.isDialogVisible()) {
bot.createPacket(Constants.OP_DIALOG_ANSWER);
bot.put1(optionIndex);
bot.finishPacket();
bot.setDialogVisible(false);
optionMenuTimeout = System.currentTimeMillis() + TIMEOUT_FIVE_SECONDS;
return 0;
}
if (System.currentTimeMillis() <= optionMenuTimeout) {
return 0;
}
final Object npc = getNearestNpcNotTalking(npcs);
if (npc == null) {
return 0;
}
if (distanceTo(npc) > 2) {
walkTo(npc);
return SLEEP_ONE_TICK;
}
talkToNpc(npc);
optionMenuTimeout = System.currentTimeMillis() + TIMEOUT_FIVE_SECONDS;
return 0;
}
protected Object getNearestNpcNotTalking(final int[] npcIds) {
return getNearestNpc(npcIds, false, true);
}
protected int distanceTo(final Object character) {
return distanceTo(getX(character), getY(character), getPlayerX(), getPlayerY());
}
protected void walkTo(final Object character) {
bot.walkDirectly(bot.getMobLocalX(character), bot.getMobLocalY(character), true);
bot.setActionInd(24);
}
protected void talkToNpc(final Object npc) {
bot.walkDirectly(bot.getMobLocalX(npc), bot.getMobLocalY(npc), true);
bot.createPacket(Constants.OP_NPC_TALK);
bot.put2(bot.getMobServerIndex(npc));
bot.finishPacket();
}
protected Object getNearestNpc(final int[] npcIds, final boolean notInCombat, final boolean notTalking) {
Object nearestNpc = null;
int currentDistance = Integer.MAX_VALUE;
final int playerX = getPlayerX();
final int playerY = getPlayerY();
for (int index = 0; index < bot.getNpcCount(); index++) {
final Object npc = bot.getNpc(index);
if (!inArray(npcIds, bot.getNpcId(npc)) ||
(notInCombat && isInCombat(npc)) ||
(notTalking && isTalking(npc))) {
continue;
}
final int npcX = bot.getMobLocalX(npc) + bot.getAreaX();
final int npcY = bot.getMobLocalY(npc) + bot.getAreaY();
final int distance = distanceTo(npcX, npcY, playerX, playerY);
if (distance < currentDistance) {
nearestNpc = npc;
currentDistance = distance;
}
}
return nearestNpc;
}
protected int getX(final Object character) {
return bot.getMobLocalX(character) + bot.getAreaX();
}
protected int getY(final Object character) {
return bot.getMobLocalY(character) + bot.getAreaY();
}
protected boolean isInCombat(final Object character) {
return bot.isMobInCombat(character);
}
protected boolean isTalking(final Object character) {
return bot.isMobTalking(character);
}
protected int openShop(final int... shopkeepers) {
return openInterface(0, shopkeepers);
}
protected int openShop(final int optionIndex, final int[] shopkeepers) {
return openInterface(optionIndex, shopkeepers);
}
protected int sleep() {
final int index = getInventoryItemIndex(ITEM_ID_SLEEPING_BAG);
if (index == -1) {
return exit("Sleeping bag missing from inventory.");
}
useItem(index);
return SLEEP_ONE_SECOND;
}
protected int getInventoryItemIndex(final int itemId) {
for (int index = 0; index < bot.getInventorySize(); index++) {
if (bot.getInventoryId(index) == itemId) {
return index;
}
}
return -1;
}
protected int exit(final String reason) {
bot.setAutoLogin(false);
bot.stopScript();
System.err.println(reason);
return 0;
}
protected int getInventoryItemIndex(final int[] itemIds) {
for (final int itemId : itemIds) {
for (int index = 0; index < bot.getInventorySize(); index++) {
if (bot.getInventoryId(index) == itemId) {
return index;
}
}
}
return -1;
}
protected int getBaseHits() {
return bot.getBaseLevel(3);
}
protected int getCurrentHits() {
return bot.getCurrentLevel(3);
}
protected int getCurrentHits(final java.lang.Object character) {
return ((ta) character).B;
}
protected Object getPlayerObjByName(final String playerName) {
Object player;
for (int index = 0; index < bot.getPlayerCount(); index++) {
player = bot.getPlayer(index);
if (playerName.equalsIgnoreCase(getName(player))) return player;
}
return null;
}
protected String getName(final java.lang.Object character) {
final String name = ((ta) character).c;
if (name == null) {
return null;
}
return name.replace((char) 160, ' ');
}
protected int getWaypointX(final java.lang.Object character) {
return ((ta) character).i;
}
protected int getWaypointY(final java.lang.Object character) {
return ((ta) character).K;
}
protected void useObject1(final int x, final int y) {
bot.createPacket(Constants.OP_OBJECT_ACTION1);
bot.put2(x);
bot.put2(y);
bot.finishPacket();
}
protected void useObject2(final int x, final int y) {
bot.createPacket(Constants.OP_OBJECT_ACTION2);
bot.put2(x);
bot.put2(y);
bot.finishPacket();
}
protected void useWithObject(final int inventoryIndex, final int x, final int y) {
bot.createPacket(Constants.OP_OBJECT_USEWITH);
bot.put2(x);
bot.put2(y);
bot.put2(inventoryIndex);
bot.finishPacket();
}
protected void takeGroundItem(final int itemId, final int x, final int y) {
bot.createPacket(Constants.OP_GITEM_TAKE);
bot.put2(x);
bot.put2(y);
bot.put2(itemId);
bot.finishPacket();
}
protected int getGroundItemX(final int groundItemIndex) {
return bot.getGroundItemLocalX(groundItemIndex) + bot.getAreaX();
}
protected int getGroundItemY(final int groundItemIndex) {
return bot.getGroundItemLocalY(groundItemIndex) + bot.getAreaY();
}
protected boolean isTradeConfirmed() {
return bot.hasLocalConfirmedTrade();
}
protected boolean hasTradeItem(final int[] itemIds) {
for (final int itemId : itemIds) {
for (int index = 0; index < bot.getLocalTradeItemCount(); index++) {
if (bot.getLocalTradeItemId(index) == itemId) {
return true;
}
}
}
return false;
}
protected int getTradeItemCount() {
return bot.getLocalTradeItemCount();
}
protected int getTradeItemIdCount(final int itemId) {
int count = 0;
for (int index = 0; index < bot.getLocalTradeItemCount(); index++) {
if (bot.getLocalTradeItemId(index) == itemId) {
count += bot.getLocalTradeItemStack(index);
}
}
return count;
}
protected void offerTradeItemId(final int itemId, final int amount) {
final int inventoryIndex = getInventoryIndex(itemId);
if (inventoryIndex == -1) {
return;
}
bot.offerItemTrade(inventoryIndex, amount);
}
protected void removeTradeItemId(final int itemId, final int amount) {
final int tradeIndex = getTradeItemIndex(itemId);
if (tradeIndex == -1) {
return;
}
removeTradeItem(tradeIndex, amount);
}
protected int getTradeItemIndex(final int itemId) {
for (int index = 0; index < bot.getLocalTradeItemCount(); index++) {
if (bot.getLocalTradeItemId(index) == itemId) {
return index;
}
}
return -1;
}
protected void removeTradeItem(final int tradeIndex, final int amount) {
bot.c(amount, (byte) 124, tradeIndex);
}
protected double getSkillExperience(final int skillId) {
return bot.getExperience(skillId);
}
protected int getCurrentSkillLevel(final int skillId) {
return bot.oh[skillId];
}
protected int getFatiguePercent() {
return (int) bot.getAccurateFatigue();
}
protected boolean isBankOpen() {
return bot.isBankVisible();
}
protected boolean isInCombat() {
return bot.getCombatTimer() == 499;
}
protected int getBankItemIdCount(final int itemId) {
int count = 0;
for (int index = 0; index < bot.getBankSize(); index++) {
if (bot.getBankId(index) == itemId) {
count += bot.getBankStack(index);
break;
}
}
return count;
}
protected int getBankItemIdCount(final int[] itemIds) {
int count = 0;
for (final int itemId : itemIds) {
for (int index = 0; index < bot.getBankSize(); index++) {
if (bot.getBankId(index) == itemId) {
count += bot.getBankStack(index);
break;
}
}
}
return count;
}
protected int getBaseSkillLevel(final int skillId) {
return bot.getBaseLevel(skillId);
}
protected int getObjectId(final int x, final int y) {
for (int index = 0; index < bot.getObjectCount(); index++) {
if (bot.getObjectLocalX(index) == (x - bot.getAreaX()) && bot.getObjectLocalY(index) == (y - bot.getAreaY())) {
return bot.getObjectId(index);
}
}
return -1;
}
protected int getWallObjectId(final int x, final int y) {
for (int index = 0; index < bot.getBoundCount(); index++) {
if (bot.getBoundLocalX(index) == (x - bot.getAreaX()) && bot.getBoundLocalY(index) == (y - bot.getAreaY())) {
return bot.getBoundId(index);
}
}
return -1;
}
protected void answerOptionMenu(final int menuIndex) {
bot.createPacket(Constants.OP_DIALOG_ANSWER);
bot.put1(menuIndex);
bot.finishPacket();
bot.setDialogVisible(false);
}
protected Object getNearestNpcNotInCombat(final int npcId) {
return getNearestNpc(npcId, true, false);
}
protected Object getNearestNpc(final int npcId, final boolean notInCombat, final boolean notTalking) {
Object nearestNpc = null;
int currentDistance = Integer.MAX_VALUE;
final int playerX = getPlayerX();
final int playerY = getPlayerY();
for (int index = 0; index < bot.getNpcCount(); index++) {
final Object npc = bot.getNpc(index);
if (bot.getNpcId(npc) != npcId ||
(notInCombat && isInCombat(npc)) ||
(notTalking && isTalking(npc))) {
continue;
}
final int npcX = bot.getMobLocalX(npc) + bot.getAreaX();
final int npcY = bot.getMobLocalY(npc) + bot.getAreaY();
final int distance = distanceTo(npcX, npcY, playerX, playerY);
if (distance < currentDistance) {
nearestNpc = npc;
currentDistance = distance;
}
}
return nearestNpc;
}
protected Object getNearestNpcNotInCombat(final int[] npcIds) {
return getNearestNpc(npcIds, true, false);
}
protected Object getNearestNpcNotTalking(final int npcId) {
return getNearestNpc(npcId, false, true);
}
protected boolean isOptionMenuOpen() {
return bot.isDialogVisible();
}
protected void castOnNpc(final int spellId, final Object npc) {
bot.walkDirectly(bot.getMobLocalX(npc), bot.getMobLocalY(npc), true);
bot.createPacket(Constants.OP_NPC_CAST);
bot.put2(bot.getMobServerIndex(npc));
bot.put2(spellId);
bot.finishPacket();
}
protected void attackNpc(final Object npc) {
bot.walkDirectly(bot.getMobLocalX(npc), bot.getMobLocalY(npc), true);
bot.createPacket(Constants.OP_NPC_ATTACK);
bot.put2(bot.getMobServerIndex(npc));
bot.finishPacket();
}
protected int getInventoryItemIdCount(final int itemId) {
int count = 0;
for (int index = 0; index < bot.getInventorySize(); index++) {
if (bot.getInventoryId(index) == itemId) {
if (isItemStackableId(itemId)) {
count += bot.getInventoryStack(index);
} else {
count++;
}
}
}
return count;
}
protected int getInventoryItemIdCount(final int[] itemIds) {
int count = 0;
for (final int itemId : itemIds) {
for (int index = 0; index < getInventoryItemCount(); index++) {
if (getInventoryItemId(index) == itemId) count += getInventoryItemCount(index);
}
}
return count;
}
protected int getInventoryItemCount() {
return bot.getInventorySize();
}
protected int getInventoryItemId(final int inventoryIndex) {
return bot.getInventoryId(inventoryIndex);
}
protected int getInventoryItemCount(final int inventoryIndex) {
return bot.getInventoryStack(inventoryIndex);
}
protected int getShopItemCount(final int shopIndex) {
return bot.getShopStack(shopIndex);
}
protected int getOptionMenuCount() {
return bot.getDialogOptionCount();
}
protected void useItemOnNpc(final int inventoryIndex, final Object npc) {
bot.walkDirectly(bot.getMobLocalX(npc), bot.getMobLocalY(npc), true);
bot.createPacket(Constants.OP_NPC_USEWITH);
bot.put2(bot.getMobServerIndex(npc));
bot.put2(inventoryIndex);
bot.finishPacket();
}
protected int getShopItemIndex(final int itemId) {
for (int index = 0; index < bot.getShopSize(); index++) {
if (bot.getShopId(index) == itemId) {
return index;
}
}
return -1;
}
protected Coordinate getWalkableCoordinate() {
int x;
int y;
for (int i = -1; i <= 1; i++) {
x = getX() + i;
for (int j = -1; j <= 1; j++) {
y = getY() + j;
if (i == 0 && j == 0) {
continue;
}
if (isReachable(x, y) && !isObjectAt(x, y)) {
return new Coordinate(x, y);
}
}
}
return null;
}
protected enum CombatStyle {
CONTROLLED(0),
STRENGTH(1),
ATTACK(2),
DEFENSE(3);
private final int index;
CombatStyle(final int index) {
this.index = index;
}
@Override
public String toString() {
return name().charAt(0) + name().substring(1).toLowerCase();
}
public int getIndex() {
return index;
}
}
protected enum Skill {
ATTACK(0),
DEFENSE(1),
STRENGTH(2),
HITS(3),
RANGED(4),
PRAYER(5),
MAGIC(6),
COOKING(7),
WOODCUT(8),
FLETCHING(9),
FISHING(10),
FIREMAKING(11),
CRAFTING(12),
SMITHING(13),
MINING(14),