-
Notifications
You must be signed in to change notification settings - Fork 11
/
D2BotLead.dbj
495 lines (398 loc) · 11.8 KB
/
D2BotLead.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
var StarterConfig = {
MinGameTime: 180, // Minimum game length in seconds. If a game is ended too soon, the rest of the time is waited in the lobby
CreateGameDelay: 5, // Seconds to wait before creating a new game
JoinChannel: "", // Name of the channel to join
FirstJoinMessage: "", // Message to say when first joining a channel, usually ".login"
AnnounceGames: false, // Announce next game in channel
ChatActionsDelay: 2, // Seconds to wait in lobby before entering a channel
SwitchKeys: true, // Set to true to switch keys when they're in use, banned or after realm down
SwitchKeyDelay: 0, // Seconds to wait before switching a used/banned key or after realm down
RealmDownDelay: 10, // 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. SwitchKeys overrides this!
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
};
// No touchy!
include("json2.js");
include("OOG.js");
include("gambling.js");
load("tools/heartbeat.js");
var D2BOT_JOIN = 1,
D2BOT_GAMEINFO = 2,
D2BOT_REQUESTGAME = 3,
lastGameStatus = "ready",
chatActionsDone = false,
connectFail = false,
gameCount = DataFile.getStats().runs + 1,
gamePass = "",
gameName = "",
difficulty,
gameStart,
isUp = "no",
nextGame = "",
ingame = false;
if (!FileTools.exists("data/" + me.profile + ".json")) {
DataFile.create();
}
function RecieveCopyData(msgID, msg) {
switch (msgID) {
case D2BOT_GAMEINFO:
print("Recieved Game Info");
[gameName, gamePass, difficulty] = msg.split('/');
break;
case D2BOT_JOIN:
[nextGame, gamePass, isUp] = msg.split('/');
break;
case D2BOT_REQUESTGAME:
D2Bot.joinMe(msg, gameName, gameCount, gamePass, isUp);
break;
}
}
function timeoutDelay(text, time) {
var endTime = getTickCount() + time;
while (getTickCount() < endTime) {
D2Bot.updateStatus(text + " (" + Math.floor((endTime - getTickCount()) / 1000) + "s)");
delay(500);
}
}
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 main() {
addEventListener('copydata', RecieveCopyData);
delay(rand(1, 2) * 1000);
D2Bot.requestGameInfo();
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) {
if (me.gamepassword.toLowerCase() !== gamePass.toLowerCase()) {
print("leaving game");
quit();
}
print("Updating Status");
D2Bot.updateStatus("Game: " + me.gamename);
lastGameStatus = "ingame";
ingame = true;
gameStart = getTickCount();
DataFile.updateStats("runs", gameCount);
}
}
delay(1000);
}
isUp = "no";
locationAction(getLocation());
delay(1000);
}
}
function locationAction(location) {
var i, string, text, gambleGame;
MainSwitch:
switch (location) {
case 0:
break;
case 1: // Lobby
D2Bot.updateStatus("Lobby");
if (StarterConfig.JoinChannel !== "") {
ControlAction.click(6, 27, 480, 120, 20);
break;
}
if (ingame) {
print("updating runs");
D2Bot.updateRuns();
gameCount += 1;
lastGameStatus = "ready";
ingame = false;
if (getTickCount() - gameStart < StarterConfig.MinGameTime * 1e3) {
timeoutDelay("Min game time wait", StarterConfig.MinGameTime * 1e3 + gameStart - getTickCount());
}
}
// #### experimental gambling system start ####
gambleGame = Gambling.checkGamblers();
if (gambleGame && DataFile.getStats().gold > Gambling.minGold) {
delay(3000);
joinGame(gambleGame[0], gambleGame[1]);
delay(1000);
locationTimeout(5000, location);
break;
}
// #### experimental gambling system end ####
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);
break;
case 3: // Lobby Chat
D2Bot.updateStatus("Lobby Chat");
if (ingame) {
print("updating runs");
D2Bot.updateRuns();
gameCount += 1;
lastGameStatus = "ready";
ingame = false;
if (getTickCount() - gameStart < StarterConfig.MinGameTime * 1e3) {
timeoutDelay("Min game time wait", StarterConfig.MinGameTime * 1e3 + gameStart - getTickCount());
}
}
// #### experimental gambling system start ####
gambleGame = Gambling.checkGamblers();
if (gambleGame && DataFile.getStats().gold > Gambling.minGold) {
delay(3000);
joinGame(gambleGame[0], gambleGame[1]);
delay(1000);
locationTimeout(5000, location);
break;
}
// #### experimental gambling system end ####
if (!chatActionsDone) {
chatActionsDone = true;
timeoutDelay("Chat delay", StarterConfig.ChatActionsDelay * 1e3);
say("/j " + StarterConfig.JoinChannel);
delay(1000);
if (StarterConfig.FirstJoinMessage !== "") {
say(StarterConfig.FirstJoinMessage);
delay(500);
}
}
if (StarterConfig.AnnounceGames) {
delay(1000);
say("Next game is " + gameName + gameCount + (gamePass === "" ? "" : "//" + 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");
while (!gameName) {
D2Bot.requestGameInfo();
delay(500);
}
if (lastGameStatus === "pending") {
gameCount += 1;
}
timeoutDelay("Make Game Delay", StarterConfig.CreateGameDelay * 1e3);
createGame(gameName + gameCount, gamePass, difficulty === "Hell" ? 2 : difficulty === "Nightmare" ? 1 : 0);
lastGameStatus = "pending";
locationTimeout(5000, 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
D2Bot.updateStatus("Logging In");
try {
login(me.profile);
} catch (e) {
print(e);
}
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(5207):
D2Bot.updateStatus("Invalid Password");
D2Bot.printToConsole("Invalid Password");
break;
case getLocaleString(5208):
D2Bot.updateStatus("Invalid Account");
D2Bot.printToConsole("Invalid Account");
break;
case getLocaleString(5199):
D2Bot.updateStatus("Disabled CDKey");
D2Bot.printToConsole("Disabled CDKey");
D2Bot.CDKeyDisabled();
if (StarterConfig.SwitchKeys) {
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);
break;
}
}
ControlAction.click(6, 335, 412, 128, 35);
while (true) {
delay(1000);
}
break;
case 11: // Unable To Connect
D2Bot.updateStatus("Unable To Connect");
if (connectFail) {
timeoutDelay("Unable to Connect", StarterConfig.UnableToConnectDelay * 6e4);
connectFail = false;
}
if (!ControlAction.click(6, 335, 450, 128, 35)) {
break;
}
connectFail = true;
break;
case 12: // Character Select
try {
login(me.profile);
} catch (e2) {
}
break;
case 13: // Realm Down - Character Select screen
D2Bot.updateStatus("Realm Down");
delay(1000);
if (!ControlAction.click(6, 33, 572, 128, 35)) {
break;
}
updateCount();
timeoutDelay("Realm Down", StarterConfig.RealmDownDelay * 6e4);
if (StarterConfig.SwitchKeys) {
D2Bot.printToConsole("Realm Down - Changing CD-Key");
timeoutDelay("Key switch delay", StarterConfig.SwitchKeyDelay * 1000);
D2Bot.restart(true);
} else {
D2Bot.restart();
}
break;
case 14: // Character Select / Main Menu - Disconnected
D2Bot.updateStatus("Disconnected");
delay(500);
ControlAction.click(6, 351, 337, 96, 32);
break;
case 15: // New Character
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.printToConsole("CD-Key in use by " + ControlAction.getText(4, 158, 310, 485, 40));
D2Bot.CDKeyInUse();
if (StarterConfig.SwitchKeys) {
timeoutDelay("Key switch delay", StarterConfig.SwitchKeyDelay * 1000);
D2Bot.restart(true);
} else {
ControlAction.click(6, 335, 450, 128, 35);
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)
if (StarterConfig.SwitchKeys) {
D2Bot.printToConsole("Invalid CD-Key");
timeoutDelay("Key switch delay", StarterConfig.SwitchKeyDelay * 1000);
D2Bot.restart(true);
} else {
ControlAction.click(6, 335, 450, 128, 35);
timeoutDelay("Invalid CD-Key", StarterConfig.CDKeyInUseDelay * 6e4);
}
break;
case 23: // Character Select - Connecting
if (!locationTimeout(StarterConfig.ConnectingTimeout * 1e3, location)) {
ControlAction.click(6, 33, 572, 128, 35);
}
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
gameCount += 1;
delay(500);
ControlAction.click(6, 533, 469, 120, 20);
break;
case 27: // Gateway Select
break;
case 28: // Lobby - Game Does Not Exist
D2Bot.printToConsole("Game doesn't exist");
lastGameStatus = "ready";
locationTimeout(StarterConfig.GameDoesNotExistTimeout * 1e3, location);
break;
case 38: // Game is full
D2Bot.printToConsole("Game is full");
lastGameStatus = "ready";
delay(500);
ControlAction.click(6, 652, 469, 120, 20);
break;
case 42: // Empty character screen
delay(1000);
ControlAction.click(6, 33, 572, 128, 35);
break;
default:
if (location !== undefined) {
D2Bot.printToConsole("Unhandled location " + location);
delay(500);
D2Bot.restart();
}
break;
}
}