Add out of zone handicap

This commit is contained in:
Sebastien Riviere
2025-09-14 16:27:35 +02:00
parent 7e4d9f910a
commit 0f64fc59f9
6 changed files with 70 additions and 28 deletions

View File

@@ -106,6 +106,7 @@ export default {
// Zone
team.outOfZone = false;
team.outOfZoneDeadline = null;
team.hasHandicap = false;
// Stats
team.distance = 0;
team.nCaptures = 0;
@@ -274,6 +275,7 @@ export default {
// Zone
outOfZone: false,
outOfZoneDeadline: null,
hasHandicap: false,
// Stats
distance: 0,
nCaptures: 0,
@@ -362,7 +364,17 @@ export default {
},
handicapTeam(teamId) {
// TODO
// Test of parameters
if (!this.hasTeam(teamId)) return false;
// Variables
const team = this.getTeam(teamId);
// Make the capture
team.hasHandicap = true;
sendPositionTimeouts.clear(team.id);
// Broadcast new infos
secureAdminBroadcast("teams", this.teams);
sendUpdatedTeamInformations(team.id);
return true;
},
@@ -375,12 +387,20 @@ export default {
if (!location) return false;
// Variables
const team = this.getTeam(teamId);
const enemyTeam = this.getTeam(team.chasing);
const dateNow = Date.now();
// Update distance
if (team.currentLocation) team.distance += Math.floor(getDistanceFromLatLon({lat: location[0], lng: location[1]}, {lat: team.currentLocation[0], lng: team.currentLocation[1]}));
// Update of currentLocation
team.currentLocation = location;
team.lastCurrentLocationDate = dateNow;
if (team.hasHandicap) {
team.lastSentLocation = team.currentLocation;
}
// Update of enemyLocation
if (enemyTeam.hasHandicap) {
team.enemyLocation = enemyTeam.currentLocation;
}
// Update of ready
if (this.state == GameState.PLACEMENT && team.startingArea) {
team.ready = isInCircle({ lat: location[0], lng: location[1] }, team.startingArea.center, team.startingArea.radius);
@@ -394,6 +414,11 @@ export default {
} else if (!teamCurrentlyOutOfZone && team.outOfZone) {
team.outOfZone = false;
team.outOfZoneDeadline = null;
team.hasHandicap = false;
if (!sendPositionTimeouts.has(team.id)) {
team.locationSendDeadline = dateNow + sendPositionTimeouts.delay * 60 * 1000;
sendPositionTimeouts.set(team.id);
}
outOfZoneTimeouts.clear(teamId);
}
// Broadcast new infos

View File

@@ -31,15 +31,18 @@ export function playersBroadcast(event, data) {
* @param {String} teamId The team that will receive the message
*/
export function sendUpdatedTeamInformations(teamId) {
// Test of parameters
if (!game.hasTeam(teamId)) return false;
// Variables
const team = game.getTeam(teamId);
if (!team) return;
const enemyTeam = game.getTeam(team.chasing);
teamBroadcast(teamId, "update_team", {
// Identification
name: team.name,
captureCode: team.captureCode,
// Chasing
captured: team.captured,
enemyName: game.getTeam(team.chasing)?.name ?? null,
enemyName: enemyTeam?.name,
// Locations
lastSentLocation: team.lastSentLocation,
enemyLocation: team.enemyLocation,
@@ -50,6 +53,8 @@ export function sendUpdatedTeamInformations(teamId) {
outOfZone: team.outOfZone,
outOfZoneDeadline: team.outOfZoneDeadline,
locationSendDeadline: team.locationSendDeadline,
hasHandicap: team.hasHandicap,
enemyHasHandicap: enemyTeam?.hasHandicap,
// Stats
distance: team.distance,
nCaptures: team.nCaptures,

View File

@@ -5,6 +5,10 @@ class TimeoutManager {
this.timeouts = new Map();
}
has(key) {
return this.timeouts.has(key);
}
set(key, callback, delay) {
const newCallback = () => {
this.timeouts.delete(key);
@@ -32,6 +36,10 @@ export const sendPositionTimeouts = {
timeoutManager: new TimeoutManager(),
delay: 10, // Minutes
has(teamID) {
return this.timeoutManager.has(teamID);
},
set(teamID) {
const callback = () => {
game.sendLocation(teamID);
@@ -58,6 +66,10 @@ export const outOfZoneTimeouts = {
timeoutManager: new TimeoutManager(),
delay: 10, // Minutes
has(teamID) {
return this.timeoutManager.has(teamID);
},
set(teamID) {
const callback = () => {
game.handicapTeam(teamID);