From 5f26cf72c8496742f51490eee6dec9a9057ccf3e Mon Sep 17 00:00:00 2001 From: Evan Date: Tue, 18 Feb 2025 20:36:00 -0800 Subject: [PATCH] Make world & europe maps more likely for public multiplayer --- src/server/GameManager.ts | 24 +++++++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) diff --git a/src/server/GameManager.ts b/src/server/GameManager.ts index 103085334..c949ead5f 100644 --- a/src/server/GameManager.ts +++ b/src/server/GameManager.ts @@ -79,10 +79,28 @@ export class GameManager { } private getNextMap(): GameMapType { - if (this.mapsPlaylist.length == 0) { - this.mapsPlaylist = this.random.shuffleArray(Object.values(GameMapType)); + if (this.mapsPlaylist.length > 0) { + return this.mapsPlaylist.shift(); } - return this.mapsPlaylist.shift(); + while (true) { + this.mapsPlaylist = Object.values(GameMapType); + this.mapsPlaylist.push(GameMapType.World); + this.mapsPlaylist.push(GameMapType.Europe); + this.random.shuffleArray(this.mapsPlaylist); + if (this.allNonConsecutive(this.mapsPlaylist)) { + return this.mapsPlaylist.shift(); + } + } + } + + private allNonConsecutive(maps: GameMapType[]): boolean { + // Check for consecutive duplicates in the maps array + for (let i = 0; i < maps.length - 1; i++) { + if (maps[i] === maps[i + 1]) { + return false; + } + } + return true; } tick() {