This commit is contained in:
evanpelle
2025-03-27 20:43:56 -07:00
committed by GitHub
parent 9ed1fe865c
commit d8fe41de7a
37 changed files with 767 additions and 387 deletions
+33 -1
View File
@@ -1,5 +1,5 @@
import { EventBus, GameEvent } from "../EventBus";
import { Execution, Game, Player, PlayerID } from "../game/Game";
import { Execution, Game, GameMode, Player, Team } from "../game/Game";
export class WinEvent implements GameEvent {
constructor(public readonly winner: Player) {}
@@ -20,6 +20,14 @@ export class WinCheckExecution implements Execution {
if (ticks % 10 != 0) {
return;
}
if (this.mg.config().gameConfig().gameMode == GameMode.FFA) {
this.checkWinnerFFA();
} else {
this.checkWinnerTeam();
}
}
checkWinnerFFA(): void {
const sorted = this.mg
.players()
.sort((a, b) => b.numTilesOwned() - a.numTilesOwned());
@@ -39,6 +47,30 @@ export class WinCheckExecution implements Execution {
}
}
checkWinnerTeam(): void {
const teamToTiles = new Map<Team, number>();
for (const player of this.mg.players()) {
teamToTiles.set(
player.team(),
(teamToTiles.get(player.team()) ?? 0) + player.numTilesOwned(),
);
}
const sorted = Array.from(teamToTiles.entries()).sort(
(a, b) => b[1] - a[1],
);
if (sorted.length == 0) {
return;
}
const max = sorted[0];
const numTilesWithoutFallout =
this.mg.numLandTiles() - this.mg.numTilesWithFallout();
const percentage = (max[1] / numTilesWithoutFallout) * 100;
if (percentage > this.mg.config().percentageTilesOwnedToWin()) {
this.mg.setWinner(max[0].name, this.mg.stats().stats());
console.log(`${max[0].name} has won the game`);
this.active = false;
}
}
owner(): Player {
return null;
}