From 2299ff1b645ebcec5a89e67d4dc39d29ed7b687e Mon Sep 17 00:00:00 2001 From: Sebastien Riviere Date: Sun, 24 Aug 2025 21:51:16 +0200 Subject: [PATCH] =?UTF-8?q?Am=C3=A9liorations=20mineures?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- traque-back/game.js | 16 ++++++--------- traque-back/team_socket.js | 41 +++++++++++++++++--------------------- 2 files changed, 24 insertions(+), 33 deletions(-) diff --git a/traque-back/game.js b/traque-back/game.js index 81d674b..2fca5cf 100644 --- a/traque-back/game.js +++ b/traque-back/game.js @@ -96,10 +96,9 @@ export default { team.penalties = 0; team.captured = false; team.enemyLocation = null; - team.enemyName = null; team.currentLocation = null; team.lastSentLocation = null; - team.distance = null; + team.distance = 0; team.finishDate = null; team.nCaptures = 0; team.nSentLocation = 0; @@ -179,19 +178,18 @@ export default { */ addTeam(teamName) { this.teams.push({ + sockets: [], id: this.getNewTeamId(), name: teamName, chasing: null, chased: null, - currentLocation: null, lastSentLocation: null, - locationSendDeadline: null, + currentLocation: null, enemyLocation: null, - enemyName: null, - captureCode: this.createCaptureCode(), - sockets: [], + locationSendDeadline: null, startingArea: null, ready: false, + captureCode: this.createCaptureCode(), captured: false, penalties: 0, outOfZone: false, @@ -228,7 +226,7 @@ export default { /** * Update the chasing chain of the teams based of the ordre of the teams array * If there are only 2 teams left, the game will end - * This function will update the enemyName, chasing and chased values of each teams + * This function will update the chasing and chased values of each teams * @returns true if successful */ updateTeamChasing() { @@ -245,7 +243,6 @@ export default { if (previousTeam != null) { this.teams[i].chased = previousTeam; this.getTeam(previousTeam).chasing = this.teams[i].id; - this.getTeam(previousTeam).enemyName = this.teams[i].name; } else { firstTeam = this.teams[i].id; } @@ -254,7 +251,6 @@ export default { } this.getTeam(firstTeam).chased = previousTeam; this.getTeam(previousTeam).chasing = firstTeam; - this.getTeam(previousTeam).enemyName = this.getTeam(firstTeam).name; secureAdminBroadcast("teams", this.teams); return true; }, diff --git a/traque-back/team_socket.js b/traque-back/team_socket.js index 7b0ddef..6c40301 100644 --- a/traque-back/team_socket.js +++ b/traque-back/team_socket.js @@ -37,29 +37,24 @@ export function playersBroadcast(event, data) { */ export function sendUpdatedTeamInformations(teamId) { const team = game.getTeam(teamId); - if (!team) { - return; - } - team.sockets.forEach(socketId => { - io.of("player").to(socketId).emit("update_team", { - name: team.name, - enemyLocation: team.enemyLocation, - enemyName: team.enemyName, - lastSentLocation: team.lastSentLocation, - locationSendDeadline: team.locationSendDeadline, - captureCode: team.captureCode, - startingArea: team.startingArea, - ready: team.ready, - captured: team.captured, - penalties: team.penalties, - outOfZone: team.outOfZone, - outOfZoneDeadline: team.outOfZoneDeadline, - distance: team.distance, - startDate: game.startDate, - finishDate: team.finishDate, - nCaptures: team.nCaptures, - nSentLocation: team.nSentLocation, - }) + teamBroadcast(teamId, "update_team", { + name: team.name, + enemyName: game.getTeam(team.chasing).name, + lastSentLocation: team.lastSentLocation, + enemyLocation: team.enemyLocation, + locationSendDeadline: team.locationSendDeadline, + startingArea: team.startingArea, + ready: team.ready, + captureCode: team.captureCode, + captured: team.captured, + penalties: team.penalties, + outOfZone: team.outOfZone, + outOfZoneDeadline: team.outOfZoneDeadline, + distance: team.distance, + startDate: game.startDate, + finishDate: team.finishDate, + nCaptures: team.nCaptures, + nSentLocation: team.nSentLocation, }) secureAdminBroadcast("teams", game.teams); }