feat: update stat handling by introducing specific types for GeneralStatName and WarStatName across various modules
This commit is contained in:
@@ -1,5 +1,15 @@
|
||||
import type { GeneralTriggerState } from '@sammo-ts/logic/domain/entities.js';
|
||||
import { type GeneralActionContext, GeneralTriggerCaller } from './general.js';
|
||||
import type {
|
||||
GeneralStatName,
|
||||
TriggerActionPhase,
|
||||
TriggerActionType,
|
||||
TriggerDomesticActionType,
|
||||
TriggerDomesticVarType,
|
||||
TriggerNationalIncomeType,
|
||||
TriggerStrategicActionType,
|
||||
TriggerStrategicVarType,
|
||||
} from './types.js';
|
||||
|
||||
export interface GeneralActionModule<TriggerState extends GeneralTriggerState = GeneralTriggerState> {
|
||||
getName?(): string;
|
||||
@@ -11,43 +21,43 @@ export interface GeneralActionModule<TriggerState extends GeneralTriggerState =
|
||||
|
||||
onCalcDomestic?(
|
||||
context: GeneralActionContext<TriggerState>,
|
||||
turnType: string,
|
||||
varType: string,
|
||||
turnType: TriggerDomesticActionType,
|
||||
varType: TriggerDomesticVarType,
|
||||
value: number,
|
||||
aux?: unknown
|
||||
): number;
|
||||
|
||||
onCalcStat?(
|
||||
context: GeneralActionContext<TriggerState>,
|
||||
statName: string,
|
||||
statName: GeneralStatName,
|
||||
value: number,
|
||||
aux?: unknown
|
||||
): number;
|
||||
|
||||
onCalcOpposeStat?(
|
||||
context: GeneralActionContext<TriggerState>,
|
||||
statName: string,
|
||||
statName: GeneralStatName,
|
||||
value: number,
|
||||
aux?: unknown
|
||||
): number;
|
||||
|
||||
onCalcStrategic?(
|
||||
context: GeneralActionContext<TriggerState>,
|
||||
turnType: string,
|
||||
varType: string,
|
||||
turnType: TriggerStrategicActionType,
|
||||
varType: TriggerStrategicVarType,
|
||||
value: number
|
||||
): number;
|
||||
|
||||
onCalcNationalIncome?(
|
||||
context: GeneralActionContext<TriggerState>,
|
||||
type: string,
|
||||
type: TriggerNationalIncomeType,
|
||||
amount: number
|
||||
): number;
|
||||
|
||||
onArbitraryAction?(
|
||||
context: GeneralActionContext<TriggerState>,
|
||||
actionType: string,
|
||||
phase?: string | null,
|
||||
actionType: TriggerActionType,
|
||||
phase?: TriggerActionPhase | null,
|
||||
aux?: Record<string, unknown> | null
|
||||
): Record<string, unknown> | null;
|
||||
}
|
||||
@@ -76,8 +86,8 @@ export class GeneralActionPipeline<TriggerState extends GeneralTriggerState = Ge
|
||||
|
||||
onCalcDomestic(
|
||||
context: GeneralActionContext<TriggerState>,
|
||||
turnType: string,
|
||||
varType: string,
|
||||
turnType: TriggerDomesticActionType,
|
||||
varType: TriggerDomesticVarType,
|
||||
value: number,
|
||||
aux?: unknown
|
||||
): number {
|
||||
@@ -93,7 +103,7 @@ export class GeneralActionPipeline<TriggerState extends GeneralTriggerState = Ge
|
||||
|
||||
onCalcStat(
|
||||
context: GeneralActionContext<TriggerState>,
|
||||
statName: string,
|
||||
statName: GeneralStatName,
|
||||
value: number,
|
||||
aux?: unknown
|
||||
): number {
|
||||
@@ -109,7 +119,7 @@ export class GeneralActionPipeline<TriggerState extends GeneralTriggerState = Ge
|
||||
|
||||
onCalcOpposeStat(
|
||||
context: GeneralActionContext<TriggerState>,
|
||||
statName: string,
|
||||
statName: GeneralStatName,
|
||||
value: number,
|
||||
aux?: unknown
|
||||
): number {
|
||||
@@ -125,8 +135,8 @@ export class GeneralActionPipeline<TriggerState extends GeneralTriggerState = Ge
|
||||
|
||||
onCalcStrategic(
|
||||
context: GeneralActionContext<TriggerState>,
|
||||
turnType: string,
|
||||
varType: string,
|
||||
turnType: TriggerStrategicActionType,
|
||||
varType: TriggerStrategicVarType,
|
||||
value: number
|
||||
): number {
|
||||
let current = value;
|
||||
@@ -141,7 +151,7 @@ export class GeneralActionPipeline<TriggerState extends GeneralTriggerState = Ge
|
||||
|
||||
onCalcNationalIncome(
|
||||
context: GeneralActionContext<TriggerState>,
|
||||
type: string,
|
||||
type: TriggerNationalIncomeType,
|
||||
amount: number
|
||||
): number {
|
||||
let current = amount;
|
||||
@@ -156,8 +166,8 @@ export class GeneralActionPipeline<TriggerState extends GeneralTriggerState = Ge
|
||||
|
||||
onArbitraryAction(
|
||||
context: GeneralActionContext<TriggerState>,
|
||||
actionType: string,
|
||||
phase?: string | null,
|
||||
actionType: TriggerActionType,
|
||||
phase?: TriggerActionPhase | null,
|
||||
aux?: Record<string, unknown> | null
|
||||
): Record<string, unknown> | null {
|
||||
let current = aux ?? null;
|
||||
|
||||
@@ -1,6 +1,17 @@
|
||||
import type { GeneralTriggerState } from '@sammo-ts/logic/domain/entities.js';
|
||||
import type { GeneralActionContext } from '@sammo-ts/logic/triggers/general.js';
|
||||
import type { GeneralActionModule } from '@sammo-ts/logic/triggers/general-action.js';
|
||||
import type {
|
||||
GeneralStatName,
|
||||
TriggerActionPhase,
|
||||
TriggerActionType,
|
||||
TriggerDomesticActionType,
|
||||
TriggerDomesticVarType,
|
||||
TriggerNationalIncomeType,
|
||||
TriggerStrategicActionType,
|
||||
TriggerStrategicVarType,
|
||||
WarStatName,
|
||||
} from '@sammo-ts/logic/triggers/types.js';
|
||||
import type { WarActionContext, WarActionModule } from '@sammo-ts/logic/war/actions.js';
|
||||
import type { WarUnit } from '@sammo-ts/logic/war/units.js';
|
||||
import type { WarTriggerCaller } from '@sammo-ts/logic/war/triggers.js';
|
||||
@@ -57,8 +68,8 @@ export class SpecialGeneralActionRouter<
|
||||
|
||||
onCalcDomestic(
|
||||
context: GeneralActionContext<TriggerState>,
|
||||
turnType: string,
|
||||
varType: string,
|
||||
turnType: TriggerDomesticActionType,
|
||||
varType: TriggerDomesticVarType,
|
||||
value: number,
|
||||
aux?: unknown
|
||||
): number {
|
||||
@@ -68,7 +79,7 @@ export class SpecialGeneralActionRouter<
|
||||
|
||||
onCalcStat(
|
||||
context: GeneralActionContext<TriggerState>,
|
||||
statName: string,
|
||||
statName: GeneralStatName,
|
||||
value: number,
|
||||
aux?: unknown
|
||||
): number {
|
||||
@@ -78,7 +89,7 @@ export class SpecialGeneralActionRouter<
|
||||
|
||||
onCalcOpposeStat(
|
||||
context: GeneralActionContext<TriggerState>,
|
||||
statName: string,
|
||||
statName: GeneralStatName,
|
||||
value: number,
|
||||
aux?: unknown
|
||||
): number {
|
||||
@@ -90,8 +101,8 @@ export class SpecialGeneralActionRouter<
|
||||
|
||||
onCalcStrategic(
|
||||
context: GeneralActionContext<TriggerState>,
|
||||
turnType: string,
|
||||
varType: string,
|
||||
turnType: TriggerStrategicActionType,
|
||||
varType: TriggerStrategicVarType,
|
||||
value: number
|
||||
): number {
|
||||
const module = this.getModule(context);
|
||||
@@ -100,7 +111,7 @@ export class SpecialGeneralActionRouter<
|
||||
|
||||
onCalcNationalIncome(
|
||||
context: GeneralActionContext<TriggerState>,
|
||||
type: string,
|
||||
type: TriggerNationalIncomeType,
|
||||
amount: number
|
||||
): number {
|
||||
const module = this.getModule(context);
|
||||
@@ -109,8 +120,8 @@ export class SpecialGeneralActionRouter<
|
||||
|
||||
onArbitraryAction(
|
||||
context: GeneralActionContext<TriggerState>,
|
||||
actionType: string,
|
||||
phase?: string | null,
|
||||
actionType: TriggerActionType,
|
||||
phase?: TriggerActionPhase | null,
|
||||
aux?: Record<string, unknown> | null
|
||||
): Record<string, unknown> | null {
|
||||
const module = this.getModule(context);
|
||||
@@ -156,7 +167,7 @@ export class SpecialWarActionRouter<
|
||||
|
||||
onCalcStat(
|
||||
context: WarActionContext<TriggerState>,
|
||||
statName: string,
|
||||
statName: WarStatName,
|
||||
value: number | [number, number],
|
||||
aux?: unknown
|
||||
): number | [number, number] {
|
||||
@@ -166,7 +177,7 @@ export class SpecialWarActionRouter<
|
||||
|
||||
onCalcOpposeStat(
|
||||
context: WarActionContext<TriggerState>,
|
||||
statName: string,
|
||||
statName: WarStatName,
|
||||
value: number | [number, number],
|
||||
aux?: unknown
|
||||
): number | [number, number] {
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import type { GeneralActionContext } from '@sammo-ts/logic/triggers/general.js';
|
||||
import type { GeneralStatName, WarStatName } from '@sammo-ts/logic/triggers/types.js';
|
||||
import type { WarActionContext } from '@sammo-ts/logic/war/actions.js';
|
||||
import type { SpecialActionModule } from '@sammo-ts/logic/triggers/special/types.js';
|
||||
|
||||
@@ -18,19 +19,19 @@ const resolveLeadershipBonus = (
|
||||
|
||||
function onCalcStat(
|
||||
context: GeneralActionContext,
|
||||
statName: string,
|
||||
statName: GeneralStatName,
|
||||
value: number,
|
||||
aux?: unknown
|
||||
): number;
|
||||
function onCalcStat(
|
||||
context: WarActionContext,
|
||||
statName: string,
|
||||
statName: WarStatName,
|
||||
value: number | [number, number],
|
||||
aux?: unknown
|
||||
): number | [number, number];
|
||||
function onCalcStat(
|
||||
context: GeneralActionContext | WarActionContext,
|
||||
statName: string,
|
||||
statName: GeneralStatName | WarStatName,
|
||||
value: number | [number, number]
|
||||
): number | [number, number] {
|
||||
if (statName !== 'leadership') {
|
||||
|
||||
@@ -0,0 +1,46 @@
|
||||
export type TriggerActionType = '장비매매';
|
||||
|
||||
export type TriggerActionPhase = '판매' | '구매';
|
||||
|
||||
export type TriggerDomesticActionType =
|
||||
| '상업'
|
||||
| '인재탐색'
|
||||
| '징병'
|
||||
| '징집인구'
|
||||
| '계략'
|
||||
| '민심'
|
||||
| '인구'
|
||||
| '기술'
|
||||
| '모병';
|
||||
|
||||
export type TriggerDomesticVarType =
|
||||
| 'cost'
|
||||
| 'score'
|
||||
| 'success'
|
||||
| 'fail'
|
||||
| 'train'
|
||||
| 'atmos'
|
||||
| 'rice'
|
||||
| 'probability';
|
||||
|
||||
export type TriggerStrategicActionType = '의병모집';
|
||||
|
||||
export type TriggerStrategicVarType = 'delay' | 'globalDelay';
|
||||
|
||||
export type TriggerNationalIncomeType = 'gold' | 'rice';
|
||||
|
||||
export type GeneralStatName = 'leadership' | 'strength' | 'intelligence';
|
||||
|
||||
export type WarStatName =
|
||||
| GeneralStatName
|
||||
| 'cityBattleOrder'
|
||||
| 'initWarPhase'
|
||||
| 'bonusTrain'
|
||||
| 'bonusAtmos'
|
||||
| 'warCriticalRatio'
|
||||
| 'warAvoidRatio'
|
||||
| 'killRice'
|
||||
| 'criticalDamageRange'
|
||||
| 'warMagicSuccessDamage'
|
||||
| 'warMagicTrialProb'
|
||||
| `dex${number}`;
|
||||
Reference in New Issue
Block a user