Repository navigation
Expand file tree
/
Copy pathAA_TaverleyBlackDragons.java
More file actions
1609 lines (1276 loc) · 44.3 KB
/
Copy pathAA_TaverleyBlackDragons.java
File metadata and controls
1609 lines (1276 loc) · 44.3 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 javax.swing.*;
import java.awt.*;
import java.awt.event.KeyEvent;
import java.util.List;
import java.util.*;
import java.util.stream.Collectors;
import java.util.stream.Stream;
/**
* DESCRIPTION
* -----------
* Kills Black Dragons in Taverley Dungeon. Trades with mule for Catherby banking.
* Start Master on the island and Mule across from the island.
* Have anti dragon breath shield, prayer gear, or tank gear with an optional shield switch.
* <p>
* FEATURES
* --------
* Pray setup or tank setup.
* Super sets or no pots.
* Shield switch in combat if tanking.
* Combat style switching if tanking.
* Prayer flicking if praying.
* <p>
* KEYBINDS
* --------
* l - toggle loot paint
* s - toggle settings paint
* <p>
* NOTES
* -----
* Items must be equipped on start and must not move inventory slots.
* Script will stop if food runs out, prayer pots run out, pm fails, or too many items in inventory.
* <p>
*
* @Author Chomp
*/
public class AA_TaverleyBlackDragons extends AA_Script {
private static final Coordinate COORD_LOAD_BANK = new Coordinate(416, 499);
private static final Coordinate COORD_TRADE_MASTER = new Coordinate(412, 506);
private static final Coordinate COORD_TRADE_MULE = new Coordinate(411, 503);
private static final Coordinate COORD_WAIT_RESPAWN = new Coordinate(410, 3336);
private static final Set<Integer> ITEM_IDS_LOOT = Stream.of(
10, 11, 31, 33, 38, 40, 42, 75, 79, 81, 93,
120, 130, 174,
403, 404, 405, 408, 438, 439, 441, 442, 443,
518, 520, 523, 526, 527,
619, 795, 814, 1092, 1277
).collect(Collectors.toCollection(HashSet::new));
private static final Set<Integer> ITEM_IDS_LOOT_STACKABLE = Stream.of(
10, 11, 31, 33, 38, 40, 42, 518, 520, 619
).collect(Collectors.toCollection(HashSet::new));
private static final int ITEM_ID_ANTI_DRAGON_BREATH_SHIELD = 420;
private static final int ITEM_ID_VIAL = 465;
private static final int NPC_ID_BLACK_DRAGON = 291;
private static final int HITS_XP_BLACK_DRAGON = 105;
private static final int PRAYER_ID_PARALYZE_MONSTER = 12;
private static final int MAX_FATIGUE = 95;
private static final int MAX_DIST_FROM_DRAGON = 2;
private static final int PAINT_OFFSET_X_SETTINGS = 110;
private static final int PAINT_OFFSET_Y_LOOT = 188;
private final Map<Integer, Spawn> spawnMap = new HashMap<>();
private final Map<Integer, Integer> lootMap = new TreeMap<>();
private final Set<Integer> equipmentIndexes = new HashSet<>();
private final List<String> traders = new ArrayList<>();
private final int[] loot = new int[3];
private Role role;
private Food food;
private String currentTrader;
private State state;
private SupplyRequest supplyRequest;
private Coordinate nextRespawn;
private double initHitsXp;
private long startTime;
private long pmTimeout;
private long tradeReqTimeout;
private long foodTimeout;
private long consumeTimeout;
private long disablePrayerTimeout;
private long tickCount;
private long disableTick;
private int playerX;
private int playerY;
private int foodCount;
private int foodAte;
private int minHits;
private int minPrayer;
private int minAtk;
private int minStr;
private int minDef;
private int eatAt;
private int prayAt;
private int antiShieldIndex;
private int shieldIndex;
private boolean idle;
private boolean spawnCamp;
private boolean paintLoot;
private boolean paintSettings;
private boolean initialized;
public AA_TaverleyBlackDragons(final Extension ex) {
super(ex);
}
@Override
public void init(final String parameters) {
if (!bot.isLoggedIn()) throw new IllegalStateException("Error: Must be logged-in to start this script.");
createGUI();
}
@Override
public int main() {
if (!initialized) {
bot.displayMessage("@red@ERROR: Script was not initialized.");
return exit("Error: Script was not initialized.");
}
playerX = getPlayerX();
playerY = getPlayerY();
return role == Role.MASTER ? master() : mule();
}
@Override
public void onServerMessage(final String message) {
if (message.startsWith("eat", 4)) {
foodAte++;
consumeTimeout = System.currentTimeMillis() + TIMEOUT_ONE_TICK;
} else if (message.endsWith("prayer potion")) {
Potion.PRAYER.sip();
} else if (message.endsWith("attack potion")) {
Potion.SUPER_ATTACK.sip();
} else if (message.endsWith("strength potion")) {
Potion.SUPER_STRENGTH.sip();
} else if (message.endsWith("defense potion")) {
Potion.SUPER_DEFENSE.sip();
} else if (message.endsWith("left") || message.startsWith("finished", 9)) {
consumeTimeout = System.currentTimeMillis() + TIMEOUT_ONE_TICK;
} else if (message.endsWith("successfully")) {
pmTimeout = 0L;
tradeReqTimeout = 0L;
foodTimeout = 0L;
consumeTimeout = 0L;
} else if (message.startsWith("declined", 17)) {
pmTimeout = System.currentTimeMillis() + TIMEOUT_TWO_SECONDS;
tradeReqTimeout = 0L;
} else if (message.endsWith("area")) {
idle = true;
} else if (message.startsWith("Unable") || message.startsWith("Other") || message.endsWith("objects")) {
setState(State.STOP);
} else {
super.onServerMessage(message);
}
}
private void createGUI() {
// Top-level container
final JFrame frame = new JFrame("Taverley Black Dragons");
final Container contentPane = frame.getContentPane();
contentPane.setLayout(new BoxLayout(contentPane, BoxLayout.Y_AXIS));
// Panel with shared settings for all Roles
final JPanel sharedPanel = new JPanel(new GridLayout(0, 2, 5, 5));
sharedPanel.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
// Panel with settings for Master Role
final JPanel masterPanel = new JPanel(new GridLayout(0, 2, 5, 5));
masterPanel.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
// Panel with Ok / Cancel Buttons
final JPanel buttonPanel = new JPanel(new GridLayout(0, 2));
buttonPanel.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
// Choose Role
final JComboBox<Role> roleComboBox = new JComboBox<>(Role.values());
roleComboBox.addActionListener(e -> {
final JComboBox cb = (JComboBox) e.getSource();
for (final Component component : masterPanel.getComponents()) {
component.setEnabled(cb.getSelectedItem() == Role.MASTER);
}
});
sharedPanel.add(new JLabel("Role"));
sharedPanel.add(roleComboBox);
// Specify Traders
final JTextField traderTextField = new JTextField(12);
sharedPanel.add(new JLabel("Traders (comma sep.)"));
sharedPanel.add(traderTextField);
// Choose Food
final JComboBox<Food> foodComboBox = new JComboBox<>(new Food[]{Food.SHARK, Food.SWORDFISH, Food.LOBSTER, Food.BASS});
sharedPanel.add(new JLabel("Food"));
sharedPanel.add(foodComboBox);
// Set Food Count
final JSpinner foodCountSpinner = new JSpinner(new SpinnerNumberModel(10, 1, 28, 1));
sharedPanel.add(new JLabel("Food Count"));
sharedPanel.add(foodCountSpinner);
// Set Prayer Pot Count
final JSpinner ppSpinner = new JSpinner(new SpinnerNumberModel(0, 0, 27, 1));
ppSpinner.setValue(0);
sharedPanel.add(new JLabel("Prayer Potions"));
sharedPanel.add(ppSpinner);
// Set Super Atk Pot Count
final JSpinner supAtkSpinner = new JSpinner(new SpinnerNumberModel(0, 0, 27, 1));
supAtkSpinner.setValue(0);
sharedPanel.add(new JLabel("Super Attack Potions"));
sharedPanel.add(supAtkSpinner);
// Set Super Str Pot Count
final JSpinner supStrSpinner = new JSpinner(new SpinnerNumberModel(0, 0, 27, 1));
supStrSpinner.setValue(0);
sharedPanel.add(new JLabel("Super Strength Potions"));
sharedPanel.add(supStrSpinner);
// Set Super Def Pot Count
final JSpinner supDefSpinner = new JSpinner(new SpinnerNumberModel(0, 0, 27, 1));
supDefSpinner.setValue(0);
sharedPanel.add(new JLabel("Super Defense Potions"));
sharedPanel.add(supDefSpinner);
// Choose Combat Style
final JComboBox<CombatStyle> combatStyleComboBox = new JComboBox<>(new CombatStyle[]{CombatStyle.ATTACK, CombatStyle.STRENGTH, CombatStyle.DEFENSE});
masterPanel.add(new JLabel("Combat Style"));
masterPanel.add(combatStyleComboBox);
// Set Shield Swap
final JComboBox<Shield> shieldComboBox = new JComboBox<>(Shield.values());
masterPanel.add(new JLabel("Shield Swap"));
masterPanel.add(shieldComboBox);
// Set Min Hits
int defaultValue;
defaultValue = (int) Math.ceil(getBaseHits() * 0.60);
final JSpinner minHitsSpinner = new JSpinner(new SpinnerNumberModel(defaultValue, 1, 99, 1));
masterPanel.add(new JLabel("Min. Hits"));
masterPanel.add(minHitsSpinner);
// Set Min Prayer
defaultValue = 10;
final JSpinner minPrayerSpinner = new JSpinner(new SpinnerNumberModel(defaultValue, 1, 99, 1));
masterPanel.add(new JLabel("Min. Prayer"));
masterPanel.add(minPrayerSpinner);
// Set Min Attack
defaultValue = getBaseSkillLevel(Skill.ATTACK.getIndex()) + (calcSuperPotBoost(Skill.ATTACK.getIndex()) / 2);
final JSpinner minAtkSpinner = new JSpinner(new SpinnerNumberModel(defaultValue, 1, 118, 1));
masterPanel.add(new JLabel("Min. Attack"));
masterPanel.add(minAtkSpinner);
// Set Min Strength
defaultValue = getBaseSkillLevel(Skill.STRENGTH.getIndex()) + (calcSuperPotBoost(Skill.STRENGTH.getIndex()) / 2);
final JSpinner minStrSpinner = new JSpinner(new SpinnerNumberModel(defaultValue, 1, 118, 1));
masterPanel.add(new JLabel("Min. Strength"));
masterPanel.add(minStrSpinner);
// Set Min Defense
defaultValue = getBaseSkillLevel(Skill.DEFENSE.getIndex()) + (calcSuperPotBoost(Skill.DEFENSE.getIndex()) / 2);
final JSpinner minDefSpinner = new JSpinner(new SpinnerNumberModel(defaultValue, 1, 118, 1));
masterPanel.add(new JLabel("Min. Defense"));
masterPanel.add(minDefSpinner);
// Enable Spawn Camp
final JCheckBox spawnCampCheckBox = new JCheckBox("Spawn Camp");
masterPanel.add(spawnCampCheckBox);
masterPanel.add(Box.createGlue());
// Ok Button
final JButton okButton = new JButton("OK");
okButton.addActionListener(e -> {
role = (Role) roleComboBox.getSelectedItem();
if (role == Role.MASTER) {
if (!hasInventoryItem(ITEM_ID_SLEEPING_BAG)) {
System.err.println("Error: Sleeping bag missing from inventory.");
return;
}
if ((antiShieldIndex = getInventoryItemIndex(ITEM_ID_ANTI_DRAGON_BREATH_SHIELD)) == -1) {
System.err.println("Error: Anti dragon breath shield missing from inventory.");
return;
}
}
final String text = traderTextField.getText().trim();
if (text.contains(" ")) {
System.err.println("Error: Traders field cannot contain spaces. Use underscores.");
return;
}
final String[] traders = text.split(",");
if (traders.length == 0 || traders[0].isEmpty()) {
System.err.println("Error: Traders text field is empty.");
return;
}
if (role == Role.MASTER) {
if (traders.length > 1) {
System.err.println("Error: Master can only trade one mule.");
return;
}
currentTrader = traders[0].replace('_', ' ');
if (!isOnFriendList(currentTrader)) addToFriendList(currentTrader);
} else {
for (final String trader : traders) {
final String rsn = trader.replace('_', ' ');
if (!isOnFriendList(rsn)) addToFriendList(rsn);
this.traders.add(rsn);
}
}
food = (Food) foodComboBox.getSelectedItem();
foodCount = (int) foodCountSpinner.getValue();
int potionCount;
potionCount = (int) ppSpinner.getValue();
Potion.PRAYER.setUsing(potionCount > 0);
Potion.PRAYER.setCount(potionCount);
potionCount = (int) supAtkSpinner.getValue();
Potion.SUPER_ATTACK.setUsing(potionCount > 0);
Potion.SUPER_ATTACK.setCount(potionCount);
potionCount = (int) supStrSpinner.getValue();
Potion.SUPER_STRENGTH.setUsing(potionCount > 0);
Potion.SUPER_STRENGTH.setCount(potionCount);
potionCount = (int) supDefSpinner.getValue();
Potion.SUPER_DEFENSE.setUsing(potionCount > 0);
Potion.SUPER_DEFENSE.setCount(potionCount);
if (Potion.PRAYER.isUsing() && Potion.SUPER_DEFENSE.isUsing()) {
System.err.println("Error: Cannot use both ppots and sup def pots.");
return;
}
if (role == Role.MASTER) {
eatAt = getBaseHits() - food.getHealAmount();
prayAt = getBaseSkillLevel(Skill.PRAYER.getIndex()) - (int) (getBaseSkillLevel(Skill.PRAYER.getIndex()) * 0.25 + 7);
combatStyle = (CombatStyle) combatStyleComboBox.getSelectedItem();
final Shield shield = (Shield) shieldComboBox.getSelectedItem();
assert shield != null;
shieldIndex = getInventoryItemIndex(shield.getItemId());
if (shieldIndex != -1) equipmentIndexes.add(shieldIndex);
minHits = (int) minHitsSpinner.getValue();
minPrayer = (int) minPrayerSpinner.getValue();
minAtk = (int) minAtkSpinner.getValue();
minStr = (int) minStrSpinner.getValue();
minDef = (int) minDefSpinner.getValue();
spawnCamp = spawnCampCheckBox.isSelected();
for (int index = 0; index < getInventoryItemCount(); index++) {
if (!bot.isEquipped(index)) continue;
equipmentIndexes.add(index);
}
playerX = getPlayerX();
playerY = getPlayerY();
if (TBDArea.BLACK_DRAGONS.contains(playerX, playerY)) {
setState(State.KILL);
} else if (TBDArea.ISLAND.contains(playerX, playerY)) {
setState(State.TRADE);
} else {
System.err.println("Error: Must start script at Black Dragons or on the island.");
return;
}
bot.setCombatStyle(combatStyle.getIndex());
initHitsXp = getSkillExperience(Skill.HITS.getIndex());
} else {
if (getInventoryItemIdCount(food.getId()) < foodCount) {
setState(State.BANK);
} else {
for (final Potion potion : Potion.VALUES) {
if (potion.isUsing() && getInventoryItemIdCount(potion.getIds()[2]) < potion.getCount()) {
setState(State.BANK);
break;
}
}
}
if (state == null) setState(State.TRADE);
}
System.out.println("Info: Press 'l' to display loot paint.");
System.out.println("Info: Press 's' to display settings paint.");
System.out.printf("[%s] Script ready.%n", this);
startTime = System.currentTimeMillis();
initialized = true;
frame.dispose();
});
// Cancel Button
final JButton cancelButton = new JButton("Cancel");
cancelButton.addActionListener(e -> frame.dispose());
buttonPanel.add(okButton);
buttonPanel.add(cancelButton);
// Build
frame.add(sharedPanel);
frame.add(Box.createVerticalStrut(5));
frame.add(masterPanel);
frame.add(buttonPanel);
frame.setResizable(false);
frame.setLocationRelativeTo(null);
frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
frame.pack();
frame.setVisible(true);
frame.toFront();
frame.requestFocus();
}
private int calcSuperPotBoost(final int skillIndex) {
return (int) (getBaseSkillLevel(skillIndex) * 0.15 + 5);
}
private void setState(final State state) {
switch (state) {
case BANK:
if (traders.size() > 1) currentTrader = null;
updateLootMap();
break;
case TRADE:
if (role == Role.MASTER) updateLootMap();
break;
case KILL:
case FATIGUE:
case STOP:
break;
}
this.state = state;
}
private void updateLootMap() {
for (int index = 0; index < getInventoryItemCount(); index++) {
if (equipmentIndexes.contains(index)) continue;
final int itemId = getInventoryItemId(index);
if (!ITEM_IDS_LOOT.contains(itemId)) continue;
final int count = getInventoryItemCount(index);
lootMap.merge(itemId, count, Integer::sum);
}
}
@Override
public void paint() {
int y = PAINT_OFFSET_Y;
bot.drawString("@yel@Taverley Black Dragons", PAINT_OFFSET_X, y, 1, 0);
bot.drawString(String.format("@yel@State: @whi@%s", state.description),
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);
if (role == Role.MASTER) {
final double gainedHitsXp = getSkillExperience(Skill.HITS.getIndex()) - initHitsXp;
final int kills = (int) (gainedHitsXp / HITS_XP_BLACK_DRAGON);
if (kills != 0) {
bot.drawString(String.format("@yel@Dragons: @whi@%d @cya@(@whi@%s @whi@kills@cya@/@whi@hr@cya@)",
kills, toUnitsPerHour(kills, startTime)),
PAINT_OFFSET_X, y += PAINT_OFFSET_Y_INCREMENT * 2, 1, 0);
}
if (foodAte != 0) {
bot.drawString(String.format("@yel@%s: @whi@%d @cya@(@whi@%s @whi@food@cya@/@whi@hr@cya@)",
food, foodAte, toUnitsPerHour(foodAte, startTime)),
PAINT_OFFSET_X, y += PAINT_OFFSET_Y_INCREMENT, 1, 0);
}
for (final Potion potion : Potion.VALUES) {
if (!potion.isUsing()) continue;
final int consumed = potion.getSips() / 3;
if (consumed == 0) continue;
bot.drawString(String.format("@yel@%s: @whi@%d @cya@(@whi@%s @whi@pots@cya@/@whi@hr@cya@)",
potion.getDesc(), consumed, toUnitsPerHour(consumed, startTime)),
PAINT_OFFSET_X, y += PAINT_OFFSET_Y_INCREMENT, 1, 0);
}
}
if (paintLoot) {
y = PAINT_OFFSET_Y_LOOT;
int index = 0;
int xOffset = 107;
for (final Map.Entry<Integer, Integer> entry : lootMap.entrySet()) {
final int itemId = entry.getKey();
if (++index % 9 == 0) {
xOffset += 100;
y = PAINT_OFFSET_Y_LOOT;
}
String name = getItemName(itemId);
if (name.length() > 12) name = name.substring(0, 12);
bot.drawString(String.format("%s: @whi@%d", name, entry.getValue()),
xOffset, y += PAINT_OFFSET_Y_INCREMENT, 1, 0xFF0000);
}
} else if (paintSettings) {
y = PAINT_OFFSET_Y;
bot.drawString(String.format("Role: @whi@%s", role),
PAINT_OFFSET_X_SETTINGS, y, 1, 0x00FF00);
if (role == Role.MASTER) {
bot.drawString(String.format("Trader: @whi@%s", currentTrader),
PAINT_OFFSET_X_SETTINGS, y += PAINT_OFFSET_Y_INCREMENT, 1, 0x00FF00);
bot.drawString(String.format("Spawn Camp: @whi@%s", spawnCamp),
PAINT_OFFSET_X_SETTINGS, y += PAINT_OFFSET_Y_INCREMENT, 1, 0x00FF00);
bot.drawString(String.format("Shield Index: @whi@%d", shieldIndex),
PAINT_OFFSET_X_SETTINGS, y += PAINT_OFFSET_Y_INCREMENT, 1, 0x00FF00);
bot.drawString(String.format("Anti Index: @whi@%d", antiShieldIndex),
PAINT_OFFSET_X_SETTINGS, y += PAINT_OFFSET_Y_INCREMENT, 1, 0x00FF00);
bot.drawString(String.format("Min Stats: @whi@H%d P%d A%d S%d D%d",
minHits, minPrayer, minAtk, minStr, minDef),
PAINT_OFFSET_X_SETTINGS, y += PAINT_OFFSET_Y_INCREMENT, 1, 0x00FF00);
bot.drawString(String.format("Thresholds: @whi@H%d P%d", eatAt, prayAt),
PAINT_OFFSET_X_SETTINGS, y += PAINT_OFFSET_Y_INCREMENT, 1, 0x00FF00);
} else {
for (final String trader : traders) {
bot.drawString(String.format("Trader: @whi@%s", trader),
PAINT_OFFSET_X_SETTINGS, y += PAINT_OFFSET_Y_INCREMENT, 1, 0x00FF00);
}
}
bot.drawString(String.format("%s: @whi@%d", food, foodCount),
PAINT_OFFSET_X_SETTINGS, y += PAINT_OFFSET_Y_INCREMENT, 1, 0x00FF00);
for (final Potion potion : Potion.VALUES) {
bot.drawString(String.format("%s: @whi@%d", potion.getDesc(), potion.count),
PAINT_OFFSET_X_SETTINGS, y += PAINT_OFFSET_Y_INCREMENT, 1, 0x00FF00);
}
}
}
@Override
public void onTradeRequest(final String playerName) {
if (role != Role.MULE || !isAtCoordinate(COORD_TRADE_MULE)) return;
if (currentTrader != null) {
if (!playerName.equalsIgnoreCase(currentTrader)) return;
final Object player = getPlayerObjByName(playerName);
if (player != null) {
sendTradeRequest(getServerIndex(player));
} else {
currentTrader = null;
}
return;
}
for (final String trader : traders) {
if (!playerName.equalsIgnoreCase(trader)) continue;
final Object player = getPlayerObjByName(playerName);
if (player == null) return;
currentTrader = playerName;
sendTradeRequest(getServerIndex(player));
break;
}
}
@Override
public void onPrivateMessage(final String message, final String playerName, final boolean moderator,
final boolean administrator) {
if (role == Role.MASTER) {
if (!playerName.equalsIgnoreCase(currentTrader)) return;
if (message.equalsIgnoreCase("stop")) {
setState(State.STOP);
} else {
final Potion potion = Potion.valueOf(message.toUpperCase());
potion.setUsing(false);
}
} else {
if (!playerName.equalsIgnoreCase(currentTrader)) return;
if (message.equalsIgnoreCase("bank")) {
setState(State.BANK);
} else {
supplyRequest = SupplyRequest.parse(message);
}
}
}
@Override
public void onKeyPress(final KeyEvent keyEvent) {
switch (keyEvent.getKeyCode()) {
case KeyEvent.VK_L:
if (lootMap.isEmpty()) {
bot.displayMessage("@red@You have no loot to display.");
keyEvent.consume();
return;
}
if (paintSettings) paintSettings = false;
paintLoot = !paintLoot;
keyEvent.consume();
break;
case KeyEvent.VK_S:
if (paintLoot) paintLoot = false;
paintSettings = !paintSettings;
keyEvent.consume();
break;
}
}
@Override
public void onPlayerDamaged(final Object player) {
if (!isInCombat() || player != bot.getPlayer()) return;
final int index = combatStyle.getIndex();
if (bot.getCombatStyle() != index) bot.setCombatStyle(index);
}
@Override
public void onNpcDamaged(final Object npc) {
if (!isInCombat() || getWaypointX(npc) != bot.getPlayerWaypointX() ||
getWaypointY(npc) != bot.getPlayerWaypointY()) {
return;
}
final int index;
if (Potion.PRAYER.isUsing()) {
index = combatStyle.getIndex();
disableTick = tickCount + 1;
enableParalyzeMonster();
} else {
index = CombatStyle.DEFENSE.getIndex();
if (shieldIndex != -1 && !bot.isEquipped(shieldIndex)) equipItem(shieldIndex);
}
if (bot.getCombatStyle() != index) bot.setCombatStyle(index);
}
@Override
public void onNpcSpawned(final java.lang.Object npc) {
if (!spawnCamp || bot.getNpcId(npc) != NPC_ID_BLACK_DRAGON) return;
final int serverIndex = getServerIndex(npc);
final Spawn spawn = spawnMap.get(serverIndex);
final int x = getX(npc);
final int y = getY(npc);
if (spawn != null) {
spawn.getCoordinate().set(x, y);
spawn.setTimestamp(Long.MAX_VALUE);
} else {
spawnMap.put(serverIndex, new Spawn(new Coordinate(x, y), Long.MAX_VALUE));
}
nextRespawn = getNextRespawn();
}
@Override
public void onNpcDespawned(final Object npc) {
if (!spawnCamp || bot.getNpcId(npc) != NPC_ID_BLACK_DRAGON || state != State.KILL) return;
final int serverIndex = getServerIndex(npc);
final Spawn spawn = spawnMap.get(serverIndex);
if (spawn == null) return;
spawn.setTimestamp(System.currentTimeMillis());
nextRespawn = getNextRespawn();
}
@Override
public void onPlayerCoord(final int x, final int y) {
++tickCount;
if (!isInCombat() || !Potion.PRAYER.isUsing()) return;
if (tickCount == disableTick) disableParalyzeMonster();
}
private void disableParalyzeMonster() {
if (!bot.isPrayerEnabled(PRAYER_ID_PARALYZE_MONSTER)) return;
disablePrayer(PRAYER_ID_PARALYZE_MONSTER);
}
private Coordinate getNextRespawn() {
if (spawnMap.isEmpty()) return null;
return spawnMap.values().stream().min(Comparator.naturalOrder()).get().getCoordinate();
}
private void enableParalyzeMonster() {
if (!Potion.PRAYER.isUsing() || bot.isPrayerEnabled(PRAYER_ID_PARALYZE_MONSTER) || !hasPrayer()) return;
enablePrayer(PRAYER_ID_PARALYZE_MONSTER);
}
private boolean hasPrayer() {
return getCurrentSkillLevel(Skill.PRAYER.getIndex()) > 0;
}
private int master() {
switch (state) {
case KILL:
return kill();
case FATIGUE:
return fatigue();
case TRADE:
return tradeWithMule();
case STOP:
return stop();
default:
return exit(String.format("%s invalid state for role %s", state, role));
}
}
private int kill() {
if (TBDArea.ISLAND.contains(playerX, playerY)) {
int index;
if ((canEat() && (index = getInventoryItemIndex(food.getId())) != -1) ||
(canRestorePrayer() && (index = getInventoryItemIndex(Potion.PRAYER.getIds())) != -1)) {
return consumeIndex(index);
}
final Coordinate ladder = TBDObject.LADDER_DOWN.getCoordinate();
atObject(ladder.getX(), ladder.getY());
return SLEEP_ONE_TICK;
}
updateLoot();
if (isInCombat()) {
if (loot[0] != -1 ||
needToEat() ||
needToRestorePrayer() ||
needToDrinkSuperAtkPot() ||
needToDrinkSuperStrPot() ||
needToDrinkSuperDefPot()) {
walkTo(playerX, playerY);
return SLEEP_ONE_TICK;
}
return 0;
}
if (!bot.isEquipped(antiShieldIndex)) {
equipItem(antiShieldIndex);
return SLEEP_ONE_TICK;
}
if (needToEat()) return consumeItemId(food.getId());
if (needToRestorePrayer()) return consumeItemId(Potion.PRAYER.getIds());
if (isInventoryFull() && !hasInventoryItem(food.getId()) && !hasInventoryItem(ITEM_ID_VIAL)) {
setState(State.TRADE);
return 0;
}
if (loot[0] != -1) return pickUpLoot();
if (getFatiguePercent() >= MAX_FATIGUE) {
setState(State.FATIGUE);
return 0;
}
final Object dragon = getNearestNpcNotInCombat(NPC_ID_BLACK_DRAGON);
if (dragon != null) {
if (needToDrinkSuperAtkPot()) return consumeItemId(Potion.SUPER_ATTACK.getIds());
if (needToDrinkSuperStrPot()) return consumeItemId(Potion.SUPER_STRENGTH.getIds());
if (needToDrinkSuperDefPot()) return consumeItemId(Potion.SUPER_DEFENSE.getIds());
return attack(dragon);
}
if (bot.isPrayerEnabled(PRAYER_ID_PARALYZE_MONSTER) && System.currentTimeMillis() > disablePrayerTimeout) {
disableParalyzeMonster();
}
if ((nextRespawn != null && isAtCoordinate(nextRespawn)) || isAtCoordinate(COORD_WAIT_RESPAWN)) {
return SLEEP_ONE_TICK;
}
int index;
if ((canEat() && (index = getInventoryItemIndex(food.getId())) != -1) ||
(canRestorePrayer() && (index = getInventoryItemIndex(Potion.PRAYER.getIds())) != -1)) {
return consumeIndex(index);
}
final Coordinate coord = nextRespawn != null ? nextRespawn : COORD_WAIT_RESPAWN;
walkTo(coord.getX(), coord.getY());
return SLEEP_ONE_TICK;
}
private void updateLoot() {
loot[0] = -1;
int currentDistance = Integer.MAX_VALUE;
for (int index = 0; index < bot.getGroundItemCount(); index++) {
final int id = bot.getGroundItemId(index);
if (!ITEM_IDS_LOOT.contains(id)) continue;
final int x = getGroundItemX(index);
final int y = getGroundItemY(index);
if (!TBDArea.BLACK_DRAGONS.contains(x, y)) continue;
final int distance = distanceTo(x, y);
if (distance >= currentDistance) continue;
currentDistance = distance;
loot[0] = id;
loot[1] = x;
loot[2] = y;
}
}
private int pickUpLoot() {
if (!isInventoryFull() || (ITEM_IDS_LOOT_STACKABLE.contains(loot[0]) && hasInventoryItem(loot[0]))) {
pickupItem(loot[0], loot[1], loot[2]);
return SLEEP_ONE_TICK;
}
int index;
if ((index = getInventoryItemIndex(ITEM_ID_VIAL)) != -1) {
dropItem(index);
return SLEEP_TWO_SECONDS;
}
if ((index = getInventoryItemIndex(food.getId())) != -1) return consumeIndex(index);
return 0;
}
private int attack(final Object dragon) {
if (distanceTo(dragon) <= MAX_DIST_FROM_DRAGON) {
enableParalyzeMonster();
attackNpc(dragon);
disablePrayerTimeout = System.currentTimeMillis() + TIMEOUT_FIVE_SECONDS;
return SLEEP_ONE_TICK;
}
disableParalyzeMonster();
int index;
if ((canEat() && (index = getInventoryItemIndex(food.getId())) != -1) ||
(canRestorePrayer() && (index = getInventoryItemIndex(Potion.PRAYER.getIds())) != -1)) {
return consumeIndex(index);
}
walkTo(dragon);
return SLEEP_ONE_TICK;
}
private int fatigue() {
if (!TBDArea.ISLAND.contains(playerX, playerY)) return climbUpLadder();
disableParalyzeMonster();
if (getFatiguePercent() != 0) return sleep();
setState(State.KILL);
return 0;
}
private int tradeWithMule() {
if (!TBDArea.ISLAND.contains(playerX, playerY)) return climbUpLadder();
if (isTradeConfirmOpen()) {
if (!isTradeConfirmed()) confirmTrade();
return 0;
}
if (isTradeAcceptOpen()) return masterAcceptTrade();
disableParalyzeMonster();
final int vialIndex = getInventoryItemIndex(ITEM_ID_VIAL);
if (vialIndex != -1) {
dropItem(vialIndex);
return SLEEP_TWO_SECONDS;
}
if (getInventoryItemIdCount(food.getId()) < foodCount) return requestTrade();
if (hasLoot()) return requestTrade();
for (final Potion potion : Potion.VALUES) {
if (!potion.isUsing()) continue;
if (getInventoryItemIdCount(potion.getIds()) < potion.getCount()) return requestTrade();
}
final Object player = getPlayerObjByName(currentTrader);
if (player == null || getX(player) != COORD_TRADE_MULE.getX() || getY(player) != COORD_TRADE_MULE.getY()) {
setState(State.KILL);
return 0;
}
if (System.currentTimeMillis() <= pmTimeout) return 0;
bot.sendPrivateMessage("bank", currentTrader);
pmTimeout = System.currentTimeMillis() + TIMEOUT_THREE_SECONDS;
return 0;
}
private int climbUpLadder() {
if (isInCombat()) {
final Coordinate ladder = TBDObject.LADDER_UP.getCoordinate();
walkTo(ladder.getX(), ladder.getY() - 1);
return SLEEP_ONE_TICK;
}
if (!bot.isEquipped(antiShieldIndex)) {
equipItem(antiShieldIndex);
return SLEEP_ONE_TICK;
}
if (needToEat()) {
final int index = getInventoryItemIndex(food.getId());
if (index != -1) return consumeIndex(index);
}
if (needToRestorePrayer()) {
final int index = getInventoryItemIndex(Potion.PRAYER.getIds());
if (index != -1) return consumeIndex(index);
}
final Coordinate ladder = TBDObject.LADDER_UP.getCoordinate();
if (distanceTo(ladder.getX(), ladder.getY()) > 1) {
final Object npc = getBlockingNpc();
if (npc != null) {
attackNpc(npc);
} else {
walkTo(ladder.getX(), ladder.getY() - 1);
}
} else {
atObject(ladder.getX(), ladder.getY());
}
return SLEEP_ONE_TICK;
}
private Object getBlockingNpc() {
final Coordinate ladder = TBDObject.LADDER_UP.getCoordinate();
for (int index = 0; index < bot.getNpcCount(); index++) {
final Object npc = bot.getNpc(index);
final int x = getX(npc);
final int y = getY(npc);
if (distanceTo(x, y) != 1 || distanceTo(x, y, ladder.getX(), ladder.getY()) != 1) continue;
return npc;