feat: eslint 적용 및 관련 코드 일괄 수정
This commit is contained in:
@@ -18,11 +18,7 @@ const asRecord = (value: unknown): Record<string, unknown> => {
|
||||
return value as Record<string, unknown>;
|
||||
};
|
||||
|
||||
const resolveNumber = (
|
||||
record: Record<string, unknown>,
|
||||
keys: string[],
|
||||
fallback: number
|
||||
): number => {
|
||||
const resolveNumber = (record: Record<string, unknown>, keys: string[], fallback: number): number => {
|
||||
for (const key of keys) {
|
||||
const value = record[key];
|
||||
if (typeof value === 'number' && Number.isFinite(value)) {
|
||||
@@ -32,10 +28,7 @@ const resolveNumber = (
|
||||
return fallback;
|
||||
};
|
||||
|
||||
const resolveUnitSetName = (
|
||||
worldState: WorldStateRow,
|
||||
fallback: string
|
||||
): string => {
|
||||
const resolveUnitSetName = (worldState: WorldStateRow, fallback: string): string => {
|
||||
const config = asRecord(worldState.config);
|
||||
const environment = asRecord(config.environment ?? config.map);
|
||||
const unitSet = environment.unitSet;
|
||||
@@ -76,9 +69,12 @@ const resolveCastleCrewTypeId = (unitSet: {
|
||||
return crewTypes[0]?.id ?? 0;
|
||||
};
|
||||
|
||||
const resolveCastleArmType = (unitSet: {
|
||||
crewTypes?: Array<{ id: number; armType: number }>;
|
||||
}, castleCrewTypeId: number): number => {
|
||||
const resolveCastleArmType = (
|
||||
unitSet: {
|
||||
crewTypes?: Array<{ id: number; armType: number }>;
|
||||
},
|
||||
castleCrewTypeId: number
|
||||
): number => {
|
||||
const crewTypes = unitSet.crewTypes ?? [];
|
||||
return crewTypes.find((crewType) => crewType.id === castleCrewTypeId)?.armType ?? 0;
|
||||
};
|
||||
@@ -93,39 +89,15 @@ export const buildBattleSimJobPayload = async (
|
||||
|
||||
const configRecord = asRecord(worldState.config);
|
||||
const constValues = asRecord(configRecord.const ?? configRecord.consts);
|
||||
const castleCrewTypeId = resolveNumber(
|
||||
constValues,
|
||||
['castleCrewTypeId'],
|
||||
resolveCastleCrewTypeId(unitSet)
|
||||
);
|
||||
const castleCrewTypeId = resolveNumber(constValues, ['castleCrewTypeId'], resolveCastleCrewTypeId(unitSet));
|
||||
const castleArmType = resolveCastleArmType(unitSet, castleCrewTypeId);
|
||||
|
||||
const config: WarEngineConfig = {
|
||||
armPerPhase: resolveNumber(
|
||||
constValues,
|
||||
['armPerPhase', 'armperphase'],
|
||||
DEFAULT_WAR_CONFIG.armPerPhase
|
||||
),
|
||||
maxTrainByCommand: resolveNumber(
|
||||
constValues,
|
||||
['maxTrainByCommand'],
|
||||
DEFAULT_WAR_CONFIG.maxTrainByCommand
|
||||
),
|
||||
maxAtmosByCommand: resolveNumber(
|
||||
constValues,
|
||||
['maxAtmosByCommand'],
|
||||
DEFAULT_WAR_CONFIG.maxAtmosByCommand
|
||||
),
|
||||
maxTrainByWar: resolveNumber(
|
||||
constValues,
|
||||
['maxTrainByWar'],
|
||||
DEFAULT_WAR_CONFIG.maxTrainByWar
|
||||
),
|
||||
maxAtmosByWar: resolveNumber(
|
||||
constValues,
|
||||
['maxAtmosByWar'],
|
||||
DEFAULT_WAR_CONFIG.maxAtmosByWar
|
||||
),
|
||||
armPerPhase: resolveNumber(constValues, ['armPerPhase', 'armperphase'], DEFAULT_WAR_CONFIG.armPerPhase),
|
||||
maxTrainByCommand: resolveNumber(constValues, ['maxTrainByCommand'], DEFAULT_WAR_CONFIG.maxTrainByCommand),
|
||||
maxAtmosByCommand: resolveNumber(constValues, ['maxAtmosByCommand'], DEFAULT_WAR_CONFIG.maxAtmosByCommand),
|
||||
maxTrainByWar: resolveNumber(constValues, ['maxTrainByWar'], DEFAULT_WAR_CONFIG.maxTrainByWar),
|
||||
maxAtmosByWar: resolveNumber(constValues, ['maxAtmosByWar'], DEFAULT_WAR_CONFIG.maxAtmosByWar),
|
||||
castleCrewTypeId,
|
||||
armTypes: {
|
||||
footman: 1,
|
||||
|
||||
@@ -4,9 +4,7 @@ export interface BattleSimQueueKeys {
|
||||
notifyKeyPrefix: string;
|
||||
}
|
||||
|
||||
export const buildBattleSimQueueKeys = (
|
||||
profileName: string
|
||||
): BattleSimQueueKeys => ({
|
||||
export const buildBattleSimQueueKeys = (profileName: string): BattleSimQueueKeys => ({
|
||||
queueKey: `sammo:${profileName}:battle-sim:queue`,
|
||||
resultKeyPrefix: `sammo:${profileName}:battle-sim:result:`,
|
||||
notifyKeyPrefix: `sammo:${profileName}:battle-sim:notify:`,
|
||||
|
||||
@@ -20,11 +20,7 @@ import {
|
||||
type WarActionModule,
|
||||
} from '@sammo-ts/logic';
|
||||
|
||||
import {
|
||||
type BattleSimJobPayload,
|
||||
type BattleSimLogBuckets,
|
||||
type BattleSimResultPayload,
|
||||
} from './types.js';
|
||||
import { type BattleSimJobPayload, type BattleSimLogBuckets, type BattleSimResultPayload } from './types.js';
|
||||
import { convertLog } from './logFormatter.js';
|
||||
|
||||
const DEFAULT_GENERAL_AGE = 20;
|
||||
@@ -33,8 +29,7 @@ const itemWarModules: WarActionModule[] = createItemActionModules(
|
||||
createItemModuleRegistry(await loadItemModules([...ITEM_KEYS]))
|
||||
).war;
|
||||
|
||||
const normalizeItemCode = (value: string | null): string | null =>
|
||||
value === 'None' ? null : value;
|
||||
const normalizeItemCode = (value: string | null): string | null => (value === 'None' ? null : value);
|
||||
|
||||
const mapNationPayload = (payload: BattleSimJobPayload['attackerNation']): Nation => ({
|
||||
id: payload.nation,
|
||||
@@ -81,9 +76,7 @@ const mapCityPayload = (payload: BattleSimJobPayload['attackerCity']): City => (
|
||||
},
|
||||
});
|
||||
|
||||
const mapGeneralPayload = (
|
||||
payload: BattleSimJobPayload['attackerGeneral']
|
||||
): General => ({
|
||||
const mapGeneralPayload = (payload: BattleSimJobPayload['attackerGeneral']): General => ({
|
||||
id: payload.no,
|
||||
name: payload.name,
|
||||
nationId: payload.nation,
|
||||
@@ -121,9 +114,7 @@ const mapGeneralPayload = (
|
||||
flags: {},
|
||||
counters: {},
|
||||
modifiers: {},
|
||||
meta: payload.inheritBuff
|
||||
? { inheritBuff: JSON.stringify(payload.inheritBuff) }
|
||||
: {},
|
||||
meta: payload.inheritBuff ? { inheritBuff: JSON.stringify(payload.inheritBuff) } : {},
|
||||
},
|
||||
meta: {
|
||||
explevel: payload.explevel,
|
||||
@@ -226,9 +217,7 @@ const resolveCityRiceConsumption = (options: {
|
||||
year: number;
|
||||
startYear: number;
|
||||
}): number => {
|
||||
const cityReport = options.battle.reports.find(
|
||||
(report) => report.type === 'city'
|
||||
);
|
||||
const cityReport = options.battle.reports.find((report) => report.type === 'city');
|
||||
if (!cityReport) {
|
||||
return 0;
|
||||
}
|
||||
@@ -236,9 +225,7 @@ const resolveCityRiceConsumption = (options: {
|
||||
return 0;
|
||||
}
|
||||
|
||||
const crewType = options.unitSet.crewTypes?.find(
|
||||
(item) => item.id === options.castleCrewTypeId
|
||||
);
|
||||
const crewType = options.unitSet.crewTypes?.find((item) => item.id === options.castleCrewTypeId);
|
||||
const riceCoef = crewType?.rice ?? 1;
|
||||
const tech = Number(options.defenderNation.meta.tech ?? 0);
|
||||
const trainAtmos = resolveCityTrainAtmos(options.year, options.startYear);
|
||||
@@ -346,9 +333,7 @@ export const processBattleSimJob = (payload: BattleSimJobPayload): BattleSimResu
|
||||
});
|
||||
|
||||
lastBattle = outcome;
|
||||
const attackerReport = outcome.reports.find(
|
||||
(report) => report.type === 'general' && report.isAttacker
|
||||
);
|
||||
const attackerReport = outcome.reports.find((report) => report.type === 'general' && report.isAttacker);
|
||||
const killed = attackerReport?.killed ?? 0;
|
||||
const dead = attackerReport?.dead ?? 0;
|
||||
|
||||
@@ -386,8 +371,7 @@ export const processBattleSimJob = (payload: BattleSimJobPayload): BattleSimResu
|
||||
|
||||
const attackerActivated = outcome.metrics?.attackerActivatedSkills ?? {};
|
||||
for (const [skillName, value] of Object.entries(attackerActivated)) {
|
||||
attackerSkills[skillName] =
|
||||
(attackerSkills[skillName] ?? 0) + value * weight;
|
||||
attackerSkills[skillName] = (attackerSkills[skillName] ?? 0) + value * weight;
|
||||
}
|
||||
|
||||
const defenderActivated = outcome.metrics?.defenderActivatedSkills ?? [];
|
||||
|
||||
@@ -3,10 +3,7 @@ import crypto from 'node:crypto';
|
||||
import type { BattleSimJobPayload, BattleSimResultPayload, BattleSimTransportResponse } from './types.js';
|
||||
import type { BattleSimQueueKeys } from './keys.js';
|
||||
|
||||
type RedisBlPopResult =
|
||||
| { key: string; element: string }
|
||||
| [string, string]
|
||||
| null;
|
||||
type RedisBlPopResult = { key: string; element: string } | [string, string] | null;
|
||||
|
||||
interface RedisClientLike {
|
||||
rPush(key: string, value: string): Promise<number>;
|
||||
@@ -22,8 +19,7 @@ export interface RedisBattleSimTransportOptions {
|
||||
resultTtlSeconds: number;
|
||||
}
|
||||
|
||||
const toTimeoutSeconds = (timeoutMs: number): number =>
|
||||
Math.max(1, Math.ceil(timeoutMs / 1000));
|
||||
const toTimeoutSeconds = (timeoutMs: number): number => Math.max(1, Math.ceil(timeoutMs / 1000));
|
||||
|
||||
const parseBlPopValue = (result: RedisBlPopResult): string | null => {
|
||||
if (!result) {
|
||||
|
||||
@@ -6,15 +6,7 @@ import { parseUnitSetDefinition, type UnitSetDefinition } from '@sammo-ts/logic'
|
||||
|
||||
const __filename = fileURLToPath(import.meta.url);
|
||||
const __dirname = path.dirname(__filename);
|
||||
const DEFAULT_UNIT_SET_ROOT = path.resolve(
|
||||
__dirname,
|
||||
'..',
|
||||
'..',
|
||||
'..',
|
||||
'game-engine',
|
||||
'resources',
|
||||
'unitset'
|
||||
);
|
||||
const DEFAULT_UNIT_SET_ROOT = path.resolve(__dirname, '..', '..', '..', 'game-engine', 'resources', 'unitset');
|
||||
|
||||
export interface UnitSetLoaderOptions {
|
||||
unitSetRoot?: string;
|
||||
@@ -26,20 +18,14 @@ const readJsonFile = async (filePath: string): Promise<unknown> => {
|
||||
return JSON.parse(raw) as unknown;
|
||||
};
|
||||
|
||||
const resolveUnitSetRoot = (options?: UnitSetLoaderOptions): string =>
|
||||
options?.unitSetRoot ?? DEFAULT_UNIT_SET_ROOT;
|
||||
const resolveUnitSetRoot = (options?: UnitSetLoaderOptions): string => options?.unitSetRoot ?? DEFAULT_UNIT_SET_ROOT;
|
||||
|
||||
export const resolveUnitSetDefinitionPath = (
|
||||
unitSetName: string,
|
||||
options?: UnitSetLoaderOptions
|
||||
): string => {
|
||||
export const resolveUnitSetDefinitionPath = (unitSetName: string, options?: UnitSetLoaderOptions): string => {
|
||||
const prefix = options?.filePrefix ?? 'unitset_';
|
||||
return path.resolve(resolveUnitSetRoot(options), `${prefix}${unitSetName}.json`);
|
||||
};
|
||||
|
||||
export const loadUnitSetDefinition = async (
|
||||
unitSetPath: string
|
||||
): Promise<UnitSetDefinition> => {
|
||||
export const loadUnitSetDefinition = async (unitSetPath: string): Promise<UnitSetDefinition> => {
|
||||
const raw = await readJsonFile(unitSetPath);
|
||||
return parseUnitSetDefinition(raw);
|
||||
};
|
||||
|
||||
@@ -6,10 +6,7 @@ import { processBattleSimJob } from './processor.js';
|
||||
import { RedisBattleSimTransport } from './redisTransport.js';
|
||||
import type { BattleSimJob } from './types.js';
|
||||
|
||||
type RedisBlPopResult =
|
||||
| { key: string; element: string }
|
||||
| [string, string]
|
||||
| null;
|
||||
type RedisBlPopResult = { key: string; element: string } | [string, string] | null;
|
||||
|
||||
const parseBlPopValue = (result: RedisBlPopResult): string | null => {
|
||||
if (!result) {
|
||||
@@ -57,8 +54,7 @@ export const runBattleSimWorker = async (): Promise<void> => {
|
||||
const result = processBattleSimJob(job.payload);
|
||||
await transport.pushResult(job.jobId, result);
|
||||
} catch (error) {
|
||||
const reason =
|
||||
error instanceof Error ? error.message : '전투 시뮬레이션 오류';
|
||||
const reason = error instanceof Error ? error.message : '전투 시뮬레이션 오류';
|
||||
await transport.pushResult(job.jobId, {
|
||||
result: false,
|
||||
reason,
|
||||
|
||||
Reference in New Issue
Block a user