mirror of
https://git.rezel.net/LudoTech/traque.git
synced 2026-02-09 10:20:16 +01:00
game over detection system
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
import { penaltyController } from "./index.js";
|
||||
import { isInCircle } from "./map_utils.js";
|
||||
import { sendUpdatedTeamInformations } from "./team_socket.js";
|
||||
import { playersBroadcast, sendUpdatedTeamInformations } from "./team_socket.js";
|
||||
import { ZoneManager } from "./zone_manager.js";
|
||||
|
||||
export const GameState = {
|
||||
@@ -35,6 +36,7 @@ export default class Game {
|
||||
}
|
||||
if (newState != GameState.PLAYING) {
|
||||
this.zone.reset();
|
||||
penaltyController.stop();
|
||||
}
|
||||
this.state = newState;
|
||||
return true;
|
||||
@@ -86,7 +88,10 @@ export default class Game {
|
||||
}
|
||||
|
||||
updateTeamChasing() {
|
||||
if (this.playingTeamCount() <= 1) {
|
||||
if (this.playingTeamCount() <= 2) {
|
||||
if(this.state == GameState.PLAYING) {
|
||||
this.finishGame()
|
||||
}
|
||||
return false;
|
||||
}
|
||||
let firstTeam = null;
|
||||
@@ -187,7 +192,7 @@ export default class Game {
|
||||
requestCapture(teamId, captureCode) {
|
||||
let enemyTeam = this.getTeam(this.getTeam(teamId).chasing)
|
||||
if (enemyTeam && enemyTeam.captureCode == captureCode) {
|
||||
this.capture(enemyTeam);
|
||||
this.capture(enemyTeam.id);
|
||||
this.updateTeamChasing();
|
||||
return true;
|
||||
}
|
||||
@@ -216,4 +221,10 @@ export default class Game {
|
||||
}
|
||||
return this.zone.udpateSettings(newSettings)
|
||||
}
|
||||
|
||||
finishGame() {
|
||||
this.setState(GameState.FINISHED);
|
||||
this.zone.reset();
|
||||
playersBroadcast("game_state", this.state);
|
||||
}
|
||||
}
|
||||
@@ -48,7 +48,7 @@ function onUpdateZone(zone) {
|
||||
|
||||
|
||||
export const game = new Game(onUpdateZone, onUpdateNewZone);
|
||||
const penaltyController = new PenaltyController(game);
|
||||
export const penaltyController = new PenaltyController();
|
||||
penaltyController.init()
|
||||
|
||||
|
||||
|
||||
@@ -3,10 +3,11 @@ import { getDistanceFromLatLon, isInCircle } from "./map_utils.js";
|
||||
import { sendUpdatedTeamInformations, teamBroadcast } from "./team_socket.js";
|
||||
import { GameState } from "./game.js";
|
||||
import { secureAdminBroadcast } from "./admin_socket.js";
|
||||
import { game } from "./index.js";
|
||||
config()
|
||||
|
||||
export class PenaltyController {
|
||||
constructor(game) {
|
||||
constructor() {
|
||||
//Number of penalties needed to be eliminated
|
||||
this.game = game;
|
||||
this.outOfBoundsSince = {};
|
||||
@@ -27,6 +28,13 @@ export class PenaltyController {
|
||||
}, 100);
|
||||
}
|
||||
|
||||
stop(){
|
||||
this.outOfBoundsSince = {};
|
||||
if(this.checkIntervalId) {
|
||||
clearInterval(this.checkIntervalId)
|
||||
this.checkIntervalId = null;
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Increment the penalty score of a team, send a message to the team and eliminated if necessary
|
||||
* @param {Number} teamId The team that will recieve a penalty
|
||||
|
||||
Reference in New Issue
Block a user