feat: 여러 아이템의 onCalcStat 함수 개선 및 통일성 있는 statValue 상수화

This commit is contained in:
2026-01-17 16:19:49 +00:00
parent d78fab4e6c
commit 1b7423e1f6
12 changed files with 106 additions and 114 deletions
@@ -4,12 +4,14 @@ import type { WarActionContext } from '@sammo-ts/logic/war/actions.js';
import { createStatItemModule } from './base.js'; import { createStatItemModule } from './base.js';
import type { ItemModule } from './types.js'; import type { ItemModule } from './types.js';
const STAT_VALUE = 7;
const baseModule = createStatItemModule({ const baseModule = createStatItemModule({
key: 'che_명마_07_백상', key: 'che_명마_07_백상',
rawName: '백상', rawName: '백상',
slot: 'horse', slot: 'horse',
statName: 'leadership', statName: 'leadership',
statValue: 7, statValue: STAT_VALUE,
cost: 200, cost: 200,
buyable: false, buyable: false,
reqSecu: 0, reqSecu: 0,
@@ -20,22 +22,20 @@ const baseModule = createStatItemModule({
export const itemModule: ItemModule = { export const itemModule: ItemModule = {
...baseModule, ...baseModule,
onCalcStat: function ( onCalcStat: function (
context: GeneralActionContext | WarActionContext, _context: GeneralActionContext | WarActionContext,
statName: GeneralStatName | WarStatName, statName: GeneralStatName | WarStatName,
value: unknown, value: number | [number, number],
aux?: unknown _aux?: unknown
): unknown { ): number | [number, number] {
const newValue = baseModule.onCalcStat!( let newValue: number | [number, number] = value;
context as unknown as GeneralActionContext, if (statName === 'leadership' && typeof value === 'number') {
statName as unknown as GeneralStatName, newValue = value + STAT_VALUE;
value as unknown as number,
aux
);
if (statName === 'killRice') {
return (newValue as number) * 1.1;
} }
if (statName === 'initWarPhase') { if (statName === 'killRice' && typeof newValue === 'number') {
return (newValue as number) - 1; return newValue * 1.1;
}
if (statName === 'initWarPhase' && typeof newValue === 'number') {
return newValue - 1;
} }
return newValue; return newValue;
} as NonNullable<ItemModule['onCalcStat']>, } as NonNullable<ItemModule['onCalcStat']>,
@@ -4,12 +4,14 @@ import type { WarActionContext } from '@sammo-ts/logic/war/actions.js';
import { createStatItemModule } from './base.js'; import { createStatItemModule } from './base.js';
import type { ItemModule } from './types.js'; import type { ItemModule } from './types.js';
const STAT_VALUE = 12;
const baseModule = createStatItemModule({ const baseModule = createStatItemModule({
key: 'che_명마_12_옥란백용구', key: 'che_명마_12_옥란백용구',
rawName: '옥란백용구', rawName: '옥란백용구',
slot: 'horse', slot: 'horse',
statName: 'leadership', statName: 'leadership',
statValue: 12, statValue: STAT_VALUE,
cost: 200, cost: 200,
buyable: false, buyable: false,
reqSecu: 0, reqSecu: 0,
@@ -22,20 +24,18 @@ export const itemModule: ItemModule = {
onCalcStat: function ( onCalcStat: function (
context: GeneralActionContext | WarActionContext, context: GeneralActionContext | WarActionContext,
statName: GeneralStatName | WarStatName, statName: GeneralStatName | WarStatName,
value: unknown, value: number | [number, number],
aux?: unknown _aux?: unknown
): unknown { ): number | [number, number] {
const newValue = baseModule.onCalcStat!( let newValue: number | [number, number] = value;
context as unknown as GeneralActionContext, if (statName === 'leadership' && typeof value === 'number') {
statName as unknown as GeneralStatName, newValue = value + STAT_VALUE;
value as unknown as number, }
aux if (statName === 'warAvoidRatio' && typeof newValue === 'number') {
); const { leadership } = context.general.stats;
if (statName === 'warAvoidRatio') { const crewL = context.general.crew / 100;
const { leadership } = (context as unknown as GeneralActionContext).general.stats;
const crewL = (context as unknown as GeneralActionContext).general.crew / 100;
const boost = (1 - crewL / leadership) * 0.5; const boost = (1 - crewL / leadership) * 0.5;
return (newValue as number) + Math.min(Math.max(boost, 0), 0.5); return newValue + Math.min(Math.max(boost, 0), 0.5);
} }
return newValue; return newValue;
} as NonNullable<ItemModule['onCalcStat']>, } as NonNullable<ItemModule['onCalcStat']>,
@@ -21,10 +21,10 @@ export const itemModule: ItemModule = {
onCalcStat: function ( onCalcStat: function (
_context: GeneralActionContext | WarActionContext, _context: GeneralActionContext | WarActionContext,
statName: GeneralStatName | WarStatName, statName: GeneralStatName | WarStatName,
value: unknown value: number | [number, number]
): unknown { ): number | [number, number] {
if (statName === ('injuryProb' as unknown as WarStatName)) { if (statName === 'injuryProb' && typeof value === 'number') {
return (value as number) - 1; return value - 1;
} }
return value; return value;
} as NonNullable<ItemModule['onCalcStat']>, } as NonNullable<ItemModule['onCalcStat']>,
@@ -21,19 +21,17 @@ const baseModule = createStatItemModule({
export const itemModule: ItemModule = { export const itemModule: ItemModule = {
...baseModule, ...baseModule,
onCalcStat: function ( onCalcStat: function (
context: GeneralActionContext | WarActionContext, _context: GeneralActionContext | WarActionContext,
statName: GeneralStatName | WarStatName, statName: GeneralStatName | WarStatName,
value: unknown, value: number | [number, number],
aux?: unknown _aux?: unknown
): unknown { ): number | [number, number] {
const newValue = baseModule.onCalcStat!( let newValue: number | [number, number] = value;
context as unknown as GeneralActionContext, if (statName === 'intelligence' && typeof value === 'number') {
statName as unknown as GeneralStatName, newValue = value + STAT_VALUE;
value as unknown as number, }
aux if (statName === 'warMagicTrialProb' && typeof newValue === 'number') {
); return newValue + 0.01;
if (statName === 'warMagicTrialProb') {
return (newValue as number) + 0.01;
} }
return newValue; return newValue;
} as NonNullable<ItemModule['onCalcStat']>, } as NonNullable<ItemModule['onCalcStat']>,
@@ -21,19 +21,17 @@ const baseModule = createStatItemModule({
export const itemModule: ItemModule = { export const itemModule: ItemModule = {
...baseModule, ...baseModule,
onCalcStat: function ( onCalcStat: function (
context: GeneralActionContext | WarActionContext, _context: GeneralActionContext | WarActionContext,
statName: GeneralStatName | WarStatName, statName: GeneralStatName | WarStatName,
value: unknown, value: number | [number, number],
aux?: unknown _aux?: unknown
): unknown { ): number | [number, number] {
const newValue = baseModule.onCalcStat!( let newValue: number | [number, number] = value;
context as unknown as GeneralActionContext, if (statName === 'intelligence' && typeof value === 'number') {
statName as unknown as GeneralStatName, newValue = value + STAT_VALUE;
value as unknown as number, }
aux if (statName === 'warMagicTrialProb' && typeof newValue === 'number') {
); return newValue + 0.01;
if (statName === 'warMagicTrialProb') {
return (newValue as number) + 0.01;
} }
return newValue; return newValue;
} as NonNullable<ItemModule['onCalcStat']>, } as NonNullable<ItemModule['onCalcStat']>,
@@ -21,19 +21,17 @@ const baseModule = createStatItemModule({
export const itemModule: ItemModule = { export const itemModule: ItemModule = {
...baseModule, ...baseModule,
onCalcStat: function ( onCalcStat: function (
context: GeneralActionContext | WarActionContext, _context: GeneralActionContext | WarActionContext,
statName: GeneralStatName | WarStatName, statName: GeneralStatName | WarStatName,
value: unknown, value: number | [number, number],
aux?: unknown _aux?: unknown
): unknown { ): number | [number, number] {
const newValue = baseModule.onCalcStat!( let newValue: number | [number, number] = value;
context as unknown as GeneralActionContext, if (statName === 'intelligence' && typeof value === 'number') {
statName as unknown as GeneralStatName, newValue = value + STAT_VALUE;
value as unknown as number, }
aux if (statName === 'warMagicTrialProb' && typeof newValue === 'number') {
); return newValue + 0.02;
if (statName === 'warMagicTrialProb') {
return (newValue as number) + 0.02;
} }
return newValue; return newValue;
} as NonNullable<ItemModule['onCalcStat']>, } as NonNullable<ItemModule['onCalcStat']>,
@@ -21,19 +21,17 @@ const baseModule = createStatItemModule({
export const itemModule: ItemModule = { export const itemModule: ItemModule = {
...baseModule, ...baseModule,
onCalcStat: function ( onCalcStat: function (
context: GeneralActionContext | WarActionContext, _context: GeneralActionContext | WarActionContext,
statName: GeneralStatName | WarStatName, statName: GeneralStatName | WarStatName,
value: unknown, value: number | [number, number],
aux?: unknown _aux?: unknown
): unknown { ): number | [number, number] {
const newValue = baseModule.onCalcStat!( let newValue: number | [number, number] = value;
context as unknown as GeneralActionContext, if (statName === 'intelligence' && typeof value === 'number') {
statName as unknown as GeneralStatName, newValue = value + STAT_VALUE;
value as unknown as number, }
aux if (statName === 'warMagicTrialProb' && typeof newValue === 'number') {
); return newValue + 0.03;
if (statName === 'warMagicTrialProb') {
return (newValue as number) + 0.03;
} }
return newValue; return newValue;
} as NonNullable<ItemModule['onCalcStat']>, } as NonNullable<ItemModule['onCalcStat']>,
@@ -21,19 +21,17 @@ const baseModule = createStatItemModule({
export const itemModule: ItemModule = { export const itemModule: ItemModule = {
...baseModule, ...baseModule,
onCalcStat: function ( onCalcStat: function (
context: GeneralActionContext | WarActionContext, _context: GeneralActionContext | WarActionContext,
statName: GeneralStatName | WarStatName, statName: GeneralStatName | WarStatName,
value: unknown, value: number | [number, number],
aux?: unknown _aux?: unknown
): unknown { ): number | [number, number] {
const newValue = baseModule.onCalcStat!( let newValue: number | [number, number] = value;
context as unknown as GeneralActionContext, if (statName === 'intelligence' && typeof value === 'number') {
statName as unknown as GeneralStatName, newValue = value + STAT_VALUE;
value as unknown as number, }
aux if (statName === 'warMagicTrialProb' && typeof newValue === 'number') {
); return newValue + 0.03;
if (statName === 'warMagicTrialProb') {
return (newValue as number) + 0.03;
} }
return newValue; return newValue;
} as NonNullable<ItemModule['onCalcStat']>, } as NonNullable<ItemModule['onCalcStat']>,
@@ -4,12 +4,14 @@ import type { WarActionContext } from '@sammo-ts/logic/war/actions.js';
import { createStatItemModule } from './base.js'; import { createStatItemModule } from './base.js';
import type { ItemModule } from './types.js'; import type { ItemModule } from './types.js';
const STAT_VALUE = 7;
const baseModule = createStatItemModule({ const baseModule = createStatItemModule({
key: 'che_서적_07_위료자', key: 'che_서적_07_위료자',
rawName: '위료자', rawName: '위료자',
slot: 'book', slot: 'book',
statName: 'intelligence', statName: 'intelligence',
statValue: 7, statValue: STAT_VALUE,
cost: 200, cost: 200,
buyable: false, buyable: false,
reqSecu: 0, reqSecu: 0,
@@ -20,19 +22,17 @@ const baseModule = createStatItemModule({
export const itemModule: ItemModule = { export const itemModule: ItemModule = {
...baseModule, ...baseModule,
onCalcStat: function ( onCalcStat: function (
context: GeneralActionContext | WarActionContext, _context: GeneralActionContext | WarActionContext,
statName: GeneralStatName | WarStatName, statName: GeneralStatName | WarStatName,
value: unknown, value: number | [number, number],
aux?: unknown _aux?: unknown
): unknown { ): number | [number, number] {
const newValue = baseModule.onCalcStat!( let newValue: number | [number, number] = value;
context as unknown as GeneralActionContext, if (statName === 'intelligence' && typeof value === 'number') {
statName as unknown as GeneralStatName, newValue = value + STAT_VALUE;
value as unknown as number, }
aux if (statName === 'warMagicTrialProb' && typeof newValue === 'number') {
); return newValue + 0.2;
if (statName === 'warMagicTrialProb') {
return (newValue as number) + 0.2;
} }
return newValue; return newValue;
} as NonNullable<ItemModule['onCalcStat']>, } as NonNullable<ItemModule['onCalcStat']>,
@@ -19,10 +19,10 @@ export const itemModule: ItemModule = {
onCalcStat: function ( onCalcStat: function (
_context: GeneralActionContext | WarActionContext, _context: GeneralActionContext | WarActionContext,
statName: GeneralStatName | WarStatName, statName: GeneralStatName | WarStatName,
value: unknown value: number | [number, number]
): unknown { ): number | [number, number] {
if (statName === ('addDex' as unknown as GeneralStatName)) { if (statName === 'addDex' && typeof value === 'number') {
return (value as number) * 1.2; return value * 1.2;
} }
return value; return value;
} as NonNullable<ItemModule['onCalcStat']>, } as NonNullable<ItemModule['onCalcStat']>,
@@ -28,10 +28,10 @@ export const itemModule: ItemModule = {
onCalcStat: function ( onCalcStat: function (
context: GeneralActionContext | WarActionContext, context: GeneralActionContext | WarActionContext,
statName: GeneralStatName | WarStatName, statName: GeneralStatName | WarStatName,
value: unknown value: number | [number, number]
): unknown { ): number | [number, number] {
if (statName === 'leadership') { if (statName === 'leadership' && typeof value === 'number') {
return (value as number) + (context as unknown as GeneralActionContext).general.stats.leadership * 0.15; return value + context.general.stats.leadership * 0.15;
} }
return value; return value;
} as NonNullable<ItemModule['onCalcStat']>, } as NonNullable<ItemModule['onCalcStat']>,
+2
View File
@@ -44,9 +44,11 @@ export type WarStatName =
| 'bonusAtmos' | 'bonusAtmos'
| 'warCriticalRatio' | 'warCriticalRatio'
| 'warAvoidRatio' | 'warAvoidRatio'
| 'injuryProb'
| 'killRice' | 'killRice'
| 'criticalDamageRange' | 'criticalDamageRange'
| 'warMagicSuccessDamage' | 'warMagicSuccessDamage'
| 'warMagicTrialProb' | 'warMagicTrialProb'
| 'warMagicSuccessProb' | 'warMagicSuccessProb'
| 'addDex'
| `dex${number}`; | `dex${number}`;