This repository was archived by the owner on Dec 30, 2025. It is now read-only.
forked from crazyeyes-pb/Scripts
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTFighterEE.java
More file actions
1616 lines (1425 loc) · 44.9 KB
/
TFighterEE.java
File metadata and controls
1616 lines (1425 loc) · 44.9 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 java.awt.BorderLayout;
import java.awt.Color;
import java.awt.FlowLayout;
import java.awt.Font;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Point;
import java.awt.Polygon;
import java.awt.RenderingHints;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.text.NumberFormat;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Properties;
import javax.swing.BorderFactory;
import javax.swing.BoxLayout;
import javax.swing.JButton;
import javax.swing.JCheckBox;
import javax.swing.JComboBox;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JTextField;
import org.rsbot.Configuration;
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.Filter;
import org.rsbot.script.wrappers.RSCharacter;
import org.rsbot.script.wrappers.RSComponent;
import org.rsbot.script.wrappers.RSGroundItem;
import org.rsbot.script.wrappers.RSInterface;
import org.rsbot.script.wrappers.RSItem;
import org.rsbot.script.wrappers.RSModel;
import org.rsbot.script.wrappers.RSNPC;
import org.rsbot.script.wrappers.RSPlayer;
import org.rsbot.script.wrappers.RSTile;
/**
* Change log: v1.61: Made SDN compatible v1.60: Stable: Potions and ash
* scattering added. v1.55: Unstable: Potions and ash scattering added. v1.50:
* Project branched by Zalgo2462. Bone burial added. v1.02: Includes click here
* to continue hotfix. v1.01: Prioritize looting over combat. Safespotting +
* looting is now possible. Implemented new LoopAction structure internally.
* v1.00: Milestone release. Added: -Safespot ability -Central clicking
* -Clicking continue -Antiban - performs camera + mouse at same time!
* (sometimes) -Declared stable v0.96: Hopefully finally fixed food v0.95: Small
* error, caused null pointer v0.94: Fixed eating. v0.93: Hide paint by clicking
* it. v0.92: Loot support, mainly. Many small changes. v0.91: Oops, forgot to
* add mouse speed settings! v0.9: Initial release
*/
@ScriptManifest(name = "TFighterEE", authors = { "!@!@!", "Zalgo2462" }, version = 1.61, description = "TFighter by !@!@! with additions by Zalgo2462", website = "http://www.powerbot.org/vb/showthread.php?t=477661", requiresVersion = 244)
public class TFighterEE extends Script implements PaintListener, MouseListener {
private class AttackLoop implements LoopAction {
public boolean activate() {
return !u.npcs.isInCombat();
}
public int loop() {
final RSNPC inter = u.npcs.getInteracting();
final RSNPC n = inter != null ? inter : u.npcs.getNPC();
if (n != null) {
final int result = u.npcs.clickNPC(n, "Attack " + n.getName());
if (result == 0) {
if (!useSafespot) {
waitWhileMoving();
} else {
waitForAnim();
}
return random(300, 500);
} else if (result == 1) {
waitWhileMoving();
return random(0, 200);
}
} else {
if (calc.distanceTo(startTile) > 5) {
walking.walkTileMM(walking.getClosestTileOnMap(startTile));
waitWhileMoving();
} else {
antiban();
}
}
return random(50, 200);
}
}
private class BonesLoop implements LoopAction {
private final int[] BONE_IDS = new int[] { 526, 528, 530, 532, 534,
536, 2859, 3123, 3125, 3183, 6182, 20268, 20266, 20264 };
public boolean activate() {
return inventory.getCount(BONE_IDS) != 0;
}
public int loop() {
for (final RSItem item : inventory.getItems(BONE_IDS)) {
item.doClick(true);
waitForInvChange(inventory.getCount(true));
return random(20, 150);
}
return random(50, 200);
}
}
private class Eating {
private final int[] B2P_TAB_ID = new int[] { 8015 };
private final int[] BONES_ID = new int[] { 526, 532, 530, 528, 3183,
2859 };
private int toEatAtPercent = getRandomEatPercent();
/**
* Breaks a B2P tab.
*/
private void breakB2pTab() {
final RSItem i = inventory.getItem(B2P_TAB_ID);
if (i != null) {
i.doClick(true);
}
}
/**
* Attempts to eat food.
*
* @return True if we ate.
*/
private boolean eatFood() {
final RSItem i = getFood();
for (int j = 0; j < 3; j++) {
if (i == null) {
break;
}
if (i.doAction("Eat")) {
return true;
}
}
return false;
}
/**
* Finds food based on inventory actions.
*
* @return The RSItem of food, or null if none was found.
*/
private RSItem getFood() {
for (final RSItem i : inventory.getItems()) {
if (i == null || i.getID() == -1) {
continue;
}
if (i.getComponent().getActions() == null
|| i.getComponent().getActions()[0] == null) {
continue;
}
if (i.getComponent().getActions()[0].contains("Eat")) {
return i;
}
}
return null;
}
/**
* Returns an integer representing the current health percentage.
*
* @return The current health percentage.
*/
public int getHPPercent() {
try {
return (int) (Integer.parseInt(interfaces.get(748).getComponent(8).getText().trim())
/ (double) (skills.getRealLevel(Skills.CONSTITUTION) * 10) * 100);
} catch (final Exception e) {
return 100;
}
}
/**
* Returns a random integer of when to eat.
*
* @return A random integer of the percent to eat at.
*/
private int getRandomEatPercent() {
return random(45, 60);
}
/**
* Checks if we have at least one B2P tab.
*
* @return True if we have a tab.
*/
private boolean haveB2pTab() {
return inventory.getCount(B2P_TAB_ID) > 0;
}
/**
* Checks if the inventory contains bones, for B2P.
*
* @return True if we have bones.
*/
private boolean haveBones() {
return inventory.getCount(BONES_ID) > 0;
}
/**
* Checks if we have food.
*
* @return True if we have food.
*/
private boolean haveFood() {
return getFood() != null;
}
/**
* Checks whether you need to eat or not.
*
* @return True if we need to eat.
*/
private boolean needEat() {
if (getHPPercent() <= toEatAtPercent) {
toEatAtPercent = getRandomEatPercent();
return true;
}
return false;
}
}
@SuppressWarnings("serial")
private class FighterGUI extends JFrame {
private final File file = new File(Configuration.Paths.getScriptCacheDirectory()
+ File.separator + "TFighter.txt");
private JCheckBox useMulti, useRadius, useSafe, useCentral,
prioritizeLoot, useBones;
private JTextField npcBox, lootBox, mouseSpeedBox;
private final ActionListener onStart = new ActionListener() {
@Override
public void actionPerformed(final ActionEvent e) {
saveProperties();
startScript = true;
mouseSpeedMin = Integer.parseInt(mouseSpeedBox.getText().split(",")[0]);
mouseSpeedMax = Integer.parseInt(mouseSpeedBox.getText().split(",")[0]);
utilizeMultiwayCombat = useMulti.isSelected();
onlyInRadius = useRadius.isSelected();
useSafespot = useSafe.isSelected();
useCentralClicking = useCentral.isSelected();
buryBones = useBones.isSelected();
TFighterEE.this.prioritizeLoot = prioritizeLoot.isSelected();
if (onlyInRadius) {
u.npcs.maxRadius = Integer.parseInt(JOptionPane.showInputDialog("Enter the max radius. Example: 10"));
}
String[] ids = npcBox.getText().split(",");
ArrayList<Integer> idList = new ArrayList<Integer>();
ArrayList<String> nameList = new ArrayList<String>();
for (int i = 0; i < ids.length; i++) {
if (ids[i] != null && !ids[i].equals("")) {
try {
final int id = Integer.parseInt(ids[i]);
idList.add(id);
} catch (final Exception e1) {
nameList.add(ids[i]);
}
}
}
u.npcs.npcIDs = idList.size() > 0 ? toIntArray(idList.toArray(new Integer[0]))
: new int[0];
u.npcs.npcNames = nameList.size() > 0 ? nameList.toArray(new String[0])
: new String[0];
ids = lootBox.getText().split(",");
idList = new ArrayList<Integer>();
nameList = new ArrayList<String>();
for (int i = 0; i < ids.length; i++) {
if (ids[i] != null && !ids[i].equals("")) {
try {
final int id = Integer.parseInt(ids[i]);
idList.add(id);
} catch (final Exception e1) {
nameList.add(ids[i]);
}
}
}
u.loot.lootIDs = idList.size() > 0 ? toIntArray(idList.toArray(new Integer[0]))
: new int[0];
u.loot.lootNames = nameList.size() > 0 ? nameList.toArray(new String[0])
: new String[0];
dispose();
}
};
private FighterGUI() {
init();
pack();
setVisible(true);
}
private void init() {
final Properties props = loadProperties();
final JPanel north = new JPanel(new FlowLayout());
north.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
{
final JLabel title = new JLabel("TFighterEE");
title.setFont(new Font("Arial", Font.PLAIN, 28));
north.add(title);
}
add(north, BorderLayout.NORTH);
final JPanel center = new JPanel();
center.setLayout(new BoxLayout(center, BoxLayout.PAGE_AXIS));
center.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
{
final JLabel mouseSpeedLabel = new JLabel("Enter your desired mouse speed (max,min)");
mouseSpeedBox = new JTextField("4,7");
final JLabel npcLabel1 = new JLabel("Enter the IDs and/or names of the NPCs to fight.");
final JLabel npcLabel2 = new JLabel("You can mix and match these, all in the same box!");
npcBox = new JTextField("2,5,1,Chicke");
final JLabel lootLabel = new JLabel("Enter the IDs and/or names of items to loot.");
lootBox = new JTextField("arrow,feather");
useMulti = new JCheckBox("Utilize multiway combat");
useRadius = new JCheckBox("Only attack within a radius");
useSafe = new JCheckBox("Use safespot?");
useCentral = new JCheckBox("Use central point on NPC? (instead of random)");
useBones = new JCheckBox("Bury the bones you pick up?");
final JLabel prioritizeLabel = new JLabel("If selected, you will loot while in combat.");
prioritizeLoot = new JCheckBox("Prioritize loot over combat?");
mouseSpeedLabel.setAlignmentX(JLabel.CENTER_ALIGNMENT);
mouseSpeedBox.setAlignmentX(JTextField.CENTER_ALIGNMENT);
npcLabel1.setAlignmentX(JLabel.CENTER_ALIGNMENT);
npcLabel2.setAlignmentX(JLabel.CENTER_ALIGNMENT);
npcBox.setAlignmentX(JTextField.CENTER_ALIGNMENT);
lootLabel.setAlignmentX(JLabel.CENTER_ALIGNMENT);
lootBox.setAlignmentX(JTextField.CENTER_ALIGNMENT);
useMulti.setAlignmentX(JCheckBox.CENTER_ALIGNMENT);
useRadius.setAlignmentX(JCheckBox.CENTER_ALIGNMENT);
useSafe.setAlignmentX(JCheckBox.CENTER_ALIGNMENT);
useCentral.setAlignmentX(JCheckBox.CENTER_ALIGNMENT);
useBones.setAlignmentX(JCheckBox.CENTER_ALIGNMENT);
prioritizeLabel.setAlignmentX(JLabel.CENTER_ALIGNMENT);
prioritizeLoot.setAlignmentX(JComboBox.CENTER_ALIGNMENT);
if (props.getProperty("mouseSpeed") != null) {
mouseSpeedBox.setText(props.getProperty("mouseSpeed"));
}
if (props.getProperty("npcBox") != null) {
npcBox.setText(props.getProperty("npcBox"));
}
if (props.getProperty("lootBox") != null) {
lootBox.setText(props.getProperty("lootBox"));
}
if (props.getProperty("useMulti") != null) {
if (props.getProperty("useMulti").equals("true")) {
useMulti.setSelected(true);
}
}
if (props.getProperty("useRadius") != null) {
if (props.getProperty("useRadius").equals("true")) {
useRadius.setSelected(true);
}
}
if (props.getProperty("useSafe") != null) {
if (props.getProperty("useSafe").equals("true")) {
useSafe.setSelected(true);
}
}
if (props.getProperty("useCentral") != null) {
if (props.getProperty("useCentral").equals("true")) {
useCentral.setSelected(true);
}
}
if (props.getProperty("prioritizeLoot") != null) {
if (props.get("prioritizeLoot").equals("true")) {
prioritizeLoot.setSelected(true);
}
}
if (props.getProperty("useBones") != null) {
if (props.get("useBones").equals("true")) {
useBones.setSelected(true);
}
}
center.add(mouseSpeedLabel);
center.add(mouseSpeedBox);
center.add(new JLabel(" "));
center.add(npcLabel1);
center.add(npcLabel2);
center.add(npcBox);
center.add(new JLabel(" "));
center.add(lootLabel);
center.add(lootBox);
center.add(new JLabel(" "));
center.add(useMulti);
center.add(useRadius);
center.add(useSafe);
center.add(useCentral);
center.add(useBones);
center.add(new JLabel(" "));
center.add(prioritizeLabel);
center.add(prioritizeLoot);
}
add(center, BorderLayout.CENTER);
final JPanel south = new JPanel(new FlowLayout());
south.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
{
final JButton start = new JButton("Start script!");
start.setAlignmentX(JButton.CENTER_ALIGNMENT);
start.addActionListener(onStart);
south.add(start);
}
add(south, BorderLayout.SOUTH);
setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
setTitle("TFighter GUI");
}
private Properties loadProperties() {
try {
if (!file.exists()) {
file.createNewFile();
}
final Properties p = new Properties();
p.load(new FileInputStream(file));
return p;
} catch (final Exception e) {
e.printStackTrace();
}
return null;
}
private void saveProperties() {
final Properties p = new Properties();
p.put("mouseSpeed", mouseSpeedBox.getText());
p.put("npcBox", npcBox.getText());
p.put("lootBox", lootBox.getText());
p.put("useMulti", Boolean.toString(useMulti.isSelected()));
p.put("useRadius", Boolean.toString(useRadius.isSelected()));
p.put("useSafe", Boolean.toString(useSafe.isSelected()));
p.put("useCentral", Boolean.toString(useCentral.isSelected()));
p.put("useBones", Boolean.toString(useBones.isSelected()));
p.put("prioritizeLoot", Boolean.toString(prioritizeLoot.isSelected()));
try {
p.store(new FileOutputStream(file), "");
} catch (final Exception e) {
e.printStackTrace();
}
}
private int[] toIntArray(final Integer[] ints) {
final int[] done = new int[ints.length];
for (int i = 0; i < done.length; i++) {
done[i] = ints[i].intValue();
}
return done;
}
}
private class InCombatLoop implements LoopAction {
public boolean activate() {
return u.npcs.isInCombat();
}
public int loop() {
antiban();
return random(50, 200);
}
}
private interface LoopAction {
public boolean activate();
public int loop();
}
private class Loot {
private int[] lootIDs = new int[0];
private String[] lootNames = new String[0];
private final Map<String, Integer> lootTaken = new HashMap<String, Integer>();
private final Filter<RSGroundItem> lootFilter = new Filter<RSGroundItem>() {
@Override
public boolean accept(final RSGroundItem t) {
// Skip if we can't hold it
RSItem i;
if (inventory.isFull()
&& ((i = inventory.getItem(t.getItem().getID())) == null || i.getStackSize() <= 1)) {
return false;
}
// Skip if its out of radius or far away
if (onlyInRadius
&& calc.distanceBetween(t.getLocation(), startTile) > u.npcs.maxRadius
|| calc.distanceTo(t.getLocation()) > 25) {
return false;
}
// Check ID/name
boolean good = false;
final int id = t.getItem().getID();
for (final int iD : lootIDs) {
if (iD == id) {
good = true;
}
}
final String name = t.getItem().getName();
for (final String s : lootNames) {
if (name != null
&& name.toLowerCase().contains(s.toLowerCase())) {
good = true;
}
}
return good;
}
};
private void addItem(final String name, final int count) {
if (lootTaken.get(name) != null) {
final int newCount = count + lootTaken.get(name);
lootTaken.remove(name);
lootTaken.put(name, newCount);
} else {
lootTaken.put(name, count);
}
}
/**
* Gets the nearest loot, based on the filter
*
* @return The nearest item to loot, or null if none.
*/
private RSGroundItem getLoot() {
return groundItems.getNearest(lootFilter);
}
private Map<String, Integer> getLootTaken() {
final HashMap<String, Integer> m = new HashMap<String, Integer>();
m.putAll(lootTaken);
return m;
}
/**
* Attempts to take an item.
*
* @param item
* The item to take.
* @return -1 if error, 0 if taken, 1 if walked
*/
private int takeItem(final RSGroundItem item) {
if (item == null) {
return -1;
}
final String action = "Take " + item.getItem().getName();
if (item.isOnScreen()) {
for (int i = 0; i < 5; i++) {
if (menu.isOpen()) {
mouse.moveRandomly(300, 500);
}
final Point p = calc.tileToScreen(item.getLocation(), random(0.48, 0.52), random(0.48, 0.52), 0);
if (!calc.pointOnScreen(p)) {
continue;
}
mouse.move(p, 3, 3);
if (menu.contains(action)) {
if (menu.getItems()[0].contains(action)) {
mouse.click(true);
return 0;
} else {
mouse.click(false);
sleep(random(100, 200));
if (menu.doAction(action)) {
return 0;
}
}
}
}
} else {
walking.walkTileMM(walking.getClosestTileOnMap(item.getLocation()));
return 1;
}
return -1;
}
}
private class LootLoop implements LoopAction {
private RSGroundItem loot = null;
public boolean activate() {
return (loot = u.loot.getLoot()) != null;
}
@Override
public int loop() {
final int origCount = inventory.getCount(true);
final String name = loot.getItem().getName();
final int count = loot.getItem().getStackSize();
final int result = u.loot.takeItem(loot);
if (result == 0) {
waitWhileMoving();
if (waitForInvChange(origCount)) {
u.loot.addItem(name, count);
}
} else if (result == 1) {
waitWhileMoving();
}
return random(50, 200);
}
}
private class NPCs {
private int[] npcIDs = new int[0];
private String[] npcNames = new String[0];
private int maxRadius = 10;
/**
* The filter we use!
*/
private final Filter<RSNPC> npcFilter = new Filter<RSNPC>() {
@Override
public boolean accept(final RSNPC t) {
return isOurNPC(t)
&& t.isValid()
&& (!onlyInRadius || calc.distanceBetween(t.getLocation(), startTile) < maxRadius)
&& (utilizeMultiwayCombat || !t.isInCombat()
&& t.getInteracting() == null)
&& t.getHPPercent() != 0;
}
};
/**
* Will only return an on screen NPC. Based on npcFilter.
*/
private final Filter<RSNPC> npcOnScreenFilter = new Filter<RSNPC>() {
@Override
public boolean accept(final RSNPC n) {
return npcFilter.accept(n)
&& getPointOnScreen(n.getModel(), true) != null;
}
};
/**
* Clicks an NPC based on its model.
*
* @param npc
* The NPC to click.
* @param action
* The action to perform.
* @return 0 if the NPC was clicked, 1 if we walked to it, or -1 if
* nothing happened.
*/
private int clickNPC(final RSNPC npc, final String action) {
for (int i = 0; i < 10; i++) {
if (isPartiallyOnScreen(npc.getModel())) {
final Point p = useCentralClicking ? getCentralPoint(npc.getModel())
: getPointOnScreen(npc.getModel(), false);
if (p == null || !calc.pointOnScreen(p)) {
continue;
}
mouse.move(p, useCentralClicking ? 3 : 0, useCentralClicking ? 3
: 0);
final String[] items = menu.getItems();
if (items.length > 0 && items[0].contains(action)) {
mouse.click(true);
return 0;
} else if (menu.contains(action)) {
mouse.click(false);
sleep(random(100, 200));
for (int x = 0; x < 4; x++) {
if (!menu.contains(action)) {
break;
}
if (menu.doAction(action)) {
return 0;
}
}
}
} else {
if (!useSafespot) {
walking.walkTileMM(closerTile(npc.getLocation(), 1), 2, 2);
return 1;
} else {
final int angle = camera.getCharacterAngle(npc);
if (calc.distanceTo(npc) < 10
&& Math.abs(angle - camera.getAngle()) > 20) {
camera.setAngle(angle + random(-20, 20));
}
}
}
}
return -1;
}
/**
* Gets a closer tile to us within dist.
*
* @param t
* The tile to start with.
* @param dist
* The max dist.
* @return A closer tile.
*/
private RSTile closerTile(final RSTile t, final int dist) {
final RSTile loc = getMyPlayer().getLocation();
int newX = t.getX(), newY = t.getY();
for (int i = 1; i < dist; i++) {
newX = t.getX() != loc.getX() ? (t.getX() < loc.getX() ? newX--
: newX++) : newX;
newY = t.getY() != loc.getY() ? (t.getY() < loc.getY() ? newY--
: newY++) : newY;
}
return new RSTile(newX, newY);
}
/**
* Calculates the distance between two points.
*
* @param p1
* The first point.
* @param p2
* The second point.
* @return The distance between the two points, using the distance
* formula.
*/
private double distanceBetween(final Point p1, final Point p2) {
return Math.sqrt((p1.x - p2.x) * (p1.x - p2.x) + (p1.y - p2.y)
* (p1.y - p2.y));
}
/**
* Generates a rough central point. Performs the calculation by first
* generating a rough point, and then finding the point closest to the
* rough point that is actually on the RSModel.
*
* @param m
* The RSModel to test.
* @return The rough central point.
*/
private Point getCentralPoint(final RSModel m) {
if (m == null) {
return null;
}
try {
/* Add X and Y of all points, to get a rough central point */
int x = 0, y = 0, total = 0;
for (final Polygon poly : m.getTriangles()) {
for (int i = 0; i < poly.npoints; i++) {
x += poly.xpoints[i];
y += poly.ypoints[i];
total++;
}
}
final Point central = new Point(x / total, y / total);
/*
* Find a real point on the NPC that is closest to the central
* point
*/
Point curCentral = null;
double dist = 20000;
for (final Polygon poly : m.getTriangles()) {
for (int i = 0; i < poly.npoints; i++) {
final Point p = new Point(poly.xpoints[i], poly.ypoints[i]);
if (!calc.pointOnScreen(p)) {
continue;
}
final double dist2 = distanceBetween(central, p);
if (curCentral == null || dist2 < dist) {
curCentral = p;
dist = dist2;
}
}
}
return curCentral;
} catch (final Exception e) {
}
return null;
}
/**
* Returns the interacting NPC that matches our description, if any.
*
* @return The closest interacting NPC that matches the filter.
*/
private RSNPC getInteracting() {
RSNPC npc = null;
int dist = 20;
for (final RSNPC n : npcs.getAll()) {
if (!isOurNPC(n)) {
continue;
}
final RSCharacter inter = n.getInteracting();
if (inter != null && inter instanceof RSPlayer
&& inter.equals(getMyPlayer())
&& calc.distanceTo(n) < dist) {
dist = calc.distanceTo(n);
npc = n;
}
}
return npc;
}
/**
* Returns the nearest NPC.
*
* @return The nearest NPC that matches the filter.
*/
private RSNPC getNPC() {
final RSNPC onScreen = npcs.getNearest(npcOnScreenFilter);
if (onScreen != null) {
return onScreen;
}
return npcs.getNearest(npcFilter);
}
/**
* Gets a point on a model that is on screen.
*
* @param m
* The RSModel to test.
* @param first
* If true, it will return the first point that it finds on
* screen.
* @return A random point on screen of an object.
*/
private Point getPointOnScreen(final RSModel m, final boolean first) {
if (m == null) {
return null;
}
final ArrayList<Point> list = new ArrayList<Point>();
try {
final Polygon[] tris = m.getTriangles();
for (final Polygon p : tris) {
for (int j = 0; j < p.xpoints.length; j++) {
final Point pt = new Point(p.xpoints[j], p.ypoints[j]);
if (calc.pointOnScreen(pt)) {
if (first) {
return pt;
}
list.add(pt);
}
}
}
} catch (final Exception e) {
}
return list.size() > 0 ? list.get(random(0, list.size())) : null;
}
/**
* Checks if we are in combat.
*
* @return True if we are in combat.
*/
private boolean isInCombat() {
return getMyPlayer().getInteracting() instanceof RSNPC;
}
private boolean isOurNPC(final RSNPC t) {
final int id = t.getID();
final String name = t.getName();
boolean good = false;
for (final int i : npcIDs) {
if (id == i) {
good = true;
}
}
for (final String s : npcNames) {
if (name.toLowerCase().contains(s.toLowerCase())) {
good = true;
}
}
return good;
}
/**
* Checks if a model is partially on screen.
*
* @param m
* The RSModel to check.
* @return True if any point on the model is on screen.
*/
private boolean isPartiallyOnScreen(final RSModel m) {
return getPointOnScreen(m, true) != null;
}
}
private class Potion {
private final int[] MAGIC_POTIONS = new int[] { 3040, 3042, 3044, 3046,
11513, 11515, 13520, 13521, 13522, 13523 };
private final int[] PRAYER_POTIONS = new int[] { 2434, 139, 141, 143,
11465, 11467 };
private final int[] RANGE_POTIONS = new int[] { 2444, 169, 171, 173,
11509, 11511, 13524, 13525, 15326, 15327 };
private final int[] ENERGY_POTIONS = new int[] { 3008, 3010, 3012,
3014, 3016, 3018, 3020, 3022, 11453, 11455, 11481, 11483 };
private final int[] COMBAT_POTIONS = new int[] { 9739, 9741, 9743,
9745, 11445, 11447 };
private final int[] ATTACK_POTIONS = new int[] { 2428, 121, 123, 125,
2436, 145, 147, 149, 11429, 11431, 11429, 11431, 11429, 11431,
11469, 11471, 15308, 15309, 15310, 15311 };
private final int[] STRENGTH_POTIONS = new int[] { 113, 115, 117, 119,
2440, 157, 159, 161, 11443, 11441, 11485, 11487, 15312, 15313,
15314, 15315 };
private final int[] DEFENSE_POTIONS = new int[] { 2432, 133, 135, 137,
2442, 163, 165, 167, 11457, 11459, 11497, 11499, 15316, 15317,
15318, 15319 };
private final int[] ANTIPOISON = new int[] { 2446, 175, 177, 179, 2448,
181, 183, 185, 5952, 5954, 5956, 5958, 5943, 5945, 5947, 5949,
11433, 11435, 11501, 11503 };
private final int[] ZAMORAK_POTIONS = new int[] { 2450, 189, 191, 193,
11521, 11523 };
private final int[] SARADOMIN_POTIONS = new int[] { 6685, 6687, 6689,
6691 };
private final int[] OVERLOAD_POTIONS = new int[] { 15332, 15333, 15334,
15335 };
private final int[] VIAL = new int[] { 229 };
private HashMap<String, RSItem[]> getPotions() {
final HashMap<String, RSItem[]> potions = new HashMap<String, RSItem[]>();
potions.put("MAGIC", inventory.getItems(MAGIC_POTIONS));
potions.put("PRAYER", inventory.getItems(PRAYER_POTIONS));
potions.put("RANGE", inventory.getItems(RANGE_POTIONS));
potions.put("ENERGY", inventory.getItems(ENERGY_POTIONS));
potions.put("COMBAT", inventory.getItems(COMBAT_POTIONS));
potions.put("ATTACK", inventory.getItems(ATTACK_POTIONS));
potions.put("STRENGTH", inventory.getItems(STRENGTH_POTIONS));
potions.put("DEFENSE", inventory.getItems(DEFENSE_POTIONS));
potions.put("ANTIPOISON", inventory.getItems(ANTIPOISON));
potions.put("ZAMORAK", inventory.getItems(ZAMORAK_POTIONS));
potions.put("SARADOMIN", inventory.getItems(SARADOMIN_POTIONS));
potions.put("OVERLOAD", inventory.getItems(OVERLOAD_POTIONS));
return potions;
}
private boolean needPot() {
final HashMap<String, RSItem[]> potions = u.pot.getPotions();
if (inventory.getItems(VIAL).length != 0) {
for (final RSItem i : inventory.getItems(VIAL)) {
final int n = inventory.getCount(true);
i.doAction("Drop Vial");
waitForInvChange(n);
}
}
if (potions.get("MAGIC").length != 0
&& !statIsBoosted(Skills.MAGIC)) {
return true;
}