From 910aee5b2cdc751cdb63bfd324fc528234e300bd Mon Sep 17 00:00:00 2001 From: Quentin Roussel Date: Fri, 19 Apr 2024 11:41:15 +0000 Subject: [PATCH] chagned format of the penalty for not sending location --- traque-back/game.js | 7 +++++-- traque-back/penalty_controller.js | 6 +++--- traque-back/team_socket.js | 4 ++-- 3 files changed, 10 insertions(+), 7 deletions(-) diff --git a/traque-back/game.js b/traque-back/game.js index d7087fd..8aeead2 100644 --- a/traque-back/game.js +++ b/traque-back/game.js @@ -1,4 +1,5 @@ import { isInCircle } from "./map_utils.js"; +import { sendUpdatedTeamInformations } from "./team_socket.js"; import { ZoneManager } from "./zone_manager.js"; export const GameState = { @@ -56,7 +57,7 @@ export default class Game { chased: null, currentLocation: null, lastSentLocation: null, - lastSentLocationDate: null, + locationSendDeadline: null, enemyLocation: null, captureCode: this.createCaptureCode(), sockets: [], @@ -140,6 +141,8 @@ export default class Game { initLastSentLocations() { for(let team of this.teams) { team.lastSentLocation = team.currentLocation; + team.locationSendDeadline = Number(new Date()) + process.env.ALLOWED_TIME_BETWEEN_POSITION_UPDATE_IN_MINUTES * 60 * 1000; + sendUpdatedTeamInformations(team.id); } } @@ -148,7 +151,7 @@ export default class Game { if(team == undefined) { return false; } - team.lastSentLocationDate = new Date(); + team.locationSendDeadline = Number(new Date()) + process.env.ALLOWED_TIME_BETWEEN_POSITION_UPDATE_IN_MINUTES * 60 * 1000; team.lastSentLocation = team.currentLocation; if(this.getTeam(team.chasing) != null) { team.enemyLocation = this.getTeam(team.chasing).lastSentLocation; diff --git a/traque-back/penalty_controller.js b/traque-back/penalty_controller.js index af24885..e4abcb2 100644 --- a/traque-back/penalty_controller.js +++ b/traque-back/penalty_controller.js @@ -78,11 +78,11 @@ export class PenaltyController { this.game.teams.forEach((team) => { //If the team has not sent their location for more than the allowed period, automatically send it and add a penalty if (team.captured) { return } - if(team.lastSentLocationDate == null) { - team.lastSentLocationDate = new Date(); + if(team.locationSendDeadline == null) { + team.locationSendDeadline = Number(new Date()) + process.env.ALLOWED_TIME_BETWEEN_POSITION_UPDATE_IN_MINUTES * 60 * 1000; return; } - if (new Date() - team.lastSentLocationDate > process.env.ALLOWED_TIME_BETWEEN_POSITION_UPDATE_IN_MINUTES * 60 * 1000) { + if (new Date() > team.locationSendDeadline) { this.addPenalty(team.id); this.game.sendLocation(team.id); sendUpdatedTeamInformations(team.id); diff --git a/traque-back/team_socket.js b/traque-back/team_socket.js index c51ed34..e93fdb8 100644 --- a/traque-back/team_socket.js +++ b/traque-back/team_socket.js @@ -42,7 +42,7 @@ export function sendUpdatedTeamInformations(teamId) { enemyLocation: team.enemyLocation, currentLocation: team.currentLocation, lastSentLocation: team.lastSentLocation, - lastSentLocationDate: team.lastSentLocationDate, + locationSendDeadline: team.locationSendDeadline, captureCode: team.captureCode, startingArea: team.startingArea, ready: team.ready, @@ -104,7 +104,7 @@ export function initTeamSocket() { return; } game.updateTeamChasing(); - teamBroadcast(teamId, "update_team", { enemyLocation: team.enemyLocation }); + teamBroadcast(teamId, "update_team", { enemyLocation: team.enemyLocation,locationSendDeadline: team.locationSendDeadline }); }); socket.on('capture', (captureCode) => {