Public lobbies map will now be picked from a randomized playlist, assuring each map is played at least once, without duplicates.

This commit is contained in:
NewHappyRabbit
2025-02-17 21:32:36 +02:00
parent 0f325d4be8
commit 2249f5207e
2 changed files with 18 additions and 1 deletions
+9
View File
@@ -47,4 +47,13 @@ export class PseudoRandom {
chance(odds: number): boolean {
return this.nextInt(0, odds) == 0;
}
shuffleArray(array: any[]) {
for (let i = array.length - 1; i >= 0; i--) {
const j = Math.floor(Math.random() * (i + 1));
[array[i], array[j]] = [array[j], array[i]];
}
return array;
}
}
+9 -1
View File
@@ -9,6 +9,7 @@ import { PseudoRandom } from "../core/PseudoRandom";
export class GameManager {
private lastNewLobby: number = 0;
private mapsPlaylist: GameMapType[] = [];
private games: GameServer[] = [];
@@ -77,6 +78,13 @@ export class GameManager {
}
}
private getNextMap(): GameMapType {
if (this.mapsPlaylist.length == 0) {
this.mapsPlaylist = this.random.shuffleArray(Object.values(GameMapType));
}
return this.mapsPlaylist.shift();
}
tick() {
const lobbies = this.gamesByPhase(GamePhase.Lobby);
const active = this.gamesByPhase(GamePhase.Active);
@@ -87,7 +95,7 @@ export class GameManager {
this.lastNewLobby = now;
lobbies.push(
new GameServer(generateID(), now, true, this.config, {
gameMap: this.random.randElement(Object.values(GameMapType)),
gameMap: this.getNextMap(),
gameType: GameType.Public,
difficulty: Difficulty.Medium,
disableBots: false,