mirror of
https://github.com/openfrontio/OpenFrontIO.git
synced 2026-06-23 23:43:37 +00:00
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:
@@ -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,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,
|
||||
|
||||
Reference in New Issue
Block a user