feat: port scenario action effects

This commit is contained in:
2026-07-30 19:00:04 +00:00
parent 7f31459385
commit c68d992046
39 changed files with 1131 additions and 95 deletions
+1
View File
@@ -1,2 +1,3 @@
export * from './types.js';
export * from './parseScenario.js';
export * from './scenarioEffect.js';
+3 -5
View File
@@ -13,6 +13,7 @@ import type {
ScenarioNation,
ScenarioStatBlock,
} from './types.js';
import { normalizeScenarioEffect } from './scenarioEffect.js';
type UnknownRecord = Record<string, unknown>;
@@ -45,12 +46,9 @@ const parseScenarioEnvironment = (mapConfig: UnknownRecord, constConfig: Unknown
const merged = { ...mapConfig, ...constConfig };
const mapName = asString(merged.mapName, 'che');
const unitSet = asString(merged.unitSet, 'che');
const scenarioEffect =
typeof merged.scenarioEffect === 'string' || merged.scenarioEffect === null ? merged.scenarioEffect : undefined;
const result: ScenarioEnvironment = { mapName, unitSet };
if (scenarioEffect !== undefined) {
result.scenarioEffect = scenarioEffect;
if (Object.hasOwn(merged, 'scenarioEffect')) {
result.scenarioEffect = normalizeScenarioEffect(merged.scenarioEffect);
}
return result;
};
@@ -0,0 +1,31 @@
export const SCENARIO_EFFECT_KEYS = [
'event_UnlimitedDefenceThresholdChange',
'event_StrongAttacker',
'event_MoreEffect',
] as const;
export type ScenarioEffectKey = (typeof SCENARIO_EFFECT_KEYS)[number];
const DEFENCE_TRAIN_PENALTY_WAIVER_EFFECTS = new Set<ScenarioEffectKey>([
'event_UnlimitedDefenceThresholdChange',
'event_StrongAttacker',
'event_MoreEffect',
]);
export const isScenarioEffectKey = (value: string): value is ScenarioEffectKey =>
SCENARIO_EFFECT_KEYS.includes(value as ScenarioEffectKey);
export const normalizeScenarioEffect = (value: unknown): ScenarioEffectKey | null => {
if (value === undefined || value === null || value === '' || value === 'None') {
return null;
}
if (typeof value === 'string' && isScenarioEffectKey(value)) {
return value;
}
throw new Error(`Unknown scenario effect: ${String(value)}`);
};
export const isDefenceTrainPenaltyWaivedByScenarioEffect = (value: string | null | undefined): boolean => {
const effect = normalizeScenarioEffect(value);
return effect !== null && DEFENCE_TRAIN_PENALTY_WAIVER_EFFECTS.has(effect);
};
+2 -1
View File
@@ -16,7 +16,7 @@ export interface ScenarioDefaults {
export interface ScenarioEnvironment {
mapName: string;
unitSet: string;
scenarioEffect?: string | null;
scenarioEffect?: ScenarioEffectKey | null;
}
export interface ScenarioConfig {
@@ -86,3 +86,4 @@ export interface ScenarioDefinition {
initialEvents: unknown[];
ignoreDefaultEvents: boolean;
}
import type { ScenarioEffectKey } from './scenarioEffect.js';