mirror of
https://git.rezel.net/LudoTech/traque.git
synced 2026-02-09 02:10:18 +01:00
Merge branch 'main' of github.com:quentinrsl/traque
This commit is contained in:
@@ -130,6 +130,7 @@ export function initAdminSocketHandler() {
|
|||||||
if (game.updateTeam(teamId, newTeam)) {
|
if (game.updateTeam(teamId, newTeam)) {
|
||||||
secureAdminBroadcast("teams", game.teams);
|
secureAdminBroadcast("teams", game.teams);
|
||||||
sendUpdatedTeamInformations(teamId)
|
sendUpdatedTeamInformations(teamId)
|
||||||
|
sendUpdatedTeamInformations(game.getTeam(teamId).chased)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|||||||
@@ -27,7 +27,11 @@ export default class Game {
|
|||||||
}
|
}
|
||||||
this.initLastSentLocations();
|
this.initLastSentLocations();
|
||||||
this.zone.reset()
|
this.zone.reset()
|
||||||
this.zone.start()
|
//If the zone cannot be setup, reset everything
|
||||||
|
if(!this.zone.start()) {
|
||||||
|
this.setState(GameState.SETUP);
|
||||||
|
return;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if (newState != GameState.PLAYING) {
|
if (newState != GameState.PLAYING) {
|
||||||
this.zone.reset();
|
this.zone.reset();
|
||||||
@@ -59,6 +63,7 @@ export default class Game {
|
|||||||
lastSentLocation: null,
|
lastSentLocation: null,
|
||||||
locationSendDeadline: null,
|
locationSendDeadline: null,
|
||||||
enemyLocation: null,
|
enemyLocation: null,
|
||||||
|
enemyName: null,
|
||||||
captureCode: this.createCaptureCode(),
|
captureCode: this.createCaptureCode(),
|
||||||
sockets: [],
|
sockets: [],
|
||||||
startingArea: null,
|
startingArea: null,
|
||||||
@@ -91,6 +96,7 @@ export default class Game {
|
|||||||
if (previousTeam != null) {
|
if (previousTeam != null) {
|
||||||
this.teams[i].chased = previousTeam;
|
this.teams[i].chased = previousTeam;
|
||||||
this.getTeam(previousTeam).chasing = this.teams[i].id;
|
this.getTeam(previousTeam).chasing = this.teams[i].id;
|
||||||
|
this.getTeam(previousTeam).enemyName = this.teams[i].name;
|
||||||
} else {
|
} else {
|
||||||
firstTeam = this.teams[i].id;
|
firstTeam = this.teams[i].id;
|
||||||
}
|
}
|
||||||
@@ -99,6 +105,7 @@ export default class Game {
|
|||||||
}
|
}
|
||||||
this.getTeam(firstTeam).chased = previousTeam;
|
this.getTeam(firstTeam).chased = previousTeam;
|
||||||
this.getTeam(previousTeam).chasing = firstTeam;
|
this.getTeam(previousTeam).chasing = firstTeam;
|
||||||
|
this.getTeam(previousTeam).enemyName = this.getTeam(firstTeam).name;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -179,7 +186,7 @@ export default class Game {
|
|||||||
*/
|
*/
|
||||||
requestCapture(teamId, captureCode) {
|
requestCapture(teamId, captureCode) {
|
||||||
let enemyTeam = this.getTeam(this.getTeam(teamId).chasing)
|
let enemyTeam = this.getTeam(this.getTeam(teamId).chasing)
|
||||||
if (enemyTeam.captureCode == captureCode) {
|
if (enemyTeam && enemyTeam.captureCode == captureCode) {
|
||||||
this.capture(enemyTeam);
|
this.capture(enemyTeam);
|
||||||
this.updateTeamChasing();
|
this.updateTeamChasing();
|
||||||
return true;
|
return true;
|
||||||
|
|||||||
@@ -40,6 +40,7 @@ export function sendUpdatedTeamInformations(teamId) {
|
|||||||
io.of("player").to(socketId).emit("update_team", {
|
io.of("player").to(socketId).emit("update_team", {
|
||||||
name: team.name,
|
name: team.name,
|
||||||
enemyLocation: team.enemyLocation,
|
enemyLocation: team.enemyLocation,
|
||||||
|
enemyName: team.enemyName,
|
||||||
currentLocation: team.currentLocation,
|
currentLocation: team.currentLocation,
|
||||||
lastSentLocation: team.lastSentLocation,
|
lastSentLocation: team.lastSentLocation,
|
||||||
locationSendDeadline: team.locationSendDeadline,
|
locationSendDeadline: team.locationSendDeadline,
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import randomLocation, { randomCirclePoint } from 'random-location'
|
import { randomCirclePoint } from 'random-location'
|
||||||
import { getDistanceFromLatLon, isInCircle } from './map_utils.js';
|
import { isInCircle } from './map_utils.js';
|
||||||
import { map } from './util.js';
|
import { map } from './util.js';
|
||||||
|
|
||||||
export class ZoneManager {
|
export class ZoneManager {
|
||||||
@@ -108,7 +108,8 @@ export class ZoneManager {
|
|||||||
this.nextZone = JSON.parse(JSON.stringify(this.zoneSettings.max));
|
this.nextZone = JSON.parse(JSON.stringify(this.zoneSettings.max));
|
||||||
this.currentStartZone = JSON.parse(JSON.stringify(this.zoneSettings.max));
|
this.currentStartZone = JSON.parse(JSON.stringify(this.zoneSettings.max));
|
||||||
this.currentZone = JSON.parse(JSON.stringify(this.zoneSettings.max));
|
this.currentZone = JSON.parse(JSON.stringify(this.zoneSettings.max));
|
||||||
this.setNextZone();
|
return this.setNextZone();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -121,11 +122,16 @@ export class ZoneManager {
|
|||||||
getRandomNextCenter(newRadius) {
|
getRandomNextCenter(newRadius) {
|
||||||
let ok = false;
|
let ok = false;
|
||||||
let res = null
|
let res = null
|
||||||
|
let tries = 0;
|
||||||
|
const MAX_TRIES = 100000
|
||||||
//take a random point satisfying both conditions
|
//take a random point satisfying both conditions
|
||||||
while (!ok) {
|
while (tries++ < MAX_TRIES && !ok) {
|
||||||
res = randomCirclePoint({ latitude: this.currentZone.center.lat, longitude: this.currentZone.center.lng }, this.currentZone.radius - newRadius);
|
res = randomCirclePoint({ latitude: this.currentZone.center.lat, longitude: this.currentZone.center.lng }, this.currentZone.radius - newRadius);
|
||||||
ok = (isInCircle({ lat: res.latitude, lng: res.longitude }, this.zoneSettings.min.center, newRadius - this.zoneSettings.min.radius))
|
ok = (isInCircle({ lat: res.latitude, lng: res.longitude }, this.zoneSettings.min.center, newRadius - this.zoneSettings.min.radius))
|
||||||
}
|
}
|
||||||
|
if(tries>=MAX_TRIES) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
return {
|
return {
|
||||||
lat: res.latitude,
|
lat: res.latitude,
|
||||||
lng: res.longitude
|
lng: res.longitude
|
||||||
@@ -149,6 +155,11 @@ export class ZoneManager {
|
|||||||
this.currentZoneCount++;
|
this.currentZoneCount++;
|
||||||
} else if (this.currentZoneCount < this.zoneSettings.reductionCount) {
|
} else if (this.currentZoneCount < this.zoneSettings.reductionCount) {
|
||||||
this.nextZone.center = this.getRandomNextCenter(this.nextZone.radius - this.nextZoneDecrement)
|
this.nextZone.center = this.getRandomNextCenter(this.nextZone.radius - this.nextZoneDecrement)
|
||||||
|
//Next center cannot be found
|
||||||
|
if(this.nextZone.center === false) {
|
||||||
|
console.log("no center")
|
||||||
|
return false;
|
||||||
|
}
|
||||||
this.nextZone.radius -= this.nextZoneDecrement;
|
this.nextZone.radius -= this.nextZoneDecrement;
|
||||||
this.currentStartZone = JSON.parse(JSON.stringify(this.currentZone))
|
this.currentStartZone = JSON.parse(JSON.stringify(this.currentZone))
|
||||||
this.nextZoneTimeoutId = setTimeout(() => this.startShrinking(), 1000 * 60 * this.zoneSettings.reductionInterval)
|
this.nextZoneTimeoutId = setTimeout(() => this.startShrinking(), 1000 * 60 * this.zoneSettings.reductionInterval)
|
||||||
@@ -159,6 +170,7 @@ export class ZoneManager {
|
|||||||
begin: JSON.parse(JSON.stringify(this.currentStartZone)),
|
begin: JSON.parse(JSON.stringify(this.currentStartZone)),
|
||||||
end: JSON.parse(JSON.stringify(this.nextZone))
|
end: JSON.parse(JSON.stringify(this.nextZone))
|
||||||
})
|
})
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|||||||
Reference in New Issue
Block a user