forked from SetupSonic/clean-sonic
-
Notifications
You must be signed in to change notification settings - Fork 0
/
D2BotSonic.dbj
956 lines (749 loc) · 23.4 KB
/
D2BotSonic.dbj
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
var StarterConfig = {
MinGameTime: 2, // Minimum game length in seconds. If a game is ended too soon, the rest of the time is waited in the lobby
PingQuitDelay: 30, // Time in seconds to wait in lobby after quitting due to high ping
CreateGameDelay: 2, // Seconds to wait before creating a new game
ResetCount: 999, // Reset game count back to 1 every X games.
CharacterDifference: 99, // Character level difference. Set to false to disable character difference.
ChatActionsDelay: 2, // Seconds to wait in lobby before entering a channel
// ChannelConfig can override these options for individual profiles.
JoinChannel: "", // Default channel. Can be an array of channels - ["channel 1", "channel 2"]
FirstJoinMessage: "", // Default join message. Can be an array of messages
AnnounceGames: false, // Default value
AfterGameMessage: "", // Default message after a finished game. Can be an array of messages
SwitchKeyDelay: 5, // Seconds to wait before switching a used/banned key or after realm down
CrashDelay: 5, // Seconds to wait after a d2 window crash
FTJDelay: 40, // Seconds to wait after failing to create a game
RealmDownDelay: 3, // Minutes to wait after getting Realm Down message
UnableToConnectDelay: 5, // Minutes to wait after Unable To Connect message
CDKeyInUseDelay: 5, // Minutes to wait before connecting again if CD-Key is in use.
ConnectingTimeout: 20, // Seconds to wait before cancelling the 'Connecting...' screen
PleaseWaitTimeout: 10, // Seconds to wait before cancelling the 'Please Wait...' screen
WaitInLineTimeout: 60, // Seconds to wait before cancelling the 'Waiting in Line...' screen
GameDoesNotExistTimeout: 30 // Seconds to wait before cancelling the 'Game does not exist.' screen
};
var ChannelConfig = {
/* Override default values for JoinChannel, FirstJoinMessage, AnnounceGames and AfterGameMessage per profile
It's possible to override any number of these options (you don't have to put all of them)
**** DO NOT EDIT ANYTHING INSIDE THIS COMMENT BLOCK ***
Format:
"Profile Name": {
JoinChannel: "channel name", -OR- ["channel 1", "channel 2"],
FirstJoinMessage: "first message", -OR- ["join msg 1", "join msg 2"],
AnnounceGames: true,
AfterGameMessage: "message after a finished run" -OR- ["msg 1", msg 2"]
}
Multiple entries are separated by a comma
Examples:
"Profile 1": {
JoinChannel: "my channel",
FirstJoinMessage: ".login",
AnnounceGames: true,
AfterGameMessage: "follow my runs or die"
},
"Profile 2": {
JoinChannel: ["channel 1", "channel 2"],
FirstJoinMessage: [".login", "^login"],
AfterGameMessage: ["follow my runs or die", "seriously, you'll die"]
}
*/
// Add your lines here
};
// No touchy!
include("json2.js");
include("OOG.js");
include("automule.js");
include("gambling.js");
include("craftingsystem.js");
include("torchsystem.js");
include("common/misc.js");
include("common/pather.js");
include("include/OOG.js");
include("include/polyfill.js");
include("include/misc.js");
include("sonic/settings/settings.js");
include("sonic/common/account.js");
if (!FileTools.exists("data/" + me.profile + ".json")) {
DataFile.create();
}
if (!FileTools.exists("libs/sonic/data/" + me.profile + ".json")) {
Account.set();
makeAccount = true;
}
/*
if (!Account.db.exists()) {
Account.db.insert();
makeAccount = true;
}*/
var gameInfo, gameStart, ingame, chatActionsDone, pingQuit,
handle, useChat, firstLogin, connectFail,
gameCount = DataFile.getStats().runs + 1,
lastGameStatus = "ready",
isUp = "no",
chanInfo = {
joinChannel: "",
firstMsg: "",
afterMsg: "",
announce: false
};
// vita variables
var makeAccount;
var account = Account.get(); //Account.db.query();
var gold;
var connectFailRetry = 0;
function sayMsg(string) {
if (!useChat) {
return;
}
say(string);
}
function ReceiveCopyData(mode, msg) {
var obj;
switch (msg) {
case "Handle":
handle = mode;
break;
}
switch (mode) {
case 2: // Game info
print("Recieved Game Info");
gameInfo = JSON.parse(msg);
break;
case 3: // Game request
// Don't let others join mule/torch/key/gold drop game
if (AutoMule.inGame || Gambling.inGame || TorchSystem.inGame || CraftingSystem.inGame) {
break;
}
if (gameInfo) {
obj = JSON.parse(msg);
if (me.gameReady) {
D2Bot.joinMe(obj.profile, me.gamename.toLowerCase(), "", me.gamepassword.toLowerCase(), isUp);
} else {
D2Bot.joinMe(obj.profile, gameInfo.gameName.toLowerCase(), gameCount, gameInfo.gamePass.toLowerCase(), isUp);
}
}
break;
case 4: // Heartbeat ping
if (msg === "pingreq") {
sendCopyData(null, me.windowtitle, 4, "pingrep");
}
break;
case 0xf124: // Cached info retreival
if (msg !== "null") {
gameInfo.crashInfo = JSON.parse(msg);
}
break;
}
}
function setNextGame() {
var nextGame = gameInfo.gameName;
if (StarterConfig.ResetCount && gameCount + 1 >= StarterConfig.ResetCount) {
nextGame += 1;
} else {
nextGame += (gameCount + 1);
}
DataFile.updateStats("nextGame", nextGame);
}
function locationTimeout(time, location) {
var endtime = getTickCount() + time;
while (getLocation() === location && endtime > getTickCount()) {
delay(500);
}
return (getLocation() !== location);
}
function updateCount() {
D2Bot.updateCount();
delay(1000);
ControlAction.click(6, 264, 366, 272, 35);
try {
login(me.profile);
} catch (e) {
}
delay(1000);
ControlAction.click(6, 33, 572, 128, 35);
}
function ScriptMsgEvent(msg) {
switch (msg) {
case "mule":
AutoMule.check = true;
break;
case "muleTorch":
AutoMule.torchAnniCheck = 1;
break;
case "muleAnni":
AutoMule.torchAnniCheck = 2;
break;
case "torch":
TorchSystem.check = true;
break;
case "crafting":
CraftingSystem.check = true;
break;
case "getMuleMode":
if (AutoMule.torchAnniCheck === 2) {
scriptBroadcast("2");
} else if (AutoMule.torchAnniCheck === 1) {
scriptBroadcast("1");
} else if (AutoMule.check) {
scriptBroadcast("0");
}
break;
case "pingquit":
pingQuit = true;
break;
}
}
function timer(tick) {
if (!tick) {
return "";
}
var min, sec;
min = Math.floor((getTickCount() - tick) / 60000).toString();
if (min <= 9) {
min = "0" + min;
}
sec = (Math.floor((getTickCount() - tick) / 1000) % 60).toString();
if (sec <= 9) {
sec = "0" + sec;
}
return " (" + min + ":" + sec + ")";
}
function main() {
debugLog(me.profile);
addEventListener('copydata', ReceiveCopyData);
addEventListener('scriptmsg', ScriptMsgEvent);
while (!handle) {
delay(100);
}
DataFile.updateStats("handle", handle);
delay(500);
D2Bot.init();
load("tools/heartbeat.js");
while (!gameInfo) {
D2Bot.requestGameInfo();
delay(500);
}
if (gameInfo.error) {
//D2Bot.retrieve();
delay(200);
/*if (!!DataFile.getStats().debugInfo) {
gameInfo.crashInfo = DataFile.getStats().debugInfo;
D2Bot.printToConsole("Crash Info: Script: " + JSON.parse(gameInfo.crashInfo).currScript + " Area: " + JSON.parse(gameInfo.crashInfo).area, 10);
}*/
/*if (gameInfo.crashInfo) {
D2Bot.printToConsole("Crash Info: Script: " + gameInfo.crashInfo.currScript + " Area: " + gameInfo.crashInfo.area + (gameInfo.crashInfo.hasOwnProperty("lastAction") ? " " + gameInfo.crashInfo.lastAction : ""), 10);
}*/
ControlAction.timeoutDelay("Crash Delay", StarterConfig.CrashDelay * 1e3);
D2Bot.updateRuns();
}
//D2Bot.store(JSON.stringify({currScript: "none", area: "out of game"}));
DataFile.updateStats("debugInfo", JSON.stringify({currScript: "none", area: "out of game"}));
while (true) {
while (me.ingame) { // returns true before actually in game so we can't only use this check
if (me.gameReady) { // returns false when switching acts so we can't use while
isUp = "yes";
if (!ingame) {
gameStart = getTickCount();
lastGameStatus = "ingame";
ingame = true;
DataFile.updateStats("runs", gameCount);
DataFile.updateStats("ingameTick");
}
gold = me.getStat(14) + me.getStat(15);
D2Bot.updateStatus("lvl: " + me.charlvl + " | gold: " + gold + " | " + Pather.getAreaName(me.area) + " | " + Misc.difficultyString[me.diff]);
}
delay(10000);
}
isUp = "no";
locationAction(getLocation());
delay(1000);
}
}
function locationAction(location) {
var i, control, string, text;
MainSwitch:
switch (location) {
case 0:
break;
case 1: // Lobby
D2Bot.updateStatus("Lobby");
delay(2500);
if (!firstLogin) {
firstLogin = true;
}
if (lastGameStatus === "pending") {
gameCount += 1;
}
if (StarterConfig.PingQuitDelay && pingQuit) {
ControlAction.timeoutDelay("Ping Delay", StarterConfig.PingQuitDelay * 1e3);
pingQuit = false;
}
if (StarterConfig.JoinChannel !== "" || (ChannelConfig[me.profile] && ChannelConfig[me.profile].JoinChannel !== "")) {
ControlAction.click(6, 27, 480, 120, 20);
break;
}
if (ingame || gameInfo.error) {
if (!gameStart) {
gameStart = DataFile.getStats().ingameTick;
}
if (getTickCount() - gameStart < StarterConfig.MinGameTime * 1e3) {
ControlAction.timeoutDelay("Min game time wait", StarterConfig.MinGameTime * 1e3 + gameStart - getTickCount());
}
}
if (ingame) {
//D2Bot.store(JSON.stringify({currScript: "none", area: "out of game"}));
if (AutoMule.outOfGameCheck() || TorchSystem.outOfGameCheck() || Gambling.outOfGameCheck() || CraftingSystem.outOfGameCheck()) {
break;
}
D2Bot.updateRuns();
gameCount += 1;
lastGameStatus = "ready";
ingame = false;
if (StarterConfig.ResetCount && gameCount >= StarterConfig.ResetCount) {
gameCount = 1;
DataFile.updateStats("runs", gameCount);
}
}
if (!ControlAction.click(6, 533, 469, 120, 20)) { // Create
break;
}
if (!locationTimeout(5000, location)) { // in case create button gets bugged
if (!ControlAction.click(6, 652, 469, 120, 20)) { // Join
break;
}
if (!ControlAction.click(6, 533, 469, 120, 20)) { // Create
break;
}
}
break;
case 2: // Waiting In Line
D2Bot.updateStatus("Waiting...");
locationTimeout(StarterConfig.WaitInLineTimeout * 1e3, location);
ControlAction.click(6, 433, 433, 96, 32);
break;
case 3: // Lobby Chat
D2Bot.updateStatus("Lobby Chat");
if (lastGameStatus === "pending") {
gameCount += 1;
}
if (ingame || gameInfo.error) {
if (!gameStart) {
gameStart = DataFile.getStats().ingameTick;
}
if (getTickCount() - gameStart < StarterConfig.MinGameTime * 1e3) {
ControlAction.timeoutDelay("Min game time wait", StarterConfig.MinGameTime * 1e3 + gameStart - getTickCount());
}
}
if (ingame) {
//D2Bot.store(JSON.stringify({currScript: "none", area: "out of game"}));
if (AutoMule.outOfGameCheck() || TorchSystem.outOfGameCheck() || Gambling.outOfGameCheck() || CraftingSystem.outOfGameCheck()) {
break;
}
print("updating runs");
D2Bot.updateRuns();
gameCount += 1;
lastGameStatus = "ready";
ingame = false;
if (StarterConfig.ResetCount && gameCount >= StarterConfig.ResetCount) {
gameCount = 1;
DataFile.updateStats("runs", gameCount);
}
if (ChannelConfig[me.profile] && ChannelConfig[me.profile].hasOwnProperty("AfterGameMessage")) {
chanInfo.afterMsg = ChannelConfig[me.profile].AfterGameMessage;
} else {
chanInfo.afterMsg = StarterConfig.AfterGameMessage;
}
if (chanInfo.afterMsg) {
if (typeof chanInfo.afterMsg === "string") {
chanInfo.afterMsg = [chanInfo.afterMsg];
}
for (i = 0; i < chanInfo.afterMsg.length; i += 1) {
sayMsg(chanInfo.afterMsg[i]);
delay(500);
}
}
}
if (!chatActionsDone) {
chatActionsDone = true;
if (ChannelConfig[me.profile] && ChannelConfig[me.profile].hasOwnProperty("JoinChannel")) {
chanInfo.joinChannel = ChannelConfig[me.profile].JoinChannel;
} else {
chanInfo.joinChannel = StarterConfig.JoinChannel;
}
if (ChannelConfig[me.profile] && ChannelConfig[me.profile].hasOwnProperty("FirstJoinMessage")) {
chanInfo.firstMsg = ChannelConfig[me.profile].FirstJoinMessage;
} else {
chanInfo.firstMsg = StarterConfig.FirstJoinMessage;
}
if (chanInfo.joinChannel) {
if (typeof chanInfo.joinChannel === "string") {
chanInfo.joinChannel = [chanInfo.joinChannel];
}
if (typeof chanInfo.firstMsg === "string") {
chanInfo.firstMsg = [chanInfo.firstMsg];
}
for (i = 0; i < chanInfo.joinChannel.length; i += 1) {
ControlAction.timeoutDelay("Chat delay", StarterConfig.ChatActionsDelay * 1e3);
if (ControlAction.joinChannel(chanInfo.joinChannel[i])) {
useChat = true;
} else {
print("�c1Unable to join channel, disabling chat messages.");
useChat = false;
}
if (chanInfo.firstMsg[i] !== "") {
sayMsg(chanInfo.firstMsg[i]);
delay(500);
}
}
}
}
// Announce game
if (ChannelConfig[me.profile] && ChannelConfig[me.profile].hasOwnProperty("AnnounceGames")) {
chanInfo.announce = ChannelConfig[me.profile].AnnounceGames;
} else {
chanInfo.announce = StarterConfig.AnnounceGames;
}
if (chanInfo.announce) {
sayMsg("Next game is " + gameInfo.gameName + gameCount + (gameInfo.gamePass === "" ? "" : "//" + gameInfo.gamePass));
}
if (!ControlAction.click(6, 533, 469, 120, 20)) { // Create
break;
}
if (!locationTimeout(5000, location)) { // in case create button gets bugged
if (!ControlAction.click(6, 652, 469, 120, 20)) { // Join
break;
}
if (!ControlAction.click(6, 533, 469, 120, 20)) { // Create
break;
}
}
break;
case 4: // Create Game
D2Bot.updateStatus("Creating Game");
control = getControl(1, 657, 342, 27, 20);
// Set character difference
if (typeof StarterConfig.CharacterDifference === "number") {
if (control.disabled === 4) {
ControlAction.click(6, 431, 341, 15, 16);
}
ControlAction.setText(1, 657, 342, 27, 20, StarterConfig.CharacterDifference.toString());
} else if (StarterConfig.CharacterDifference === false && control.disabled === 5) {
ControlAction.click(6, 431, 341, 15, 16);
}
// Get game name if there is none
while (!gameInfo.gameName) {
D2Bot.requestGameInfo();
delay(500);
}
// FTJ handler
if (lastGameStatus === "pending") {
isUp = "no";
//D2Bot.printToConsole("Failed to create game");
ControlAction.timeoutDelay("FTJ delay", StarterConfig.FTJDelay * 1e3);
D2Bot.updateRuns();
}
ControlAction.createGame(Misc.randomString(15, true), Misc.randomString(15, true), Account.get().difficulty, StarterConfig.CreateGameDelay * 1000);
lastGameStatus = "pending";
setNextGame();
locationTimeout(10000, location);
break;
case 5: // Join Game
break;
case 6: // Ladder
break;
case 7: // Channel List
break;
case 8: // Main Menu
case 9: // Login
case 18: // D2 Splash
// Single Player screen fix
if (getLocation() === 12 && !getControl(4, 626, 100, 151, 44)) {
ControlAction.click(6, 33, 572, 128, 35);
break;
}
if (firstLogin && getLocation() === 9) { // multiple realm botting fix in case of R/D or disconnect
ControlAction.click(6, 33, 572, 128, 35);
}
D2Bot.updateStatus("Logging In");
if (makeAccount) {
ControlAction.makeAccount(account);
//D2Bot.printToConsole("Made account: " + account.account, 7);
makeAccount = false;
break;
}
if (account) {
ControlAction.loginAccount(account);
}
break;
case 10: // Login Error
string = "";
text = ControlAction.getText(4, 199, 377, 402, 140);
if (text) {
for (i = 0; i < text.length; i += 1) {
string += text[i];
if (i !== text.length - 1) {
string += " ";
}
}
switch (string) {
case getLocaleString(5232): // illegal characters
case getLocaleString(5233): // disallowed words
case getLocaleString(5239): // Account Name Exists
D2Bot.stop(); // stop or delete json and regenerate info?
break;
case getLocaleString(5207):
D2Bot.updateStatus("Invalid Password");
D2Bot.printToConsole("Invalid Password");
D2Bot.stop(); // stop from keep trying
break;
case getLocaleString(5208):
D2Bot.updateStatus("Invalid Account");
makeAccount = true;
if (!ControlAction.click(6, 335, 412, 128, 35)) {
break;
}
break MainSwitch;
case getLocaleString(5202): // cd key intended for another product
case getLocaleString(10915): // lod key intended for another product
D2Bot.updateStatus("Invalid CDKey");
D2Bot.printToConsole("Invalid CDKey: " + gameInfo.mpq, 6);
D2Bot.CDKeyDisabled();
if (gameInfo.switchKeys) {
ControlAction.timeoutDelay("Key switch delay", StarterConfig.SwitchKeyDelay * 1000);
D2Bot.restart(true);
} else {
D2Bot.stop();
}
break;
case getLocaleString(5199):
D2Bot.updateStatus("Disabled CDKey");
D2Bot.printToConsole("Disabled CDKey: " + gameInfo.mpq, 6);
D2Bot.CDKeyDisabled();
if (gameInfo.switchKeys) {
ControlAction.timeoutDelay("Key switch delay", StarterConfig.SwitchKeyDelay * 1000);
D2Bot.restart(true);
} else {
D2Bot.stop();
}
break;
case getLocaleString(10913):
D2Bot.updateStatus("Disabled LoD CDKey");
D2Bot.printToConsole("Disabled LoD CDKey: " + gameInfo.mpq, 6);
D2Bot.CDKeyDisabled();
if (gameInfo.switchKeys) {
ControlAction.timeoutDelay("Key switch delay", StarterConfig.SwitchKeyDelay * 1000);
D2Bot.restart(true);
} else {
D2Bot.stop();
}
break;
case getLocaleString(5347):
D2Bot.updateStatus("Disconnected");
D2Bot.printToConsole("Disconnected");
ControlAction.click(6, 335, 412, 128, 35);
break MainSwitch;
default:
D2Bot.updateStatus("Login Error");
D2Bot.printToConsole("Login Error - " + string);
if (gameInfo.switchKeys) {
ControlAction.timeoutDelay("Key switch delay", StarterConfig.SwitchKeyDelay * 1000);
D2Bot.restart(true);
} else {
D2Bot.stop();
}
break;
}
}
ControlAction.click(6, 335, 412, 128, 35);
delay(1000);
ControlAction.click(6, 33, 572, 128, 35); //back to main screen
break;
case 11: // Unable To Connect
D2Bot.updateStatus("Unable To Connect");
if (connectFailRetry < 2) { // vita
connectFailRetry += 1;
ControlAction.click(6, 335, 450, 128, 35);
break;
}
if (connectFailRetry >= 2) {
connectFail = true;
}
if (connectFail) {
ControlAction.timeoutDelay("Unable to Connect", StarterConfig.UnableToConnectDelay * 6e4);
connectFail = false;
}
if (!ControlAction.click(6, 335, 450, 128, 35)) {
break;
}
connectFailRetry = 0;
connectFail = true;
break;
case 34: // e-mail
if (getControl(6, 415, 412, 128, 35)) {
ControlAction.click(6, 415, 412, 128, 35);
} else {
ControlAction.click(6, 265, 572, 272, 35);
}
break;
// vita
case 12: // Character Select
case 23: // Character Select - Connecting
case 42: // Empty character screen
// Single Player screen fix
if (getLocation() === 12 && !getControl(4, 626, 100, 151, 44)) {
ControlAction.click(6, 33, 572, 128, 35);
break;
}
string = "";
text = ControlAction.getText(4, 45, 318, 531, 140);
if (text) {
for (i = 0; i < text.length; i += 1) {
string += text[i];
if (i !== text.length - 1) {
string += " ";
}
}
if (string === getLocaleString(11161)) { // CDKey disabled from realm play
D2Bot.updateStatus("Realm Disabled CDKey");
D2Bot.printToConsole("Realm Disabled CDKey: " + gameInfo.mpq, 6);
D2Bot.CDKeyDisabled();
if (gameInfo.switchKeys) {
ControlAction.timeoutDelay("Key switch delay", StarterConfig.SwitchKeyDelay * 1000);
D2Bot.restart(true);
} else {
D2Bot.stop();
}
}
}
if (account) {
if (!ControlAction.findCharacter(account)) {
ControlAction.makeCharacter(account);
} else {
ControlAction.loginCharacter(account);
}
}
break;
case 13: // Realm Down - Character Select screen
D2Bot.updateStatus("Realm Down");
delay(1000);
if (!ControlAction.click(6, 33, 572, 128, 35)) {
break;
}
updateCount();
ControlAction.timeoutDelay("Realm Down", StarterConfig.RealmDownDelay * 6e4);
D2Bot.CDKeyRD();
if (gameInfo.switchKeys && !gameInfo.rdBlocker) {
D2Bot.printToConsole("Realm Down - Changing CD-Key");
ControlAction.timeoutDelay("Key switch delay", StarterConfig.SwitchKeyDelay * 1000);
D2Bot.restart(true);
} else {
D2Bot.printToConsole("Realm Down - Restart");
D2Bot.restart();
}
break;
case 14: // Character Select / Main Menu - Disconnected
D2Bot.updateStatus("Disconnected");
delay(500);
ControlAction.click(6, 351, 337, 96, 32);
break;
case 16: // Character Select - Please Wait popup
if (!locationTimeout(StarterConfig.PleaseWaitTimeout * 1e3, location)) {
ControlAction.click(6, 351, 337, 96, 32);
}
break;
case 17: // Lobby - Lost Connection - just click okay, since we're toast anyway
delay(1000);
ControlAction.click(6, 351, 337, 96, 32);
break;
case 19: // Login - Cdkey In Use
D2Bot.CDKeyInUse();
if (gameInfo.switchKeys) {
ControlAction.timeoutDelay("Key switch delay", StarterConfig.SwitchKeyDelay * 1000);
D2Bot.restart(true);
} else {
ControlAction.click(6, 335, 450, 128, 35);
ControlAction.timeoutDelay("CD-Key in use", StarterConfig.CDKeyInUseDelay * 6e4);
}
break;
case 20: // Single Player - Select Difficulty
break;
case 21: // Main Menu - Connecting
if (!locationTimeout(StarterConfig.ConnectingTimeout * 1e3, location)) {
ControlAction.click(6, 330, 416, 128, 35);
}
break;
case 22: // Login - Invalid Cdkey (classic or xpac)
text = ControlAction.getText(4, 162, 270, 477, 50);
string = "";
if (text) {
for (i = 0; i < text.length; i += 1) {
string += text[i];
if (i !== text.length - 1) {
string += " ";
}
}
}
switch (string) {
case getLocaleString(10914):
D2Bot.printToConsole(gameInfo.mpq + " LoD key in use by " + ControlAction.getText(4, 158, 310, 485, 40), 6);
D2Bot.CDKeyInUse();
if (gameInfo.switchKeys) {
ControlAction.timeoutDelay("Key switch delay", StarterConfig.SwitchKeyDelay * 1000);
D2Bot.restart(true);
} else {
ControlAction.click(6, 335, 450, 128, 35);
ControlAction.timeoutDelay("LoD key in use", StarterConfig.CDKeyInUseDelay * 6e4);
}
break;
default:
if (gameInfo.switchKeys) {
D2Bot.printToConsole("Invalid CD-Key");
ControlAction.timeoutDelay("Key switch delay", StarterConfig.SwitchKeyDelay * 1000);
D2Bot.restart(true);
} else {
ControlAction.click(6, 335, 450, 128, 35);
ControlAction.timeoutDelay("Invalid CD-Key", StarterConfig.CDKeyInUseDelay * 6e4);
}
break;
}
break;
case 24: // Server Down - not much to do but wait..
break;
case 25: // Lobby - Please Wait
if (!locationTimeout(StarterConfig.PleaseWaitTimeout * 1e3, location)) {
ControlAction.click(6, 351, 337, 96, 32);
}
break;
case 26: // Lobby - Game Name Exists
ControlAction.click(6, 533, 469, 120, 20);
gameCount += 1;
lastGameStatus = "ready";
break;
case 27: // Gateway Select
ControlAction.click(6, 436, 538, 96, 32);
break;
case 28: // Lobby - Game Does Not Exist
D2Bot.printToConsole("Game doesn't exist");
if (gameInfo.rdBlocker) {
D2Bot.printToConsole(gameInfo.mpq + " is probably flagged.", 6);
if (gameInfo.switchKeys) {
ControlAction.timeoutDelay("Key switch delay", StarterConfig.SwitchKeyDelay * 1000);
D2Bot.restart(true);
}
} else {
locationTimeout(StarterConfig.GameDoesNotExistTimeout * 1e3, location);
}
lastGameStatus = "ready";
break;
case 38: // Game is full
// doesn't happen when making
break;
default:
/*if (location !== undefined) {
D2Bot.printToConsole("Unhandled location " + location);
//takeScreenshot();
delay(500);
D2Bot.restart();
}*/
break;
}
}