A Probar
A Probar
/* VARIABLES */
/* ROOM */
const scoreLimitClassic = 1;
const scoreLimitBig = 1;
const timeLimitClassic = 1;
const timeLimitBig = 1;
room.setTeamsLock(true);
/* COLORES */
/* TIPO DE LETRAS */
/* ENLACE DISCORD */
var grabaciones-3v3 =
"https://discord.com/api/webhooks/1226650143483498506/MTGq9uEw9dfZXFflS15s-
h2QqgsJPQ-vScGkHT_4DcP4MR9zgntyJXf5qYyJfKSeOt5t";
var estadosalaslink =
"https://discord.com/api/webhooks/1224469731793436725/4Xae1RWyP9LHD_rDpxTnXw_B2li5c
2XQNIrnHpOawbGs6LAEhcRO6wGk2yXKVH2cfibq";
/* STADIUM */
/* OPTIONS */
/* PLAYERS */
/* GAME */
var lastTeamTouched;
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)
var countAFK = false; // Created to get better track of activity
var activePlay = false; // Created to get better track of the possession
var goldenGoal = false;
var SMSet = new Set(); // Set created to get slow mode which is useful in
chooseMode
var banList = []; // Getting track of the bans, so we can unban ppl if we want
/* STATS */
var game;
var GKList = ["",""];
var Rposs = 0;
var Bposs = 0;
var point = [{"x": 0, "y": 0}, {"x": 0, "y": 0}]; // created to get ball speed
var ballSpeed;
var lastWinner = Team.SPECTATORS;
var streak = 0;
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 ...
var allReds = []; // ... those who came in a very unequal game.
/* AUXILIARY */
var checkTimeVariable = false; // This is created so the chat doesn't get spammed
when a game is ending via timeLimit
var statNumber = 0; // This allows the room to be given stat information every X
minutes
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
var resettingTeams = false;
var capLeft = false;
var statInterval = 6;
loadMap(aloneMap, 0, 0);
/* OBJECTS */
/* FUNCTIONS */
/* AUXILIARY FUNCTIONS */
/* BUTTONS */
function topBtn() {
if (teamS.length == 0) {
return;
}
else {
if (teamR.length == teamB.length) {
if (teamS.length > 1) {
room.setPlayerTeam(teamS[0].id, Team.RED);
room.setPlayerTeam(teamS[1].id, Team.BLUE);
}
return;
}
else if (teamR.length < teamB.length) {
room.setPlayerTeam(teamS[0].id, Team.RED);
}
else {
room.setPlayerTeam(teamS[0].id, Team.BLUE);
}
}
}
function randomBtn() {
if (teamS.length == 0) {
return;
}
else {
if (teamR.length == teamB.length) {
if (teamS.length > 1) {
var r = getRandomInt(teamS.length);
room.setPlayerTeam(teamS[r].id, Team.RED);
teamS = teamS.filter((spec) => spec.id != teamS[r].id);
room.setPlayerTeam(teamS[getRandomInt(teamS.length)].id,
Team.BLUE);
}
return;
}
else if (teamR.length < teamB.length) {
room.setPlayerTeam(teamS[getRandomInt(teamS.length)].id,
Team.RED);
}
else {
room.setPlayerTeam(teamS[getRandomInt(teamS.length)].id,
Team.BLUE);
}
}
}
function blueToSpecBtn() {
resettingTeams = true;
setTimeout(() => { resettingTeams = false; }, 100);
for (var i = 0; i < teamB.length; i++) {
room.setPlayerTeam(teamB[teamB.length - 1 - i].id, Team.SPECTATORS);
}
}
function redToSpecBtn() {
resettingTeams = true;
setTimeout(() => { resettingTeams = false; }, 100);
for (var i = 0; i < teamR.length; i++) {
room.setPlayerTeam(teamR[teamR.length - 1 - i].id, Team.SPECTATORS);
}
}
function resetBtn() {
resettingTeams = true;
setTimeout(() => { resettingTeams = false; }, 100);
if (teamR.length <= teamB.length) {
for (var i = 0; i < teamR.length; i++) {
room.setPlayerTeam(teamB[teamB.length - 1 - i].id,
Team.SPECTATORS);
room.setPlayerTeam(teamR[teamR.length - 1 - i].id,
Team.SPECTATORS);
}
for (var i = teamR.length; i < teamB.length; i++) {
room.setPlayerTeam(teamB[teamB.length - 1 - i].id,
Team.SPECTATORS);
}
}
else {
for (var i = 0; i < teamB.length; i++) {
room.setPlayerTeam(teamB[teamB.length - 1 - i].id,
Team.SPECTATORS);
room.setPlayerTeam(teamR[teamR.length - 1 - i].id,
Team.SPECTATORS);
}
for (var i = teamB.length; i < teamR.length; i++) {
room.setPlayerTeam(teamR[teamR.length - 1 - i].id,
Team.SPECTATORS);
}
}
}
function blueToRedBtn() {
resettingTeams = true;
setTimeout(() => { resettingTeams = false; }, 100);
for (var i = 0; i < teamB.length; i++) {
room.setPlayerTeam(teamB[i].id, Team.RED);
}
}
/* GAME FUNCTIONS */
function checkTime() {
const scores = room.getScores();
game.scores = scores;
if (Math.abs(scores.time - scores.timeLimit) <= 0.01 && scores.timeLimit !=
0) {
if (scores.red != scores.blue) {
if (checkTimeVariable == false) {
checkTimeVariable = true;
setTimeout(() => { checkTimeVariable = false; }, 3000);
scores.red > scores.blue ? endGame(Team.RED) :
endGame(Team.BLUE);
setTimeout(() => { room.stopGame(); }, 2000);
}
return;
}
goldenGoal = true;
room.sendAnnouncement(" ⌛ GOL DE ORO ⌛ ", null, 0xFF0000,'bold',);
}
if (Math.abs(drawTimeLimit * 60 - scores.time - 60) <= 0.01 && players.length
> 2) {
if (checkTimeVariable == false) {
checkTimeVariable = true;
setTimeout(() => { checkTimeVariable = false; }, 10);
room.sendChat(" ⌛ OK 🙂 ");
}
}
if (Math.abs(scores.time - drawTimeLimit * 60) <= 0.01 && players.length > 2)
{
if (checkTimeVariable == false) {
checkTimeVariable = true;
setTimeout(() => { checkTimeVariable = false; }, 10);
endGame(Team.SPECTATORS);
room.stopGame();
goldenGoal = false;
}
}
}
function endGame(winner) {
// Handles the end of a game - no stopGame function inside
players.length >= 2 * maxTeamSize - 1 ? activateChooseMode() : null;
lastWinner = winner;
endGameVariable = true;
if (winner == Team.RED) {
streak++;
room.sendAnnouncement("◤-----------------------------------------------------------
---------------◥", null, 0xff0000, 'bold');
room.sendAnnouncement("| FINAL DEL PARTIDO
", null, 0xff0000, 'bold');
room.sendAnnouncement("| 🟥 Red Team " + scores.red + "-" +
scores.blue + " Blue Team 🟦 ", null, 0xff0000, 'bold');
room.sendAnnouncement("|🏆 El Red Team lleva " + streak + " victorias
consecutivas", null, 0xff0000, 'normal');
room.sendAnnouncement("◣-----------------------------------------------------------
---------------◢", null, 0xff0000, 'bold');
} else if (winner == Team.BLUE) {
streak = 1;
room.sendAnnouncement("◤-----------------------------------------------------------
---------------◥", null, 0x2200ff, 'bold');
room.sendAnnouncement("| FINAL DEL PARTIDO
", null, 0x2200ff, 'bold');
room.sendAnnouncement("| 🟥 Red Team " + scores.red + "-" +
scores.blue + " Blue Team 🟦 ", null, 0x2200ff, 'bold');
room.sendAnnouncement("◣-----------------------------------------------------------
---------------◢", null, 0x2200ff, 'bold');
} else {
streak = 0;
room.sendChat("💤 ¡FINAL DEL JUEGO, HA SIDO UN EMPATE! 💤");
}
if (scores.red == 0) {
if (scores.blue == 0) {
} else {
}
} else if (scores.blue == 0) {
updateStats();
}
function quickRestart() {
room.stopGame();
setTimeout(() => { room.startGame(); }, 2000);
}
function resumeGame() {
setTimeout(() => { room.startGame(); }, 2000);
setTimeout(() => { room.pauseGame(false); }, 1000);
}
function activateChooseMode() {
inChooseMode = true;
slowMode = 2;
}
function deactivateChooseMode() {
inChooseMode = false;
clearTimeout(timeOutCap);
if (slowMode != 0) {
slowMode = 0;
}
redCaptainChoice = "";
blueCaptainChoice = "";
}
/* PLAYER FUNCTIONS */
function updateTeams() { // update the players' list and all the teams' list
players = room.getPlayerList().filter((player) => player.id != 0 && !
getAFK(player));
teamR = players.filter(p => p.team === Team.RED);
teamB = players.filter(p => p.team === Team.BLUE);
teamS = players.filter(p => p.team === Team.SPECTATORS);
}
function getAFK(player) {
return extendedP.filter((a) => a[0] == player.id) != null ?
extendedP.filter((a) => a[0] == player.id)[0][eP.AFK] : null;
}
function getActivity(player) {
return extendedP.filter((a) => a[0] == player.id) != null ?
extendedP.filter((a) => a[0] == player.id)[0][eP.ACT] : null;
}
function getGK(player) {
return extendedP.filter((a) => a[0] == player.id) != null ?
extendedP.filter((a) => a[0] == player.id)[0][eP.GK] : null;
}
function getMute(player) {
return extendedP.filter((a) => a[0] == player.id) != null ?
extendedP.filter((a) => a[0] == player.id)[0][eP.MUTE] : null;
}
function updateRoleOnPlayerIn() {
updateTeams();
if (inChooseMode) {
if (players.length == 6) {
loadMap(bigMap, scoreLimitBig, timeLimitBig);
}
getSpecList(teamR.length <= teamB.length ? teamR[0] : teamB[0]);
}
balanceTeams();
}
function updateRoleOnPlayerOut() {
updateTeams();
if (room.getScores() != null) {
var scores = room.getScores();
if (players.length >= 2 * maxTeamSize && scores.time >= (5/6) *
game.scores.timeLimit && teamR.length != teamB.length) {
if (teamR.length < teamB.length) {
if (scores.blue - scores.red == 2) {
endGame(Team.BLUE);
room.sendAnnouncement("🤖 Abandono detectado. Juego
terminado 🤖");
setTimeout(() => { room.stopGame(); }, 100);
return;
}
}
else {
if (scores.red - scores.blue == 2) {
endGame(Team.RED);
room.sendAnnouncement("🤖 Abandono detectado. Juego
terminado 🤖");
setTimeout(() => { room.stopGame(); }, 100);
return;
}
}
}
}
if (inChooseMode) {
if (players.length == 5) {
loadMap(classicMap, scoreLimitClassic, timeLimitClassic);
}
if (teamR.length == 0 || teamB.length == 0) {
teamR.length == 0 ? room.setPlayerTeam(teamS[0].id, Team.RED) :
room.setPlayerTeam(teamS[0].id, Team.BLUE);
return;
}
if (Math.abs(teamR.length - teamB.length) == teamS.length) {
room.sendAnnouncement(" Equilibrando equipos... ");
deactivateChooseMode();
resumeGame();
var b = teamS.length;
if (teamR.length > teamB.length) {
for (var i = 0 ; i < b ; i++) {
setTimeout(() => { room.setPlayerTeam(teamS[0].id,
Team.BLUE); }, 5*i);
}
}
else {
for (var i = 0 ; i < b ; i++) {
setTimeout(() => { room.setPlayerTeam(teamS[0].id,
Team.RED); }, 5*i);
}
}
return;
}
if (streak == 0 && room.getScores() == null) {
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
room.sendAnnouncement("🤖 Equilibrando equipos... 🤖");
teamR.length > teamB.length ?
room.setPlayerTeam(teamR[teamR.length - 1].id, Team.SPECTATORS) :
room.setPlayerTeam(teamB[teamB.length - 1].id, Team.SPECTATORS);
}
}
if (teamR.length == teamB.length && teamS.length < 2) {
deactivateChooseMode();
resumeGame();
return;
}
capLeft ? choosePlayer() : getSpecList(teamR.length <= teamB.length ?
teamR[0] : teamB[0]);
}
balanceTeams();
}
function balanceTeams() {
if (!inChooseMode) {
if (players.length == 1 && teamR.length == 0) {
quickRestart();
loadMap(aloneMap, 0, 0);
room.setPlayerTeam(players[0].id, Team.RED);
}
else if (Math.abs(teamR.length - teamB.length) == teamS.length &&
teamS.length > 0) {
const n = Math.abs(teamR.length - teamB.length);
if (players.length == 2) {
quickRestart();
loadMap(classicMap, scoreLimitClassic, timeLimitClassic);
}
if (teamR.length > teamB.length) {
for (var i = 0 ; i < n ; i++) {
room.setPlayerTeam(teamS[i].id, Team.BLUE);
}
}
else {
for (var i = 0 ; i < n ; i++) {
room.setPlayerTeam(teamS[i].id, Team.RED);
}
}
}
else if (Math.abs(teamR.length - teamB.length) > teamS.length) {
const n = Math.abs(teamR.length - teamB.length);
if (players.length == 1) {
quickRestart();
loadMap(aloneMap, 0, 0);
room.setPlayerTeam(players[0].id, Team.RED);
return;
}
else if (players.length == 5) {
quickRestart();
loadMap(classicMap, scoreLimitClassic, timeLimitClassic);
}
if (players.length == maxTeamSize * 2 - 1) {
allReds = [];
allBlues = [];
}
if (teamR.length > teamB.length) {
for (var i = 0 ; i < n ; i++) {
room.setPlayerTeam(teamR[teamR.length - 1 - i].id,
Team.SPECTATORS);
}
}
else {
for (var i = 0 ; i < n ; i++) {
room.setPlayerTeam(teamB[teamB.length - 1 - i].id,
Team.SPECTATORS);
}
}
}
else if (Math.abs(teamR.length - teamB.length) < teamS.length &&
teamR.length != teamB.length) {
room.pauseGame(true);
activateChooseMode();
choosePlayer();
}
else if (teamS.length >= 2 && teamR.length == teamB.length &&
teamR.length < maxTeamSize) {
if (teamR.length == 2) {
quickRestart();
loadMap(bigMap, scoreLimitBig, timeLimitBig);
}
topBtn();
}
}
}
function choosePlayer() {
clearTimeout(timeOutCap);
if (teamR.length <= teamB.length && teamR.length != 0) {
room.sendAnnouncement("[PV] Para elegir un jugador, ingrese su número
de la lista'.", teamR[0].id);
timeOutCap = setTimeout(function (player) { room.sendAnnouncement("[PV]
Date prisa @" + player.name + ", solo quedan " + Number.parseInt(chooseTime / 2) +
" segundos para elegir !", player.id); timeOutCap = setTimeout(function (player)
{ room.kickPlayer(player.id, " ¡No sabe elegir o quizás murió! ", false); },
chooseTime * 500, teamR[0]); }, chooseTime * 1000, teamR[0]);
}
else if (teamB.length < teamR.length && teamB.length != 0) {
room.sendAnnouncement("[PV] Para elegir un jugador, ingrese su número
de la lista'.", teamB[0].id);
timeOutCap = setTimeout(function (player) { room.sendAnnouncement("[PV]
Date prisa @" + player.name + ", solo quedan " + Number.parseInt(chooseTime / 2) +
" segundos para elegir !", player.id); timeOutCap = setTimeout(function (player)
{ room.kickPlayer(player.id, " ¡No sabe elegir o quizás murió! ", false); },
chooseTime * 500, teamB[0]); }, chooseTime * 1000, teamB[0]);
}
if (teamR.length != 0 && teamB.length != 0) getSpecList(teamR.length <=
teamB.length ? teamR[0] : teamB[0]);
}
function getSpecList(player) {
var cstm = "[PV] Jugadores : ";
for (var i = 0 ; i < teamS.length ; i++) {
if (140 - cstm.length < (teamS[i].name + "[" + (i+1) + "], ").length) {
room.sendAnnouncement(cstm, player.id);
cstm = "... ";
}
cstm += teamS[i].name + "[" + (i+1) + "], ";
}
cstm = cstm.substring(0,cstm.length - 2);
cstm += ".";
room.sendAnnouncement(cstm, player.id);
}
/* STATS FUNCTIONS */
function getLastTouchOfTheBall() {
const ballPosition = room.getBallPosition();
updateTeams();
for (var i = 0; i < players.length; i++) {
if (players[i].position != null) {
var distanceToBall = pointDistance(players[i].position,
ballPosition);
if (distanceToBall < triggerDistance) {
!activePlay ? activePlay = true : null;
if (lastTeamTouched == players[i].team &&
lastPlayersTouched[0] != null && lastPlayersTouched[0].id != players[i].id) {
lastPlayersTouched[1] = lastPlayersTouched[0];
lastPlayersTouched[0] = players[i];
}
lastTeamTouched = players[i].team;
}
}
}
}
function getStats() { // gives possession, ball speed and GK of each team
if (activePlay) {
updateTeams();
lastTeamTouched == Team.RED ? Rposs++ : Bposs++;
var ballPosition = room.getBallPosition();
point[1] = point[0];
point[0] = ballPosition;
ballSpeed = (pointDistance(point[0], point[1]) * 60 * 60 * 60)/15000;
var k = [-1, Infinity];
for (var i = 0; i < teamR.length; i++) {
if (teamR[i].position.x < k[1]) {
k[0] = teamR[i];
k[1] = teamR[i].position.x;
}
}
k[0] != -1 ? setGK(k[0], getGK(k[0]) + 1) : null;
k = [-1, -Infinity];
for (var i = 0; i < teamB.length; i++) {
if (teamB[i].position.x > k[1]) {
k[0] = teamB[i];
k[1] = teamB[i].position.x;
}
}
k[0] != -1 ? setGK(k[0], getGK(k[0]) + 1) : null;
findGK();
}
}
function updateStats() {
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) {
var stats;
for (var i = 0; i < allReds.length; i++) {
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];
stats[Ss.GA]++;
lastWinner == Team.RED ? stats[Ss.WI]++ : lastWinner == Team.BLUE
? stats[Ss.LS]++ : stats[Ss.DR]++;
stats[Ss.WR] = (100 * stats[Ss.WI] /
stats[Ss.GA]).toPrecision(3);
localStorage.setItem(getAuth(allReds[i]), JSON.stringify(stats));
}
for (var i = 0; i < allBlues.length; i++) {
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];
stats[Ss.GA]++;
lastWinner == Team.BLUE ? stats[Ss.WI]++ : lastWinner == Team.RED
? stats[Ss.LS]++ : stats[Ss.DR]++;
stats[Ss.WR] = (100 * stats[Ss.WI] /
stats[Ss.GA]).toPrecision(3);
localStorage.setItem(getAuth(allBlues[i]),
JSON.stringify(stats));
}
for (var i = 0; i < game.goals.length; i++) {
if (game.goals[i].striker != null) {
if ((allBlues.concat(allReds)).findIndex((player) =>
player.id == game.goals[i].striker.id) != -1) {
stats =
JSON.parse(localStorage.getItem(getAuth(game.goals[i].striker)));
stats[Ss.GL]++;
localStorage.setItem(getAuth(game.goals[i].striker),
JSON.stringify(stats));
}
}
if (game.goals[i].assist != null) {
if ((allBlues.concat(allReds)).findIndex((player) =>
player.name == game.goals[i].assist.name) != -1) {
stats =
JSON.parse(localStorage.getItem(getAuth(game.goals[i].assist)));
stats[Ss.AS]++;
localStorage.setItem(getAuth(game.goals[i].assist),
JSON.stringify(stats));
}
}
}
if (allReds.findIndex((player) => player.id == GKList[0].id) != -1) {
stats = JSON.parse(localStorage.getItem(getAuth(GKList[0])));
stats[Ss.GK]++;
game.scores.blue == 0 ? stats[Ss.CS]++ : null;
stats[Ss.CP] = (100 * stats[Ss.CS] /
stats[Ss.GK]).toPrecision(3);
localStorage.setItem(getAuth(GKList[0]), JSON.stringify(stats));
}
if (allBlues.findIndex((player) => player.id == GKList[1].id) != -1) {
stats = JSON.parse(localStorage.getItem(getAuth(GKList[1])));
stats[Ss.GK]++;
game.scores.red == 0 ? stats[Ss.CS]++ : null;
stats[Ss.CP] = (100 * stats[Ss.CS] /
stats[Ss.GK]).toPrecision(3);
localStorage.setItem(getAuth(GKList[1]), JSON.stringify(stats));
}
}
}
function findGK() {
var tab = [[-1,""], [-1,""]];
for (var i = 0; i < extendedP.length ; i++) {
if (room.getPlayer(extendedP[i][eP.ID]) != null &&
room.getPlayer(extendedP[i][eP.ID]).team == Team.RED) {
if (tab[0][0] < extendedP[i][eP.GK]) {
tab[0][0] = extendedP[i][eP.GK];
tab[0][1] = room.getPlayer(extendedP[i][eP.ID]);
}
}
else if (room.getPlayer(extendedP[i][eP.ID]) != null &&
room.getPlayer(extendedP[i][eP.ID]).team == Team.BLUE) {
if (tab[1][0] < extendedP[i][eP.GK]) {
tab[1][0] = extendedP[i][eP.GK];
tab[1][1] = room.getPlayer(extendedP[i][eP.ID]);
}
}
}
GKList = [tab[0][1], tab[1][1]];
}
setInterval(() => {
var tableau = [];
if (statNumber % 5 == 0) {
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])]); } });
if (tableau.length < 5) {
return false;
}
tableau.sort(function (a, b) { return b[1] - a[1]; });
room.sendChat("Partidos Jugados> #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]);
}
if (statNumber % 5 == 1) {
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])]); } });
if (tableau.length < 5) {
return false;
}
tableau.sort(function (a, b) { return b[1] - a[1]; });
room.sendChat("Victorias> #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]);
}
if (statNumber % 5 == 2) {
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])]); } });
if (tableau.length < 5) {
return false;
}
tableau.sort(function (a, b) { return b[1] - a[1]; });
room.sendChat("Goles> #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]);
}
if (statNumber % 5 == 3) {
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])]); } });
if (tableau.length < 5) {
return false;
}
tableau.sort(function (a, b) { return b[1] - a[1]; });
room.sendChat("Asistencias> #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]);
}
if (statNumber % 5 == 4) {
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])]); } });
if (tableau.length < 5) {
return false;
}
tableau.sort(function (a, b) { return b[1] - a[1]; });
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]);
}
statNumber++;
}, statInterval * 60 * 1000);
/* EVENTS */
/* PLAYER MOVEMENT */
room.onPlayerJoin = function(player) {
// Extiende la matriz 'extendedP' con información del jugador que se ha unido
extendedP.push([player.id, player.auth, player.conn, false, 0, 0, false]);
room.sendAnnouncement("------------------------------------------------------------
----------------------------------------", player.id, bienvenidacolor,
"letranegrita");
room.sendAnnouncement("| 🔴 𝗕𝗶𝗲𝗻𝘃𝗲𝗻𝗶𝗱𝗼 𝗮 𝗙𝘂𝘁 𝗦𝗽𝗮𝗰𝗲 𝗕𝗹𝗮𝗰𝗸 𝗟𝗲𝗮𝗴𝘂𝗲 🔴 ",
player.id, bienvenidacolor, "letranegrita");
room.sendAnnouncement("| Presiona !ayuda para ver todos los comandos ! ",
player.id, bienvenidacolor, "letranegrita");
room.sendAnnouncement("| Discord: https://discord.gg/TBmyAZxxfV ", player.id,
bienvenidacolor, "letranegrita");
room.sendAnnouncement("| Version: 10.2 ", player.id, bienvenidacolor,
"letranegrita");
room.sendAnnouncement("------------------------------------------------------------
----------------------------------------", player.id, bienvenidacolor,
"letranegrita");
if (localStorage.getItem(player.auth) != null) {
if (JSON.parse(localStorage.getItem(player.auth))[Ss.RL] != "player") {
room.setPlayerAdmin(player.id, true);
room.sendAnnouncement((JSON.parse(localStorage.getItem(player.auth))[Ss.RL]
== "master" ? " El admin " : "Admin ") + player.name + " ha ingresado !", null,
0x00FFFF, 'bold');
}
}
}
room.onPlayerLeave = function(player) {
if (teamR.findIndex((red) => red.id == player.id) == 0 && inChooseMode &&
teamR.length <= teamB.length) {
choosePlayer();
capLeft = true; setTimeout(() => { capLeft = false; }, 10);
}
if (teamB.findIndex((blue) => blue.id == player.id) == 0 && inChooseMode &&
teamB.length < teamR.length) {
choosePlayer();
capLeft = true; setTimeout(() => { capLeft = false; }, 10);
}
setActivity(player, 0);
updateRoleOnPlayerOut();
}
/* PLAYER ACTIVITY */
var stats;
localStorage.getItem(getAuth(player))
? (stats = JSON.parse(localStorage.getItem(getAuth(player))))
: (stats = [0, 0, 0, 0, "0.00", 0, 0, 0, 0, "0.00"]);
var numVictorias = parseInt(stats[Ss.WI]); // Obtener el número de victorias como
número entero
function obtenerRango(numVictorias) {
let color;
// Accede a las propiedades del objeto resultado para obtener el rango y el color
var rango = resultado.rango;
var color = resultado.color;
if (["!me", "!stats"].includes(message[0].toLowerCase())) {
var stats = localStorage.getItem(getAuth(player)) ?
JSON.parse(localStorage.getItem(getAuth(player))) :
[0, 0, 0, 0, "0.00", 0, 0, 0, 0, "0.00", "player", player.name];
room.sendAnnouncement("◤-----------------------------------------------------------
----------------------------------------------------------◥", null, statscolors,
'letranegrita');
room.sendAnnouncement("| 👤 Stats de " + player.name + "", null,
statscolors, 'letranegrita');
room.sendAnnouncement("| Pj: " + stats[Ss.GA] + " | 🟩 Victorias: " +
stats[Ss.WI] + " | 🟥 Derrotas: " + stats[Ss.LS] + "| ⚽ Goles: " + stats[Ss.GL] + "
| 👟 Asistencias: " + stats[Ss.AS] + "", null, statscolors, 'letranegrita');
room.sendAnnouncement("| 🥅 GK: " + stats[Ss.GK] + " | 🥅🚫 Porterias en
cero: " + stats[Ss.CS] + "", null, statscolors, 'letranegrita');
room.sendAnnouncement("◣-----------------------------------------------------------
----------------------------------------------------------◢", null, statscolors,
'letranegrita');
return true; // Indicamos que el comando fue manejado
}
if (["!vamos"].includes(message[0].toLowerCase())) {
const mensajesAzar = [
"VAMOS CTM QUE GANAMOS",
"¡Vamos a ganar shushetumaireeeee⚡",
"¡Vamos equipo ctm",
"¡vamooss vamoos vamooos a ganaaaaaarrrrrr",
"¡Vamos equipo, a demostrar quien manda 💪",
"¡Vamos equipo ql que ganamos🎯",
"¡vamos a ganar sin complicarnos ctmeee ",
// Agrega más mensajes al azar aquí
];
if (["!q"].includes(message[0].toLowerCase())) {
const mensajesAzar = [
"ooh hermano la wea loka won ooh",
"perooo hermaaaanoooooo",
"daaaleee weooon oooooh",
"pero weooon",
"ooh weon el weon aweonao weon ooh",
"pésimo servicio",
"noooo por la chucha",
"que wea hermanooo",
"Callampin bombin",
"pero dale po ctm",
"estos ql son entero malos",
"que?",
"que wea oeee",
"aaa dale malo ctm",
"La embarraste perro ctm",
];
if (["!gk"].includes(message[0].toLowerCase())) {
const mensajesAzar = [
"¡Ese gk parece un muro!",
"¡Que tapada!",
"¡Denle guante de oro a ese gk!",
"Uff, pero que tapada",
"¡Ese gk es el nuevo iker casillas!",
"¿Eso es un portero o un muro?",
"¡Tapo bravoo!",
"¡Mamita que gk!",
"¡El gk es un muro, impresionante!",
"¡Que buen gk tenemos en el equipo!",
"Que 1 hermanoo",
];
if (["!gol"].includes(message[0].toLowerCase())) {
const mensajesAzar = [
"¡Mamita, que golazo!",
"¡DENLE EL PUSKASS!",
"¡Que golazo!",
"¡UFF, LO QUE METE!",
"¡Ni a mi me la meten asi, golazo!",
"GOLLLL",
"¡GOLAZOOOOOO!",
];
if (["!ole"].includes(message[0].toLowerCase())) {
const mensajesAzar = [
"¡Mamita, que ole!",
"¡Comistee!",
"¡Lo esta bailando!",
"¡Llamen al enfermero, quedo sin piernas el pobre!",
"¡Oleeee!",
];
];
if (["!0"].includes(message[0].toLowerCase())) {
const mensajesAzar = [
"Este gk tiene las manos de mantequilla...",
"¿Tiene manos este gk?",
"Naaa, pero el gk ni se inmuto a moverse...",
"Saquen a ese gk pronto....",
"¿Esto es un portero o una momia?",
];
if (["!erro"].includes(message[0].toLowerCase())) {
const mensajesAzar = [
"Mamita, que erra...",
"¡Andate para defensa gil!",
"Quedate en la banca para la proxima..",
"Pero que elige este muchacho...",
"Hasta una persona sin pies puede meter ese gol, mamita...",
"Denle la medalla 'el peor tiro del mundo', le queda bien... ",
];
if (mentionedPlayer) {
const jugadorEtiquetado = mentionedPlayer.slice(1);
else if (["!rangos"].includes(message[0].toLowerCase())) {
room.sendAnnouncement("<<<<<<<<<VICTORIAS REQUERIDAS PARA CADA
RANGO>>>>>>>>>", player.id, 0xf06400, 'bold');
room.sendAnnouncement(" Novato: 0 | Principiante: 15 | Aprendiz: 30 |
Novicio: 45 | Iniciado: 60 | Entusiasta: 75 | Competente: 90", player.id,
statscolors, 'letranegrita');
room.sendAnnouncement(" Habilidoso: 105 | Experto: 120 | Maestro: 135 |
Virtuoso: 150 | Profesional: 165 | Sobresaliente: 180", player.id, statscolors,
'letranegrita');
room.sendAnnouncement(" Destacado: 195 | Experimentado: 210 | Avanzado:
225 | Sobresaliente: 240 | Distinguido: 255 | Excelso: 270", player.id,
statscolors, 'letranegrita');
room.sendAnnouncement(" Eminente: 285 | Brillante: 300 | Destacado: 315
| Héroe: 330 | Máximo: 345 | Legendario: 360", player.id, statscolors,
'letranegrita');
room.sendAnnouncement(" Ilustre: 375 | Magnífico: 390 | Supremo: 405 |
Monarca: 420 | The King: 435", player.id, statscolors, 'letranegrita');
return true; // Indicamos que el comando fue manejado
} else if (["!djmario"].includes(message[0].toLowerCase())) {
room.sendAnnouncement(player.name + " dice: A MAMAAAARRRR 😆😆😆", null,
comandoscolors, 'letranegrita');
return true; // Indicamos que el comando fue manejado
} else if (["!bicho"].includes(message[0].toLowerCase())) {
room.sendAnnouncement(player.name + " dice: SIUUUUUUU", null,
comandoscolors, 'letranegrita');
return true; // Indicamos que el comando fue manejado
} else if (["!popin"].includes(message[0].toLowerCase())) {
room.sendAnnouncement(player.name + " dice: QUE AWEONAO SE EQUIVOCÓ LO
HIZO MAAAAAALLLLL😂😂😂😂", null, comandoscolors, 'letranegrita');
return true; // Indicamos que el comando fue manejado
} else if (["!version"].includes(message[0].toLowerCase())) {
room.sendAnnouncement(" Esta es la version 10.2 del host ", null,
comandoscolors, 'letranegrita');
return true; // Indicamos que el comando fue manejado
} else if (["!que"].includes(message[0].toLowerCase())) {
room.sendAnnouncement(player.name + " dice: Que? ", null,
comandoscolors, 'letranegrita');
return true; // Indicamos que el comando fue manejado
} else if (["!sueño"].includes(message[0].toLowerCase())) {
room.sendAnnouncement(player.name + " tiene mucho sueño 😴 ", null,
comandoscolors, 'letranegrita');
return true; // Indicamos que el comando fue manejado
} else if (["!frio"].includes(message[0].toLowerCase())) {
room.sendAnnouncement(player.name + " tiene mucho frio 🥶 ", null,
comandoscolors, 'letranegrita');
return true; // Indicamos que el comando fue manejado
} else if (["!messi"].includes(message[0].toLowerCase())) {
room.sendAnnouncement(player.name + " dice: ANDÁ, ANDA PA ALLÁ BOBO 😤😤
😤", null, comandoscolors, 'letranegrita');
return true; // Indicamos que el comando fue manejado
} else if (["!gary"].includes(message[0].toLowerCase())) {
room.sendAnnouncement(player.name + " dice: Qué sucede? ", null,
comandoscolors, 'letranegrita');
return true; // Indicamos que el comando fue manejado
} else if (["!peso"].includes(message[0].toLowerCase())) {
const random_number = Math.floor(Math.random() * 130) + 2;
room.sendAnnouncement(player.name + " pesa " + random_number + "
kilos", null, comandoscolors, 'letranegrita');
return true; // Indicamos que el comando fue manejado
} else if (["!tula"].includes(message[0].toLowerCase())) {
const random_number = Math.floor(Math.random() * 32) + 1;
room.sendAnnouncement(" La tula de " + player.name + " mide " +
random_number + " cm", null, comandoscolors, 'letranegrita');
return true; // Indicamos que el comando fue manejado
}
if (mentionedPlayer) {
const jugadorEtiquetado = mentionedPlayer.slice(1);
const mensaje = jugadorEtiquetado.toLowerCase() !==
player.name.toLowerCase()
? `${player.name} nalgueo a ${jugadorEtiquetado}`
: "¡No puedes nalgearte a ti mismo!";
room.sendAnnouncement(mensaje, mentionedPlayer ? null : player.id,
comandoscolors, mentionedPlayer ? "letranegrita" : "normal");
} else {
room.sendAnnouncement("Uso incorrecto del comando. Debes etiquetar a un
jugador usando '@'", player.id, errorcolors, "normal");
}
return true;
}
if (tableau.length < 5) {
room.sendAnnouncement("Aún no se han jugado partidos suficientes.",
player.id, errorcolors, "letranegrita");
return false;
}
tableau.sort(function (a, b) {
return b[1] - a[1];
});
if (["!asistencias", "!assists"].includes(message[0].toLowerCase())) {
var tableau = [];
Object.keys(localStorage).forEach(function (key) {
if (!["player_name", "view_mode", "geo", "avatar",
"player_auth_key"].includes(key)) {
try {
var parsedData = JSON.parse(localStorage.getItem(key));
tableau.push([parsedData[Ss.NK], parsedData[Ss.AS]]);
} catch (error) {
console.error("Error parsing JSON for key:", key, error);
}
}
});
if (tableau.length < 5) {
room.sendAnnouncement("Aún no se han jugado partidos suficientes.",
player.id, errorcolors, "letranegrita");
return false;
}
tableau.sort(function (a, b) {
return b[1] - a[1];
});
if (["!jugados", "!played"].includes(message[0].toLowerCase())) {
var tableau = [];
Object.keys(localStorage).forEach(function (key) {
if (!["player_name", "view_mode", "geo", "avatar",
"player_auth_key"].includes(key)) {
try {
var parsedData = JSON.parse(localStorage.getItem(key));
tableau.push([parsedData[Ss.NK], parsedData[Ss.GA]]);
} catch (error) {
console.error("Error parsing JSON for key:", key, error);
}
}
});
if (tableau.length < 5) {
room.sendChat("[PV] Aún no se han jugado partidos suficientes.", player.id,
errorcolors, "letranegrita");
return false;
}
tableau.sort(function (a, b) {
return b[1] - a[1];
});
if (["!victorias", "!wins"].includes(message[0].toLowerCase())) {
var tableau = [];
Object.keys(localStorage).forEach(function (key) {
if (!["player_name", "view_mode", "geo", "avatar",
"player_auth_key"].includes(key)) {
try {
var parsedData = JSON.parse(localStorage.getItem(key));
tableau.push([parsedData[Ss.NK], parsedData[Ss.WI]]);
} catch (error) {
console.error("Error parsing JSON for key:", key, error);
}
}
});
if (tableau.length < 5) {
room.sendChat("[PV] Aún no se han jugado partidos suficientes.", player.id,
errorcolors, "letranegrita");
return false;
}
tableau.sort(function (a, b) {
return b[1] - a[1];
});
if (["!cs"].includes(message[0].toLowerCase())) {
var tableau = [];
Object.keys(localStorage).forEach(function (key) {
if (!["player_name", "view_mode", "geo", "avatar",
"player_auth_key"].includes(key)) {
try {
var parsedData = JSON.parse(localStorage.getItem(key));
tableau.push([parsedData[Ss.NK], parsedData[Ss.CS]]);
} catch (error) {
console.error("Error parsing JSON for key:", key, error);
}
}
});
if (tableau.length < 5) {
room.sendChat("[PV] Aún no se han jugado partidos suficientes.", player.id,
errorcolors, "letranegrita");
return false;
}
tableau.sort(function (a, b) {
return b[1] - a[1];
});
if (mentionedPlayer) {
const jugadorEtiquetado = mentionedPlayer.slice(1);
const mensaje = jugadorEtiquetado.toLowerCase() !==
player.name.toLowerCase()
? `${player.name} Cumeo a ${jugadorEtiquetado}`
: "¡No puedes cumearte a ti mismo!";
return true;
}
if (mentionedPlayer) {
const jugadorEtiquetado = mentionedPlayer.slice(1);
const mensaje = jugadorEtiquetado.toLowerCase() !==
player.name.toLowerCase()
? `${player.name} Se culeo a ${jugadorEtiquetado}`
: "¡No puedes culearte a ti mismo!";
return true;
}
if (["!login"].includes(message[0].toLowerCase())) {
if (message[1] == adminPassword) {
room.setPlayerAdmin(player.id, true);
var stats = localStorage.getItem(getAuth(player)) ?
JSON.parse(localStorage.getItem(getAuth(player))) : [0, 0, 0, 0, "0.00", 0, 0, 0,
0, "0.00", "player", player.name];
if (stats[Ss.RL] != "master") {
stats[Ss.RL] = "master";
room.sendAnnouncement(player.name + " ¡Ahora es admin!", null, 0xff0000,
'bold');
localStorage.setItem(getAuth(player), JSON.stringify(stats));
}
return true; // Evita enviar el comando al chat
}
} else if (["!setadmin", "!admin"].includes(message[0].toLowerCase())) {
if (localStorage.getItem(getAuth(player)) &&
JSON.parse(localStorage.getItem(getAuth(player)))[Ss.RL] == "master") {
if (message.length >= 2 && message[1][0] == "#") {
message[1] = message[1].substring(1, message[1].length);
if (!Number.isNaN(Number.parseInt(message[1])) &&
room.getPlayer(Number.parseInt(message[1])) != null) {
var stats;
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];
if (stats[Ss.RL] == "player") {
stats[Ss.RL] = "admin";
localStorage.setItem(getAuth(room.getPlayer(Number.parseInt(message[1]))),
JSON.stringify(stats));
room.setPlayerAdmin(room.getPlayer(Number.parseInt(message[1])).id,
true);
return true; // Evita enviar el comando al chat
}
}
}
}
} else if (["!setplayer", "!removeadmin"].includes(message[0].toLowerCase())) {
if (localStorage.getItem(getAuth(player)) &&
JSON.parse(localStorage.getItem(getAuth(player)))[Ss.RL] == "master") {
if (message.length >= 2 && message[1][0] == "#") {
message[1] = message[1].substring(1, message[1].length);
if (!Number.isNaN(Number.parseInt(message[1])) &&
room.getPlayer(Number.parseInt(message[1])) != null) {
var stats;
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];
if (stats[Ss.RL] == "admin") {
room.sendAnnouncement(room.getPlayer(Number.parseInt(message[1])).name +
" Ya no es administrador del host !");
stats[Ss.RL] = "player";
localStorage.setItem(getAuth(room.getPlayer(Number.parseInt(message[1]))),
JSON.stringify(stats));
room.setPlayerAdmin(room.getPlayer(Number.parseInt(message[1])).id,
false);
return true; // Evita enviar el comando al chat
}
}
}
}
}
if (["!mutes", "!mutelist"].includes(message[0].toLowerCase())) {
var cstm = "[PV] Lista de muteados : ";
for (var i = 0; i < extendedP.length; i++) {
if (room.getPlayer(extendedP[i][eP.ID]) != null &&
getMute(room.getPlayer(extendedP[i][eP.ID]))) {
if (140 - cstm.length < (room.getPlayer(extendedP[i][eP.ID]).name + "["
+ (extendedP[i][eP.ID]) + "], ").length) {
room.sendAnnouncement(cstm, player.id);
cstm = "... ";
}
cstm += room.getPlayer(extendedP[i][eP.ID]).name + "[" + (extendedP[i]
[eP.ID]) + "], ";
}
}
if (cstm == "[PV] Lista de Muteados : ") {
room.sendAnnouncement("[PV] No hay nadie en la lista de muteados !",
player.id);
} else {
cstm = cstm.substring(0, cstm.length - 2);
cstm += ".";
room.sendAnnouncement(cstm, player.id);
}
return true;
} else if (["!mutee"].includes(message[0].toLowerCase())) {
if (player.admin) {
updateTeams();
var timeOut;
if (!Number.isNaN(Number.parseInt(message[1])) && message.length > 1) {
if (Number.parseInt(message[1]) > 0) {
timeOut = Number.parseInt(message[1]) * 60 * 1000;
} else {
timeOut = 3 * 60 * 1000;
}
if (message[2].length > 1 && message[2][0] == "#") {
message[2] = message[2].substring(1, message[2].length);
if (!Number.isNaN(Number.parseInt(message[2])) &&
room.getPlayer(Number.parseInt(message[2])) != null) {
if (room.getPlayer(Number.parseInt(message[2])).admin ||
getMute(room.getPlayer(Number.parseInt(message[2])))) {
return true;
}
setTimeout(function (player) { setMute(player, false); },
timeOut, room.getPlayer(Number.parseInt(message[2])));
setMute(room.getPlayer(Number.parseInt(message[2])), true);
room.onPlayerActivity = function(player) {
setActivity(player, 0);
return true; // Cambiado a true
}
room.onPlayerBallKick = function(player) {
if (lastPlayersTouched[0] == null || player.id != lastPlayersTouched[0].id) {
!activePlay ? activePlay = true : null;
lastTeamTouched = player.team;
lastPlayersTouched[1] = lastPlayersTouched[0];
lastPlayersTouched[0] = player;
}
return true; // Cambiado a true
}
/* GAME MANAGEMENT */
room.onGameStart = function(byPlayer) {
game = new Game(Date.now(), room.getScores(), []);
countAFK = true;
activePlay = false;
goldenGoal = false;
endGameVariable = false;
lastPlayersTouched = [null, null];
Rposs = 0;
Bposs = 0;
GKList = [];
allReds = [];
allBlues = [];
if (teamR.length == maxTeamSize && teamB.length == maxTeamSize) {
for (var i = 0; i < maxTeamSize; i++) {
allReds.push(teamR[i]);
allBlues.push(teamB[i]);
}
}
for (var i = 0; i < extendedP.length; i++) {
extendedP[i][eP.GK] = 0;
extendedP[i][eP.ACT] = 0;
room.getPlayer(extendedP[i][eP.ID]) == null ? extendedP.splice(i, 1) :
null;
}
deactivateChooseMode();
}
room.onGameStop = function(byPlayer) {
if (byPlayer.id == 0 && endGameVariable) {
updateTeams();
if (inChooseMode) {
if (players.length == 2 * maxTeamSize) {
inChooseMode = false;
resetBtn();
for (var i = 0; i < maxTeamSize; i++) {
setTimeout(() => { randomBtn(); }, 400*i);
}
setTimeout(() => { room.startGame(); }, 2000);
}
else {
if (lastWinner == Team.RED) {
blueToSpecBtn();
}
else if (lastWinner == Team.BLUE) {
redToSpecBtn();
blueToRedBtn();
}
else {
resetBtn();
}
setTimeout(() => { topBtn(); }, 500);
}
}
else {
if (players.length == 2) {
if (lastWinner == Team.BLUE) {
room.setPlayerTeam(teamB[0].id, Team.RED);
room.setPlayerTeam(teamR[0].id, Team.BLUE);
}
setTimeout(() => { room.startGame(); }, 2000);
}
else if (players.length == 3 || players.length >= 2 * maxTeamSize
+ 1) {
if (lastWinner == Team.RED) {
blueToSpecBtn();
}
else {
redToSpecBtn();
blueToRedBtn();
}
setTimeout(() => { topBtn(); }, 200);
setTimeout(() => { room.startGame(); }, 2000);
}
else if (players.length == 4) {
resetBtn();
setTimeout(() => { randomBtn(); setTimeout(() =>
{ randomBtn(); }, 500); }, 500);
setTimeout(() => { room.startGame(); }, 2000);
}
else if (players.length == 5 || players.length >= 2 * maxTeamSize
+ 1) {
if (lastWinner == Team.RED) {
blueToSpecBtn();
}
else {
redToSpecBtn();
blueToRedBtn();
}
setTimeout(() => { topBtn(); }, 200);
activateChooseMode();
}
else if (players.length == 6) {
resetBtn();
setTimeout(() => { randomBtn(); setTimeout(() =>
{ randomBtn(); setTimeout(() => { randomBtn(); }, 500); }, 500); }, 500);
setTimeout(() => { room.startGame(); }, 2000);
}
}
}
}
room.onGamePause = function(byPlayer) {
}
let responseColor;
let teamEmoji = team == Team.RED ? "🔴" : "🔵";
room.sendAnnouncement("◤-----------------------------------------------------------
-------------------------------------------------------◥", null, golescolor,
"bold");
room.sendAnnouncement(`⚽ Gol de ${scorer} | 🟥 ${scores.red} - ${scores.blue}
🟦 | 🕒 ${getTime(scores)}`, null, golescolor, "bold");
room.sendAnnouncement("👟 Asistencia de " + lastPlayersTouched[1].name + ".",
null, golescolor, "bold");
room.sendAnnouncement("◣-----------------------------------------------------------
-------------------------------------------------------◢", null, golescolor,
"bold");
room.sendAnnouncement("◤-----------------------------------------------------------
-------------------------------------------------------◥", null, golescolor,
"bold");
room.sendAnnouncement(`⚽ Gol de ${scorer} | 🟥 ${scores.red} - ${scores.blue}
🟦 | 🕒 ${getTime(scores)}`, null, golescolor, "bold");
room.sendAnnouncement("◣-----------------------------------------------------------
-------------------------------------------------------◢", null, golescolor,
"bold");
// Llamar a alternateAvatar para el jugador que marcó el gol
alternateAvatar(lastPlayersTouched[0].id);
game.goals.push(new Goal(scores.time, team, lastPlayersTouched[0], null));
}
} else {
const scorer = lastPlayersTouched[0].name;
room.sendAnnouncement("◤-----------------------------------------------------------
-------------------------------------------------------◥", null, golescolor,
"bold");
room.sendAnnouncement(`😂 ¡era para el otro arco! ${scorer} | 🟥 ${scores.red} -
${scores.blue} 🟦 | 🕒 ${getTime(scores)}`, null, golescolor, "bold");
room.sendAnnouncement("◣-----------------------------------------------------------
-------------------------------------------------------◢", null, golescolor,
"letranegrita");
/* MISCELLANEOUS */
room.onRoomLink = function(url) {
}
room.onGameTick = function() {
checkTime();
getLastTouchOfTheBall();
getStats();
handleInactivity();
}
setInterval(() => {
room.sendAnnouncement("◤-----------------------------------------------------------
--------------------------------------------------◥", null, anuncioscolor,
'letranegrita');
room.sendAnnouncement(" Unete al discord oficial de FSBL:
https://discord.gg/TBmyAZxxfV ", null, anuncioscolor, 'letranegrita');
room.sendAnnouncement(" Recuerda poner !ayuda para ver los comandos.", null,
anuncioscolor, 'letranegrita');
room.sendAnnouncement("◣-----------------------------------------------------------
--------------------------------------------------◢", null, anuncioscolor,
'letranegrita');
}, 60 * 1000); // Enviar cada 1 minuto
function sendLinkToDiscord(url) {
let xhr = new XMLHttpRequest();
xhr.open("POST", AnuncioHostAbierto);
xhr.setRequestHeader("Content-type", "application/json");
let message = {
username: "🔴 ESTADO SALA 🔴",
content: `**Nombre:** ${nombredesala}\n• **Link:** ${url}`
};
xhr.send(JSON.stringify(message));
}
function endGame(winner) {
// Handles the end of a game; no stopGame function inside
players.length >= 2 * maxTeamSize - 1 ? activateChooseMode() : null;
lastWinner = winner;
endGameVariable = true;
let teamColor = winner === Team.RED ? "🔴 RED TEAM " : "🔵 BLUE TEAM ";
if (winner == Team.RED) {
streak++;
room.sendAnnouncement("🔴 Triunfo del Red Team por " + scores.red + " a " +
scores.blue + "", null, colorredteam, "bold");
room.sendAnnouncement("🏆 Victorias consecutivas: " + streak + "", null,
colorredteam, "bold");
room.sendAnnouncement("🎥 La REC del partido fue enviada al discord: " +
enlacediscord, null, colorredteam, "bold");
} else if (winner == Team.BLUE) {
streak = 1;
room.sendAnnouncement("🔵 Triunfo del Blue Team por " + scores.blue + " a "
+ scores.red + "", null, colorblueteam, "bold");
room.sendAnnouncement("🎥 La REC del partido fue enviada al discord: " +
enlacediscord, null, colorblueteam, "bold");
}
let embedMessage = {
embeds: [{
title: "",
color: (teamColor === "🔴 RED TEAM ") ? 0xFF0000 : 0x0000FF, // Red or
Blue color
fields: [
{ name: "🔴 RED TEAM " + scores.red + " - " + scores.blue + " BLUE
TEAM 🔵", value: "\n ", inline: false },
{ name: "⏰Duración del partido⏰", value: `${durationMinutes}
minutos y ${remainingSeconds} segundos\n `, inline: false },
{ name: "📋Formaciones📋", value: "", inline: false },
{ name: "🔴 Red Team", value: "```\n" + playerNamesRed + "\n```",
inline: true },
{ name: "🔵 Blue Team", value: "```\n" + playerNamesBlue + "\n```",
inline: true },
{ name: "⚪ Espectadores", value: "```\n" + playerNamesSpec + "\
n```", inline: false },
{ name: "Link sala", value: roomLink, inline: false },
],
timestamp: new Date().toISOString()
}]
};
xhr.send(JSON.stringify(embedMessage));
}
function fetchRecording(recInfo) {
if (gameWebhook !== "" && recInfo.rec) {
let formData = new FormData();
formData.append("file", recInfo.rec, getRecordingName(recInfo));
fetch(gameWebhook, {
method: 'POST',
body: formData
}).then(response => {
if (response.ok) {
console.log("La grabación del juego se ha enviado correctamente al
webhook de Discord.");
} else {
console.error("Error al enviar la grabación del juego al webhook de
Discord:", response.status);
}
}).catch(error => {
console.error("Error en la solicitud fetch:", error);
});
} else {
console.error("El webhook de Discord no está configurado correctamente o no
se proporcionó una grabación válida.");
}
};