-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathNTLeader.ntj
515 lines (422 loc) · 29.8 KB
/
NTLeader.ntj
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
var gameMinLength = 10000; // time in milliseconds, minimum game length, 180 seconds default (1 game/3 minutes)
var unableToConnectRetry = 5; // time in minutes to retry connecting on connection fail (real value is +/- 1 min)
var realmDownRetry = 300; // time in minutes to retry connecting on a realm down (default is 300 minutes)
var disconnectedRetry = 5; // time in minutes to retry on a disconnection (usually ip ban related)
var cdkeyInUseRetry = 5; // time in minutes to retry on a cdkey in use error message (set to 0 to stop)
var connectingToBnetTimeout = 20000; // time in milliseconds to wait for a login to time out and click cancel and retry
var characterScreenTimeout = 10000; // time in milliseconds to wait for character screen to appear
var pleaseWaitTimeout = 10000; // time in milliseconds to wait for a please wait popup
var createGameThreshold = 3000; // time in milliseconds to wait between making games
var createGameThresholdRandom = 1000; // time in milliseconds to randomly add +/- to the game create time
var createGameTimeout = 15000; // time in milliseconds to register a failed to create game
var waitInLineTimeout = 60000; // time in milliseconds to wait in lines for a create game (60 second default)
var characterSelectDelay = 1000; // time in milliseconds to wait before selecting a character on the char screen
var loginDelay = 1000; // time in milliseconds to wait before submitting login information
var clickDelay = 500; // wait X milliseconds before next action after a click event
var textDelay = 500; // wait X milliseconds before next action after inserting text into a textbox
var clickDelayRandom = 500; // random amount of time to add to a click
var textDelayRandom = 500; // random amount of time to add to a text set
var gameDoesNotExistDelayMin = 600000; // how long to wait when a Game Does Not Exist occurs - minimum - default 10 minutes
var gameDoesNotExistDelayMax = 900000; // how long to wait when a Game Does Not Exist occurs - maximum - default 15 minutes
var gameDoesNotExistTimeout = 30000; // how long to wait for the dialog to disappear (default 30 seconds, don't change this)
var joinChatAfterGame = false; // join chat after leaving a game
var joinRandomChannel = true; // if this is true, will join a random channel, otherwise it will use the channel below..
var joinChannelInChat = ""; // leave blank to not join a private channel
var waitBeforeEnterChatMin = 1000; // min how long to wait before entering chat
var waitBeforeEnterChatMax = 2000; // max how long to wait before entering chat
var waitInChatBeforeActionsMin = 2000; // min how long to wait before joining channel
var waitInChatBeforeActionsMax = 3000; // max how long to wait before joining channel
// DONT EDIT ANYTHING BELOW THIS
// D2NT Manager Command
const D2NT_MGR_LOADING = 1;
const D2NT_MGR_READY = 2;
const D2NT_MGR_LOGIN = 3;
const D2NT_MGR_CREATE_GAME = 4;
const D2NT_MGR_INGAME = 5;
const D2NT_MGR_RESTART = 6;
const D2NT_MGR_CHICKEN = 7;
const D2NT_MGR_PRINT_STATUS = 8;
const D2NT_MGR_PRINT_LOG = 9;
var lastGameMade = GetTickCount();
var lastGameStatus = 0;
var nextGameMake = 0;
var inGameAt = 0;
var chatActionsDone = false;
var lastGameFailed = false;
var gameInfo = "";
var bugIgnor = true;
var failToJoinCount = 0;
Include("libs/controlInfo.ntl");
Include("libs/common/NTTeamBot.ntl");
var controlData = new controlInfo();
function NTMain()
{
Delay(1000);
var _ingame = false;
controlData.clickDelay = clickDelay;
controlData.textDelay = textDelay;
controlData.clickDelayRandom = clickDelayRandom;
controlData.textDelayRandom = textDelayRandom;
while(1)
{
if(me.ingame)
{
if(!inGameAt)
inGameAt = GetTickCount();
if(!_ingame)
{
RunGC(); // run garbage collector between each game
if(Load("NTBot/NTBotGame.ntj"))
{
_ingame = true;
if(me.playtype > 0)
sendEventToOOG(D2NT_MGR_INGAME, "In Game [" + me.gamename + "]", 0);
else
sendEventToOOG(D2NT_MGR_INGAME, "In Game", 0);
lastGameStatus = 2; // in game successful
}
}
Delay(1000);
}
else
{
// Clear TeamBot messages
NT_File("logs/msg/"+me.charname+"-helpernextgame.txt", 1, " ");
NT_File("logs/msg/"+me.charname+"-leechernextgame.txt", 1, " ");
if(_ingame)
{
_ingame = false;
sendEventToOOG(D2NT_MGR_READY, "", 0);
}
locationAction(controlData.getLocation());
Delay(500);
}
}
}
function locationAction(location)
{
switch(location.id)
{
case 3: // Lobby Chat
if(!chatActionsDone)
{
chatActionsDone = true;
Delay(Random(waitInChatBeforeActionsMin, waitInChatBeforeActionsMax));
if(joinRandomChannel || joinChannelInChat != "")
{
Say("/join " + (joinRandomChannel ? getRandomString(Random(3,10)) : joinChannelInChat));
Delay(1000);
}
}
case 1: // Lobby
if(location.id == 1 && joinChatAfterGame)
{
Delay(Random(waitBeforeEnterChatMin, waitBeforeEnterChatMax));
controlData.click(controlData.controls.lobby.button.enterChat);
break;
}
if(GetTickCount() > nextGameMake)
{
var _control;
lastGameFailed = false;
switch(lastGameStatus)
{
case 0:
_control = controlData.get(controlData.controls.lobby.button.create);
if(_control && _control.pressed)
{
controlData.click(controlData.controls.lobby.button.join);
Delay(500);
}
controlData.click(controlData.controls.lobby.button.create);
Delay(500);
switch(TB_difficulty)
{
case 1:
controlData.click(controlData.controls.lobby.create.button.normal);
break;
case 2:
controlData.click(controlData.controls.lobby.create.button.nightmare);
break;
case 3:
controlData.click(controlData.controls.lobby.create.button.hell);
break;
default:
controlData.click(controlData.controls.lobby.create.button.hell);
break;
}
Delay(500);
controlData.setText(controlData.controls.lobby.create.editBox.gameName, TB_GenerateRandomGamename(3));
Delay(500);
controlData.click(controlData.controls.lobby.create.button.createGame);
nextGameMake = GetTickCount() + createGameTimeout; // set our timeout
sendEventToOOG(D2NT_MGR_PRINT_STATUS, location.name, 0);
break;
case 1: // game failed, rollover to reset timer
inGameAt = GetTickCount(); // reset inGameAt, to wait how long we should have waited..
lastGameFailed = true;
case 2:
outputGameLength();
lastGameStatus = 0;
setNextGameMake();
sendEventToOOG(D2NT_MGR_PRINT_STATUS, location.name, 0);
break;
}
}
else
timeoutDelay(nextGameMake-GetTickCount(), location);
break;
case 2: // Waiting In Line
if(GetTickCount()-lastGameMade > waitInLineTimeout)
controlData.click(controlData.controls.lobby.inLine.button.cancel);
break;
case 4: // Create Game
// sendEventToOOG(D2NT_MGR_CREATE_GAME, location.name, 0);
// locationTimeout(5000, location);
// lastGameMade = GetTickCount();
// lastGameStatus = 1; // pending creation
break;
case 5: // Join Game
break;
case 6: // Ladder
break;
case 7: // Channel List
break;
case 8: // Main Menu
if(controlData.getCurrentRealmIndex() == me.gatewayid)
{
outputGameLength();
controlData.click(controlData.gameTypes[me.playtype]);
}
else
controlData.click(controlData.controls.mainMenu.button.gateway);
break;
case 9: // Login
sendEventToOOG(D2NT_MGR_PRINT_STATUS, location.name, 0);
Delay(loginDelay);
controlData.setText(controlData.controls.login.editBox.accountName, me.account);
sendEventToOOG(D2NT_MGR_LOGIN, location.name, 0);
locationTimeout(5000, location);
break;
case 10: // Login Error (this is a fatal error, so stop)
sendEventToOOG(D2NT_MGR_RESTART, location.name, 10);
Delay(3500);
break;
case 11: // Unable To Connect
timeoutDelay(unableToConnectRetry*60*1000, location)
controlData.click(controlData.controls.login.unableToConnect.button.ok);
break;
case 12: // Character Select
var _time, _control;
sendEventToOOG(D2NT_MGR_PRINT_STATUS, location.name, 0);
for(_time = 0 ; _time < characterScreenTimeout ; _time += 500)
{
_control = controlData.get(controlData.controls.characterSelect.textBox.characterInfo[me.charloc]);
if(_control && _control.GetText() != undefined)
break;
Delay(500);
}
if(_time < characterScreenTimeout)
{
Delay(characterSelectDelay);
controlData.click(controlData.controls.characterSelect.textBox.characters[me.charloc], 0, 0, 1);
controlData.click(controlData.controls.characterSelect.textBox.characterInfo[me.charloc], 0, 0, 1);
// reset last game made, so it doesnt make a game immediately
inGameAt = 0;
setNextGameMake();
}
else
{
controlData.click(controlData.controls.characterSelect.button.exit);
timeoutDelay(realmDownRetry*60*1000, location);
}
break;
case 13: // Realm Down - Character Select screen
controlData.click(controlData.controls.characterSelect.button.exit);
timeoutDelay(realmDownRetry*60*1000, location);
break;
case 14: // Character Select - Disconnected
timeoutDelay(disconnectedRetry*60*1000, location);
controlData.click(controlData.controls.characterSelect.disconnected.button.ok);
break;
case 15: // New Character
break;
case 16: // Character Select - Please Wait popup
if(!locationTimeout(pleaseWaitTimeout, location))
controlData.click(controlData.controls.characterSelect.pleaseWait.button.cancel);
break;
case 17: // Lobby - Lost Connection - just click okay, since we're toast anyway
controlData.click(controlData.controls.lobby.lostConnection.button.ok);
break;
case 18: // D2 Splash
controlData.click(controlData.controls.d2Splash.textBox.copyright);
break;
case 19: // Login - Cdkey In Use
timeoutDelay(cdkeyInUseRetry*60*1000, location);
controlData.click(controlData.controls.login.cdkeyInUse.button.ok);
break;
case 20: // Single Player - Select Difficulty
controlData.click(controlData.singlePlayerDifficulties[me.diff]);
break;
case 21: // Main Menu - Connecting
if(!locationTimeout(connectingToBnetTimeout, location))
controlData.click(controlData.controls.mainMenu.connecting.button.cancel);
break;
case 22: // Login - Invalid Cdkey (classic or xpac)
sendEventToOOG(D2NT_MGR_RESTART, location.name, 3600);
Delay(3500);
break;
case 23: // Character Select - Connecting
if(!locationTimeout(characterScreenTimeout, location))
controlData.click(controlData.controls.characterSelect.button.exit);
break;
case 24: // Server Down - not much to do but wait..
break;
case 25: // Lobby - Please Wait
if(!locationTimeout(pleaseWaitTimeout, location))
controlData.click(controlData.controls.lobby.pleaseWait.button.cancel);
break;
case 26: // Lobby - Game Name Exists
sendEventToOOG(D2NT_MGR_PRINT_LOG, "ÿE00000Game already exists", 0);
inGameAt = 0;
lastGameStatus = 0;
setNextGameMake();
locationTimeout(15000, location);
break;
case 27: // Gateway Select
controlData.clickRealmEntry(me.gatewayid);
controlData.click(controlData.controls.gateway.button.ok);
break;
case 28: // Lobby - Game Does Not Exist
inGameAt = Random(gameDoesNotExistDelayMin, gameDoesNotExistDelayMax);
lastGameStatus = 0;
setNextGameMake();
locationTimeout(gameDoesNotExistTimeout, location);
break;
default:
//sendEventToOOG(D2NT_MGR_PRINT_LOG, "ÿE00000Unhandled location : "+location.id, 0);
break;
}
}
function sendEventToOOG(locationId, statusString, pendingTime)
{
return SendCopyData("D2NT Manager", null, (locationId<<16)|pendingTime, statusString);
}
function setNextGameMake()
{
lastGameMade = GetTickCount();
nextGameMake = lastGameMade + createGameThreshold + Random(0-createGameThresholdRandom, createGameThresholdRandom) + inGameAt;
inGameAt = 0;
chatActionsDone = false;
}
function outputGameLength()
{
if(inGameAt)
{
duration = GetTickCount() - inGameAt;
inGameAt = (duration < gameMinLength ? gameMinLength - duration : 0);
}
}
function locationTimeout(time, location)
{
endtime = GetTickCount() + time;
while(controlData.getLocation().id == location.id && endtime > GetTickCount())
{
sendEventToOOG(D2NT_MGR_PRINT_STATUS, location.name + " (" + parseInt((endtime-GetTickCount())/1000) + "s)", 0);
Delay(500);
}
return (controlData.getLocation().id != location.id);
}
function timeoutDelay(time, location)
{
endtime = GetTickCount() + time;
while(endtime > GetTickCount())
{
sendEventToOOG(D2NT_MGR_PRINT_STATUS, location.name + " (" + parseInt((endtime-GetTickCount())/1000) + "s)", 0);
Delay(1000);
}
}
function getRandomString(_length)
{
_retString = "";
_charSet = "0123456789abcdefghijklmnopqrstuvwxyz";
while(_length--)
{
_retString += _charSet.charAt(Random(0, _charSet.length-1));
}
return _retString;
}
function getGameName(lastGameString)
{
if(!lastGameString)
return "";
else
return (lastGameString.split("-")[0] + "-");
}
function getGameCounter(lastGameString, simple)
{
var myCount;
if(!lastGameString)
return "-1";
else
{
switch(lastGameString.split("-")[1])
{
case "08":
myCount = 9;
break;
case "09":
myCount = 10;
break;
case "99":
myCount = 00;
break;
default:
myCount = parseInt(lastGameString.split("-")[1]) + 1;
break;
}
if(!simple)
{
if(myCount <= 9)
return ('0' + myCount);
}
return myCount;
}
}
// modes 0 = read only, 1 = overwrite the file, 2 = add to file
function NT_File(path, mode, msg, delay) { //big thanks to all the koreans out there
var _msg = "";
var _line = "";
var _fileHandle;
var _isFileCheck = false;
if (arguments.length < 3) { msg = ""; }
if (arguments.length < 4) { delay = (mode > 0) ? 5 : 2; }
while (delay--) {
if (mode == 2 && !_isFileCheck) {
_fileHandle = FileOpen(path, 0);
if (!_fileHandle)
_fileHandle = FileOpen(path, 1);
if (_fileHandle)
_fileHandle.Close();
_isFileCheck = true;
}
_fileHandle = FileOpen(path, mode);
if (_fileHandle)
break;
if (delay)
Delay(200);
}
if (_fileHandle) {
if (mode == 0) {
while (!_fileHandle.eof) {
_line = _fileHandle.ReadLine();
if (_line || !_fileHandle.eof)
_msg += _line + msg;
}
}
else if (msg)
_fileHandle.WriteLine(msg);
_fileHandle.Close();
}
return _msg;
}