Merge branch 'main' of github.com:quentinrsl/traque

This commit is contained in:
Quentin Roussel
2024-04-19 13:41:46 +02:00
3 changed files with 10 additions and 7 deletions

View File

@@ -1,4 +1,5 @@
import { isInCircle } from "./map_utils.js"; import { isInCircle } from "./map_utils.js";
import { sendUpdatedTeamInformations } from "./team_socket.js";
import { ZoneManager } from "./zone_manager.js"; import { ZoneManager } from "./zone_manager.js";
export const GameState = { export const GameState = {
@@ -56,7 +57,7 @@ export default class Game {
chased: null, chased: null,
currentLocation: null, currentLocation: null,
lastSentLocation: null, lastSentLocation: null,
lastSentLocationDate: null, locationSendDeadline: null,
enemyLocation: null, enemyLocation: null,
captureCode: this.createCaptureCode(), captureCode: this.createCaptureCode(),
sockets: [], sockets: [],
@@ -140,6 +141,8 @@ export default class Game {
initLastSentLocations() { initLastSentLocations() {
for(let team of this.teams) { for(let team of this.teams) {
team.lastSentLocation = team.currentLocation; 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) { if(team == undefined) {
return false; 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; team.lastSentLocation = team.currentLocation;
if(this.getTeam(team.chasing) != null) { if(this.getTeam(team.chasing) != null) {
team.enemyLocation = this.getTeam(team.chasing).lastSentLocation; team.enemyLocation = this.getTeam(team.chasing).lastSentLocation;

View File

@@ -78,11 +78,11 @@ export class PenaltyController {
this.game.teams.forEach((team) => { 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 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.captured) { return }
if(team.lastSentLocationDate == null) { if(team.locationSendDeadline == null) {
team.lastSentLocationDate = new Date(); team.locationSendDeadline = Number(new Date()) + process.env.ALLOWED_TIME_BETWEEN_POSITION_UPDATE_IN_MINUTES * 60 * 1000;
return; 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.addPenalty(team.id);
this.game.sendLocation(team.id); this.game.sendLocation(team.id);
sendUpdatedTeamInformations(team.id); sendUpdatedTeamInformations(team.id);

View File

@@ -42,7 +42,7 @@ export function sendUpdatedTeamInformations(teamId) {
enemyLocation: team.enemyLocation, enemyLocation: team.enemyLocation,
currentLocation: team.currentLocation, currentLocation: team.currentLocation,
lastSentLocation: team.lastSentLocation, lastSentLocation: team.lastSentLocation,
lastSentLocationDate: team.lastSentLocationDate, locationSendDeadline: team.locationSendDeadline,
captureCode: team.captureCode, captureCode: team.captureCode,
startingArea: team.startingArea, startingArea: team.startingArea,
ready: team.ready, ready: team.ready,
@@ -104,7 +104,7 @@ export function initTeamSocket() {
return; return;
} }
game.updateTeamChasing(); game.updateTeamChasing();
teamBroadcast(teamId, "update_team", { enemyLocation: team.enemyLocation }); teamBroadcast(teamId, "update_team", { enemyLocation: team.enemyLocation,locationSendDeadline: team.locationSendDeadline });
}); });
socket.on('capture', (captureCode) => { socket.on('capture', (captureCode) => {