Files
WT-Offline/packages/local-service/src/game-modes/mode-definition.ts
T
N0VAN0M4LY b260d2899e chore(battle): snapshot the LocalMP rework baseline
Records the uncommitted battle-session work exactly as it was left
(local service matchmaking, settlement, chat, native LocalMP hooks,
battle gui/exe patches) so the following review and rework commits
show every correction as a diff against this state.

This commit is not reviewed and is known to be incomplete: in-game
testing reported wrong settlement rewards, single-country teams,
missing random/fixed supplement slots, misattributed hit messages and
other regressions. Do not merge this branch before the rework lands.
2026-11-28 03:15:47 +08:00

99 lines
4.6 KiB
TypeScript

/**
* A game mode in the form the stock UI reads from the matching server
* (match.fetch_game_modes_info, docs/implementation notes):
*
* - difficulty: the matching name (scripts/difficulty.nut matchingName: arcade, realistic,
* simulation); mission_decl.difficulty: the mission name of the same difficulty
* (arcade, realistic, hardcore; scripts/events/eventsManager.nut diffTable).
* - teamA / teamB: identical, so the UI treats the mode as symmetric
* (scripts/events/eventTeamsInfo.nut initSidesOnce); a missing team B would count as
* playable and mark the mode invalid. Craft rules name a vehicle class; requiredCrafts
* is what greys the mode out for a player without that class (gameModeManagerState.nut
* createEventGameMode).
* - mission_decl.missions_list: mission name -> {} (a value may carry "enableIf" rank
* limits, scripts/missions/mapPreferencesParams.nut; none are set).
* - tag: required, the script reads it unguarded (scripts/matching/matchingGameModes.nut,
* onGameModesUpdated; local verification stopped there without it). Tag prefixes mark sub-modes
* (night battles, small teams, bullet hell, nuclear escalation, naval EC;
* SUB_GAME_MODE_TAG_PREFIXES in matchingGameModes.nut:28-42).
* - rankCalcMode: required, read unguarded when the slotbar computes the lineup's battle
* rating (scripts/slotbar/slotbarPresets/calcRanks.nut calculateBR; local verification).
* "average" or "maximum" (lang: multiplayer/battleRatingCalcHint/*); random battles
* take the highest battle rating of the lineup.
*
* Fields the stock scripts read unguarded only in later stages are not set yet:
* suggestToChangeTeamOnQueueDisbalanceSec (queueing for an event, eventsHandler.nut) and
* missionsBanMode (map preferences; absent means none, mapPreferencesParams.nut).
*/
import type { MissionHeader } from '../game-data/datasets/multiplayer-missions.ts';
import type { GameModeDeclaration, ModeDifficulty } from './catalogue/game-mode-declaration.ts';
const MATCHING_DIFFICULTY: Readonly<Record<ModeDifficulty, string>> = {
arcade: 'arcade',
realistic: 'realistic',
simulator: 'simulation',
};
export const MISSION_DIFFICULTY: Readonly<Record<ModeDifficulty, string>> = {
arcade: 'arcade',
realistic: 'realistic',
simulator: 'hardcore',
};
export type ModeDefinition = Readonly<Record<string, unknown>>;
export function buildModeDefinition(mode: GameModeDeclaration, missions: readonly MissionHeader[],
countries: readonly string[]): ModeDefinition {
const minTeamSize = mode.teamSizeOverride?.min ?? 1;
const maxTeamSize = mode.teamSizeOverride?.max ?? teamSize(mode, missions);
const team = {
countries: [...countries],
allowedCrafts: mode.allowedClasses.map((unitClass) => {
const minMrank = mode.allowedCraftMinMrank?.[unitClass];
return minMrank === undefined
? { class: unitClass }
: { class: unitClass, mranks: { min: minMrank } };
}),
requiredCrafts: [{ class: mode.requiredClass }],
minTeamSize,
maxTeamSize,
};
return {
gameModeId: mode.gameModeId,
name: mode.name,
tag: mode.tag ?? '',
economicName: mode.economicName,
loc_name: mode.locName,
difficulty: MATCHING_DIFFICULTY[mode.difficulty],
rankCalcMode: 'maximum',
displayType: mode.displayType,
multiSlot: mode.multiSlot ?? true,
minTeamSize,
...(mode.chapter === undefined ? {} : { chapter: mode.chapter }),
...(mode.minCraftsToPlay === undefined ? {} : { minCraftsToPlay: mode.minCraftsToPlay }),
...(mode.minMRankForNightBattles === undefined ? {} : { minMRankForNightBattles: mode.minMRankForNightBattles }),
...(mode.minMRankForSmallTeamsBattles === undefined ? {} : { minMRankForSmallTeamsBattles: mode.minMRankForSmallTeamsBattles }),
visible: true,
disabled: false,
teamA: team,
teamB: structuredClone(team),
mission_decl: {
difficulty: MISSION_DIFFICULTY[mode.difficulty],
missions_list: Object.fromEntries(missions.map((mission) => [mission.name, {}])),
},
};
}
/**
* The fewest player spawn slots per side among the missions, so every mission can hold a
* full team. A side without player slots is the AI side of a PvE mission and is not counted.
*/
function teamSize(mode: GameModeDeclaration, missions: readonly MissionHeader[]): number {
const slots = missions.flatMap(({ playerSlots: { teamA, teamB } }) => {
const sides = [teamA, teamB].filter((count) => count > 0);
return sides.length ? [Math.min(...sides)] : [];
});
if (!slots.length) throw new Error(`game mode ${mode.name}: none of its missions lists player spawn slots`);
return Math.min(...slots);
}