Advertisement
Guest User

Untitled

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