refactor: tighten backend and logic boundaries
This commit is contained in:
@@ -8,19 +8,6 @@ import { che_필살발동, che_필살시도 } from './triggers/che_필살.js';
|
||||
import { che_회피발동, che_회피시도 } from './triggers/che_회피.js';
|
||||
import { che_계략발동, che_계략실패, che_계략시도 } from './triggers/che_계략.js';
|
||||
|
||||
export const CREW_TYPE_WAR_TRIGGER_KEYS = [
|
||||
'che_성벽부상무효',
|
||||
'che_기병병종전투',
|
||||
'che_방어력증가5p',
|
||||
'che_선제사격시도',
|
||||
'che_선제사격발동',
|
||||
'che_저지시도',
|
||||
'che_저지발동',
|
||||
'che_필살',
|
||||
'che_회피',
|
||||
'che_계략',
|
||||
] as const;
|
||||
|
||||
export const createCrewTypeWarTriggerRegistry = (): WarTriggerRegistry => ({
|
||||
che_성벽부상무효: (unit) => new che_성벽부상무효(unit),
|
||||
che_기병병종전투: (unit) => new che_기병병종전투(unit),
|
||||
@@ -31,6 +18,5 @@ export const createCrewTypeWarTriggerRegistry = (): WarTriggerRegistry => ({
|
||||
che_저지발동: (unit) => new che_저지(unit),
|
||||
che_필살: (unit) => new WarTriggerCaller(new che_필살시도(unit), new che_필살발동(unit)),
|
||||
che_회피: (unit) => new WarTriggerCaller(new che_회피시도(unit), new che_회피발동(unit)),
|
||||
che_계략: (unit) =>
|
||||
new WarTriggerCaller(new che_계략시도(unit), new che_계략발동(unit), new che_계략실패(unit)),
|
||||
che_계략: (unit) => new WarTriggerCaller(new che_계략시도(unit), new che_계략발동(unit), new che_계략실패(unit)),
|
||||
});
|
||||
|
||||
@@ -2,9 +2,8 @@ import { JosaUtil } from '@sammo-ts/common';
|
||||
|
||||
import { LogFormat } from '@sammo-ts/logic/logging/types.js';
|
||||
import { TriggerPriority } from '@sammo-ts/logic/triggers/core.js';
|
||||
import { BaseWarUnitTrigger, WarTriggerCaller } from '@sammo-ts/logic/war/triggers.js';
|
||||
import { BaseWarUnitTrigger } from '@sammo-ts/logic/war/triggers.js';
|
||||
import { WarUnitCity, WarUnitGeneral, type WarUnit } from '@sammo-ts/logic/war/units.js';
|
||||
import type { WarTriggerModule } from './types.js';
|
||||
|
||||
const MAGIC_TO_GENERAL = {
|
||||
위보: [1.2, 1.1],
|
||||
@@ -83,13 +82,7 @@ export class che_계략시도 extends BaseWarUnitTrigger {
|
||||
const table = oppose instanceof WarUnitCity ? MAGIC_TO_CITY : MAGIC_TO_GENERAL;
|
||||
const magic = self.rng.choice(Object.keys(table));
|
||||
const [rawSuccessDamage, failDamage] = table[magic as keyof typeof table];
|
||||
const successDamage = applyMagicDamageModifiers(
|
||||
self,
|
||||
oppose,
|
||||
'warMagicSuccessDamage',
|
||||
rawSuccessDamage,
|
||||
magic
|
||||
);
|
||||
const successDamage = applyMagicDamageModifiers(self, oppose, 'warMagicSuccessDamage', rawSuccessDamage, magic);
|
||||
|
||||
self.activateSkill('계략시도', magic);
|
||||
if (self.rng.nextBool(successProbability)) {
|
||||
@@ -145,7 +138,8 @@ export class che_계략실패 extends BaseWarUnitTrigger {
|
||||
selfEnv: Record<string, unknown>,
|
||||
_opposeEnv: Record<string, unknown>
|
||||
): boolean {
|
||||
if (!(self instanceof WarUnitGeneral) || !self.hasActivatedSkill('계략실패') || selfEnv['계략실패']) return true;
|
||||
if (!(self instanceof WarUnitGeneral) || !self.hasActivatedSkill('계략실패') || selfEnv['계략실패'])
|
||||
return true;
|
||||
const magicState = readMagic(selfEnv);
|
||||
if (!magicState) return true;
|
||||
selfEnv['계략실패'] = true;
|
||||
@@ -159,11 +153,3 @@ export class che_계략실패 extends BaseWarUnitTrigger {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
export const triggerModule: WarTriggerModule = {
|
||||
key: 'che_계략',
|
||||
name: '계략',
|
||||
info: '[전투] 귀병의 계략 시도/성공/실패',
|
||||
createTriggerList: (unit) =>
|
||||
new WarTriggerCaller(new che_계략시도(unit), new che_계략발동(unit), new che_계략실패(unit)),
|
||||
};
|
||||
|
||||
@@ -1,8 +1,7 @@
|
||||
import { LogFormat } from '@sammo-ts/logic/logging/types.js';
|
||||
import { TriggerPriority } from '@sammo-ts/logic/triggers/core.js';
|
||||
import { BaseWarUnitTrigger, WarTriggerCaller } from '@sammo-ts/logic/war/triggers.js';
|
||||
import { BaseWarUnitTrigger } from '@sammo-ts/logic/war/triggers.js';
|
||||
import { WarUnitGeneral, type WarUnit } from '@sammo-ts/logic/war/units.js';
|
||||
import type { WarTriggerModule } from './types.js';
|
||||
|
||||
export class che_회피시도 extends BaseWarUnitTrigger {
|
||||
constructor(unit: WarUnit) {
|
||||
@@ -41,10 +40,3 @@ export class che_회피발동 extends BaseWarUnitTrigger {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
export const triggerModule: WarTriggerModule = {
|
||||
key: 'che_회피',
|
||||
name: '회피',
|
||||
info: '[전투] 페이즈마다 확률로 회피 발동',
|
||||
createTriggerList: (unit) => new WarTriggerCaller(new che_회피시도(unit), new che_회피발동(unit)),
|
||||
};
|
||||
|
||||
@@ -1,9 +1,6 @@
|
||||
import type { WarTriggerModule, WarTriggerModuleExport } from './types.js';
|
||||
import type { WarTriggerRegistry } from '@sammo-ts/logic/war/triggers.js';
|
||||
|
||||
export const WAR_TRIGGER_KEYS = ['che_필살', 'che_의술'] as const;
|
||||
|
||||
export type WarTriggerKey = (typeof WAR_TRIGGER_KEYS)[number];
|
||||
export type WarTriggerKey = 'che_필살' | 'che_의술';
|
||||
|
||||
export type WarTriggerImporter = () => Promise<WarTriggerModuleExport>;
|
||||
|
||||
@@ -12,9 +9,6 @@ const defaultImporters: Record<WarTriggerKey, WarTriggerImporter> = {
|
||||
che_의술: async () => import('./che_의술.js'),
|
||||
};
|
||||
|
||||
export const isWarTriggerKey = (value: string): value is WarTriggerKey =>
|
||||
WAR_TRIGGER_KEYS.includes(value as WarTriggerKey);
|
||||
|
||||
export class WarTriggerLoader {
|
||||
private readonly cache = new Map<WarTriggerKey, Promise<WarTriggerModule>>();
|
||||
|
||||
@@ -60,12 +54,4 @@ export const loadWarTriggerModules = async (
|
||||
return modules;
|
||||
};
|
||||
|
||||
export const createWarTriggerRegistry = (modules: WarTriggerModule[]): WarTriggerRegistry => {
|
||||
const registry: WarTriggerRegistry = {};
|
||||
for (const module of modules) {
|
||||
registry[module.key] = (unit) => module.createTriggerList(unit);
|
||||
}
|
||||
return registry;
|
||||
};
|
||||
|
||||
export type { WarTriggerModule, WarTriggerModuleExport } from './types.js';
|
||||
|
||||
@@ -1,3 +1,3 @@
|
||||
export { WarUnit, WAR_CRITICAL_RANGE, resolveNationTech } from './units/base.js';
|
||||
export { WarUnit } from './units/base.js';
|
||||
export { WarUnitGeneral } from './units/general.js';
|
||||
export { WarUnitCity } from './units/city.js';
|
||||
|
||||
@@ -9,8 +9,6 @@ export const clamp = (value: number, min: number, max: number): number => Math.m
|
||||
|
||||
export const clampMin = (value: number, min: number): number => (value < min ? min : value);
|
||||
|
||||
export const clampMax = (value: number, max: number): number => (value > max ? max : value);
|
||||
|
||||
// REF-COMPAT:BEGIN ref-php-half-rounding
|
||||
// PHP's round() compensates for small binary floating-point drift around a
|
||||
// half boundary and rounds halves away from zero. War state is persisted to
|
||||
@@ -36,11 +34,6 @@ export const getMetaNumber = (meta: Record<string, TriggerValue>, key: string, f
|
||||
return typeof value === 'number' && Number.isFinite(value) ? value : fallback;
|
||||
};
|
||||
|
||||
export const getMetaString = (meta: Record<string, TriggerValue>, key: string): string | null => {
|
||||
const value = meta[key];
|
||||
return typeof value === 'string' ? value : null;
|
||||
};
|
||||
|
||||
export const setMetaNumber = (meta: Record<string, TriggerValue>, key: string, value: number): void => {
|
||||
meta[key] = round(value);
|
||||
};
|
||||
@@ -120,23 +113,6 @@ export const sortConflictEntries = (
|
||||
.map(([key, value]) => [key, value] as const);
|
||||
};
|
||||
|
||||
export const stringifyConflict = (conflict: Record<number, number> | null): string => {
|
||||
if (!conflict) {
|
||||
return '{}';
|
||||
}
|
||||
const sorted = Object.entries(conflict)
|
||||
.map(([key, value]) => [Number(key), value] as const)
|
||||
.filter(([key, value]) => Number.isFinite(key) && typeof value === 'number')
|
||||
.sort(([, lhs], [, rhs]) => rhs - lhs);
|
||||
|
||||
const ordered: Record<string, number> = {};
|
||||
for (const [key, value] of sorted) {
|
||||
ordered[String(key)] = value;
|
||||
}
|
||||
|
||||
return JSON.stringify(ordered);
|
||||
};
|
||||
|
||||
export const sortConflict = (
|
||||
conflict: Record<number, number>,
|
||||
preferredOrder: number[] = []
|
||||
|
||||
Reference in New Issue
Block a user