forked from Wazarr94/haxball_bot_headless
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathHaxBot_private.js
2131 lines (1962 loc) · 76.4 KB
/
HaxBot_private.js
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
/* VARIABLES */
/* ROOM */
const roomName = 'Private Room';
const maxPlayers = 40;
const roomPublic = false;
const token = ""; // Insert token here
var roomWebhook = ''; // this webhook is used to send the details of the room (chat, join, leave) ; it should be in a private discord channel
var gameWebhook = ''; // this webhook is used to send the summary of the games ; it should be in a public discord channel
var fetchRecordingVariable = true;
var timeLimit = 3;
var scoreLimit = 3;
var gameConfig = {
roomName: roomName,
maxPlayers: maxPlayers,
public: roomPublic,
noPlayer: true,
}
if (typeof token == 'string' && token.length == 39) {
gameConfig.token = token;
}
var room = HBInit(gameConfig);
const trainingMap = '{"name":"Classic Training","width":420,"height":200,"spawnDistance":170,"bg":{"type":"grass","width":370,"height":170,"kickOffRadius":75,"cornerRadius":0},"vertexes":[{"x":-370,"y":170,"trait":"ballArea"},{"x":-370,"y":64,"trait":"ballArea"},{"x":-370,"y":-64,"trait":"ballArea"},{"x":-370,"y":-170,"trait":"ballArea"},{"x":370,"y":170,"trait":"ballArea"},{"x":370,"y":64,"trait":"ballArea"},{"x":370,"y":-64,"trait":"ballArea"},{"x":370,"y":-170,"trait":"ballArea"},{"x":0,"y":200,"trait":"kickOffBarrier"},{"x":0,"y":75,"trait":"kickOffBarrier"},{"x":0,"y":-75,"trait":"kickOffBarrier"},{"x":0,"y":-200,"trait":"kickOffBarrier"},{"x":-380,"y":-64,"trait":"goalNet"},{"x":-400,"y":-44,"trait":"goalNet"},{"x":-400,"y":44,"trait":"goalNet"},{"x":-380,"y":64,"trait":"goalNet"},{"x":380,"y":-64,"trait":"goalNet"},{"x":400,"y":-44,"trait":"goalNet"},{"x":400,"y":44,"trait":"goalNet"},{"x":380,"y":64,"trait":"goalNet"}],"segments":[{"v0":0,"v1":1,"trait":"ballArea"},{"v0":2,"v1":3,"trait":"ballArea"},{"v0":4,"v1":5,"trait":"ballArea"},{"v0":6,"v1":7,"trait":"ballArea"},{"v0":12,"v1":13,"trait":"goalNet","curve":-90},{"v0":13,"v1":14,"trait":"goalNet"},{"v0":14,"v1":15,"trait":"goalNet","curve":-90},{"v0":16,"v1":17,"trait":"goalNet","curve":90},{"v0":17,"v1":18,"trait":"goalNet"},{"v0":18,"v1":19,"trait":"goalNet","curve":90},{"v0":8,"v1":9,"trait":"kickOffBarrier"},{"v0":9,"v1":10,"trait":"kickOffBarrier","curve":180,"cGroup":["blueKO"]},{"v0":9,"v1":10,"trait":"kickOffBarrier","curve":-180,"cGroup":["redKO"]},{"v0":10,"v1":11,"trait":"kickOffBarrier"}],"goals":[],"discs":[{"pos":[-370,64],"trait":"goalPost","color":"FFCCCC"},{"pos":[-370,-64],"trait":"goalPost","color":"FFCCCC"},{"pos":[370,64],"trait":"goalPost","color":"CCCCFF"},{"pos":[370,-64],"trait":"goalPost","color":"CCCCFF"}],"planes":[{"normal":[0,1],"dist":-170,"trait":"ballArea"},{"normal":[0,-1],"dist":-170,"trait":"ballArea"},{"normal":[0,1],"dist":-200,"bCoef":0.1},{"normal":[0,-1],"dist":-200,"bCoef":0.1},{"normal":[1,0],"dist":-420,"bCoef":0.1},{"normal":[-1,0],"dist":-420,"bCoef":0.1}],"traits":{"ballArea":{"vis":false,"bCoef":1,"cMask":["ball"]},"goalPost":{"radius":8,"invMass":0,"bCoef":0.5},"goalNet":{"vis":true,"bCoef":0.1,"cMask":["ball"]},"kickOffBarrier":{"vis":false,"bCoef":0.1,"cGroup":["redKO","blueKO"],"cMask":["red","blue"]}}}';
const classicMap = '{"name":"Classic","width":420,"height":200,"spawnDistance":170,"bg":{"type":"grass","width":370,"height":170,"kickOffRadius":75,"cornerRadius":0},"vertexes":[{"x":-370,"y":170,"trait":"ballArea"},{"x":-370,"y":64,"trait":"ballArea"},{"x":-370,"y":-64,"trait":"ballArea"},{"x":-370,"y":-170,"trait":"ballArea"},{"x":370,"y":170,"trait":"ballArea"},{"x":370,"y":64,"trait":"ballArea"},{"x":370,"y":-64,"trait":"ballArea"},{"x":370,"y":-170,"trait":"ballArea"},{"x":0,"y":200,"trait":"kickOffBarrier"},{"x":0,"y":75,"trait":"kickOffBarrier"},{"x":0,"y":-75,"trait":"kickOffBarrier"},{"x":0,"y":-200,"trait":"kickOffBarrier"},{"x":-380,"y":-64,"trait":"goalNet"},{"x":-400,"y":-44,"trait":"goalNet"},{"x":-400,"y":44,"trait":"goalNet"},{"x":-380,"y":64,"trait":"goalNet"},{"x":380,"y":-64,"trait":"goalNet"},{"x":400,"y":-44,"trait":"goalNet"},{"x":400,"y":44,"trait":"goalNet"},{"x":380,"y":64,"trait":"goalNet"}],"segments":[{"v0":0,"v1":1,"trait":"ballArea"},{"v0":2,"v1":3,"trait":"ballArea"},{"v0":4,"v1":5,"trait":"ballArea"},{"v0":6,"v1":7,"trait":"ballArea"},{"v0":12,"v1":13,"trait":"goalNet","curve":-90},{"v0":13,"v1":14,"trait":"goalNet"},{"v0":14,"v1":15,"trait":"goalNet","curve":-90},{"v0":16,"v1":17,"trait":"goalNet","curve":90},{"v0":17,"v1":18,"trait":"goalNet"},{"v0":18,"v1":19,"trait":"goalNet","curve":90},{"v0":8,"v1":9,"trait":"kickOffBarrier"},{"v0":9,"v1":10,"trait":"kickOffBarrier","curve":180,"cGroup":["blueKO"]},{"v0":9,"v1":10,"trait":"kickOffBarrier","curve":-180,"cGroup":["redKO"]},{"v0":10,"v1":11,"trait":"kickOffBarrier"}],"goals":[{"p0":[-370,64],"p1":[-370,-64],"team":"red"},{"p0":[370,64],"p1":[370,-64],"team":"blue"}],"discs":[{"pos":[-370,64],"trait":"goalPost","color":"FFCCCC"},{"pos":[-370,-64],"trait":"goalPost","color":"FFCCCC"},{"pos":[370,64],"trait":"goalPost","color":"CCCCFF"},{"pos":[370,-64],"trait":"goalPost","color":"CCCCFF"}],"planes":[{"normal":[0,1],"dist":-170,"trait":"ballArea"},{"normal":[0,-1],"dist":-170,"trait":"ballArea"},{"normal":[0,1],"dist":-200,"bCoef":0.1},{"normal":[0,-1],"dist":-200,"bCoef":0.1},{"normal":[1,0],"dist":-420,"bCoef":0.1},{"normal":[-1,0],"dist":-420,"bCoef":0.1}],"traits":{"ballArea":{"vis":false,"bCoef":1,"cMask":["ball"]},"goalPost":{"radius":8,"invMass":0,"bCoef":0.5},"goalNet":{"vis":true,"bCoef":0.1,"cMask":["ball"]},"kickOffBarrier":{"vis":false,"bCoef":0.1,"cGroup":["redKO","blueKO"],"cMask":["red","blue"]}}}';
const bigMap = '{"name":"Big","width":600,"height":270,"spawnDistance":350,"bg":{"type":"grass","width":550,"height":240,"kickOffRadius":80,"cornerRadius":0},"vertexes":[{"x":-550,"y":240,"trait":"ballArea"},{"x":-550,"y":80,"trait":"ballArea"},{"x":-550,"y":-80,"trait":"ballArea"},{"x":-550,"y":-240,"trait":"ballArea"},{"x":550,"y":240,"trait":"ballArea"},{"x":550,"y":80,"trait":"ballArea"},{"x":550,"y":-80,"trait":"ballArea"},{"x":550,"y":-240,"trait":"ballArea"},{"x":0,"y":270,"trait":"kickOffBarrier"},{"x":0,"y":80,"trait":"kickOffBarrier"},{"x":0,"y":-80,"trait":"kickOffBarrier"},{"x":0,"y":-270,"trait":"kickOffBarrier"},{"x":-560,"y":-80,"trait":"goalNet"},{"x":-580,"y":-60,"trait":"goalNet"},{"x":-580,"y":60,"trait":"goalNet"},{"x":-560,"y":80,"trait":"goalNet"},{"x":560,"y":-80,"trait":"goalNet"},{"x":580,"y":-60,"trait":"goalNet"},{"x":580,"y":60,"trait":"goalNet"},{"x":560,"y":80,"trait":"goalNet"}],"segments":[{"v0":0,"v1":1,"trait":"ballArea"},{"v0":2,"v1":3,"trait":"ballArea"},{"v0":4,"v1":5,"trait":"ballArea"},{"v0":6,"v1":7,"trait":"ballArea"},{"v0":12,"v1":13,"trait":"goalNet","curve":-90},{"v0":13,"v1":14,"trait":"goalNet"},{"v0":14,"v1":15,"trait":"goalNet","curve":-90},{"v0":16,"v1":17,"trait":"goalNet","curve":90},{"v0":17,"v1":18,"trait":"goalNet"},{"v0":18,"v1":19,"trait":"goalNet","curve":90},{"v0":8,"v1":9,"trait":"kickOffBarrier"},{"v0":9,"v1":10,"trait":"kickOffBarrier","curve":180,"cGroup":["blueKO"]},{"v0":9,"v1":10,"trait":"kickOffBarrier","curve":-180,"cGroup":["redKO"]},{"v0":10,"v1":11,"trait":"kickOffBarrier"}],"goals":[{"p0":[-550,80],"p1":[-550,-80],"team":"red"},{"p0":[550,80],"p1":[550,-80],"team":"blue"}],"discs":[{"pos":[-550,80],"trait":"goalPost","color":"FFCCCC"},{"pos":[-550,-80],"trait":"goalPost","color":"FFCCCC"},{"pos":[550,80],"trait":"goalPost","color":"CCCCFF"},{"pos":[550,-80],"trait":"goalPost","color":"CCCCFF"}],"planes":[{"normal":[0,1],"dist":-240,"trait":"ballArea"},{"normal":[0,-1],"dist":-240,"trait":"ballArea"},{"normal":[0,1],"dist":-270,"bCoef":0.1},{"normal":[0,-1],"dist":-270,"bCoef":0.1},{"normal":[1,0],"dist":-600,"bCoef":0.1},{"normal":[-1,0],"dist":-600,"bCoef":0.1}],"traits":{"ballArea":{"vis":false,"bCoef":1,"cMask":["ball"]},"goalPost":{"radius":8,"invMass":0,"bCoef":0.5},"goalNet":{"vis":true,"bCoef":0.1,"cMask":["ball"]},"kickOffBarrier":{"vis":false,"bCoef":0.1,"cGroup":["redKO","blueKO"],"cMask":["red","blue"]}}}';
var bigMapObj = JSON.parse(bigMap);
room.setScoreLimit(scoreLimit);
room.setTimeLimit(timeLimit);
room.setTeamsLock(true);
room.setKickRateLimit(6, 0, 0);
var masterPassword = 10000 + getRandomInt(90000);
var roomPassword = '';
/* OPTIONS */
var drawTimeLimit = Infinity;
var maxAdmins = 2;
var disableBans = true;
var maxInactivity = 5;
var debugMode = false;
var hideClaimMessage = true;
var mentionPlayersUnpause = true;
/* OBJECTS */
class Goal {
constructor(time, team, striker, assist) {
this.time = time;
this.team = team;
this.striker = striker;
this.assist = assist;
}
}
class Game {
constructor() {
this.date = Date.now();
this.scores = room.getScores();
this.playerComp = getStartingLineups();
this.goals = [];
this.rec = room.startRecording();
this.touchArray = [];
}
}
class PlayerComposition {
constructor(player, auth, timeEntry, timeExit) {
this.player = player;
this.auth = auth;
this.timeEntry = timeEntry;
this.timeExit = timeExit;
this.inactivityTicks = 0;
this.GKTicks = 0;
}
}
class BallTouch {
constructor(player, time, goal, position) {
this.player = player;
this.time = time;
this.goal = goal;
this.position = position;
}
}
/* PLAYERS */
const Team = { SPECTATORS: 0, RED: 1, BLUE: 2 };
const State = { PLAY: 0, PAUSE: 1, STOP: 2 };
const Role = { PLAYER: 0, ADMIN_TEMP: 1, ADMIN_PERM: 2, MASTER: 3 };
const HaxNotification = { NONE: 0, CHAT: 1, MENTION: 2 };
const Situation = { STOP: 0, KICKOFF: 1, PLAY: 2, GOAL: 3 };
var gameState = State.STOP;
var playSituation = Situation.STOP;
var goldenGoal = false;
var players = [];
var teamRed = [];
var teamBlue = [];
var teamSpec = [];
var banList = [];
/* STATS */
var possession = [0, 0];
var actionZoneHalf = [0, 0];
/* AUTH */
var authArray = [];
var adminList = [
// ['INSERT_AUTH_HERE_1', 'NICK_OF_ADMIN_1'],
// ['INSERT_AUTH_HERE_2', 'NICK_OF_ADMIN_2'],
];
var masterList = [
// 'INSERT_MASTER_AUTH_HERE',
// 'INSERT_MASTER_AUTH_HERE_2'
];
/* COMMANDS */
var commands = {
help: {
aliases: ['commands'],
roles: Role.PLAYER,
desc: `
This command shows all the available commands. It also can show the description of a command in particular.
Example: \'!help bb\' will show the description of the \'bb\' command.`,
function: helpCommand,
},
claim: {
aliases: [],
roles: Role.PLAYER,
desc: false,
function: masterCommand,
},
bb: {
aliases: ['bye', 'gn', 'cya'],
roles: Role.PLAYER,
desc: `
This command makes you leave instantly (use recommended).`,
function: leaveCommand,
},
rr: {
aliases: [],
roles: Role.ADMIN_TEMP,
desc: `
This command restarts the game.`,
function: restartCommand,
},
rrs: {
aliases: [],
roles: Role.ADMIN_TEMP,
desc: `
This command swaps the teams and restarts the game.`,
function: restartSwapCommand,
},
swap: {
aliases: ['s'],
roles: Role.ADMIN_TEMP,
desc: `
This command swaps the teams when the game is stopped.`,
function: swapCommand,
},
training: {
aliases: [],
roles: Role.ADMIN_TEMP,
desc: `
This command loads the classic training stadium.`,
function: stadiumCommand,
},
classic: {
aliases: [],
roles: Role.ADMIN_TEMP,
desc: `
This command loads the classic stadium.`,
function: stadiumCommand,
},
big: {
aliases: [],
roles: Role.ADMIN_TEMP,
desc: `
This command loads the big stadium.`,
function: stadiumCommand,
},
kickred: {
aliases: ['kickr'],
roles: Role.ADMIN_TEMP,
desc: `
This command kicks all the players from the red team, including the player that entered the command. You can give as an argument the reason of the kick.`,
function: kickTeamCommand,
},
kickblue: {
aliases: ['kickb'],
roles: Role.ADMIN_TEMP,
desc: `
This command kicks all the players from the blue team, including the player that entered the command. You can give as an argument the reason of the kick.`,
function: kickTeamCommand,
},
kickspec: {
aliases: ['kicks'],
roles: Role.ADMIN_TEMP,
desc: `
This command kicks all the players from the spectators team, including the player that entered the command. You can give as an argument the reason of the kick.`,
function: kickTeamCommand,
},
clearbans: {
aliases: [],
roles: Role.MASTER,
desc: `
This command unbans everyone. It also can unban one player in particular, by adding his ID as an argument.`,
function: clearbansCommand,
},
bans: {
aliases: ['banlist'],
roles: Role.MASTER,
desc: `
This command shows all the players that were banned and their IDs.`,
function: banListCommand,
},
admins: {
aliases: ['adminlist'],
roles: Role.MASTER,
desc: `
This command shows all the players that are permanent admins.`,
function: adminListCommand,
},
setadmin: {
aliases: ['admin'],
roles: Role.MASTER,
desc: `
This command allows to set someone as admin. He will be able to connect as admin, and can be removed at any time by masters.
It takes 1 argument:
Argument 1: #<id> where <id> is the id of the player targeted.
Example: !setadmin #3 will give admin to the player with id 3.`,
function: setAdminCommand,
},
removeadmin: {
aliases: ['unadmin'],
roles: Role.MASTER,
desc: `
This command allows to remove someone as admin.
It takes 1 argument:
Argument 1: #<id> where <id> is the id of the player targeted.
OR
Argument 1: <number> where <number> is the number associated with the admin given by the 'adminList' command.
Example: !removeadmin #300 will remove admin to the player with id 300,
!removeadmin 2 will remove the admin n°2 according to the 'adminList' command.`,
function: removeAdminCommand,
},
password: {
aliases: ['pw'],
roles: Role.MASTER,
desc: `
This command allows to add a password to the room.
It takes 1 argument:
Argument 1: <password> where <password> is the password you want for the room.
To remove the room password, simply enter '!password'.`,
function: passwordCommand,
},
};
/* GAME */
var lastTouches = Array(2).fill(null);
var lastTeamTouched;
var speedCoefficient = 100 / (5 * (0.99 ** 60 + 1));
var ballSpeed = 0;
var playerRadius = 15;
var ballRadius = 10;
var triggerDistance = playerRadius + ballRadius + 0.01;
/* COLORS */
var welcomeColor = 0xc4ff65;
var announcementColor = 0xffefd6;
var infoColor = 0xbebebe;
var privateMessageColor = 0xffc933;
var redColor = 0xff4c4c;
var blueColor = 0x62cbff;
var warningColor = 0xffa135;
var errorColor = 0xa40000;
var successColor = 0x75ff75;
var defaultColor = null;
/* AUXILIARY */
var checkTimeVariable = false;
var checkStadiumVariable = true;
var endGameVariable = false;
var cancelGameVariable = false;
var kickFetchVariable = false;
var stopTimeout;
var startTimeout;
var unpauseTimeout;
var emptyPlayer = {
id: 0,
};
stadiumCommand(emptyPlayer, "!big");
var game = new Game();
/* FUNCTIONS */
/* AUXILIARY FUNCTIONS */
if (typeof String.prototype.replaceAll != 'function') {
String.prototype.replaceAll = function (search, replacement) {
var target = this;
return target.split(search).join(replacement);
};
}
function getDate() {
let d = new Date();
return d.toLocaleDateString() + ' ' + d.toLocaleTimeString();
}
/* MATH FUNCTIONS */
function getRandomInt(max) {
// returns a random number between 0 and max-1
return Math.floor(Math.random() * Math.floor(max));
}
function pointDistance(p1, p2) {
return Math.sqrt(Math.pow(p1.x - p2.x, 2) + Math.pow(p1.y - p2.y, 2));
}
/* TIME FUNCTIONS */
function getMinutesGame(time) {
var t = Math.floor(time / 60);
return `${Math.floor(t / 10)}${Math.floor(t % 10)}`;
}
function getMinutesReport(time) {
return Math.floor(Math.round(time) / 60);
}
function getMinutesEmbed(time) {
var t = Math.floor(Math.round(time) / 60);
return `${Math.floor(t / 10)}${Math.floor(t % 10)}`;
}
function getSecondsGame(time) {
var t = Math.floor(time - Math.floor(time / 60) * 60);
return `${Math.floor(t / 10)}${Math.floor(t % 10)}`;
}
function getSecondsReport(time) {
var t = Math.round(time);
return Math.floor(t - Math.floor(t / 60) * 60);
}
function getSecondsEmbed(time) {
var t = Math.round(time);
var t2 = Math.floor(t - Math.floor(t / 60) * 60);
return `${Math.floor(t2 / 10)}${Math.floor(t2 % 10)}`;
}
function getTimeGame(time) {
return `[${getMinutesGame(time)}:${getSecondsGame(time)}]`;
}
function getTimeEmbed(time) {
return `[${getMinutesEmbed(time)}:${getSecondsEmbed(time)}]`;
}
function getGoalGame() {
return game.scores.red + game.scores.blue;
}
/* REPORT FUNCTIONS */
function findFirstNumberCharString(str) {
let str_number = str[str.search(/[0-9]/g)];
return str_number === undefined ? "0" : str_number;
}
function getIdReport() {
var d = new Date();
return `${d.getFullYear() % 100}${d.getMonth() < 9 ? '0' : ''}${d.getMonth() + 1}${d.getDate() < 10 ? '0' : ''}${d.getDate()}${d.getHours() < 10 ? '0' : ''}${d.getHours()}${d.getMinutes() < 10 ? '0' : ''}${d.getMinutes()}${d.getSeconds() < 10 ? '0' : ''}${d.getSeconds()}${findFirstNumberCharString(roomName)}`;
}
function getRecordingName(game) {
let d = new Date();
let redCap = game.playerComp[0][0] != undefined ? game.playerComp[0][0].player.name : 'Red';
let blueCap = game.playerComp[1][0] != undefined ? game.playerComp[1][0].player.name : 'Blue';
let day = d.getDate() < 10 ? '0' + d.getDate() : d.getDate();
let month = d.getMonth() < 10 ? '0' + (d.getMonth() + 1) : (d.getMonth() + 1);
let year = d.getFullYear() % 100 < 10 ? '0' + (d.getFullYear() % 100) : (d.getFullYear() % 100);
let hour = d.getHours() < 10 ? '0' + d.getHours() : d.getHours();
let minute = d.getMinutes() < 10 ? '0' + d.getMinutes() : d.getMinutes();
return `${day}-${month}-${year}-${hour}h${minute}-${redCap}vs${blueCap}.hbr2`;
}
function fetchRecording(game) {
if (gameWebhook != "") {
let form = new FormData();
form.append(null, new File([game.rec], getRecordingName(game), { "type": "text/plain" }));
form.append("payload_json", JSON.stringify({
"username": roomName
}));
fetch(gameWebhook, {
method: 'POST',
body: form,
}).then((res) => res);
}
}
/* FEATURE FUNCTIONS */
function getCommand(commandStr) {
if (commands.hasOwnProperty(commandStr)) return commandStr;
for (const [key, value] of Object.entries(commands)) {
for (let alias of value.aliases) {
if (alias == commandStr) return key;
}
}
return false;
}
function getPlayerComp(player) {
if (player == null || player.id == 0) return null;
var comp = game.playerComp;
var index = comp[0].findIndex((c) => c.auth == authArray[player.id][0]);
if (index != -1) return comp[0][index];
index = comp[1].findIndex((c) => c.auth == authArray[player.id][0]);
if (index != -1) return comp[1][index];
return null;
}
function getTeamArray(team) {
return team == Team.RED ? teamRed : team == Team.BLUE ? teamBlue : teamSpec;
}
function sendAnnouncementTeam(message, team, color, style, mention) {
for (let player of team) {
room.sendAnnouncement(message, player.id, color, style, mention);
}
}
function teamChat(player, message) {
var msgArray = message.split(/ +/).slice(1);
var emoji = player.team == Team.RED ? '🔴' : player.team == Team.BLUE ? '🔵' : '⚪';
var message = `${emoji} [TEAM] ${player.name}: ${msgArray.join(' ')}`;
var team = getTeamArray(player.team);
var color = player.team == Team.RED ? redColor : player.team == Team.BLUE ? blueColor : null;
var style = 'bold';
var mention = HaxNotification.CHAT;
sendAnnouncementTeam(message, team, color, style, mention);
}
function playerChat(player, message) {
var msgArray = message.split(/ +/);
var playerTargetIndex = players.findIndex(
(p) => p.name.replaceAll(' ', '_') == msgArray[0].substring(2)
);
if (playerTargetIndex == -1) {
room.sendAnnouncement(
`Invalid player, make sure the name you entered is correct.`,
player.id,
errorColor,
'bold',
null
);
return false;
}
var playerTarget = players[playerTargetIndex];
if (player.id == playerTarget.id) {
room.sendAnnouncement(
`You can't send a PM to yourself!`,
player.id,
errorColor,
'bold',
null
);
return false;
}
var messageFrom = `📝 [PM with ${playerTarget.name}] ${player.name}: ${msgArray.slice(1).join(' ')}`
var messageTo = `📝 [PM with ${player.name}] ${player.name}: ${msgArray.slice(1).join(' ')}`
room.sendAnnouncement(
messageFrom,
player.id,
privateMessageColor,
'bold',
HaxNotification.CHAT
);
room.sendAnnouncement(
messageTo,
playerTarget.id,
privateMessageColor,
'bold',
HaxNotification.CHAT
);
}
/* PHYSICS FUNCTIONS */
function calculateStadiumVariables() {
if (checkStadiumVariable && teamRed.length + teamBlue.length > 0) {
checkStadiumVariable = false;
setTimeout(() => {
let ballDisc = room.getDiscProperties(0);
let playerDisc = room.getPlayerDiscProperties(teamRed.concat(teamBlue)[0].id);
ballRadius = ballDisc.radius;
playerRadius = playerDisc.radius;
triggerDistance = ballRadius + playerRadius + 0.01;
speedCoefficient = 100 / (5 * ballDisc.invMass * (ballDisc.damping ** 60 + 1));
}, 1);
}
}
function checkGoalKickTouch(array, index, goal) {
if (array != null && array.length >= index + 1) {
var obj = array[index];
if (obj != null && obj.goal != null && obj.goal == goal) return obj;
}
return null;
}
/* BUTTONS */
function swapButton() {
for (let player of teamBlue) {
room.setPlayerTeam(player.id, Team.RED);
}
for (let player of teamRed) {
room.setPlayerTeam(player.id, Team.BLUE);
}
}
/* COMMAND FUNCTIONS */
/* PLAYER COMMANDS */
function leaveCommand(player, message) {
room.kickPlayer(player.id, 'Bye !', false);
}
function helpCommand(player, message) {
var msgArray = message.split(/ +/).slice(1);
if (msgArray.length == 0) {
var commandString = 'Player commands :';
for (const [key, value] of Object.entries(commands)) {
if (value.desc && value.roles == Role.PLAYER) commandString += ` !${key},`;
}
commandString = commandString.substring(0, commandString.length - 1) + '.\n';
if (getRole(player) >= Role.ADMIN_TEMP) {
commandString += `Admin commands :`;
for (const [key, value] of Object.entries(commands)) {
if (value.desc && value.roles == Role.ADMIN_TEMP) commandString += ` !${key},`;
}
if (commandString.slice(commandString.length - 1) == ':')
commandString += ` None,`;
commandString = commandString.substring(0, commandString.length - 1) + '.\n';
}
if (getRole(player) >= Role.MASTER) {
commandString += `Master commands :`;
for (const [key, value] of Object.entries(commands)) {
if (value.desc && value.roles == Role.MASTER) commandString += ` !${key},`;
}
if (commandString.slice(commandString.length - 1) == ':') commandString += ` None,`;
commandString = commandString.substring(0, commandString.length - 1) + '.\n';
}
commandString += "\nTo get information on a specific command, type ''!help <command name>'.";
room.sendAnnouncement(
commandString,
player.id,
infoColor,
'bold',
HaxNotification.CHAT
);
} else if (msgArray.length >= 1) {
var commandName = getCommand(msgArray[0].toLowerCase());
if (commandName != false && commands[commandName].desc != false)
room.sendAnnouncement(
`\'${commandName}\' command :\n${commands[commandName].desc}`,
player.id,
infoColor,
'bold',
HaxNotification.CHAT
);
else
room.sendAnnouncement(
`The command you tried to get information on does not exist. To check all available commands, type \'!help\'`,
player.id,
errorColor,
'bold',
HaxNotification.CHAT
);
}
}
function masterCommand(player, message) {
var msgArray = message.split(/ +/).slice(1);
if (parseInt(msgArray[0]) == masterPassword) {
if (!masterList.includes(authArray[player.id][0])) {
room.setPlayerAdmin(player.id, true);
adminList = adminList.filter((a) => a[0] != authArray[player.id][0]);
masterList.push(authArray[player.id][0]);
room.sendAnnouncement(
`${player.name} is now a room master !`,
null,
announcementColor,
'bold',
HaxNotification.CHAT
);
} else {
room.sendAnnouncement(
`You are a master already !`,
player.id,
errorColor,
'bold',
HaxNotification.CHAT
);
}
}
}
/* ADMIN COMMANDS */
function restartCommand(player, message) {
instantRestart();
}
function restartSwapCommand(player, message) {
room.stopGame();
swapButton();
startTimeout = setTimeout(() => {
room.startGame();
}, 10);
}
function swapCommand(player, message) {
if (playSituation == Situation.STOP) {
swapButton();
room.sendAnnouncement(
'✔️ Teams swapped !',
null,
announcementColor,
'bold',
null
);
} else {
room.sendAnnouncement(
`Please stop the game before swapping.`,
player.id,
errorColor,
'bold',
HaxNotification.CHAT
);
}
}
function kickTeamCommand(player, message) {
var msgArray = message.split(/ +/);
var reasonString = `Team kick by ${player.name}`;
if (msgArray.length > 1) {
reasonString = msgArray.slice(1).join(' ');
}
if (['!kickred', '!kickr'].includes(msgArray[0].toLowerCase())) {
for (let i = 0; i < teamRed.length; i++) {
setTimeout(() => {
room.kickPlayer(teamRed[0].id, reasonString, false);
}, i * 20)
}
} else if (['!kickblue', '!kickb'].includes(msgArray[0].toLowerCase())) {
for (let i = 0; i < teamBlue.length; i++) {
setTimeout(() => {
room.kickPlayer(teamBlue[0].id, reasonString, false);
}, i * 20)
}
} else if (['!kickspec', '!kicks'].includes(msgArray[0].toLowerCase())) {
for (let i = 0; i < teamSpec.length; i++) {
setTimeout(() => {
room.kickPlayer(teamSpec[0].id, reasonString, false);
}, i * 20)
}
}
}
function stadiumCommand(player, message) {
var msgArray = message.split(/ +/);
if (gameState == State.STOP) {
if (['!classic'].includes(msgArray[0].toLowerCase())) {
if (JSON.parse(classicMap).name == 'Classic') {
room.setDefaultStadium('Classic');
} else {
room.setCustomStadium(classicMap);
}
} else if (['!big'].includes(msgArray[0].toLowerCase())) {
if (JSON.parse(bigMap).name == 'Big') {
room.setDefaultStadium('Big');
} else {
room.setCustomStadium(bigMap);
}
} else if (['!training'].includes(msgArray[0].toLowerCase())) {
room.setCustomStadium(trainingMap);
} else {
room.sendAnnouncement(
`Stadium not recognized.`,
player.id,
errorColor,
'bold',
HaxNotification.CHAT
);
}
} else {
room.sendAnnouncement(
`Please stop the game before using this command.`,
player.id,
errorColor,
'bold',
HaxNotification.CHAT
);
}
}
/* MASTER COMMANDS */
function clearbansCommand(player, message) {
var msgArray = message.split(/ +/).slice(1);
if (msgArray.length == 0) {
room.clearBans();
room.sendAnnouncement(
'✔️ Bans cleared !',
null,
announcementColor,
'bold',
null
);
banList = [];
} else if (msgArray.length == 1) {
if (parseInt(msgArray[0]) > 0) {
var ID = parseInt(msgArray[0]);
room.clearBan(ID);
if (banList.length != banList.filter((p) => p[1] != ID).length) {
room.sendAnnouncement(
`✔️ ${banList.filter((p) => p[1] == ID)[0][0]} has been unbanned from the room !`,
null,
announcementColor,
'bold',
null
);
} else {
room.sendAnnouncement(
`The ID you entered doesn't have a ban associated to. Enter "!help clearbans" for more information.`,
player.id,
errorColor,
'bold',
HaxNotification.CHAT
);
}
banList = banList.filter((p) => p[1] != ID);
} else {
room.sendAnnouncement(
`Invalid ID entered. Enter "!help clearbans" for more information.`,
player.id,
errorColor,
'bold',
HaxNotification.CHAT
);
}
} else {
room.sendAnnouncement(
`Wrong number of arguments. Enter "!help clearbans" for more information.`,
player.id,
errorColor,
'bold',
HaxNotification.CHAT
);
}
}
function banListCommand(player, message) {
if (banList.length == 0) {
room.sendAnnouncement(
"📢 There's nobody in the ban list.",
player.id,
announcementColor,
'bold',
null
);
return false;
}
var cstm = '📢 Ban list : ';
for (let ban of banList) {
cstm += ban[0] + `[${ban[1]}], `;
}
cstm = cstm.substring(0, cstm.length - 2) + '.';
room.sendAnnouncement(
cstm,
player.id,
announcementColor,
'bold',
null
);
}
function adminListCommand(player, message) {
if (adminList.length == 0) {
room.sendAnnouncement(
"📢 There's nobody in the admin list.",
player.id,
announcementColor,
'bold',
null
);
return false;
}
var cstm = '📢 Admin list : ';
for (let i = 0; i < adminList.length; i++) {
cstm += adminList[i][1] + `[${i}], `;
}
cstm = cstm.substring(0, cstm.length - 2) + '.';
room.sendAnnouncement(
cstm,
player.id,
announcementColor,
'bold',
null
);
}
function setAdminCommand(player, message) {
var msgArray = message.split(/ +/).slice(1);
if (msgArray.length > 0) {
if (msgArray[0].length > 0 && msgArray[0][0] == '#') {
msgArray[0] = msgArray[0].substring(1, msgArray[0].length);
if (room.getPlayer(parseInt(msgArray[0])) != null) {
var playerAdmin = room.getPlayer(parseInt(msgArray[0]));
if (!adminList.map((a) => a[0]).includes(authArray[playerAdmin.id][0])) {
if (!masterList.includes(authArray[playerAdmin.id][0])) {
room.setPlayerAdmin(playerAdmin.id, true);
adminList.push([authArray[playerAdmin.id][0], playerAdmin.name]);
room.sendAnnouncement(
`${playerAdmin.name} is now a room admin !`,
null,
announcementColor,
'bold',
HaxNotification.CHAT
);
} else {
room.sendAnnouncement(
`This player is a master already !`,
player.id,
errorColor,
'bold',
HaxNotification.CHAT
);
}
} else {
room.sendAnnouncement(
`This player is a permanent admin already !`,
player.id,
errorColor,
'bold',
HaxNotification.CHAT
);
}
} else {
room.sendAnnouncement(
`There is no player with such ID in the room. Enter "!help setadmin" for more information.`,
player.id,
errorColor,
'bold',
HaxNotification.CHAT
);
}
} else {
room.sendAnnouncement(
`Incorrect format for your argument. Enter "!help setadmin" for more information.`,
player.id,
errorColor,
'bold',
HaxNotification.CHAT
);
}
} else {
room.sendAnnouncement(
`Wrong number of arguments. Enter "!help setadmin" for more information.`,
player.id,
errorColor,
'bold',
HaxNotification.CHAT
);
}
}
function removeAdminCommand(player, message) {
var msgArray = message.split(/ +/).slice(1);
if (msgArray.length > 0) {
if (msgArray[0].length > 0 && msgArray[0][0] == '#') {
msgArray[0] = msgArray[0].substring(1, msgArray[0].length);
if (room.getPlayer(parseInt(msgArray[0])) != null) {
var playerAdmin = room.getPlayer(parseInt(msgArray[0]));
if (adminList.map((a) => a[0]).includes(authArray[playerAdmin.id][0])) {
room.setPlayerAdmin(playerAdmin.id, false);
adminList = adminList.filter((a) => a[0] != authArray[playerAdmin.id][0]);
room.sendAnnouncement(
`${playerAdmin.name} is not a room admin anymore !`,
null,
announcementColor,
'bold',
HaxNotification.CHAT
);
} else {
room.sendAnnouncement(
`This player isn't a permanent admin !`,
player.id,
errorColor,
'bold',
HaxNotification.CHAT
);
}
} else {
room.sendAnnouncement(
`There is no player with such ID in the room. Enter "!help removeadmin" for more information.`,
player.id,
errorColor,
'bold',
HaxNotification.CHAT
);
}
} else if (msgArray[0].length > 0 && parseInt(msgArray[0]) < adminList.length) {
var index = parseInt(msgArray[0]);
var playerAdmin = adminList[index];
if (players.findIndex((p) => authArray[p.id][0] == playerAdmin[0]) != -1) {
// check if there is the removed admin in the room
var indexRem = players.findIndex((p) => authArray[p.id][0] == playerAdmin[0]);
room.setPlayerAdmin(players[indexRem].id, false);
}
adminList.splice(index);
room.sendAnnouncement(
`${playerAdmin[1]} is not a room admin anymore !`,
null,
announcementColor,
'bold',
HaxNotification.CHAT
);
} else {
room.sendAnnouncement(
`Incorrect format for your argument. Enter "!help removeadmin" for more information.`,
player.id,
errorColor,
'bold',
HaxNotification.CHAT
);
}
} else {
room.sendAnnouncement(
`Wrong number of arguments. Enter "!help removeadmin" for more information.`,
player.id,
errorColor,
'bold',
HaxNotification.CHAT
);
}
}
function passwordCommand(player, message) {
var msgArray = message.split(/ +/).slice(1);
if (msgArray.length > 0) {
if (msgArray.length == 1 && msgArray[0] == '') {
roomPassword = '';
room.setPassword(null);
room.sendAnnouncement(
`The room password has been removed.`,
player.id,
announcementColor,
'bold',
HaxNotification.CHAT
);
}
roomPassword = msgArray.join(' ');
room.setPassword(roomPassword);
room.sendAnnouncement(
`The room password has been set to ${roomPassword}`,