forked from crazyeyes-pb/Scripts
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProfessionalRC.java
More file actions
1404 lines (1205 loc) · 37.6 KB
/
ProfessionalRC.java
File metadata and controls
1404 lines (1205 loc) · 37.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
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.BasicStroke;
import java.awt.Color;
import java.awt.Font;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Rectangle;
import java.awt.RenderingHints;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.awt.geom.Ellipse2D;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.util.ListIterator;
import java.util.LinkedList;
import java.util.Properties;
import org.rsbot.Configuration;
import org.rsbot.event.events.MessageEvent;
import org.rsbot.event.listeners.MessageListener;
import org.rsbot.event.listeners.PaintListener;
import org.rsbot.script.methods.Game;
import org.rsbot.script.methods.Skills;
import org.rsbot.script.Script;
import org.rsbot.script.ScriptManifest;
import org.rsbot.script.util.Filter;
import org.rsbot.script.wrappers.RSArea;
import org.rsbot.script.wrappers.RSItem;
import org.rsbot.script.wrappers.RSNPC;
import org.rsbot.script.wrappers.RSObject;
import org.rsbot.script.wrappers.RSPlayer;
import org.rsbot.script.wrappers.RSTile;
@ScriptManifest(
authors = "inspercho",
name = "professional runecrafting",
version = 3,
description = "AIO free to play normal or master/runner runecrafting bot.",
keywords = {"runecrafting", "runecrafter", "runecraft", "rc", "aio", "master", "runner", "slave"},
website = "http://www.powerbot.org/community/topic/435261-master-and-slave-rc/")
public class ProfessionalRC extends Script implements PaintListener, MessageListener, MouseListener, KeyListener {
private static final LinkedList<Strategy> stratagies = new LinkedList<Strategy>();
private static String status;
private static ListIterator<Strategy> iterator;
private static final int NORMAL = 0;
private static final int MASTER = 1;
private static final int RUNNER = 2;
private final int ESSENCE_ID = 1436;
private final int ESSENCE_NOTE_ID = 1437;
private final int PURE_ESSENCE_ID = 7936;
private final int PURE_ESSENCE_NOTE_ID = 7937;
private Properties prop = null;
private InfoDatabase info = null;
private boolean init = true;
private boolean init_gui = true;
private boolean hide_gui = false;
private boolean cursor = false;
private boolean location_list = false;
private boolean[] keylisten = new boolean[2];
private String[] locations = new String[]{
"Air Altar",
"Body Altar",
"Earth Altar",
"Fire Altar",
"Mind Altar",
"Water Altar (dray)",
"Water Altar (alkarhid)"
};
private int locations_index = 0;
private int requesting = -1;
private int failCount = 3;
private boolean changeWorld = false;
private String loc = Configuration.Paths.getScriptCacheDirectory() + File.separator;
private int type = -1;
private static String playerTraded = null;
private static String playerServer = null;
private static int playerWorld = -1;
private boolean useMusician = false;
private Info location = null;
private static int altarsClicked = 0;
private static int craftRune = -1;
private static int note = -1;
private static int numberToCraft = -1;
public boolean onStart() {
prop = new Properties();
FileInputStream in = null;
try {
in = new FileInputStream(loc + "rc.p");
prop.load(in);
playerServer = prop.getProperty("world");
playerTraded = prop.getProperty("name");
useMusician = prop.getProperty("musician").equals("true");
locations_index = Integer.parseInt(prop.getProperty("location"));
location = getLocation(locations[locations_index]);
} catch (Exception e) {
log.severe("No saved settings were found. Will create file on script start.");
} finally {
try { in.close(); } catch(Exception e) {}
}
return true;
}
@Override
public int loop() {
if(init) {
// if not logged in, wait
if(!game.isLoggedIn()) { return 500; }
if(init_gui) { return 500; }
try {
playerWorld = Integer.parseInt(playerServer);
} catch (Exception e) {
log.severe("failed detecting input world");
stopScript();
}
if(type != MASTER) {
FileOutputStream out = null;
try {
out = new FileOutputStream(loc + "rc.p");
prop.setProperty("world", "" + playerServer);
prop.setProperty("name", playerTraded.replace("\t", "").replace("\n", ""));
prop.setProperty("musician", "" + useMusician);
prop.setProperty("location", "" + locations_index);
prop.store(out, null);
} catch(Exception e) {
log.severe("Could not store settings! Script will still function as normal however.");
} finally {
try { out.close(); } catch(Exception e) {}
}
}
info = new InfoDatabase();
switch(type) {
case NORMAL:
numberToCraft = 28;
log(locations[locations_index] + " runecrafter started.");
stratagies.add(new ExitAltar());
stratagies.add(new GoBank());
stratagies.add(new DoBank());
stratagies.add(new EnterAltar());
stratagies.add(new GoAltar());
stratagies.add(new CraftRunes());
break;
case MASTER:
numberToCraft = 26;
log(locations[locations_index] + " master started.");
note = ESSENCE_NOTE_ID;
playerTraded = null;
stratagies.add(new OfferRunes());
stratagies.add(new ConfirmTrade());
stratagies.add(new CraftRunes());
stratagies.add(new DropJunk());
stratagies.add(new AcceptTrade());
break;
case RUNNER:
numberToCraft = 26;
log(locations[locations_index] + " runner started for " + playerTraded + ".");
stratagies.add(new OfferRunes());
stratagies.add(new ConfirmTrade());
stratagies.add(new ExitAltar());
stratagies.add(new GoBank());
stratagies.add(new DoBank());
stratagies.add(new EnterAltar());
stratagies.add(new GoAltar());
stratagies.add(new FindPlayer());
stratagies.add(new SendTrade());
break;
}
startTime = System.currentTimeMillis();
startExp = skills.getCurrentExp(Skills.RUNECRAFTING);
init = false;
}
mouse.setSpeed(random(4, 7));
if (!game.isLoggedIn() || changeWorld) {
if(!lobby.inLobby()) {
return loginAndWait();
}
if(interfaces.getComponent(910, 11).getText().endsWith(" " + playerWorld)) {
return loginAndWait();
}
if(lobby.switchWorlds(playerWorld)) {
return loginAndWait();
}
return 1000;
}
if(game.getPlane() == 1) {
useGate(info.STAIR_TILE, "Climb-down");
return 1000;
}
// somehow this opened up
if(interfaces.get(752).getComponent(1).getText().contains("Enter")) {
keyboard.sendText("", true);
}
// close any opened dialog box (level up menu, randoms, etc)
if(interfaces.get(Game.INTERFACE_LEVEL_UP).isValid() ||
interfaces.canContinue()) {
interfaces.clickContinue();
return random(900, 1100)/8;
}
iterator = stratagies.listIterator();
while(iterator.hasNext()) {
Strategy s = (Strategy)iterator.next();
if(s.isValid()) {
status = s.getStatus();
//log(status);
return s.execute();
}
}
status = "waiting.";
return random(900, 1100)/8;
}
@Override
public void messageReceived(MessageEvent e) {
//if(e.getID() == MessageEvent.MESSAGE_TRADE_REQ);
if (e.getMessage().contains("wishes to trade with ")) {
if(type == MASTER) playerTraded = e.getSender();
}
String serverString = e.getMessage().toLowerCase();
if (serverString.contains("power into ") && !serverString.contains(":")) {
altarsClicked++;
}
}
private int startExp = 0;
private int expGained = 0;
private int expHour = 0;
private int altarsHour = 0;
private long startTime = 0;
private long millis = 0;
private long hours = 0;
private long minutes = 0;
private long seconds = 0;
private long last = 0;
private final RenderingHints antialiasing = new RenderingHints(
RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
private final Rectangle normal_button = new Rectangle(18, 381, 133, 19);
private final Rectangle master_button = new Rectangle(18, 406, 133, 19);
private final Rectangle runner_button = new Rectangle(18, 431, 133, 19);
private final Rectangle start_button = new Rectangle(373, 449, 133, 19);
private final Rectangle crafter_box = new Rectangle(255, 371, 133, 15);
private final Rectangle server_box = new Rectangle(255, 386, 133, 15);
private final Rectangle musician_box = new Rectangle(255, 401, 15, 15);
private final Rectangle location_box = new Rectangle(255, 416, 133, 15);
private final Rectangle exp_percent = new Rectangle(6, 456, 1, 18);
private final Rectangle[] locations_box = new Rectangle[locations.length];
private final Ellipse2D hide_button = new Ellipse2D.Float(517, 87, 31, 29);
@Override
public void onRepaint(Graphics render) {
Graphics2D g = (Graphics2D)render;
g.setRenderingHints(antialiasing);
// draw oval
if(hide_gui) {
g.setColor(new Color(255, 102, 0, 105));
g.fill(hide_button);
return;
}
g.setColor(new Color(102, 255, 0, 105));
g.fill(hide_button);
g.setColor(new Color(204, 204, 0));
g.draw(hide_button);
// draw background
g.setColor(new Color(203, 186, 153));
g.fillRect(3, 341, 512, 135);
g.setColor(Color.black);
g.setStroke(new BasicStroke(5));
g.drawRect(3, 341, 512, 135);
g.drawRect(20, 320, 480, 40);
g.setColor(new Color(203, 186, 153));
g.fillRect(20, 320, 480, 40);
// put texts
g.setColor(Color.black);
g.setFont(new Font("Broadway", 1, 30));
g.drawString("Professional Runecrafter", 32, 352);
g.setFont(new Font("BrowalliaUPC", 1, 23));
g.drawString("GUI", 519, 107);
if(init) {
// draw seperator
g.setColor(Color.black);
g.drawLine(166, 362, 166, 474);
// draw boxes
g.setColor(Color.black);
g.setStroke(new BasicStroke(1));
g.draw(normal_button);
g.draw(master_button);
g.draw(runner_button);
g.draw(start_button);
g.setColor(new Color(0, 0, 0, 80));
g.fill(normal_button);
g.fill(master_button);
g.fill(runner_button);
g.fill(start_button);
g.setFont(new Font("Times", 0, 15));
g.setColor(Color.black);
int i = 370;
Rectangle selected = null;
switch(type) {
case NORMAL: // normal
selected = normal_button;
g.setColor(new Color(0, 0, 0, 80));
g.fill(musician_box);
g.fill(location_box);
g.setColor(Color.black);
g.setStroke(new BasicStroke(1));
g.draw(musician_box);
g.draw(location_box);
g.drawString("", 180, i+=15);
g.drawString("", 180, i+=15);
g.drawString("Musician:", 180, i+=15);
g.drawString("" + (useMusician?"X":""), 258, i);
g.drawString("Location:", 180, i+=15);
if(location_list) {
for(int l = locations.length - 1; l >= 0; l--) {
i -= 15;
locations_box[l] = new Rectangle(260, i, 133, 15);
g.setColor(new Color(203, 186, 153));
g.fill(locations_box[l]);
g.setColor(Color.black);
g.draw(locations_box[l]);
g.drawLine(260, i, 293, i);
g.setFont(new Font("Times", 0, 13));
g.drawString("" + locations[l], 263, i+14);
}
} else {
if(location == null) location = new AirInfo();
g.drawString("" + locations[locations_index].toString(), 256, i);
g.drawLine(380, i-9, 386, i-9);
g.drawString("v", 380, i);
}
break;
case MASTER: // master
selected = master_button;
String loc = detectLocation();
String ess = detectEssence();
String inv = detectInventory()?"You must only have essence in your inventory.":"Script will drop random event items.";
g.drawString("Detected " + loc + " altar.", 180, i+=15);
g.drawString("Detected " + ess + " noted essence.", 180, i+=15);
g.drawString(inv, 180, i+=15);
break;
case RUNNER: // runner
selected = runner_button;
g.setColor(new Color(0, 0, 0, 80));
g.fill(crafter_box);
g.fill(server_box);
g.fill(musician_box);
g.fill(location_box);
g.setColor(Color.black);
g.setStroke(new BasicStroke(1));
g.draw(crafter_box);
g.draw(server_box);
g.draw(musician_box);
g.draw(location_box);
g.drawString("Username:", 180, i+=15);
if(playerTraded == null) playerTraded = "";
g.drawString("" + playerTraded + (keylisten[0]?(cursor?"|":""):""), 256, i);
g.drawString("Server:", 180, i+=15);
if(playerServer == null) playerServer = "";
g.drawString("" + playerServer + (keylisten[1]?(cursor?"|":""):""), 256, i);
g.drawString("Musician:", 180, i+=15);
g.drawString("" + (useMusician?"X":""), 258, i);
g.drawString("Location:", 180, i+=15);
if(location_list) {
for(int l = locations.length - 1; l >= 0; l--) {
i -= 15;
locations_box[l] = new Rectangle(260, i, 133, 15);
g.setColor(new Color(203, 186, 153));
g.fill(locations_box[l]);
g.setColor(Color.black);
g.draw(locations_box[l]);
g.drawLine(260, i, 293, i);
g.setFont(new Font("Times", 0, 13));
g.drawString("" + locations[l], 263, i+14);
}
} else {
if(location == null) location = new AirInfo();
g.drawString("" + locations[locations_index].toString(), 256, i);
g.drawLine(380, i-9, 386, i-9);
g.drawString("v", 380, i);
}
break;
default:
g.drawString("Select an option from the left.", 180, i+=15);
}
cursor = !cursor;
if(selected != null) {
g.setColor(Color.white);
g.fill(selected);
g.setColor(Color.black);
g.draw(selected);
}
// put texts
g.setColor(Color.black);
g.setFont(new Font("BrowalliaUPC", 0, 30));
g.drawString("normal", 55, 397);
g.drawString("master", 55, 422);
g.drawString("runner", 55, 447);
g.drawString("start", 422, 467);
} else {
millis = System.currentTimeMillis() - startTime;
expGained = skills.getCurrentExp(Skills.RUNECRAFTING) - startExp;
altarsHour = (int) ((altarsClicked) * 3600000D / millis);
expHour = (int) ((expGained) * 3600000D / millis);
int i = 380;
int j = 30;
g.setFont(new Font("BrowalliaUPC", 0, 23));
g.setColor(Color.black);
g.drawString("Runtime: " + formatDuration(millis), j, i+=15);
g.drawString("Status: " + status, j, i+=15);
switch(type) {
case NORMAL:
case MASTER:
int pnl = skills.getPercentToNextLevel(Skills.RUNECRAFTING);
exp_percent.setSize((int)((double)pnl / 100 * 508), 18);
g.setColor(new Color(20, 175, 20));
g.fill(exp_percent);
g.setColor(Color.black);
g.drawLine(8, 456, 510, 456);
//g.drawString("Altars Clicked (per hour): " + altarsClicked + "(" + altarsHour + ")", j, i+=15);
g.drawString("Exp Gained (per hour): " + expGained + " (" + expHour + ")", j, i+=15);
millis = skills.getTimeTillNextLevel(Skills.RUNECRAFTING, startExp, millis);
g.drawString(pnl + "% until level " + (skills.getCurrentLevel(Skills.RUNECRAFTING)+1) + " (" + formatDuration(millis) + " remaining)", 140, 471);
break;
case RUNNER:
break;
}
}
// mouse paints
int s = 4;
if(mouse.getPressTime() == -1 ||
System.currentTimeMillis() - mouse.getPressTime() >= 1000) {
g.fillRect(mouse.getLocation().x-(s/2),mouse.getLocation().y-(s/2),s,s);
}
}
public static String formatDuration(long ms) {
String strReturn = "";
long lRest;
long t = 0;
t = ms / 86400000L;
if(t>0) strReturn += String.valueOf(t) + ":";
lRest = ms % 86400000L;
t = lRest / 3600000L;
strReturn += (t<9?"0":"") + String.valueOf(t) + ":";
lRest %= 3600000L;
t = lRest / 60000L;
strReturn += (t<9?"0":"") + String.valueOf(t) + ":";
lRest %= 60000L;
t = lRest / 1000L;
strReturn += (t<9?"0":"") + String.valueOf(t);
lRest %= 1000L;
return strReturn;
}
private int loginAndWait() {
changeWorld = false;
env.enableRandoms();
//env.enableRandom("Login");
return random(900, 1100)*2;
}
private void useGate(RSTile tile, String action) {
final RSObject g = objects.getTopAt(tile);
if (g != null) {
if (fixAngle(tile)) {
if (g.isOnScreen()) {
g.interact(action);
}
}
}
}
final private boolean fixAngle(RSTile t) {
if (calc.tileOnScreen(t))
return true;
if (!calc.tileOnScreen(t)) {
camera.setAngle(camera.getTileAngle(t));
if (!calc.tileOnScreen(t)) {
camera.setPitch(camera.getPitch() + random(20, 50));
if (!calc.tileOnScreen(t))
walking.walkTo(t);
}
}
return false;
}
// return true to continue with script, false to continue resting.
private boolean checkEnergy() {
if(!useMusician || walking.getEnergy() > 95) return true;
// are we already resting
for (int t : info.getRestingAnim()) {
if(t == getMyPlayer().getAnimation()) return false;
}
// if we have 35 run energy, do not rest.
if(walking.getEnergy() > 35) {
return true;
} else {
RSNPC musician = npcs.getNearest(info.getMusicianID());
if (musician != null) {
// only stop if we're close by, don't want to waste time backtracking
int t = info.getMusicianID()==30?25:10;
if (calc.distanceTo(musician) < t) {
walking.walkTileMM(musician.getLocation());
musician.interact("Listen-to");
return false;
}
}
}
return true;
}
private RSTile getTileInAreaTowardsTile(RSArea area, RSTile dest) {
RSTile closest = walking.getClosestTileOnMap(dest);
RSTile inArea = area.getNearestTile(closest);
inArea = inArea.randomize(3, 3);
return area.getNearestTile(inArea);
}
private void walk(RSTile location) {
if (!walking.isRunEnabled() && walking.getEnergy() > 20)
walking.setRun(true);
if (!getMyPlayer().isMoving()
|| calc.distanceTo(walking.getDestination()) < 6) {
location = location.randomize(2, 2);
RSTile newTile = walking.getClosestTileOnMap(location);
if (calc.tileOnScreen(newTile)) {
mouse.move(calc.tileToScreen(newTile));
menu.doAction("Walk here");
} else {
walking.walkTileMM(newTile);
}
}
}
private String detectLocation() {
String loc = null;
// find nearest altar
RSObject altar = objects.getNearest(
2478, 2479, 2480, 2481, 2482, 2483
);
// no altar found nearby... this is bad.
if(altar == null) {
log.severe("no altar found! move to an altar!");
stopScript();
}
// figure out what type of rune we're making.
switch(altar.getID()) {
case 2478: craftRune = 556; loc = "air"; break; // air
case 2479: craftRune = 555; loc = "mind"; break; // mind??
case 2480: craftRune = 555; loc = "water"; break; // water
case 2481: craftRune = 557; loc = "earth"; break; // earth
case 2482: craftRune = 554; loc = "fire"; break; // fire
case 2483: craftRune = 554; loc = "body"; break; // body???
}
return loc;
}
private String detectEssence() {
return Integer.toString(inventory.getCount(true, ESSENCE_NOTE_ID));
}
private boolean detectInventory() {
return inventory.getCount() > 2;
}
private Info getLocation(String loc) {
Info l = null;
if(loc.contains("Air Altar")) {
l = new AirInfo();
} else if(loc.contains("Body Altar")) {
l = new BodyInfo();
} else if(loc.contains("Earth Altar")) {
l = new EarthInfo();
} else if(loc.contains("Fire Altar")) {
l = new FireInfo();
} else if(loc.contains("Mind Altar")) {
l = new MindInfo();
} else if(loc.contains("Water Altar")) {
if(loc.contains("dray")) {
l = new WaterInfo(true);
} else if(loc.contains("alkarhid")) {
l = new WaterInfo(false);
}
}
return l;
}
@Override
public void mouseClicked(MouseEvent e) {
keylisten[0] = false;
keylisten[1] = false;
if(location_list) {
for(int i = 0; i < locations_box.length; i++) {
if(locations_box[i].contains(e.getPoint())) {
location = getLocation(locations[i]);
locations_index = i;
}
}
location_list = false;
return;
}
if(start_button.contains(e.getPoint()) && type != -1) {
init_gui = false;
} else if (hide_button.contains(e.getPoint())) {
hide_gui = !hide_gui;
} else if (crafter_box.contains(e.getPoint())) {
keylisten[0] = true;
} else if (server_box.contains(e.getPoint())) {
keylisten[1] = true;
} else if (musician_box.contains(e.getPoint())) {
useMusician = !useMusician;
} else if (location_box.contains(e.getPoint())) {
location_list = true;
} else if (normal_button.contains(e.getPoint())) {
type = 0;
} else if (master_button.contains(e.getPoint())) {
type = 1;
} else if (runner_button.contains(e.getPoint())) {
type = 2;
}
}
@Override
public void keyTyped(KeyEvent e) {
if(keylisten[0]) {
if(e.getKeyChar() == '\b') {
playerTraded = playerTraded.substring(0, playerTraded.length() - 1);
} else {
playerTraded += e.getKeyChar();
}
} else if(keylisten[1]) {
if(e.getKeyChar() == '\b') {
playerServer = playerServer.substring(0, playerServer.length() - 1);
} else if(e.getKeyChar() <= '9' && e.getKeyChar() >= '0') {
playerServer += e.getKeyChar();
}
}
}
private interface Strategy {
public boolean isValid();
public int execute();
public String getStatus();
}
private class ExitAltar implements Strategy {
public boolean isValid() {
if(trade.inTrade()) return false;
return (info.inAltar() && !inventory.contains(info.getEssenceID()));
}
public int execute() {
if(calc.distanceTo(info.PORTAL_TILE) > 5) {
walking.walkTileMM(info.PORTAL_TILE);
}
useGate(info.PORTAL_TILE, "Enter");
return random(900, 1100)/2;
}
public String getStatus() {
return "exiting the altar";
}
}
private class DoBank implements Strategy {
public boolean isValid() {
return (info.atBank() && inventory.getCount(info.getEssenceID()) != numberToCraft);
}
public int execute() {
if (bank.isOpen()) {
if (inventory.getCount() > 0)
bank.depositAll();
bank.withdraw(info.getEssenceID(), numberToCraft);
return random(900, 1100)/2;
} else {
if(bank.open()) failCount = 3;
else failCount--;
}
if(failCount < 1) {
walking.walkTileMM(info.BANK_AREA.getCentralTile());
failCount = 3;
}
return random(900, 1100)/2;
}
public String getStatus() {
return "banking";
}
}
private class GoBank implements Strategy {
public boolean isValid() {
if(info.inAltar() || info.atBank()) return false;
return !inventory.contains(info.getEssenceID());
}
public int execute() {
if (checkEnergy())
walk(getTileInAreaTowardsTile(info.getPathArea(), info.BANK_TILE));
return random(900, 1100);
}
public String getStatus() {
return "walking to bank";
}
}
private class EnterAltar implements Strategy {
public boolean isValid() {
if(!inventory.contains(info.getEssenceID()) || info.inAltar()) return false;
RSObject altar = objects.getTopAt(info.ALTAR_TILE);
return (altar != null && calc.distanceTo(info.ALTAR_TILE) < 10);
}
public int execute() {
if(calc.distanceTo(info.ALTAR_TILE) > 5) {
walking.walkTileMM(info.ALTAR_TILE);
}
useGate(info.ALTAR_TILE, "Enter");
return random(900, 1100)/2;
}
public String getStatus() {
return "entering the altar";
}
}
private class GoAltar implements Strategy {
public boolean isValid() {
return (!info.inAltar() && inventory.getCount(info.getEssenceID()) == numberToCraft);
}
public int execute() {
if(bank.close()) return random(900, 1100)/4;
if (checkEnergy()) {
walk(getTileInAreaTowardsTile(info.getPathArea(),
info.ALTAR_TILE));
}
return random(900, 1100);
}
public String getStatus() {
return "walking to altar";
}
}
private class CraftRunes implements Strategy {
RSObject altar;
public boolean isValid() {
// if we have runes to craft, craft them on nearest altar
return inventory.contains(ESSENCE_ID);
}
public int execute() {
// find nearest altar
altar = objects.getNearest(
2478, 2479, 2480, 2481, 2482, 2483
);
// no altar found nearby... this is bad.
if(altar == null) return random(900, 1100);
// if we are somewhat far from the altar, move to it before crafting.
if(calc.distanceTo(altar.getLocation()) > 2) {
walking.walkTileMM(altar.getLocation());
return random(900, 1100);
}
// craft the runes
if(altar.isOnScreen()) {
altar.interact("Craft-rune");
return random(900, 1100);
}
return random(900, 1100)/4;
}
public String getStatus() {
// no altar found nearby... this is bad.
if(objects.getNearest(2478, 2479, 2480, 2481, 2482, 2483) == null)
return "no altar found! move to an altar!";
return "crafting runes";
}
}
public class FindPlayer implements Strategy {
RSPlayer crafter = null;
public boolean isValid() {
crafter = info.getCrafter();
return (crafter == null && info.inAltar());
}
public int execute() {
if(calc.distanceTo(info.PORTAL_TILE) > 5) {
walk(info.PORTAL_TILE);
return random(1000, 1200);
}
if(game.getCurrentWorld() != playerWorld) {
changeWorld = true;
env.disableRandoms();
if(game.logout(true))
return random(1000, 1200)*5;
}
return random(900, 1100)/4;
}
public String getStatus() {
return "searching for \'" + playerTraded + "\'.";
}
}
public class SendTrade implements Strategy {
RSPlayer crafter = null;
public boolean isValid() {
if(trade.inTrade()) return false;
crafter = info.getCrafter();
return crafter != null && info.inAltar();
}
public int execute() {
if (crafter.isOnScreen()) {
if(crafter.getAnimation() == 791) requesting = -1;
if(requesting > 0) {
requesting--;
return random(350, 650);
}
trade.tradePlayer(crafter, 1000);
requesting = 8;
} else if (calc.distanceTo(crafter) < 5) {
camera.turnTo(crafter);
} else {
walk(crafter.getLocation());
}
return random(900, 1100)/4;
}
public String getStatus() {
return "found \'" + playerTraded + "\', sending trade.";
}
}
public class ConfirmTrade implements Strategy {
public boolean isValid() {
return trade.inTrade();
}
public int execute() {
// if the second trade screen is opened
if(trade.inTradeSecond()) {
// accept the trade
trade.acceptTrade();
// null out the last player traded
if(type == MASTER) playerTraded = null;
return random(900, 1100)/4;
}
// if the first trade screen is opened
if(trade.inTradeMain()) {
boolean itemOffered = trade.isWealthOffered();
boolean itemRecived = trade.isWealthReceived();
if(itemOffered) {
if(!itemRecived) return random(900, 1100)/8;
trade.acceptTrade();
}
}
return random(900, 1100)/4;
}
public String getStatus() {
return "accepting trade.";
}
}
// failsafe to drop extra items (could be dangerous)
public class DropJunk implements Strategy {
public boolean isValid() {
return (type == MASTER && inventory.getCount() > 2);
}
public int execute() {
RSItem[] items = inventory.getItems();
for (RSItem item : items) {
if(item.getID() != info.getEssenceID() && item.getID() != craftRune) {
if(!inventory.destroyItem(item.getID())) {
item.interact("Drop");
}
}
}
return random(900, 1100)/4;
}
public String getStatus() {
return "dropping junk items.";
}
}
public class AcceptTrade implements Strategy {
public boolean isValid() {
if(trade.inTrade()) return false;
return playerTraded != null;
}
public int execute() {
if(playerTraded != null) {
if(trade.tradePlayer(playerTraded, 1000)) {
requesting = 0;
return random(900, 1100)*2;
}