mirror of
https://github.com/openfrontio/OpenFrontIO.git
synced 2026-07-09 07:03:14 +00:00
fix: new comments code rabbit
This commit is contained in:
@@ -1,13 +1,13 @@
|
||||
import { numPlayersConfig } from "../core/configuration/DefaultConfig";
|
||||
import { GameMapType, GameMode } from "../core/game/Game";
|
||||
import { MatchMode, matchModeToGameMode } from "./RankedGameConfig";
|
||||
|
||||
const MAP_CAPACITIES = numPlayersConfig;
|
||||
|
||||
export interface MapSelectionCriteria {
|
||||
playerCount: number;
|
||||
gameMode: GameMode;
|
||||
matchMode: MatchMode;
|
||||
queueType: "ranked" | "unranked";
|
||||
matchMode?: "ffa" | "team" | "duel" | "duos" | "trios" | "quads";
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -17,12 +17,14 @@ export interface MapSelectionCriteria {
|
||||
export function selectMapForRanked(
|
||||
criteria: MapSelectionCriteria,
|
||||
): GameMapType {
|
||||
const { playerCount, gameMode, matchMode } = criteria;
|
||||
const { playerCount, matchMode } = criteria;
|
||||
|
||||
if (matchMode === "duel") {
|
||||
return GameMapType.Australia;
|
||||
}
|
||||
|
||||
const gameMode = matchModeToGameMode(matchMode);
|
||||
|
||||
// Get maps that can handle this player count
|
||||
const suitableMaps = getSuitableMaps(playerCount);
|
||||
|
||||
|
||||
@@ -10,13 +10,21 @@ import {
|
||||
} from "../core/game/Game";
|
||||
import { GameConfig, TeamCountConfig } from "../core/Schemas";
|
||||
|
||||
export type MatchMode = "ffa" | "team" | "duel" | "duos" | "trios" | "quads";
|
||||
|
||||
export interface RankedMatchConfig {
|
||||
queueType: "ranked" | "unranked";
|
||||
gameMode: "ffa" | "team" | "duel" | "duos" | "trios" | "quads";
|
||||
gameMode: MatchMode;
|
||||
playerCount: number;
|
||||
teamConfig?: TeamCountConfig;
|
||||
}
|
||||
|
||||
export function matchModeToGameMode(matchMode: MatchMode): GameMode {
|
||||
if (matchMode === "duel") return GameMode.Duel;
|
||||
if (matchMode === "ffa") return GameMode.FFA;
|
||||
return GameMode.Team;
|
||||
}
|
||||
|
||||
/**
|
||||
* Build a complete GameConfig for a ranked match
|
||||
* Uses the same bot rules as public games (400 bots)
|
||||
@@ -29,16 +37,8 @@ export function buildRankedGameConfig(
|
||||
const { gameMode, playerCount } = matchConfig;
|
||||
const isDuel = gameMode === "duel";
|
||||
const isFFA = gameMode === "ffa";
|
||||
const isTeamMode =
|
||||
gameMode === "team" ||
|
||||
gameMode === "duos" ||
|
||||
gameMode === "trios" ||
|
||||
gameMode === "quads";
|
||||
const mode = isDuel
|
||||
? GameMode.Duel
|
||||
: isTeamMode
|
||||
? GameMode.Team
|
||||
: GameMode.FFA;
|
||||
const isTeamMode = !isDuel && !isFFA;
|
||||
const mode = matchModeToGameMode(gameMode);
|
||||
|
||||
// Determine team configuration based on game mode
|
||||
let teamConfig: TeamCountConfig | undefined = matchConfig.teamConfig;
|
||||
|
||||
+10
-18
@@ -8,7 +8,7 @@ import { fileURLToPath } from "url";
|
||||
import { WebSocket, WebSocketServer } from "ws";
|
||||
import { z } from "zod";
|
||||
import { getServerConfigFromServer } from "../core/configuration/ConfigLoader";
|
||||
import { GameMode, GameType } from "../core/game/Game";
|
||||
import { GameType } from "../core/game/Game";
|
||||
import {
|
||||
ClientMessageSchema,
|
||||
GameID,
|
||||
@@ -80,16 +80,10 @@ export async function startWorker() {
|
||||
config,
|
||||
log,
|
||||
async (gameId, assignment) => {
|
||||
// Select map based on player count and mode
|
||||
const selectedMap = selectMapForRanked({
|
||||
playerCount: assignment.config.playerCount,
|
||||
gameMode:
|
||||
assignment.config.gameMode === "ffa" ||
|
||||
assignment.config.gameMode === "duel"
|
||||
? GameMode.FFA
|
||||
: GameMode.Team,
|
||||
queueType: assignment.config.queueType,
|
||||
matchMode: assignment.config.gameMode,
|
||||
queueType: assignment.config.queueType,
|
||||
});
|
||||
|
||||
// Build full game config
|
||||
@@ -98,7 +92,6 @@ export async function startWorker() {
|
||||
assignment.config,
|
||||
);
|
||||
|
||||
// Create game
|
||||
gm.createGame(gameId, gameConfig);
|
||||
|
||||
log.info("Created ranked match", {
|
||||
@@ -108,8 +101,13 @@ export async function startWorker() {
|
||||
players: assignment.config.playerCount,
|
||||
});
|
||||
|
||||
// TODO: Notify players to connect to this game
|
||||
// Players already have gameId from Lobby websocket
|
||||
setTimeout(() => {
|
||||
const game = gm.game(gameId);
|
||||
if (game && !game.hasStarted()) {
|
||||
log.info(`Starting ranked match ${gameId}`);
|
||||
game.start();
|
||||
}
|
||||
}, 5000);
|
||||
},
|
||||
() => gm.activeClients(), // Get CCU from GameManager
|
||||
);
|
||||
@@ -586,16 +584,10 @@ async function pollLobby(gm: GameManager) {
|
||||
const assignment = data.assignment;
|
||||
log.info(`Creating game ${gameId} with assignment`, assignment.config);
|
||||
|
||||
// Select map based on player count and mode
|
||||
const selectedMap = selectMapForRanked({
|
||||
playerCount: assignment.config.playerCount,
|
||||
gameMode:
|
||||
assignment.config.gameMode === "ffa" ||
|
||||
assignment.config.gameMode === "duel"
|
||||
? GameMode.FFA
|
||||
: GameMode.Team,
|
||||
queueType: assignment.config.queueType,
|
||||
matchMode: assignment.config.gameMode,
|
||||
queueType: assignment.config.queueType,
|
||||
});
|
||||
|
||||
// Build full game config using assignment config
|
||||
|
||||
Reference in New Issue
Block a user