Advertisement
Guest User

Untitled

a guest
Feb 24th, 2020
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 59.42 KB | None | 0 0
  1. // Stats: "Auth" : '["0-Games", "1-Wins", "2-Draws", "3-Losses", "4-Winrate", "5-Goals", "6-Assists", "7-GK", "8-CS", "9-CS%", "10-Role", "11-Nick"]'
  2.  
  3. /* VARIABLES */
  4.  
  5. /* ROOM */
  6.  
  7. const roomName = "⚽ 𝗛𝗔𝗫𝗦𝗛𝗢𝗧.𝗣𝗟 | AUTO 2V2 3V3 ❗";
  8. const botName = "𝘏𝘈𝘟𝘉𝘖𝘛";
  9. const maxPlayers = 28;
  10. const roomPublic = true;
  11. const geo = [{"code": "PL", "lat": 52, "lon": 19}, {"code": "FR", "lat": 46.2, "lon": 2.2}, {"code": "PL", "lat": 51.9, "lon": 19.1}, {"code": "GB", "lat": 55.3, "lon": -3.4}, {"code": "PT", "lat": 39.3, "lon": -8.2}];
  12.  
  13. const room = HBInit({ roomName: roomName, maxPlayers: maxPlayers, public: roomPublic, playerName: botName, geo: geo[0] });
  14.  
  15. const scoreLimitClassic = 3;
  16. const scoreLimitBig = 3;
  17. const timeLimitClassic = 3;
  18. const timeLimitBig = 3;
  19.  
  20. room.setTeamsLock(true);
  21.  
  22. var adminPassword = 1000 + getRandomInt(9000);
  23. console.log("adminPassword : " + adminPassword);
  24.  
  25. /* STADIUM */
  26.  
  27. const playerRadius = 15;
  28. var ballRadius = 10;
  29. const triggerDistance = playerRadius + ballRadius + 0.01;
  30. var aloneMap = '{"name":"STRIKESHOT - CLASSIC NO GOAL","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"]}}}'
  31. var classicMap = ''; // Insert your map for 1v1 and 2v2 here. To get minimum file size, here are the instructions : 1. Download the map 2. Go to https://cssminifier.com 3. Paste the result
  32. var bigMap = '.'; // Read above
  33.  
  34. /* OPTIONS */
  35.  
  36. var afkLimit = 12;
  37. var drawTimeLimit = Infinity;
  38. var maxTeamSize = 3; // This works for 1 (you might want to adapt things to remove some useless stats in 1v1 like assist or cs), 2, 3 or 4
  39. var slowMode = 0;
  40.  
  41. /* PLAYERS */
  42.  
  43. const Team = { SPECTATORS: 0, RED: 1, BLUE: 2 };
  44. var extendedP = [];
  45. const eP = { ID: 0, AUTH: 1, CONN: 2, AFK: 3, ACT: 4, GK: 5, MUTE: 6 };
  46. const Ss = { GA: 0, WI: 1, DR: 2, LS: 3, WR: 4, GL: 5, AS: 6, GK: 7, CS: 8, CP: 9, RL: 10, NK: 11}
  47. var players;
  48. var teamR;
  49. var teamB;
  50. var teamS;
  51.  
  52. /* GAME */
  53.  
  54. var lastTeamTouched;
  55. var lastPlayersTouched; // These allow to get good goal notifications (it should be lastPlayersKicked, waiting on a next update to get better track of shots on target)
  56. var countAFK = false; // Created to get better track of activity
  57. var activePlay = false; // Created to get better track of the possession
  58. var goldenGoal = false;
  59. var SMSet = new Set(); // Set created to get slow mode which is useful in chooseMode
  60. var banList = []; // Getting track of the bans, so we can unban ppl if we want
  61.  
  62. /* STATS */
  63.  
  64. var game;
  65. var GKList = ["",""];
  66. var Rposs = 0;
  67. var Bposs = 0;
  68. var point = [{"x": 0, "y": 0}, {"x": 0, "y": 0}]; // created to get ball speed
  69. var ballSpeed;
  70. var lastWinner = Team.SPECTATORS;
  71. var streak = 0;
  72. var allBlues = []; // This is to count the players who should be counted for the stats. This includes players who left after the game has started, doesn't include those who came too late or ...
  73. var allReds = []; // ... those who came in a very unequal game.
  74.  
  75. /* BALANCE & CHOOSE */
  76.  
  77. var inChooseMode = false; // This variable enables to distinguish the 2 phases of playing and choosing which should be dealt with very differently
  78. var redCaptainChoice = "";
  79. var blueCaptainChoice = "";
  80. var chooseTime = 20;
  81. var timeOutCap;
  82.  
  83. /* AUXILIARY */
  84.  
  85. var checkTimeVariable = false; // This is created so the chat doesn't get spammed when a game is ending via timeLimit
  86. var statNumber = 0; // This allows the room to be given stat information every X minutes
  87. var endGameVariable = false; // This variable with the one below helps distinguish the cases where games are stopped because they have finished to the ones where games are stopped due to player movements or resetting teams
  88. var resettingTeams = false;
  89. var capLeft = false;
  90. var statInterval = 6;
  91.  
  92. loadMap(aloneMap, 0, 0);
  93.  
  94. let playersInfo = {};
  95. let connections = []
  96. let messages = {
  97.  
  98. }
  99. /* OBJECTS */
  100.  
  101. function Goal(time, team, striker, assist) {
  102. this.time = time;
  103. this.team = team;
  104. this.striker = striker;
  105. this.assist = assist;
  106. }
  107.  
  108. function Game(date, scores, goals) {
  109. this.date = date;
  110. this.scores = scores;
  111. this.goals = goals;
  112. }
  113.  
  114. /* FUNCTIONS */
  115.  
  116. /* AUXILIARY FUNCTIONS */
  117.  
  118. function getRandomInt(max) { // returns a random number from 0 to max-1
  119. return Math.floor(Math.random() * Math.floor(max));
  120. }
  121.  
  122. function getTime(scores) { // returns the current time of the game
  123. return "[" + Math.floor(Math.floor(scores.time/60)/10).toString() + Math.floor(Math.floor(scores.time/60)%10).toString() + ":" + Math.floor(Math.floor(scores.time - (Math.floor(scores.time/60) * 60))/10).toString() + Math.floor(Math.floor(scores.time - (Math.floor(scores.time/60) * 60))%10).toString() + "]"
  124. }
  125.  
  126. function pointDistance(p1, p2) {
  127. var d1 = p1.x - p2.x;
  128. var d2 = p1.y - p2.y;
  129. return Math.sqrt(d1 * d1 + d2 * d2);
  130. }
  131.  
  132. /* BUTTONS */
  133.  
  134. function topBtn() {
  135. if (teamS.length == 0) {
  136. return;
  137. }
  138. else {
  139. if (teamR.length == teamB.length) {
  140. if (teamS.length > 1) {
  141. room.setPlayerTeam(teamS[0].id, Team.RED);
  142. room.setPlayerTeam(teamS[1].id, Team.BLUE);
  143. }
  144. return;
  145. }
  146. else if (teamR.length < teamB.length) {
  147. room.setPlayerTeam(teamS[0].id, Team.RED);
  148. }
  149. else {
  150. room.setPlayerTeam(teamS[0].id, Team.BLUE);
  151. }
  152. }
  153. }
  154.  
  155. function randomBtn() {
  156. if (teamS.length == 0) {
  157. return;
  158. }
  159. else {
  160. if (teamR.length == teamB.length) {
  161. if (teamS.length > 1) {
  162. var r = getRandomInt(teamS.length);
  163. room.setPlayerTeam(teamS[r].id, Team.RED);
  164. teamS = teamS.filter((spec) => spec.id != teamS[r].id);
  165. room.setPlayerTeam(teamS[getRandomInt(teamS.length)].id, Team.BLUE);
  166. }
  167. return;
  168. }
  169. else if (teamR.length < teamB.length) {
  170. room.setPlayerTeam(teamS[getRandomInt(teamS.length)].id, Team.RED);
  171. }
  172. else {
  173. room.setPlayerTeam(teamS[getRandomInt(teamS.length)].id, Team.BLUE);
  174. }
  175. }
  176. }
  177.  
  178. function blueToSpecBtn() {
  179. resettingTeams = true;
  180. setTimeout(() => { resettingTeams = false; }, 100);
  181. for (var i = 0; i < teamB.length; i++) {
  182. room.setPlayerTeam(teamB[teamB.length - 1 - i].id, Team.SPECTATORS);
  183. }
  184. }
  185.  
  186. function redToSpecBtn() {
  187. resettingTeams = true;
  188. setTimeout(() => { resettingTeams = false; }, 100);
  189. for (var i = 0; i < teamR.length; i++) {
  190. room.setPlayerTeam(teamR[teamR.length - 1 - i].id, Team.SPECTATORS);
  191. }
  192. }
  193.  
  194. function resetBtn() {
  195. resettingTeams = true;
  196. setTimeout(() => { resettingTeams = false; }, 100);
  197. if (teamR.length <= teamB.length) {
  198. for (var i = 0; i < teamR.length; i++) {
  199. room.setPlayerTeam(teamB[teamB.length - 1 - i].id, Team.SPECTATORS);
  200. room.setPlayerTeam(teamR[teamR.length - 1 - i].id, Team.SPECTATORS);
  201. }
  202. for (var i = teamR.length; i < teamB.length; i++) {
  203. room.setPlayerTeam(teamB[teamB.length - 1 - i].id, Team.SPECTATORS);
  204. }
  205. }
  206. else {
  207. for (var i = 0; i < teamB.length; i++) {
  208. room.setPlayerTeam(teamB[teamB.length - 1 - i].id, Team.SPECTATORS);
  209. room.setPlayerTeam(teamR[teamR.length - 1 - i].id, Team.SPECTATORS);
  210. }
  211. for (var i = teamB.length; i < teamR.length; i++) {
  212. room.setPlayerTeam(teamR[teamR.length - 1 - i].id, Team.SPECTATORS);
  213. }
  214. }
  215. }
  216.  
  217. function blueToRedBtn() {
  218. resettingTeams = true;
  219. setTimeout(() => { resettingTeams = false; }, 100);
  220. for (var i = 0; i < teamB.length; i++) {
  221. room.setPlayerTeam(teamB[i].id, Team.RED);
  222. }
  223. }
  224.  
  225. /* GAME FUNCTIONS */
  226.  
  227. function checkTime() {
  228. const scores = room.getScores();
  229. game.scores = scores;
  230. if (Math.abs(scores.time - scores.timeLimit) <= 0.01 && scores.timeLimit != 0) {
  231. if (scores.red != scores.blue) {
  232. if (checkTimeVariable == false) {
  233. checkTimeVariable = true;
  234. setTimeout(() => { checkTimeVariable = false; }, 3000);
  235. scores.red > scores.blue ? endGame(Team.RED) : endGame(Team.BLUE);
  236. setTimeout(() => { room.stopGame(); }, 2000);
  237. }
  238. return;
  239. }
  240. goldenGoal = true;
  241. room.sendAnnouncement("⚽ Pierwszy gol wygrywa !");
  242. }
  243. if (Math.abs(drawTimeLimit * 60 - scores.time - 60) <= 0.01 && players.length > 2) {
  244. if (checkTimeVariable == false) {
  245. checkTimeVariable = true;
  246. setTimeout(() => { checkTimeVariable = false; }, 10);
  247. room.sendAnnouncement("⌛ 60 Sekund do końca gry !");
  248. }
  249. }
  250. if (Math.abs(scores.time - drawTimeLimit * 60) <= 0.01 && players.length > 2) {
  251. if (checkTimeVariable == false) {
  252. checkTimeVariable = true;
  253. setTimeout(() => { checkTimeVariable = false; }, 10);
  254. endGame(Team.SPECTATORS);
  255. room.stopGame();
  256. goldenGoal = false;
  257. }
  258. }
  259. }
  260.  
  261. function endGame(winner) { // handles the end of a game : no stopGame function inside
  262. players.length >= 2 * maxTeamSize - 1 ? activateChooseMode() : null;
  263. const scores = room.getScores();
  264. game.scores = scores;
  265. Rposs = Rposs/(Rposs+Bposs);
  266. Bposs = 1 - Rposs;
  267. lastWinner = winner;
  268. endGameVariable = true;
  269. if (winner == Team.RED) {
  270. streak++;
  271. room.sendAnnouncement("🔴 Czerwoni Wygrywają " + scores.red + "-" + scores.blue + " ! Wygrane z rzędu : " + streak + " 🏆");
  272. }
  273. else if (winner == Team.BLUE) {
  274. streak = 1;
  275. room.sendAnnouncement("🔵 Niebiescy Wygrywają " + scores.blue + "-" + scores.red + " ! Wygrane z rzędu : " + streak + " 🏆");
  276. }
  277. else {
  278. streak = 0;
  279. room.sendAnnouncement("💤 Osiągnięty limit rysunkowy! 💤");
  280. }
  281. room.sendAnnouncement("⭐ Posiadanie : 🔴 " + (Rposs*100).toPrecision(3).toString() + "% : " + (Bposs*100).toPrecision(3).toString() + "% 🔵");
  282. scores.red == 0 ? (scores.blue == 0 ? room.sendChat("🏆 " + GKList[0].name + " and " + GKList[1].name + " Prowadził CS ❗ ") : room.sendChat("🏆 " + GKList[1].name + " Prowadził CS ❗ ")) : scores.blue == 0 ? room.sendAnnouncement("🏆 " + GKList[0].name + " Prowadził CS ❗ ") : null;
  283. updateStats();
  284. }
  285.  
  286. function quickRestart() {
  287. room.stopGame();
  288. setTimeout(() => { room.startGame(); }, 2000);
  289. }
  290.  
  291. function resumeGame() {
  292. setTimeout(() => { room.startGame(); }, 2000);
  293. setTimeout(() => { room.pauseGame(false); }, 1000);
  294. }
  295.  
  296. function activateChooseMode() {
  297. inChooseMode = true;
  298. slowMode = 2;
  299. room.sendAnnouncement("2 sekundy włączony tryb powolny !");
  300. }
  301.  
  302. function deactivateChooseMode() {
  303. inChooseMode = false;
  304. clearTimeout(timeOutCap);
  305. if (slowMode != 0) {
  306. slowMode = 0;
  307. room.sendAnnouncement("Tryb powolny zakończony. ⭐");
  308. }
  309. redCaptainChoice = "";
  310. blueCaptainChoice = "";
  311. }
  312.  
  313. function loadMap(map, scoreLim, timeLim) {
  314. if (map == aloneMap) {
  315. room.setCustomStadium(aloneMap);
  316. }
  317. else if (map == classicMap) {
  318. (classicMap != '') ? room.setCustomStadium(classicMap) : room.setDefaultStadium("Classic");
  319. }
  320. else if (map == bigMap) {
  321. (bigMap != '.') ? room.setCustomStadium(bigMap) : room.setDefaultStadium("Big");
  322. }
  323. else {
  324. room.setCustomStadium(map);
  325. }
  326. room.setScoreLimit(scoreLim);
  327. room.setTimeLimit(timeLim);
  328. }
  329.  
  330. /* PLAYER FUNCTIONS */
  331.  
  332. function updateTeams() { // update the players' list and all the teams' list
  333. players = room.getPlayerList().filter((player) => player.id != 0 && !getAFK(player));
  334. teamR = players.filter(p => p.team === Team.RED);
  335. teamB = players.filter(p => p.team === Team.BLUE);
  336. teamS = players.filter(p => p.team === Team.SPECTATORS);
  337. }
  338.  
  339. function handleInactivity() { // handles inactivity : players will be kicked after afkLimit
  340. if (countAFK && (teamR.length + teamB.length) > 1) {
  341. for (var i = 0; i < teamR.length ; i++) {
  342. setActivity(teamR[i], getActivity(teamR[i]) + 1);
  343. }
  344. for (var i = 0; i < teamB.length ; i++) {
  345. setActivity(teamB[i], getActivity(teamB[i]) + 1);
  346. }
  347. }
  348. for (var i = 0; i < extendedP.length ; i++) {
  349. if (extendedP[i][eP.ACT] == 60 * (2/3 * afkLimit)) {
  350. room.sendChat("⛔ @" + room.getPlayer(extendedP[i][eP.ID]).name + ", Jeśli nie napiszesz wiadomosci na czacie ani sie nie ruszysz w ciagu: " + Math.floor(afkLimit / 3) + " zostaniesz wyrzucony !", extendedP[i][eP.ID]);
  351. }
  352. if (extendedP[i][eP.ACT] >= 60 * afkLimit) {
  353. extendedP[i][eP.ACT] = 0;
  354. if (room.getScores().time <= afkLimit - 0.5) {
  355. setTimeout(() => { !inChooseMode ? quickRestart() : room.stopGame(); }, 10);
  356. }
  357. room.kickPlayer(extendedP[i][eP.ID], "AFK, Następnym razem graj", false);
  358. }
  359. }
  360. }
  361.  
  362. function getAuth(player) {
  363. return extendedP.filter((a) => a[0] == player.id) != null ? extendedP.filter((a) => a[0] == player.id)[0][eP.AUTH] : null;
  364. }
  365.  
  366. function getAFK(player) {
  367. return extendedP.filter((a) => a[0] == player.id) != null ? extendedP.filter((a) => a[0] == player.id)[0][eP.AFK] : null;
  368. }
  369.  
  370. function setAFK(player, value) {
  371. extendedP.filter((a) => a[0] == player.id).forEach((player) => player[eP.AFK] = value);
  372. }
  373.  
  374. function getActivity(player) {
  375. return extendedP.filter((a) => a[0] == player.id) != null ? extendedP.filter((a) => a[0] == player.id)[0][eP.ACT] : null;
  376. }
  377.  
  378. function setActivity(player, value) {
  379. extendedP.filter((a) => a[0] == player.id).forEach((player) => player[eP.ACT] = value);
  380. }
  381.  
  382. function getGK(player) {
  383. return extendedP.filter((a) => a[0] == player.id) != null ? extendedP.filter((a) => a[0] == player.id)[0][eP.GK] : null;
  384. }
  385.  
  386. function setGK(player, value) {
  387. extendedP.filter((a) => a[0] == player.id).forEach((player) => player[eP.GK] = value);
  388. }
  389.  
  390. function getMute(player) {
  391. return extendedP.filter((a) => a[0] == player.id) != null ? extendedP.filter((a) => a[0] == player.id)[0][eP.MUTE] : null;
  392. }
  393.  
  394. function setMute(player, value) {
  395. extendedP.filter((a) => a[0] == player.id).forEach((player) => player[eP.MUTE] = value);
  396. }
  397.  
  398. /* BALANCE & CHOOSE FUNCTIONS */
  399.  
  400. function updateRoleOnPlayerIn() {
  401. updateTeams();
  402. if (inChooseMode) {
  403. if (players.length == 6) {
  404. loadMap(bigMap, scoreLimitBig, timeLimitBig);
  405. }
  406. getSpecList(teamR.length <= teamB.length ? teamR[0] : teamB[0]);
  407. }
  408. balanceTeams();
  409. }
  410.  
  411. function updateRoleOnPlayerOut() {
  412. updateTeams();
  413. if (room.getScores() != null) {
  414. var scores = room.getScores();
  415. if (players.length >= 2 * maxTeamSize && scores.time >= (5/6) * game.scores.timeLimit && teamR.length != teamB.length) {
  416. if (teamR.length < teamB.length) {
  417. if (scores.blue - scores.red == 2) {
  418. endGame(Team.BLUE);
  419. room.sendAnnouncement("🤖 Wykryto Ragequit. Gra zakończona. 🤖");
  420. setTimeout(() => { room.stopGame(); }, 100);
  421. return;
  422. }
  423. }
  424. else {
  425. if (scores.red - scores.blue == 2) {
  426. endGame(Team.RED);
  427. room.sendAnnouncement("🤖 Wykryto Ragequit. Gra zakończona. 🤖");
  428. setTimeout(() => { room.stopGame(); }, 100);
  429. return;
  430. }
  431. }
  432. }
  433. }
  434. if (inChooseMode) {
  435. if (players.length == 5) {
  436. loadMap(classicMap, scoreLimitClassic, timeLimitClassic);
  437. }
  438. if (teamR.length == 0 || teamB.length == 0) {
  439. teamR.length == 0 ? room.setPlayerTeam(teamS[0].id, Team.RED) : room.setPlayerTeam(teamS[0].id, Team.BLUE);
  440. return;
  441. }
  442. if (Math.abs(teamR.length - teamB.length) == teamS.length) {
  443. room.sendAnnouncement("🤖 Nie mam wyboru, pozwól mi się tym zająć... 🤖");
  444. deactivateChooseMode();
  445. resumeGame();
  446. var b = teamS.length;
  447. if (teamR.length > teamB.length) {
  448. for (var i = 0 ; i < b ; i++) {
  449. setTimeout(() => { room.setPlayerTeam(teamS[0].id, Team.BLUE); }, 5*i);
  450. }
  451. }
  452. else {
  453. for (var i = 0 ; i < b ; i++) {
  454. setTimeout(() => { room.setPlayerTeam(teamS[0].id, Team.RED); }, 5*i);
  455. }
  456. }
  457. return;
  458. }
  459. if (streak == 0 && room.getScores() == null) {
  460. if (Math.abs(teamR.length - teamB.length) == 2) { // if someone left a team has 2 more players than the other one, put the last chosen guy back in his place so it's fair
  461. room.sendAnnouncement("🤖 Równoważenie zespołów... 🤖");
  462. teamR.length > teamB.length ? room.setPlayerTeam(teamR[teamR.length - 1].id, Team.SPECTATORS) : room.setPlayerTeam(teamB[teamB.length - 1].id, Team.SPECTATORS);
  463. }
  464. }
  465. if (teamR.length == teamB.length && teamS.length < 2) {
  466. deactivateChooseMode();
  467. resumeGame();
  468. return;
  469. }
  470. capLeft ? choosePlayer() : getSpecList(teamR.length <= teamB.length ? teamR[0] : teamB[0]);
  471. }
  472. balanceTeams();
  473. }
  474.  
  475. function balanceTeams() {
  476. if (!inChooseMode) {
  477. if (players.length == 1 && teamR.length == 0) {
  478. quickRestart();
  479. loadMap(aloneMap, 0, 0);
  480. room.setPlayerTeam(players[0].id, Team.RED);
  481. }
  482. else if (Math.abs(teamR.length - teamB.length) == teamS.length && teamS.length > 0) {
  483. const n = Math.abs(teamR.length - teamB.length);
  484. if (players.length == 2) {
  485. quickRestart();
  486. loadMap(classicMap, scoreLimitClassic, timeLimitClassic);
  487. }
  488. if (teamR.length > teamB.length) {
  489. for (var i = 0 ; i < n ; i++) {
  490. room.setPlayerTeam(teamS[i].id, Team.BLUE);
  491. }
  492. }
  493. else {
  494. for (var i = 0 ; i < n ; i++) {
  495. room.setPlayerTeam(teamS[i].id, Team.RED);
  496. }
  497. }
  498. }
  499. else if (Math.abs(teamR.length - teamB.length) > teamS.length) {
  500. const n = Math.abs(teamR.length - teamB.length);
  501. if (players.length == 1) {
  502. quickRestart();
  503. loadMap(aloneMap, 0, 0);
  504. room.setPlayerTeam(players[0].id, Team.RED);
  505. return;
  506. }
  507. else if (players.length == 5) {
  508. quickRestart();
  509. loadMap(classicMap, scoreLimitClassic, timeLimitClassic);
  510. }
  511. if (players.length == maxTeamSize * 2 - 1) {
  512. allReds = [];
  513. allBlues = [];
  514. }
  515. if (teamR.length > teamB.length) {
  516. for (var i = 0 ; i < n ; i++) {
  517. room.setPlayerTeam(teamR[teamR.length - 1 - i].id, Team.SPECTATORS);
  518. }
  519. }
  520. else {
  521. for (var i = 0 ; i < n ; i++) {
  522. room.setPlayerTeam(teamB[teamB.length - 1 - i].id, Team.SPECTATORS);
  523. }
  524. }
  525. }
  526. else if (Math.abs(teamR.length - teamB.length) < teamS.length && teamR.length != teamB.length) {
  527. room.pauseGame(true);
  528. activateChooseMode();
  529. choosePlayer();
  530. }
  531. else if (teamS.length >= 2 && teamR.length == teamB.length && teamR.length < maxTeamSize) {
  532. if (teamR.length == 2) {
  533. quickRestart();
  534. loadMap(bigMap, scoreLimitBig, timeLimitBig);
  535. }
  536. topBtn();
  537. }
  538. }
  539. }
  540.  
  541. function choosePlayer() {
  542. clearTimeout(timeOutCap);
  543. if (teamR.length <= teamB.length && teamR.length != 0) {
  544. room.sendChat("Wybierz kolege z listy do grania.", teamR[0].id);
  545. timeOutCap = setTimeout(function (player) { room.sendChat(" Hurry up @" + player.name + ", only " + Number.parseInt(chooseTime / 2) + " seconds left to choose !", player.id); timeOutCap = setTimeout(function (player) { room.kickPlayer(player.id, "Nie wybrałeś w porę !", false); }, chooseTime * 500, teamR[0]); }, chooseTime * 1000, teamR[0]);
  546. }
  547. else if (teamB.length < teamR.length && teamB.length != 0) {
  548. room.sendChat("Wybierz kolege z listy do grania.", teamB[0].id);
  549. timeOutCap = setTimeout(function (player) { room.sendChat(" Hurry up @" + player.name + ", only " + Number.parseInt(chooseTime / 2) + " seconds left to choose !", player.id); timeOutCap = setTimeout(function (player) { room.kickPlayer(player.id, "Nie wybrałeś w porę !", false); }, chooseTime * 500, teamB[0]); }, chooseTime * 1000, teamB[0]);
  550. }
  551. if (teamR.length != 0 && teamB.length != 0) getSpecList(teamR.length <= teamB.length ? teamR[0] : teamB[0]);
  552. }
  553.  
  554. function getSpecList(player) {
  555. var cstm = "Lista graczy 💜 : ";
  556. for (var i = 0 ; i < teamS.length ; i++) {
  557. if (140 - cstm.length < (teamS[i].name + "[" + (i+1) + "], ").length) {
  558. room.sendChat(cstm, player.id);
  559. cstm = "... ";
  560. }
  561. cstm += teamS[i].name + "[" + (i+1) + "], ";
  562. }
  563. cstm = cstm.substring(0,cstm.length - 2);
  564. cstm += ".";
  565. room.sendChat(cstm, player.id);
  566. }
  567.  
  568. /* STATS FUNCTIONS */
  569.  
  570. function getLastTouchOfTheBall() {
  571. const ballPosition = room.getBallPosition();
  572. updateTeams();
  573. for (var i = 0; i < players.length; i++) {
  574. if (players[i].position != null) {
  575. var distanceToBall = pointDistance(players[i].position, ballPosition);
  576. if (distanceToBall < triggerDistance) {
  577. !activePlay ? activePlay = true : null;
  578. if (lastTeamTouched == players[i].team && lastPlayersTouched[0] != null && lastPlayersTouched[0].id != players[i].id) {
  579. lastPlayersTouched[1] = lastPlayersTouched[0];
  580. lastPlayersTouched[0] = players[i];
  581. }
  582. lastTeamTouched = players[i].team;
  583. }
  584. }
  585. }
  586. }
  587.  
  588. function getStats() { // gives possession, ball speed and GK of each team
  589. if (activePlay) {
  590. updateTeams();
  591. lastTeamTouched == Team.RED ? Rposs++ : Bposs++;
  592. var ballPosition = room.getBallPosition();
  593. point[1] = point[0];
  594. point[0] = ballPosition;
  595. ballSpeed = (pointDistance(point[0], point[1]) * 60 * 60 * 60)/15000;
  596. var k = [-1, Infinity];
  597. for (var i = 0; i < teamR.length; i++) {
  598. if (teamR[i].position.x < k[1]) {
  599. k[0] = teamR[i];
  600. k[1] = teamR[i].position.x;
  601. }
  602. }
  603. k[0] != -1 ? setGK(k[0], getGK(k[0]) + 1) : null;
  604. k = [-1, -Infinity];
  605. for (var i = 0; i < teamB.length; i++) {
  606. if (teamB[i].position.x > k[1]) {
  607. k[0] = teamB[i];
  608. k[1] = teamB[i].position.x;
  609. }
  610. }
  611. k[0] != -1 ? setGK(k[0], getGK(k[0]) + 1) : null;
  612. findGK();
  613. }
  614. }
  615.  
  616. function updateStats() {
  617. if (players.length >= 2 * maxTeamSize && (game.scores.time >= (5 / 6) * game.scores.timeLimit || game.scores.red == game.scores.scoreLimit || game.scores.blue == game.scores.scoreLimit) && allReds.length >= maxTeamSize && allBlues.length >= maxTeamSize) {
  618. var stats;
  619. for (var i = 0; i < allReds.length; i++) {
  620. localStorage.getItem(getAuth(allReds[i])) ? stats = JSON.parse(localStorage.getItem(getAuth(allReds[i]))) : stats = [0, 0, 0, 0, "0.00", 0, 0, 0, 0, "0.00", "player", allReds[i].name];
  621. stats[Ss.GA]++;
  622. lastWinner == Team.RED ? stats[Ss.WI]++ : lastWinner == Team.BLUE ? stats[Ss.LS]++ : stats[Ss.DR]++;
  623. stats[Ss.WR] = (100 * stats[Ss.WI] / stats[Ss.GA]).toPrecision(3);
  624. localStorage.setItem(getAuth(allReds[i]), JSON.stringify(stats));
  625. }
  626. for (var i = 0; i < allBlues.length; i++) {
  627. localStorage.getItem(getAuth(allBlues[i])) ? stats = JSON.parse(localStorage.getItem(getAuth(allBlues[i]))) : stats = [0, 0, 0, 0, "0.00", 0, 0, 0, 0, "0.00", "player", allBlues[i].name];
  628. stats[Ss.GA]++;
  629. lastWinner == Team.BLUE ? stats[Ss.WI]++ : lastWinner == Team.RED ? stats[Ss.LS]++ : stats[Ss.DR]++;
  630. stats[Ss.WR] = (100 * stats[Ss.WI] / stats[Ss.GA]).toPrecision(3);
  631. localStorage.setItem(getAuth(allBlues[i]), JSON.stringify(stats));
  632. }
  633. for (var i = 0; i < game.goals.length; i++) {
  634. if (game.goals[i].striker != null) {
  635. if ((allBlues.concat(allReds)).findIndex((player) => player.id == game.goals[i].striker.id) != -1) {
  636. stats = JSON.parse(localStorage.getItem(getAuth(game.goals[i].striker)));
  637. stats[Ss.GL]++;
  638. localStorage.setItem(getAuth(game.goals[i].striker), JSON.stringify(stats));
  639. }
  640. }
  641. if (game.goals[i].assist != null) {
  642. if ((allBlues.concat(allReds)).findIndex((player) => player.name == game.goals[i].assist.name) != -1) {
  643. stats = JSON.parse(localStorage.getItem(getAuth(game.goals[i].assist)));
  644. stats[Ss.AS]++;
  645. localStorage.setItem(getAuth(game.goals[i].assist), JSON.stringify(stats));
  646. }
  647. }
  648. }
  649. if (allReds.findIndex((player) => player.id == GKList[0].id) != -1) {
  650. stats = JSON.parse(localStorage.getItem(getAuth(GKList[0])));
  651. stats[Ss.GK]++;
  652. game.scores.blue == 0 ? stats[Ss.CS]++ : null;
  653. stats[Ss.CP] = (100 * stats[Ss.CS] / stats[Ss.GK]).toPrecision(3);
  654. localStorage.setItem(getAuth(GKList[0]), JSON.stringify(stats));
  655. }
  656. if (allBlues.findIndex((player) => player.id == GKList[1].id) != -1) {
  657. stats = JSON.parse(localStorage.getItem(getAuth(GKList[1])));
  658. stats[Ss.GK]++;
  659. game.scores.red == 0 ? stats[Ss.CS]++ : null;
  660. stats[Ss.CP] = (100 * stats[Ss.CS] / stats[Ss.GK]).toPrecision(3);
  661. localStorage.setItem(getAuth(GKList[1]), JSON.stringify(stats));
  662. }
  663. }
  664. }
  665.  
  666. function findGK() {
  667. var tab = [[-1,""], [-1,""]];
  668. for (var i = 0; i < extendedP.length ; i++) {
  669. if (room.getPlayer(extendedP[i][eP.ID]) != null && room.getPlayer(extendedP[i][eP.ID]).team == Team.RED) {
  670. if (tab[0][0] < extendedP[i][eP.GK]) {
  671. tab[0][0] = extendedP[i][eP.GK];
  672. tab[0][1] = room.getPlayer(extendedP[i][eP.ID]);
  673. }
  674. }
  675. else if (room.getPlayer(extendedP[i][eP.ID]) != null && room.getPlayer(extendedP[i][eP.ID]).team == Team.BLUE) {
  676. if (tab[1][0] < extendedP[i][eP.GK]) {
  677. tab[1][0] = extendedP[i][eP.GK];
  678. tab[1][1] = room.getPlayer(extendedP[i][eP.ID]);
  679. }
  680. }
  681. }
  682. GKList = [tab[0][1], tab[1][1]];
  683. }
  684.  
  685. setInterval(() => {
  686. var tableau = [];
  687. if (statNumber % 5 == 0) {
  688. Object.keys(localStorage).forEach(function (key) { if (!["player_name", "view_mode", "geo", "avatar", "player_auth_key"].includes(key)) { tableau.push([(JSON.parse(localStorage.getItem(key))[Ss.NK]), (JSON.parse(localStorage.getItem(key))[Ss.GA])]); } });
  689. if (tableau.length < 5) {
  690. return false;
  691. }
  692. tableau.sort(function (a, b) { return b[1] - a[1]; });
  693. room.sendAnnouncement("Gry> #1 " + tableau[0][0] + ": " + tableau[0][1] + " #2 " + tableau[1][0] + ": " + tableau[1][1] + " #3 " + tableau[2][0] + ": " + tableau[2][1] + " #4 " + tableau[3][0] + ": " + tableau[3][1] + " #5 " + tableau[4][0] + ": " + tableau[4][1]);
  694. }
  695. if (statNumber % 5 == 1) {
  696. Object.keys(localStorage).forEach(function (key) { if (!["player_name", "view_mode", "geo", "avatar", "player_auth_key"].includes(key)) { tableau.push([(JSON.parse(localStorage.getItem(key))[Ss.NK]), (JSON.parse(localStorage.getItem(key))[Ss.WI])]); } });
  697. if (tableau.length < 5) {
  698. return false;
  699. }
  700. tableau.sort(function (a, b) { return b[1] - a[1]; });
  701. room.sendAnnouncement("Wygrane> #1 " + tableau[0][0] + ": " + tableau[0][1] + " #2 " + tableau[1][0] + ": " + tableau[1][1] + " #3 " + tableau[2][0] + ": " + tableau[2][1] + " #4 " + tableau[3][0] + ": " + tableau[3][1] + " #5 " + tableau[4][0] + ": " + tableau[4][1]);
  702. }
  703. if (statNumber % 5 == 2) {
  704. Object.keys(localStorage).forEach(function (key) { if (!["player_name", "view_mode", "geo", "avatar", "player_auth_key"].includes(key)) { tableau.push([(JSON.parse(localStorage.getItem(key))[Ss.NK]), (JSON.parse(localStorage.getItem(key))[Ss.GL])]); } });
  705. if (tableau.length < 5) {
  706. return false;
  707. }
  708. tableau.sort(function (a, b) { return b[1] - a[1]; });
  709. room.sendAnnouncement("Gole> #1 " + tableau[0][0] + ": " + tableau[0][1] + " #2 " + tableau[1][0] + ": " + tableau[1][1] + " #3 " + tableau[2][0] + ": " + tableau[2][1] + " #4 " + tableau[3][0] + ": " + tableau[3][1] + " #5 " + tableau[4][0] + ": " + tableau[4][1]);
  710. }
  711. if (statNumber % 5 == 3) {
  712. Object.keys(localStorage).forEach(function (key) { if (!["player_name", "view_mode", "geo", "avatar", "player_auth_key"].includes(key)) { tableau.push([(JSON.parse(localStorage.getItem(key))[Ss.NK]), (JSON.parse(localStorage.getItem(key))[Ss.AS])]); } });
  713. if (tableau.length < 5) {
  714. return false;
  715. }
  716. tableau.sort(function (a, b) { return b[1] - a[1]; });
  717. room.sendAnnouncement("Asysty> #1 " + tableau[0][0] + ": " + tableau[0][1] + " #2 " + tableau[1][0] + ": " + tableau[1][1] + " #3 " + tableau[2][0] + ": " + tableau[2][1] + " #4 " + tableau[3][0] + ": " + tableau[3][1] + " #5 " + tableau[4][0] + ": " + tableau[4][1]);
  718. }
  719. if (statNumber % 5 == 4) {
  720. Object.keys(localStorage).forEach(function (key) { if (!["player_name", "view_mode", "geo", "avatar", "player_auth_key"].includes(key)) { tableau.push([(JSON.parse(localStorage.getItem(key))[Ss.NK]), (JSON.parse(localStorage.getItem(key))[Ss.CS])]); } });
  721. if (tableau.length < 5) {
  722. return false;
  723. }
  724. tableau.sort(function (a, b) { return b[1] - a[1]; });
  725. room.sendAnnouncement("CS> #1 " + tableau[0][0] + ": " + tableau[0][1] + " #2 " + tableau[1][0] + ": " + tableau[1][1] + " #3 " + tableau[2][0] + ": " + tableau[2][1] + " #4 " + tableau[3][0] + ": " + tableau[3][1] + " #5 " + tableau[4][0] + ": " + tableau[4][1]);
  726. }
  727. statNumber++;
  728. }, statInterval * 60 * 1000);
  729.  
  730. /* EVENTS */
  731.  
  732. /* PLAYER MOVEMENT */
  733.  
  734. room.onPlayerJoin = function(player) {
  735. extendedP.push([player.id, player.auth, player.conn, false, 0, 0, false]);
  736. updateRoleOnPlayerIn();
  737. room.sendAnnouncement('👋🏻 Witamy Serdecznie ' + player.name + ' ❗ Wpisz !pomoc aby zobaczyć dostępne komendy.', player.id, 0xff0000, 'bold', 2);
  738. room.sendAnnouncement('Zapraszamy na Discord: https://discord.gg/bXhmkDy', player.id, 0xff0000, 'small-bold', 1);
  739. if (localStorage.getItem(player.auth) != null) {
  740. if (JSON.parse(localStorage.getItem(player.auth))[Ss.RL] != "admin") {
  741. room.setPlayerAdmin(player.id, true);
  742. room.sendChat((JSON.parse(localStorage.getItem(player.auth))[Ss.RL] == "master" ? "Admin " : "Admin ") + player.name + " Dołączył na serwer !", player.id, "0xFFA500", "bold", false);
  743. }
  744. }
  745. playersInfo[player.name] = [player.auth, player.conn];
  746. let conn = connections.find(a => a[1] === player.conn)
  747. if (conn) {
  748. room.kickPlayer(player.id, "1 gracz = 1 karta", false);
  749. } else {
  750.  
  751. connections.push([player.id, player.conn])
  752. }
  753.  
  754. messages[player.name] = {
  755. lastMsg: null,
  756. status: 0
  757. }
  758. }
  759.  
  760. room.onPlayerTeamChange = function(changedPlayer, byPlayer) {
  761. if (changedPlayer.id == 0) {
  762. room.setPlayerTeam(0, Team.SPECTATORS);
  763. return;
  764. }
  765. if (getAFK(changedPlayer) && changedPlayer.team != Team.SPECTATORS) {
  766. room.setPlayerTeam(changedPlayer.id, Team.SPECTATORS);
  767. room.sendAnnouncement(changedPlayer.name + " Nie można przenieść, bo afczy !");
  768. return;
  769. }
  770. updateTeams();
  771. if (room.getScores() != null) {
  772. var scores = room.getScores();
  773. if (changedPlayer.team != Team.SPECTATORS && scores.time <= (3/4) * scores.timeLimit && Math.abs(scores.blue - scores.red) < 2) {
  774. (changedPlayer.team == Team.RED) ? allReds.push(changedPlayer) : allBlues.push(changedPlayer);
  775. }
  776. }
  777. if (changedPlayer.team == Team.SPECTATORS) {
  778. setActivity(changedPlayer, 0);
  779. }
  780. if (inChooseMode && resettingTeams == false && byPlayer.id == 0) {
  781. if (Math.abs(teamR.length - teamB.length) == teamS.length) {
  782. deactivateChooseMode();
  783. resumeGame();
  784. var b = teamS.length;
  785. if (teamR.length > teamB.length) {
  786. for (var i = 0 ; i < b ; i++) {
  787. setTimeout(() => { room.setPlayerTeam(teamS[0].id, Team.BLUE); }, 200*i);
  788. }
  789. }
  790. else {
  791. for (var i = 0 ; i < b ; i++) {
  792. setTimeout(() => { room.setPlayerTeam(teamS[0].id, Team.RED); }, 200*i);
  793. }
  794. }
  795. return;
  796. }
  797. else if ((teamR.length == maxTeamSize && teamB.length == maxTeamSize) || (teamR.length == teamB.length && teamS.length < 2)) {
  798. deactivateChooseMode();
  799. resumeGame();
  800. }
  801. else if (teamR.length <= teamB.length && redCaptainChoice != "") { // choice remembered
  802. redCaptainChoice == "top" ? room.setPlayerTeam(teamS[0].id, Team.RED) : redCaptainChoice == "random" ? room.setPlayerTeam(teamS[getRandomInt(teamS.length)].id, Team.RED) : room.setPlayerTeam(teamS[teamS.length - 1].id, Team.RED);
  803. return;
  804. }
  805. else if (teamB.length < teamR.length && blueCaptainChoice != "") {
  806. blueCaptainChoice == "top" ? room.setPlayerTeam(teamS[0].id, Team.BLUE) : blueCaptainChoice == "random" ? room.setPlayerTeam(teamS[getRandomInt(teamS.length)].id, Team.BLUE) : room.setPlayerTeam(teamS[teamS.length - 1].id, Team.BLUE);
  807. return;
  808. }
  809. else {
  810. choosePlayer();
  811. }
  812. }
  813. }
  814.  
  815. room.onPlayerLeave = function(player) {
  816. if (teamR.findIndex((red) => red.id == player.id) == 0 && inChooseMode && teamR.length <= teamB.length) {
  817. choosePlayer();
  818. capLeft = true; setTimeout(() => { capLeft = false; }, 10);
  819. }
  820. if (teamB.findIndex((blue) => blue.id == player.id) == 0 && inChooseMode && teamB.length < teamR.length) {
  821. choosePlayer();
  822. capLeft = true; setTimeout(() => { capLeft = false; }, 10);
  823. }
  824. setActivity(player, 0);
  825. updateRoleOnPlayerOut();
  826.  
  827. setTimeout(() => delete playersInfo[player.name], 1000);
  828.  
  829. connections = connections.filter(a => a[0] !== player.id);
  830.  
  831. delete messages[player.name]
  832.  
  833. }
  834.  
  835. room.onPlayerKicked = function(kickedPlayer, reason, ban, byPlayer) {
  836. ban == true ? banList.push([kickedPlayer.name, kickedPlayer.id]) : null;
  837. }
  838.  
  839. /* PLAYER ACTIVITY */
  840.  
  841. room.onPlayerChat = function (player, message) {
  842. message = message.split(/ +/);
  843. player.team != Team.SPECTATORS ? setActivity(player, 0) : null;
  844. if (["!pomoc"].includes(message[0].toLowerCase())) {
  845. room.sendAnnouncement("❌ Komendy dla gracza : !me, !games, !wins, !goals, !assists, !cs, !afks, !mutes, !bans.", player.id, "0xFFFF00", "bold", false);
  846. player.admin ? room.sendChat("🖤 Komendy dla Admina : !mute <czas = 3> #<id>, !unmute all/#<id>, !clearbans <numer = all>, !slow <czas>, !endslow", player.id, "0xFF0000", "bold", false) : null;
  847. }
  848. else if (["!afk"].includes(message[0].toLowerCase())) {
  849. if (players.length != 1 && player.team != Team.SPECTATORS) {
  850. if (player.team == Team.RED && streak > 0 && room.getScores() == null) {
  851. room.setPlayerTeam(player.id, Team.SPECTATORS);
  852. }
  853. else {
  854. room.sendAnnouncement("Nie możesz afczyć podczas gry !", player.id, "0xFFA500", "bold", false);
  855. return false;
  856. }
  857. }
  858. else if (players.length == 1 && !getAFK(player)) {
  859. room.setPlayerTeam(player.id, Team.SPECTATORS);
  860. }
  861. setAFK(player, !getAFK(player));
  862. room.sendAnnouncement(player.name + (getAFK(player) ? " Zaraz wraca !" : " Jest z powrotem !"));
  863. getAFK(player) ? updateRoleOnPlayerOut() : updateRoleOnPlayerIn();
  864. }
  865. else if (["!afks", "!afklist"].includes(message[0].toLowerCase())) {
  866. var cstm = "Lista graczy, którzy afczą : ";
  867. for (var i = 0; i < extendedP.length; i++) {
  868. if (room.getPlayer(extendedP[i][eP.ID]) != null && getAFK(room.getPlayer(extendedP[i][eP.ID]))) {
  869. if (140 - cstm.length < (room.getPlayer(extendedP[i][eP.ID]).name + ", ").length) {
  870. room.sendChat(cstm, player.id);
  871. cstm = "... ";
  872. }
  873. cstm += room.getPlayer(extendedP[i][eP.ID]).name + ", ";
  874. }
  875. }
  876. if (cstm == " AFK List : ") {
  877. room.sendAnnouncement("Nie ma nikogo na liście AFK. !", player.id, "8A2BE2", "bold", false);
  878. return false;
  879. }
  880. cstm = cstm.substring(0, cstm.length - 2);
  881. cstm += ".";
  882. room.sendAnnouncement(cstm, player.id);
  883. }
  884. else if (["!me"].includes(message[0].toLowerCase())) {
  885. var stats;
  886. localStorage.getItem(getAuth(player)) ? stats = JSON.parse(localStorage.getItem(getAuth(player))) : stats = [0, 0, 0, 0, "0.00", 0, 0, 0, 0, "0.00"];
  887. room.sendAnnouncement(" " + player.name + "> Rozegrane gry: " + stats[Ss.GA] + ", Wygrane: " + stats[Ss.WI] + ", Remisy: " + stats[Ss.DR] + ", Przegrane: " + stats[Ss.LS] + ", WinRate: " + stats[Ss.WR] + "%, Gole: " + stats[Ss.GL] + ", Asysty: " + stats[Ss.AS] + ", GK: " + stats[Ss.GK] + ", CS: " + stats[Ss.CS] + ", CS%: " + stats[Ss.CP] + "%", player.id, "0x808080", "bold", false);
  888. }
  889. else if (["!games"].includes(message[0].toLowerCase())) {
  890. var tableau = [];
  891. Object.keys(localStorage).forEach(function (key) { if (!["player_name", "view_mode", "geo", "avatar", "player_auth_key"].includes(key)) { tableau.push([(JSON.parse(localStorage.getItem(key))[Ss.NK]), (JSON.parse(localStorage.getItem(key))[Ss.GA])]); } });
  892. if (tableau.length < 5) {
  893. room.sendAnnouncement("⚫ Za mało rozegrałeś gier.", player.id, "0x00FF00", "bold", false);
  894. return false;
  895. }
  896. tableau.sort(function (a, b) { return b[1] - a[1]; });
  897. room.sendAnnouncement("Gry> #1 " + tableau[0][0] + ": " + tableau[0][1] + " #2 " + tableau[1][0] + ": " + tableau[1][1] + " #3 " + tableau[2][0] + ": " + tableau[2][1] + " #4 " + tableau[3][0] + ": " + tableau[3][1] + " #5 " + tableau[4][0] + ": " + tableau[4][1], player.id, "0x808080", "bold", false);
  898. }
  899. else if (["!wins"].includes(message[0].toLowerCase())) {
  900. var tableau = [];
  901. Object.keys(localStorage).forEach(function (key) { if (!["player_name", "view_mode", "geo", "avatar", "player_auth_key"].includes(key)) { tableau.push([(JSON.parse(localStorage.getItem(key))[Ss.NK]), (JSON.parse(localStorage.getItem(key))[Ss.WI])]); } });
  902. if (tableau.length < 5) {
  903. room.sendChat("⚫ Za mało rozegrałeś gier.", player.id, "0x00FF00", "bold", false);
  904. return false;
  905. }
  906. tableau.sort(function (a, b) { return b[1] - a[1]; });
  907. room.sendAnnouncement("Wygrane> #1 " + tableau[0][0] + ": " + tableau[0][1] + " #2 " + tableau[1][0] + ": " + tableau[1][1] + " #3 " + tableau[2][0] + ": " + tableau[2][1] + " #4 " + tableau[3][0] + ": " + tableau[3][1] + " #5 " + tableau[4][0] + ": " + tableau[4][1], player.id, "0x808080", "bold", false);
  908. }
  909. else if (["!goals"].includes(message[0].toLowerCase())) {
  910. var tableau = [];
  911. Object.keys(localStorage).forEach(function (key) { if (!["player_name", "view_mode", "geo", "avatar", "player_auth_key"].includes(key)) { tableau.push([(JSON.parse(localStorage.getItem(key))[Ss.NK]), (JSON.parse(localStorage.getItem(key))[Ss.GL])]); } });
  912. if (tableau.length < 5) {
  913. room.sendChat("⚫ Za mało rozegrałeś gier.", player.id, "0x00FF00", "bold", false);
  914. return false;
  915. }
  916. tableau.sort(function (a, b) { return b[1] - a[1]; });
  917. room.sendAnnouncement(" Gole> #1 " + tableau[0][0] + ": " + tableau[0][1] + " #2 " + tableau[1][0] + ": " + tableau[1][1] + " #3 " + tableau[2][0] + ": " + tableau[2][1] + " #4 " + tableau[3][0] + ": " + tableau[3][1] + " #5 " + tableau[4][0] + ": " + tableau[4][1], player.id, "0x808080", "bold", false);
  918. }
  919. else if (["!assists"].includes(message[0].toLowerCase())) {
  920. var tableau = [];
  921. Object.keys(localStorage).forEach(function (key) { if (!["player_name", "view_mode", "geo", "avatar", "player_auth_key"].includes(key)) { tableau.push([(JSON.parse(localStorage.getItem(key))[Ss.NK]), (JSON.parse(localStorage.getItem(key))[Ss.AS])]); } });
  922. if (tableau.length < 5) {
  923. room.sendChat("⚫ Za mało rozegrałeś gier.", player.id, "0x00FF00", "bold", false);
  924. return false;
  925. }
  926. tableau.sort(function (a, b) { return b[1] - a[1]; });
  927. room.sendAnnouncement("Asysty> #1 " + tableau[0][0] + ": " + tableau[0][1] + " #2 " + tableau[1][0] + ": " + tableau[1][1] + " #3 " + tableau[2][0] + ": " + tableau[2][1] + " #4 " + tableau[3][0] + ": " + tableau[3][1] + " #5 " + tableau[4][0] + ": " + tableau[4][1], player.id, "0x808080", "bold", false);
  928. }
  929. else if (["!cs"].includes(message[0].toLowerCase())) {
  930. var tableau = [];
  931. Object.keys(localStorage).forEach(function (key) { if (!["player_name", "view_mode", "geo", "avatar", "player_auth_key"].includes(key)) { tableau.push([(JSON.parse(localStorage.getItem(key))[Ss.NK]), (JSON.parse(localStorage.getItem(key))[Ss.CS])]); } });
  932. if (tableau.length < 5) {
  933. room.sendChat("⚫ Za mało rozegrałeś gier.", player.id, "0x00FF00", "bold", false);
  934. return false;
  935. }
  936. tableau.sort(function (a, b) { return b[1] - a[1]; });
  937. room.sendAnnouncement(" CS> #1 " + tableau[0][0] + ": " + tableau[0][1] + " #2 " + tableau[1][0] + ": " + tableau[1][1] + " #3 " + tableau[2][0] + ": " + tableau[2][1] + " #4 " + tableau[3][0] + ": " + tableau[3][1] + " #5 " + tableau[4][0] + ": " + tableau[4][1], player.id, "0x808080", "bold", false);
  938. }
  939. else if (["!claim"].includes(message[0].toLowerCase())) {
  940. if (message[1] == adminPassword) {
  941. room.setPlayerAdmin(player.id, true);
  942. var stats;
  943. localStorage.getItem(getAuth(player)) ? stats = JSON.parse(localStorage.getItem(getAuth(player))) : stats = [0, 0, 0, 0, "0.00", 0, 0, 0, 0, "0.00", "player", player.name];
  944. if (stats[Ss.RL] != "master") {
  945. stats[Ss.RL] = "master";
  946. room.sendAnnouncement(player.name + " Został w tym momencie Administratorem 😊 !");
  947. localStorage.setItem(getAuth(player), JSON.stringify(stats));
  948. }
  949. }
  950. }
  951. else if (["!setadmin", "!admin"].includes(message[0].toLowerCase())) {
  952. if (localStorage.getItem(getAuth(player)) && JSON.parse(localStorage.getItem(getAuth(player)))[Ss.RL] == "master") {
  953. if (message.length >= 2 && message[1][0] == "#") {
  954. message[1] = message[1].substring(1, message[1].length);
  955. if (!Number.isNaN(Number.parseInt(message[1])) && room.getPlayer(Number.parseInt(message[1])) != null) {
  956. var stats;
  957. localStorage.getItem(getAuth(room.getPlayer(Number.parseInt(message[1])))) ? stats = JSON.parse(localStorage.getItem(getAuth(room.getPlayer(Number.parseInt(message[1]))))) : stats = [0, 0, 0, 0, "0.00", 0, 0, 0, 0, "0.00", "player", room.getPlayer(Number.parseInt(message[1])).name];
  958. if (stats[Ss.RL] == "player") {
  959. stats[Ss.RL] = "admin";
  960. localStorage.setItem(getAuth(room.getPlayer(Number.parseInt(message[1]))), JSON.stringify(stats));
  961. room.setPlayerAdmin(room.getPlayer(Number.parseInt(message[1])).id, true);
  962. room.sendAnnouncement(room.getPlayer(Number.parseInt(message[1])).name + " Jest teraz administratorem pokoju !");
  963. }
  964. }
  965. }
  966. }
  967. }
  968. else if (["!setplayer", "!removeadmin"].includes(message[0].toLowerCase())) {
  969. if (localStorage.getItem(getAuth(player)) && JSON.parse(localStorage.getItem(getAuth(player)))[Ss.RL] == "master") {
  970. if (message.length >= 2 && message[1][0] == "#") {
  971. message[1] = message[1].substring(1, message[1].length);
  972. if (!Number.isNaN(Number.parseInt(message[1])) && room.getPlayer(Number.parseInt(message[1])) != null) {
  973. var stats;
  974. localStorage.getItem(getAuth(room.getPlayer(Number.parseInt(message[1])))) ? stats = JSON.parse(localStorage.getItem(getAuth(room.getPlayer(Number.parseInt(message[1]))))) : stats = [0, 0, 0, 0, "0.00", 0, 0, 0, 0, "0.00", "player", room.getPlayer(Number.parseInt(message[1])).name];
  975. if (stats[Ss.RL] == "admin") {
  976. room.sendAnnouncement(room.getPlayer(Number.parseInt(message[1])).name + " Nie jest już administratorem pokoju !");
  977. stats[Ss.RL] = "player";
  978. localStorage.setItem(getAuth(room.getPlayer(Number.parseInt(message[1]))), JSON.stringify(stats));
  979. room.setPlayerAdmin(room.getPlayer(Number.parseInt(message[1])).id, false);
  980. }
  981. }
  982. }
  983. }
  984. }
  985. else if (["!mutes", "!mutelist"].includes(message[0].toLowerCase())) {
  986. var cstm = " 🔇 Lista osób mute: ";
  987. for (var i = 0; i < extendedP.length; i++) {
  988. if (room.getPlayer(extendedP[i][eP.ID]) != null && getMute(room.getPlayer(extendedP[i][eP.ID]))) {
  989. if (140 - cstm.length < (room.getPlayer(extendedP[i][eP.ID]).name + "[" + (extendedP[i][eP.ID]) + "], ").length) {
  990. room.sendChat(cstm, player.id);
  991. cstm = "... ";
  992. }
  993. cstm += room.getPlayer(extendedP[i][eP.ID]).name + "[" + (extendedP[i][eP.ID]) + "], ";
  994. }
  995. }
  996. if (cstm == " Mute List : ") {
  997. room.sendAnnouncement("🔇 Nie ma nikogo na liście mute.", player.id, "0xFFA500", "bold", false);
  998. return false;
  999. }
  1000. cstm = cstm.substring(0, cstm.length - 2);
  1001. cstm += ".";
  1002. room.sendChat(cstm, player.id);
  1003. }
  1004. else if (["!mute"].includes(message[0].toLowerCase())) {
  1005. if (player.admin) {
  1006. updateTeams();
  1007. var timeOut;
  1008. if (!Number.isNaN(Number.parseInt(message[1])) && message.length > 1) {
  1009. if (Number.parseInt(message[1]) > 0) {
  1010. timeOut = Number.parseInt(message[1]) * 60 * 1000;
  1011. }
  1012. else {
  1013. timeOut = 3 * 60 * 1000;
  1014. }
  1015. if (message[2].length > 1 && message[2][0] == "#") {
  1016. message[2] = message[2].substring(1, message[2].length);
  1017. if (!Number.isNaN(Number.parseInt(message[2])) && room.getPlayer(Number.parseInt(message[2])) != null) {
  1018. if (room.getPlayer(Number.parseInt(message[2])).admin || getMute(room.getPlayer(Number.parseInt(message[2])))) {
  1019. return false;
  1020. }
  1021. setTimeout(function (player) { setMute(player, false); }, timeOut, room.getPlayer(Number.parseInt(message[2])));
  1022. setMute(room.getPlayer(Number.parseInt(message[2])), true);
  1023. room.sendChat(room.getPlayer(Number.parseInt(message[2])).name + " has been muted for " + (timeOut / 60000) + " minutes!");
  1024. }
  1025. }
  1026. }
  1027. else if (Number.isNaN(Number.parseInt(message[1]))) {
  1028. if (message[1].length > 1 && message[1][0] == "#") {
  1029. message[1] = message[1].substring(1, message[1].length);
  1030. if (!Number.isNaN(Number.parseInt(message[1])) && room.getPlayer(Number.parseInt(message[1])) != null) {
  1031. if (room.getPlayer(Number.parseInt(message[1])).admin || getMute(room.getPlayer(Number.parseInt(message[1])))) {
  1032. return false;
  1033. }
  1034. setTimeout(function (player) { setMute(player, false); }, 3 * 60 * 1000, room.getPlayer(Number.parseInt(message[1])));
  1035. setMute(room.getPlayer(Number.parseInt(message[1])), true);
  1036. room.sendChat(room.getPlayer(Number.parseInt(message[1])).name + " has been muted for 3 minutes!");
  1037. }
  1038. }
  1039. }
  1040. }
  1041. }
  1042. else if (["!unmute"].includes(message[0].toLowerCase())) {
  1043. if (player.admin && message.length >= 2) {
  1044. if (message[1] == "all") {
  1045. extendedP.forEach((ePlayer) => { ePlayer[eP.MUTE] = false; });
  1046. room.sendChat("Mutes cleared.");
  1047. }
  1048. else if (!Number.isNaN(Number.parseInt(message[1])) && room.getPlayer(Number.parseInt(message[1])) != null && getMute(room.getPlayer(Number.parseInt(message[1])))) {
  1049. setMute(room.getPlayer(Number.parseInt(message[1])), false);
  1050. room.sendChat(room.getPlayer(Number.parseInt(message[1])).name + " has been unmuted !");
  1051. }
  1052. else if (Number.isNaN(Number.parseInt(message[1]))) {
  1053. if (message[1].length > 1 && message[1][0] == "#") {
  1054. message[1] = message[1].substring(1, message[1].length);
  1055. if (!Number.isNaN(Number.parseInt(message[1])) && room.getPlayer(Number.parseInt(message[1])) != null && getMute(room.getPlayer(Number.parseInt(message[1])))) {
  1056. setMute(room.getPlayer(Number.parseInt(message[1])), false);
  1057. room.sendChat(room.getPlayer(Number.parseInt(message[1])).name + " has been unmuted !");
  1058. }
  1059. }
  1060. }
  1061. }
  1062. }
  1063. else if (["!slow"].includes(message[0].toLowerCase())) {
  1064. if (player.admin) {
  1065. if (message.length == 1) {
  1066. slowMode = 2;
  1067. room.sendAnnouncement("2 sekundy włączony tryb powolny !");
  1068. }
  1069. else if (message.length == 2) {
  1070. if (!Number.isNaN(Number.parseInt(message[1]))) {
  1071. if (Number.parseInt(message[1]) > 0) {
  1072. slowMode = Number.parseInt(message[1]);
  1073. room.sendChat(slowMode + " seconds slow mode enabled !");
  1074. return false;
  1075. }
  1076. }
  1077. slowMode = 2;
  1078. room.sendChat("2 sekundy włączony tryb powolny !");
  1079. }
  1080. }
  1081. }
  1082. else if (["!endslow"].includes(message[0].toLowerCase())) {
  1083. if (player.admin) {
  1084. slowMode != 0 ? room.sendAnnouncement("Tryb powolny zakończony.") : null;
  1085. slowMode = 0;
  1086. }
  1087. }
  1088. else if (["!banlist", "!bans"].includes(message[0].toLowerCase())) {
  1089. if (banList.length == 0) {
  1090. room.sendAnnouncement("Nie ma nikogo na liście banów !", player.id, "0x00FF00", "bold", false);
  1091. return false;
  1092. }
  1093. var cstm = " Ban List : ";
  1094. for (var i = 0; i < banList.length; i++) {
  1095. if (140 - cstm.length < (banList[i][0] + "[" + (banList[i][1]) + "], ").length) {
  1096. room.sendChat(cstm, player.id);
  1097. cstm = "... ";
  1098. }
  1099. cstm += banList[i][0] + "[" + (banList[i][1]) + "], ";
  1100. }
  1101. cstm = cstm.substring(0, cstm.length - 2);
  1102. cstm += ".";
  1103. room.sendChat(cstm, player.id);
  1104. }
  1105. else if (["!clearbans"].includes(message[0].toLowerCase())) {
  1106. if (player.admin) {
  1107. if (message.length == 1) {
  1108. room.clearBans();
  1109. room.sendChat("✅ Bany zostały pomyślnie wyczyszczone. !");
  1110. banList = [];
  1111. }
  1112. if (message.length == 2) {
  1113. if (!Number.isNaN(Number.parseInt(message[1]))) {
  1114. if (Number.parseInt(message[1]) > 0) {
  1115. ID = Number.parseInt(message[1]);
  1116. room.clearBan(ID);
  1117. if (banList.length != banList.filter((array) => array[1] != ID)) {
  1118. room.sendChat(banList.filter((array) => array[1] == ID)[0][0] + " has been unbanned from the room !");
  1119. }
  1120. setTimeout(() => { banList = banList.filter((array) => array[1] != ID); }, 20);
  1121. }
  1122. }
  1123. }
  1124. }
  1125. }
  1126. else if (["!bb", "!bye", "!cya", "!gn"].includes(message[0].toLowerCase())) {
  1127. room.kickPlayer(player.id, "Na własne życzenie :3 !", false);
  1128. }
  1129. if (teamR.length != 0 && teamB.length != 0 && inChooseMode) {
  1130. if (player.id == teamR[0].id || player.id == teamB[0].id) { // we care if it's one of the captains choosing
  1131. if (teamR.length <= teamB.length && player.id == teamR[0].id) { // we care if it's red turn && red cap talking
  1132. if (["top", "auto"].includes(message[0].toLowerCase())) {
  1133. room.setPlayerTeam(teamS[0].id, Team.RED);
  1134. redCaptainChoice = "top";
  1135. clearTimeout(timeOutCap);
  1136. room.sendAnnouncement(player.name + " Wpisz Top, aby wybrać osobe z góry !", player.id, "0xFF00FF", "bold", false);
  1137. return false;
  1138. }
  1139. else if (["random", "rand"].includes(message[0].toLowerCase())) {
  1140. var r = getRandomInt(teamS.length);
  1141. room.setPlayerTeam(teamS[r].id, Team.RED);
  1142. redCaptainChoice = "random";
  1143. clearTimeout(timeOutCap);
  1144. room.sendAnnouncement(player.name + " Wpisz Random, aby wybrać losową osobe !", player.id, "0xFF00FF", "bold", false);
  1145. return false;
  1146. }
  1147. else if (["bottom", "bot"].includes(message[0].toLowerCase())) {
  1148. room.setPlayerTeam(teamS[teamS.length - 1].id, Team.RED);
  1149. redCaptainChoice = "bottom";
  1150. clearTimeout(timeOutCap);
  1151. room.sendAnnouncement(player.name + " Wpisz Bottom, aby wybrać osobę z dołu !", player.id, "0xFF00FF", "bold", false);
  1152. return false;
  1153. }
  1154. else if (!Number.isNaN(Number.parseInt(message[0]))) {
  1155. if (Number.parseInt(message[0]) > teamS.length || Number.parseInt(message[0]) < 1) {
  1156. room.sendChat(" Ten numer jest nieprawidłowy !", player.id);
  1157. return false;
  1158. }
  1159. else {
  1160. room.setPlayerTeam(teamS[Number.parseInt(message[0]) - 1].id, Team.RED);
  1161. room.sendAnnouncement(player.name + " Wybrał " + teamS[Number.parseInt(message[0]) - 1].name + " !");
  1162. return false;
  1163. }
  1164. }
  1165. }
  1166. if (teamR.length > teamB.length && player.id == teamB[0].id) { // we care if it's red turn && red cap talking
  1167. if (["top", "auto"].includes(message[0].toLowerCase())) {
  1168. room.setPlayerTeam(teamS[0].id, Team.BLUE);
  1169. blueCaptainChoice = "top";
  1170. clearTimeout(timeOutCap);
  1171. room.sendAnnouncement(player.name + " Wpisz Top, aby wybrać osobe z góry !", player.id, "0xFF00FF", "bold", false);
  1172. return false;
  1173. }
  1174. else if (["random", "rand"].includes(message[0].toLowerCase())) {
  1175. room.setPlayerTeam(teamS[getRandomInt(teamS.length)].id, Team.BLUE);
  1176. blueCaptainChoice = "random";
  1177. clearTimeout(timeOutCap);
  1178. room.sendAnnouncement(player.name + " Wpisz Random, aby wybrać losową osobe !", player.id, "0xFF00FF", "bold", false);
  1179. return false;
  1180. }
  1181. else if (["bottom", "bot"].includes(message[0].toLowerCase())) {
  1182. room.setPlayerTeam(teamS[teamS.length - 1].id, Team.BLUE);
  1183. blueCaptainChoice = "bottom";
  1184. clearTimeout(timeOutCap);
  1185. room.sendAnnouncement(player.name + " Wpisz Bottom, aby wybrać osobę z dołu !", player.id, "0xFF00FF", "bold", false);
  1186. return false;
  1187. }
  1188. else if (!Number.isNaN(Number.parseInt(message[0]))) {
  1189. if (Number.parseInt(message[0]) > teamS.length || Number.parseInt(message[0]) < 1) {
  1190. room.sendChat(" Ten numer jest nieprawidłowy !", player.id, "0xFF0000", "bold", false);
  1191. return false;
  1192. }
  1193. else {
  1194. room.setPlayerTeam(teamS[Number.parseInt(message[0]) - 1].id, Team.BLUE);
  1195. room.sendAnnouncement(player.name + " Wybrał " + teamS[Number.parseInt(message[0]) - 1].name + " !");
  1196. return false;
  1197. }
  1198. }
  1199. }
  1200. }
  1201. }
  1202. if (message[0][0] == "!") {
  1203. room.sendChat('Nie ma takiej komendy', player.id)
  1204. return false;
  1205. }
  1206. if (getMute(player)) {
  1207. room.sendAnnouncement("Dostałeś mute'a.", player.id, "0xFF00FF", "bold", false);
  1208. return false;
  1209. }
  1210. if (slowMode > 0) {
  1211. if (!player.admin) {
  1212. if (!SMSet.has(player.id)) {
  1213. SMSet.add(player.id);
  1214. setTimeout((number) => { SMSet.delete(number); }, slowMode * 1000, player.id);
  1215. }
  1216. else {
  1217. return false;
  1218. }
  1219. }
  1220. }
  1221.  
  1222. localStorage.getItem(getAuth(player)) ? stats = JSON.parse(localStorage.getItem(getAuth(player))) : stats = [0, 0, 0, 0, "0.00", 0, 0, 0, 0, "0.00"];
  1223. var stats;
  1224.  
  1225. if(stats[Ss.RL] == "master"){
  1226. message = message.join(' ')
  1227. room.sendAnnouncement(' ' + player.name + ': ' + message, null, 0xff0000, "bold", 2);
  1228. return false;
  1229. }
  1230.  
  1231. localStorage.getItem(getAuth(player)) ? stats = JSON.parse(localStorage.getItem(getAuth(player))) : stats = [0, 0, 0, 0, "0.00", 0, 0, 0, 0, "0.00"];
  1232. var stats;
  1233.  
  1234. if(stats[Ss.RL] == "player"){
  1235. message = message.join(' ')
  1236. room.sendAnnouncement(' ' + player.name + ': ' + message, null, 0x808080, "bold", 2);
  1237. return false;
  1238. }
  1239.  
  1240. }
  1241.  
  1242. room.onPlayerActivity = function(player) {
  1243. setActivity(player, 0);
  1244. }
  1245.  
  1246. room.onPlayerBallKick = function(player) {
  1247. if (lastPlayersTouched[0] == null || player.id != lastPlayersTouched[0].id) {
  1248. !activePlay ? activePlay = true : null;
  1249. lastTeamTouched = player.team;
  1250. lastPlayersTouched[1] = lastPlayersTouched[0];
  1251. lastPlayersTouched[0] = player;
  1252. }
  1253. }
  1254.  
  1255. /* GAME MANAGEMENT */
  1256.  
  1257. room.onGameStart = function(byPlayer) {
  1258. game = new Game(Date.now(), room.getScores(), []);
  1259. countAFK = true;
  1260. activePlay = false;
  1261. goldenGoal = false;
  1262. endGameVariable = false;
  1263. lastPlayersTouched = [null, null];
  1264. Rposs = 0;
  1265. Bposs = 0;
  1266. GKList = [];
  1267. allReds = [];
  1268. allBlues = [];
  1269. if (teamR.length == maxTeamSize && teamB.length == maxTeamSize) {
  1270. for (var i = 0; i < maxTeamSize; i++) {
  1271. allReds.push(teamR[i]);
  1272. allBlues.push(teamB[i]);
  1273. }
  1274. }
  1275. for (var i = 0; i < extendedP.length; i++) {
  1276. extendedP[i][eP.GK] = 0;
  1277. extendedP[i][eP.ACT] = 0;
  1278. room.getPlayer(extendedP[i][eP.ID]) == null ? extendedP.splice(i, 1) : null;
  1279. }
  1280. deactivateChooseMode();
  1281. }
  1282.  
  1283. room.onGameStop = function(byPlayer) {
  1284. if (byPlayer.id == 0 && endGameVariable) {
  1285. updateTeams();
  1286. if (inChooseMode) {
  1287. if (players.length == 2 * maxTeamSize) {
  1288. inChooseMode = false;
  1289. resetBtn();
  1290. for (var i = 0; i < maxTeamSize; i++) {
  1291. setTimeout(() => { randomBtn(); }, 400*i);
  1292. }
  1293. setTimeout(() => { room.startGame(); }, 2000);
  1294. }
  1295. else {
  1296. if (lastWinner == Team.RED) {
  1297. blueToSpecBtn();
  1298. }
  1299. else if (lastWinner == Team.BLUE) {
  1300. redToSpecBtn();
  1301. blueToRedBtn();
  1302. }
  1303. else {
  1304. resetBtn();
  1305. }
  1306. setTimeout(() => { topBtn(); }, 500);
  1307. }
  1308. }
  1309. else {
  1310. if (players.length == 2) {
  1311. if (lastWinner == Team.BLUE) {
  1312. room.setPlayerTeam(teamB[0].id, Team.RED);
  1313. room.setPlayerTeam(teamR[0].id, Team.BLUE);
  1314. }
  1315. setTimeout(() => { room.startGame(); }, 2000);
  1316. }
  1317. else if (players.length == 3 || players.length >= 2 * maxTeamSize + 1) {
  1318. if (lastWinner == Team.RED) {
  1319. blueToSpecBtn();
  1320. }
  1321. else {
  1322. redToSpecBtn();
  1323. blueToRedBtn();
  1324. }
  1325. setTimeout(() => { topBtn(); }, 200);
  1326. setTimeout(() => { room.startGame(); }, 2000);
  1327. }
  1328. else if (players.length == 4) {
  1329. resetBtn();
  1330. setTimeout(() => { randomBtn(); setTimeout(() => { randomBtn(); }, 500); }, 500);
  1331. setTimeout(() => { room.startGame(); }, 2000);
  1332. }
  1333. else if (players.length == 5 || players.length >= 2 * maxTeamSize + 1) {
  1334. if (lastWinner == Team.RED) {
  1335. blueToSpecBtn();
  1336. }
  1337. else {
  1338. redToSpecBtn();
  1339. blueToRedBtn();
  1340. }
  1341. setTimeout(() => { topBtn(); }, 200);
  1342. activateChooseMode();
  1343. }
  1344. else if (players.length == 6) {
  1345. resetBtn();
  1346. setTimeout(() => { randomBtn(); setTimeout(() => { randomBtn(); setTimeout(() => { randomBtn(); }, 500); }, 500); }, 500);
  1347. setTimeout(() => { room.startGame(); }, 2000);
  1348. }
  1349. }
  1350. }
  1351. }
  1352.  
  1353. room.onGamePause = function(byPlayer) {
  1354. }
  1355.  
  1356. room.onGameUnpause = function (byPlayer) {
  1357. if (teamR.length == 4 && teamB.length == 4 && inChooseMode || (teamR.length == teamB.length && teamS.length < 2 && inChooseMode)) {
  1358. deactivateChooseMode();
  1359. }
  1360. }
  1361.  
  1362. room.onTeamGoal = function(team) {
  1363. activePlay = false;
  1364. countAFK = false;
  1365. const scores = room.getScores();
  1366. game.scores = scores;
  1367. if (lastPlayersTouched[0] != null && lastPlayersTouched[0].team == team) {
  1368. if (lastPlayersTouched[1] != null && lastPlayersTouched[1].team == team) {
  1369. room.sendAnnouncement("⚽ " + getTime(scores) + " Bramkę zdobył " + lastPlayersTouched[0].name + " ! Asystuje : " + lastPlayersTouched[1].name + ". Prędkość strzału podczas bramki : " + ballSpeed.toPrecision(4).toString() + "km/h " + (team == Team.RED ? "🔴" : "🔵"));
  1370. game.goals.push(new Goal(scores.time, team, lastPlayersTouched[0], lastPlayersTouched[1]));
  1371. }
  1372. else {
  1373. room.sendAnnouncement("⚽ " + getTime(scores) + " Bramkę zdobył " + lastPlayersTouched[0].name + " ! Prędkość strzału podczas bramki : " + ballSpeed.toPrecision(4).toString() + "km/h " + (team == Team.RED ? "🔴" : "🔵"));
  1374. game.goals.push(new Goal(scores.time, team, lastPlayersTouched[0], null));
  1375. }
  1376. }
  1377. else {
  1378. room.sendAnnouncement("😂 " + getTime(scores) + " Gol samobójczy trafiony przez " + lastPlayersTouched[0].name + " ! Prędkość strzału podczas bramki : " + ballSpeed.toPrecision(4).toString() + "km/h " + (team == Team.RED ? "🔴" : "🔵"));
  1379. game.goals.push(new Goal(scores.time, team, null, null));
  1380. }
  1381. if (scores.scoreLimit != 0 && (scores.red == scores.scoreLimit || scores.blue == scores.scoreLimit && scores.blue > 0 || goldenGoal == true)) {
  1382. endGame(team);
  1383. goldenGoal = false;
  1384. setTimeout(() => { room.stopGame(); }, 1000);
  1385. }
  1386. }
  1387.  
  1388. room.onPositionsReset = function() {
  1389. countAFK = true;
  1390. lastPlayersTouched = [null, null];
  1391. }
  1392.  
  1393. /* MISCELLANEOUS */
  1394.  
  1395. room.onRoomLink = function(url) {
  1396. }
  1397.  
  1398. room.onPlayerAdminChange = function (changedPlayer, byPlayer) {
  1399. if (getMute(changedPlayer) && changedPlayer.admin) {
  1400. room.sendChat(changedPlayer.name + " has been unmuted.");
  1401. setMute(changedPlayer, false);
  1402. }
  1403. if (byPlayer.id != 0 && localStorage.getItem(getAuth(byPlayer)) && JSON.parse(localStorage.getItem(getAuth(byPlayer)))[Ss.RL] == "admin") {
  1404. room.sendChat("You don't have permission to name a player admin !", byPlayer.id);
  1405. room.setPlayerAdmin(changedPlayer.id, false);
  1406. }
  1407. }
  1408.  
  1409. room.onStadiumChange = function(newStadiumName, byPlayer) {
  1410. }
  1411.  
  1412. room.onGameTick = function() {
  1413. checkTime();
  1414. getLastTouchOfTheBall();
  1415. getStats();
  1416. handleInactivity();
  1417. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement