-
Notifications
You must be signed in to change notification settings - Fork 20
Expand file tree
/
Copy pathVoluntaryThieve.java
More file actions
3406 lines (2969 loc) · 98.8 KB
/
VoluntaryThieve.java
File metadata and controls
3406 lines (2969 loc) · 98.8 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
/*
* @(#)VoluntaryThieve.java 1.13 10/12/17
* Copyright 2010 vilon@powerbot.org. All rights reserved.
*/
import org.rsbot.event.events.MessageEvent;
import org.rsbot.event.listeners.MessageListener;
import org.rsbot.event.listeners.PaintListener;
import org.rsbot.script.Script;
import org.rsbot.script.ScriptManifest;
import org.rsbot.script.methods.Game;
import org.rsbot.script.methods.Skills;
import org.rsbot.script.util.Timer;
import org.rsbot.script.util.WindowUtil;
import org.rsbot.script.wrappers.*;
import org.rsbot.util.GlobalConfiguration;
import javax.swing.*;
import javax.swing.event.MouseInputListener;
import java.awt.*;
import java.awt.event.MouseEvent;
import java.io.*;
import java.net.URL;
import java.net.URLConnection;
import java.text.NumberFormat;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.logging.Level;
import java.util.prefs.Preferences;
@ScriptManifest(authors = "vilon", name = "Voluntary Thieve", keywords = "Thieving", version = 1.13, description = "Blackjacks/pickpockets the trainers and volunteers in the Thieves' Guild.")
public final class VoluntaryThieve extends Script implements
MouseInputListener, PaintListener, MessageListener {
/**
* The <tt>Action</tt>-class is used to represent an actual in-game action.
* Provides the skeleton for performing an action, confirming the action and
* finally verify that the result of the action matches the desired result.
*/
private static abstract class Action {
/**
* Represents the steps of an action.
*/
static final class Steps {
/**
* The constant representing the "PERFORM"-step.
*/
private static final int PERFORM = 0;
/**
* The constant representing the "CONFIRM"-step.
*/
private static final int CONFIRM = 1;
/**
* The constant representing the "FINISH"-step.
*/
private static final int FINISH = 2;
/**
* The maximum times of the steps, in order: PERFORM, CONFIRM,
* FINISH.
*/
private final long[] maximumTimes;
/**
* The starting times of the steps, in order: PERFORM, CONFIRM,
* FINISH.
*/
private final long[] startingTimes = new long[3];
/**
* The current step in the action-process.
*/
private int currentStep = PERFORM;
/**
* Creates a new instance representing the steps of an action.
*
* @param maximumTimes The maximum times of the individual steps, in the
* order: PERFORM, CONFIRM, FINISH.
* @throws IllegalArgumentException If the length of <tt>maximumTimes</tt> wasn't three,
* or if any of the maximum times were below zero.
*/
private Steps(final long... maximumTimes)
throws IllegalArgumentException {
if (maximumTimes.length != 3) {
throw new IllegalArgumentException(
"Invalid argument length, expected 3 was "
+ maximumTimes.length + ".");
}
for (final long maximumTime : maximumTimes) {
if (maximumTime < 0) {
throw new IllegalArgumentException(
"Maximum time was below zero: " + maximumTime);
}
}
this.maximumTimes = maximumTimes;
}
/**
* Gets the current step in the action-process.
*
* @return The current step in the action-process.
*/
private int getCurrent() {
return currentStep;
}
/**
* Sets the starting time to that of the systems current time.
*/
private void setStartingTime() {
startingTimes[getCurrent()] = System.currentTimeMillis();
}
/**
* Gets the starting time of the current step.
*
* @return The starting time of the current step, or <tt>0</tt> if
* not set.
*/
private long getStartingTime() {
return startingTimes[getCurrent()];
}
/**
* Checks whether the starting time has been set or not.
*
* @return <tt>true</tt> if the starting time has been set;
* otherwise <tt>false</tt>.
*/
private boolean isStartingTimeSet() {
return (getStartingTime() > 0);
}
/**
* Sets the current step to the next step in the set order.
*
* @throws IllegalStateException If the method is called when the current step is the
* <tt>FINISH</tt>-step.
*/
private void next() throws IllegalStateException {
if (getCurrent() >= FINISH) {
throw new IllegalStateException(
"Unable to switch step, current step is: "
+ getCurrent());
}
currentStep++;
}
/**
* Checks if the maximum time set has passed, i.e. if it's now
* obsolete to continue doing the action.
*
* @return <tt>true</tt> if the maximum time has passed; otherwise
* <tt>false</tt>.
* @throws IllegalStateException If the starting time has not been set.
*/
private boolean isObsolete() throws IllegalStateException {
if (!isStartingTimeSet()) {
throw new IllegalStateException(
"Starting time has not been set.");
}
return (System.currentTimeMillis() - getStartingTime() >= maximumTimes[getCurrent()]);
}
}
/**
* The states which tells if an action was completed, failed or is still
* in progress.
*/
enum State {
COMPLETED, FAILED, PROGRESSING
}
/**
* The user-friendly name of this action.
*/
private final String name;
/**
* The identification for this action.
*/
private final int id;
/**
* The current step in the action-process.
*/
final Steps steps;
/**
* This will contain the final state when the action is done (i.e.
* failed/completed).
*/
private State actionDoneState;
/**
* Creates a new <tt>Action</tt> with the maximum times for the three
* steps of the action, namely the perform-, confirm- and finish-step.
*
* @param name The user-friendly name of this action.
* @param id The identification for this action.
* @param maximumTimes The maximum times for the steps, in the order: PERFORM,
* CONFIRM, FINISH.
*/
private Action(final String name, final int id,
final long... maximumTimes) {
this.id = id;
this.name = name;
steps = new Steps(maximumTimes);
}
/**
* Creates a new <tt>Action</tt> with the maximum times for two of the
* three steps of the action, namely the perform-, and finish-step. The
* confirm-step defaults to completed but can be overridden and will in
* that case be called once before failing.
*
* @param name The user-friendly name of this action.
* @param id The identification for this action.
* @param perform The maximum time before the perform-step is obsolete.
* @param finish The maximum time before the finish-step is obsolete.
*/
private Action(final String name, final int id, final long perform,
final long finish) {
this(name, id, perform, 0, finish);
}
/**
* Gets the user-friendly name of this action.
*
* @return The user-friendly name of the action.
*/
private String getName() {
return name;
}
/**
* Gets the identification for this action.
*
* @return The identification for this action.
*/
private int getId() {
return id;
}
/**
* Performs this action. Should be looped as long as the return-value is
* <tt>State.PROGRESSING</tt>. No matter how low a maximum time for a
* step is set, the corresponding method will always be called once,
* before making any conclusions.
*
* @return One of the following states: State.PROGRESSING - The action
* is still in progress. State.COMPLETED - The action completed
* successfully. State.FAILED - The action did not complete
* successfully.
*/
private State doAction() {
if (actionDoneState != null) {
return actionDoneState;
}
if (!steps.isStartingTimeSet()) {
steps.setStartingTime();
}
State returnState;
switch (steps.getCurrent()) {
case Steps.PERFORM:
if ((returnState = perform()) == State.COMPLETED) {
steps.next();
return State.PROGRESSING;
}
break;
case Steps.CONFIRM:
if ((returnState = confirm()) == State.COMPLETED) {
steps.next();
return State.PROGRESSING;
}
break;
case Steps.FINISH:
if ((returnState = finish()) == State.COMPLETED) {
return (actionDoneState = State.COMPLETED);
}
break;
default:
throw new AssertionError("Unsupported step: "
+ steps.getCurrent());
}
return (returnState == State.FAILED || steps.isObsolete()) ? (actionDoneState = State.FAILED)
: State.PROGRESSING;
}
/**
* Performs the selected action, e.x. clicking on an object.
*
* @return The <tt>State</tt>, telling if the operation was successful
* or not, or if the action is still in progress.
*/
abstract State perform();
/**
* Confirms the selected action, e.x. the click on the object.
*
* @return The <tt>State</tt>, telling if the operation was successful
* or not, or if the action is still in progress.
*/
State confirm() {
return State.COMPLETED;
}
/**
* Checks if the actions result matches the desired result of the
* action.
*
* @return The <tt>State</tt>, telling if the operation was successful
* or not, or if the action is still in progress.
*/
abstract State finish();
}
/**
* The class <tt>Actions</tt> contains all actions used in this script.
*/
private final class Actions {
/**
* Contains all the custom methods being shared among actions.
*/
private final class Methods {
/**
* Checks if the the player is logged in and has passed the welcome
* screen. Also makes sure that skill levels and such are loaded, so
* no misreadings happen.
*
* @return <tt>true</tt> if the player is logged in and has passed
* the welcome screen; otherwise <tt>false</tt>.
*/
private boolean isLoggedIn() {
return (game.isLoggedIn() && skills
.getRealLevel(Skills.THIEVING) > 1);
}
/**
* Gets the identifications for the trainers to use in the current
* mode. Excludes trainers that have explicitly been marked as not
* to be included.
*
* @return The identifications for the trainers to use.
*/
private int[] getTrainers() {
final int[] allTrainers = options.isBlackjacking ? new int[]{
11289, 11291, 11293, 11297} : new int[]{11281,
11283, 11285, 11287};
final List<Integer> validTrainers = new ArrayList<Integer>();
for (final Integer trainer : allTrainers) {
final Boolean isIncluded = trainerInclusions.get(trainer);
if (isIncluded == null || isIncluded) {
validTrainers.add(trainer);
}
}
final int[] resultTrainers = new int[validTrainers.size()];
for (int i = 0; i < validTrainers.size(); i++) {
resultTrainers[i] = validTrainers.get(i);
}
return resultTrainers;
}
/**
* Gets if the door to the bank is open or closed.
*
* @return <tt>true</tt> if the door could be found and is open;
* <tt>false</tt> if the door could not be found or is
* closed.
*/
private boolean isDoorOpen() {
final RSObject door = getOpenDoor();
return (door != null && door.getID() == Values.OBJECT_DOOR_OPEN);
}
/**
* Gets the object at the position where the door to the bank should
* be if it is currently open.
*
* @return The <tt>RSObject</tt> at the position of the open door.
*/
private RSObject getOpenDoor() {
return objects.getTopAt(new RSTile(4755 + tileOffset.x,
5795 + tileOffset.y));
}
/**
* Gets the object at the position where the door to the bank should
* be if it is currently closed.
*
* @return The <tt>RSObject</tt> at the position of the closed door.
*/
private RSObject getClosedDoor() {
return objects.getTopAt(new RSTile(4754 + tileOffset.x,
5795 + tileOffset.y));
}
/**
* Gets if any of the interfaces for the conversation when luring is
* valid or not.
*
* @return <tt>true</tt> if any of the interfaces for the
* conversation when luring is valid; otherwise
* <tt>false</tt>.
*/
private boolean isLureScreenValid() {
if (hasKnockoutFailed()) {
return false;
}
final int[] screens = {Values.INTERFACE_LURE_FIRST,
Values.INTERFACE_LURE_SECOND};
for (final int screen : screens) {
final RSInterface screenInterface = interfaces.get(screen);
if (screenInterface != null && screenInterface.isValid()) {
return true;
}
}
return false;
}
/**
* Gets if the knock-out attempt has failed and the npc needs to be
* lured again.
*
* @return <tt>true</tt> if the knock-out attempt has failed;
* otherwise <tt>false</tt>.
*/
private boolean hasKnockoutFailed() {
final RSInterface failScreen = interfaces
.get(Values.INTERFACE_LURE_FIRST);
return (failScreen != null && failScreen.isValid() && failScreen
.getComponent(4).containsText("divert"));
}
/**
* Gets if the player is considered to be stunned.
*
* @return <tt>true</tt> if the player is stunned; otherwise
* <tt>false</tt>.
*/
private boolean isStunned() {
return (stunnedTimer != null && stunnedTimer.isRunning());
}
/**
* Gets the appropriate action to do in order to handle the opening
* of a door.
*
* @return The appropriate {@link VoluntaryThieve.Action} to take
* when opening the door.
*/
private Action getDoorAction() {
final RSObject door = methods.getClosedDoor();
return (door != null && calc.distanceTo(door.getLocation()) < 5) ? get(Values.ACTION_BANK_DOOR_OPEN)
: get(Values.ACTION_BANK_DOOR_WALK);
}
/**
* Gets if the player is inside the bank-area.
*
* @return <tt>true</tt> if the player is in the bank-area;
* otherwise <tt>false</tt>.
*/
private boolean isInBank() {
return new RSArea(new RSTile(4747 + tileOffset.x,
5793 + tileOffset.y), new RSTile(4754 + tileOffset.x,
5797 + tileOffset.y)).contains(getMyPlayer()
.getLocation());
}
/**
* Gets if the player is located inside the thieves guild or not.
*
* @return <tt>true</tt> if the player is inside the thieves guild;
* otherwise <tt>false</tt>.
*/
private boolean isInGuild() {
return new RSArea(new RSTile(4745 + tileOffset.x,
5762 + tileOffset.y), new RSTile(4794 + tileOffset.x,
5806 + tileOffset.y)).contains(getMyPlayer()
.getLocation())
&& game.getPlane() == 0;
}
/**
* Gets the offset to use for all locations in the script. This is
* used because, depending on how many capers the user has
* completed, the guild will be placed differently in the runescape
* world.
*
* @return The offset to be used for locations in the script.
*/
private Point getOffset() {
final RSTile playerLocation = getMyPlayer().getLocation();
final Point offset = new Point();
if (4617 <= playerLocation.getX()
&& playerLocation.getX() <= 4666) {
offset.x = -128;
}
if (5890 <= playerLocation.getY()
&& playerLocation.getY() <= 5934) {
offset.y = 128;
}
return offset;
}
}
/**
* Contains all the values being shared among actions.
*/
private final class Values {
/**
* An item identification - gloves of silence.
*/
private static final int ITEM_GLOVES_OF_SILENCE = 10075;
/**
* An item identification - rubber blackjack.
*/
private static final int ITEM_RUBBER_BLACKJACK = 18644;
/**
* An object identification - the door to the bank when open.
*/
private static final int OBJECT_DOOR_OPEN = 52315;
/**
* An object identification - the bank-booth in the guild.
*/
private static final int OBJECT_BANK_BOOTH = 52397;
/**
* An interface identification - the first lure conversation screen.
*/
private static final int INTERFACE_LURE_FIRST = 64;
/**
* An interface identification - the second lure conversation
* screen.
*/
private static final int INTERFACE_LURE_SECOND = 241;
/**
* An animation identification - the animation when an npc is
* knocked out.
*/
private static final int ANIMATION_KNOCKED_OUT = 12413;
/**
* An identifier for an action - walks to the specified trainer
* (passed as argument).
*/
private static final int ACTION_WALK_TO_TRAINER = 0;
/**
* An identifier for an action - walks to the area with the
* trainers.
*/
private static final int ACTION_WALK_TO_TRAINING_AREA = 1;
/**
* An identifier for an action - pickpockets the specified trainer
* (passed as argument).
*/
private static final int ACTION_PICKPOCKET_TRAINER = 2;
/**
* An identifier for an action - lures the specified trainer (passed
* as argument).
*/
private static final int ACTION_LURE_TRAINER = 3;
/**
* An identifier for an action - lures the specified trainer (passed
* as argument).
*/
private static final int ACTION_LURE_TALK_TRAINER = 4;
/**
* An identifier for an action - knocks-out the specified trainer
* (passed as argument).
*/
private static final int ACTION_KNOCK_TRAINER = 5;
/**
* An identifier for an action - walks to the nearby bank.
*/
private static final int ACTION_BANK_WALK = 6;
/**
* An identifier for an action - walks to the nearby bank area.
*/
private static final int ACTION_BANK_WALK_AREA = 7;
/**
* An identifier for an action - opens the door at the nearby bank.
*/
private static final int ACTION_BANK_DOOR_OPEN = 8;
/**
* An identifier for an action - walks to the door at the nearby
* bank.
*/
private static final int ACTION_BANK_DOOR_WALK = 9;
/**
* An identifier for an action - opens the bank at the nearby bank.
*/
private static final int ACTION_BANK_OPEN = 10;
/**
* An identifier for an action - banks at the nearby bank.
*/
private static final int ACTION_BANK_BANKING = 11;
/**
* An identifier for an action - waits while being stunned.
*/
private static final int ACTION_STUNNED_WAIT = 12;
/**
* An identifier for an action - equips a new pair of gloves.
*/
private static final int ACTION_EQUIP_GLOVES = 13;
/**
* An identifier for an action - waits for the player to get into
* the thieves guild.
*/
private static final int ACTION_FAILSAFE_TIMEOUT = 14;
/**
* The amount of actions available (from 0 to
* <tt>ACTION_COUNT_TOTAL</tt> - 1).
*/
private static final int ACTIONS_TOTAL_COUNT = 15;
}
/**
* Holds all the methods being shared among actions.
*/
private final Methods methods = new Methods();
/**
* <tt>true</tt> if the user has gloves equipped.
*/
private boolean hasGloves;
/**
* <tt>true</tt> if the player is using gloves; otherwise <tt>false</tt>
* .
*/
private boolean isUsingGloves = true;
/**
* <tt>true</tt> if the equipment has been checked for gloves.
*/
private boolean isEquipmentChecked;
/**
* <tt>true</tt> if a pickpocket has been done since the last check.
*/
private boolean hasThieved;
/**
* Checks an extra time for npcs on the mainscreen before walking.
*/
private boolean isExtraCheckDone;
/**
* When <tt>true</tt> it forces blackjack (knockout) to be performed.
*/
private boolean isForcingBlackjack;
/**
* <tt>true</tt> if the npc has been lured; otherwise <tt>false</tt>.
*/
private boolean isLured;
/**
* <tt>true</tt> if unable to reach the current trainer; otherwise
* <tt>false</tt>.
*/
private boolean isUnableToReach;
/**
* The identification for the trainer currently being targeted.
*/
private int currentTrainerId;
/**
* Keeps track of how long we been stunned for and when the stun ends.
*/
private Timer stunnedTimer;
/**
* The offset used for all locations in the script (for all actions).
*/
private Point tileOffset;
/**
* Maps the trainers ids against their status (<tt>true</tt> to be
* included).
*/
private final Map<Integer, Boolean> trainerInclusions = new HashMap<Integer, Boolean>();
/**
* Gets the next action to be performed.
*
* @return The next <tt>Action</tt> to be performed or <tt>null</tt> if
* unable to get the next step.
*/
private Action getNext() {
if (!methods.isInGuild()) {
return get(Values.ACTION_FAILSAFE_TIMEOUT);
}
if (!options.isBlackjacking && isUsingGloves) {
if (!isEquipmentChecked) {
hasGloves = equipment
.containsAll(Values.ITEM_GLOVES_OF_SILENCE);
isEquipmentChecked = true;
}
if (!hasGloves) {
if (inventory.contains(Values.ITEM_GLOVES_OF_SILENCE)) {
return get(Values.ACTION_EQUIP_GLOVES);
}
if (options.isBanking) {
currentTrainerId = 0;
if (!methods.isInBank() && !methods.isDoorOpen()) {
return methods.getDoorAction();
}
final RSObject bankBooth = objects
.getNearest(Values.OBJECT_BANK_BOOTH);
if (bankBooth == null) {
return get(Values.ACTION_BANK_WALK_AREA);
}
if (!bankBooth.isOnScreen()) {
return calc.tileOnMap(bankBooth.getLocation()) ? get(Values.ACTION_BANK_WALK)
: get(Values.ACTION_BANK_WALK_AREA);
}
return bank.isOpen() ? get(Values.ACTION_BANK_BANKING)
: get(Values.ACTION_BANK_OPEN);
} else {
isUsingGloves = false;
log("Won't be using any more gloves of silence.");
}
}
}
if (methods.isStunned()) {
currentTrainerId = 0;
return get(Values.ACTION_STUNNED_WAIT);
}
if (methods.isInBank() && !methods.isDoorOpen()) {
return methods.getDoorAction();
}
final int[] trainerIds = (currentTrainerId != 0) ? new int[]{currentTrainerId}
: methods.getTrainers();
if (trainerIds.length == 0) {
return get(Values.ACTION_WALK_TO_TRAINING_AREA);
}
final RSNPC nearestTrainer = npcs.getNearest(trainerIds);
if (nearestTrainer == null) {
return get(Values.ACTION_WALK_TO_TRAINING_AREA);
}
if (isUnableToReach) {
trainerInclusions.put(nearestTrainer.getID(), false);
isUnableToReach = false;
currentTrainerId = 0;
return getNext();
}
if (!nearestTrainer.isOnScreen()) {
if (!isExtraCheckDone) {
currentTrainerId = 0;
isExtraCheckDone = true;
return getNext();
}
isExtraCheckDone = false;
return calc.tileOnMap(nearestTrainer.getLocation()) ? get(
Values.ACTION_WALK_TO_TRAINER, nearestTrainer)
: get(Values.ACTION_WALK_TO_TRAINING_AREA);
}
currentTrainerId = nearestTrainer.getID();
if (options.isBlackjacking
&& nearestTrainer.getAnimation() != Values.ANIMATION_KNOCKED_OUT) {
if (!isForcingBlackjack) {
if (methods.hasKnockoutFailed()) {
isLured = false;
}
if (!isLured) {
return methods.isLureScreenValid() ? get(Values.ACTION_LURE_TALK_TRAINER)
: get(Values.ACTION_LURE_TRAINER,
nearestTrainer);
}
} else {
isForcingBlackjack = false;
}
return get(Values.ACTION_KNOCK_TRAINER, nearestTrainer);
}
return get(Values.ACTION_PICKPOCKET_TRAINER, nearestTrainer);
}
/**
* Gets the already defined action for the specified identifier,
* <tt>action</tt>.
*
* @param action The unique identifier for a predefined action, identifying
* a valid action.
* @param args Any arguments that should be passed to the action, see
* identifiers.
* @return The already defined action for the specified identifier.
* @throws IllegalArgumentException If an invalid action was specified.
*/
private Action get(final int action, final Object... args)
throws IllegalArgumentException {
if (0 > action || action >= Values.ACTIONS_TOTAL_COUNT) {
throw new IllegalArgumentException("Invalid action: " + action);
}
if (action == Values.ACTION_WALK_TO_TRAINER) {
return new Action("Walking to trainer",
Values.ACTION_WALK_TO_TRAINER, random(1425, 1635),
random(1645, 1850), random(4925, 5135)) {
RSNPC trainer;
@Override
State perform() {
if (trainer == null) {
if (args.length != 1 || !(args[0] instanceof RSNPC)) {
throw new IllegalArgumentException();
}
trainer = (RSNPC) args[0];
}
if (!calc.tileOnMap(trainer.getLocation())) {
return State.FAILED;
}
return walking.walkTileMM(trainer.getLocation(), 2, 2) ? State.COMPLETED
: State.PROGRESSING;
}
@Override
State confirm() {
return getMyPlayer().isMoving() ? State.COMPLETED
: State.PROGRESSING;
}
@Override
State finish() {
if (calc.distanceTo(trainer) > random(4, 7)) {
antibans.perform(
new int[]{Antibans.MOUSE_MOVE_RANDOMLY},
random(17, 23));
}
return trainer.isOnScreen() ? State.COMPLETED
: State.PROGRESSING;
}
};
}
if (action == Values.ACTION_PICKPOCKET_TRAINER) {
return new Action("Pickpocketing the trainer",
Values.ACTION_PICKPOCKET_TRAINER, random(250, 1250),
random(515, 725)) {
RSNPC trainer;
@Override
State perform() {
if (trainer == null) {
if (args.length != 1 || !(args[0] instanceof RSNPC)) {
throw new IllegalArgumentException();
}
trainer = (RSNPC) args[0];
}
if (!trainer.isOnScreen()) {
return State.FAILED;
}
return trainer.doAction(options.isBlackjacking ? "Loot"
: "Pickpocket Pickpocketing") ? State.COMPLETED
: State.PROGRESSING;
}
@Override
State finish() {
if (hasThieved) {
hasThieved = false;
return State.COMPLETED;
}
return State.PROGRESSING;
}
};
}
if (action == Values.ACTION_STUNNED_WAIT) {
return new Action("Waiting while being stunned",
Values.ACTION_STUNNED_WAIT, 0, random(4820, 5210)) {
@Override
State perform() {
return (stunnedTimer != null) ? State.COMPLETED
: State.FAILED;
}
@Override
State finish() {
antibans.perform(
new int[]{Antibans.MOUSE_MOVE_RANDOMLY}, 21);
antibans.perform(new int[]{Antibans.ALL_ANTIBANS},
65);
return stunnedTimer.isRunning() ? State.PROGRESSING
: State.COMPLETED;
}
};
}
if (action == Values.ACTION_EQUIP_GLOVES) {
return new Action("Equipping a new pair of gloves",
Values.ACTION_EQUIP_GLOVES, random(2345, 2745), random(
3215, 3445)) {
int inventoryCount;
@Override
State perform() {
if (inventoryCount == 0) {
inventoryCount = inventory.getCount();
}
final RSItem gloves = inventory
.getItem(Values.ITEM_GLOVES_OF_SILENCE);
if (gloves == null) {
return State.FAILED;
}
return gloves.doAction("Wear") ? State.COMPLETED
: State.PROGRESSING;
}
@Override
State finish() {
if (inventory.getCount() != inventoryCount) {
hasGloves = true;
return State.COMPLETED;
}
return State.PROGRESSING;
}
};
}
if (action == Values.ACTION_LURE_TRAINER) {
return new Action("Luring the trainer",
Values.ACTION_LURE_TRAINER, random(250, 1250), random(
1455, 2135)) {
RSNPC trainer;
@Override