wip: 바보 젬3플. type 재정의 준비
This commit is contained in:
@@ -2,7 +2,7 @@ import type { RandUtil } from '@sammo-ts/common';
|
||||
|
||||
import type { City, General, GeneralTriggerState, Nation } from '@sammo-ts/logic/domain/entities.js';
|
||||
import type { ActionLogger } from '@sammo-ts/logic/logging/actionLogger.js';
|
||||
import type { WarStatName } from '@sammo-ts/logic/triggers/types.js';
|
||||
import type { WarStatBundleMap, WarStatName } from '@sammo-ts/logic/triggers/types.js';
|
||||
import type { WarUnit } from './units.js';
|
||||
import { WarTriggerCaller } from './triggers.js';
|
||||
|
||||
@@ -24,30 +24,30 @@ export interface WarActionModule<TriggerState extends GeneralTriggerState = Gene
|
||||
getBattlePhaseTriggerList?: ((context: WarActionContext<TriggerState>) => WarTriggerCaller | null) | undefined;
|
||||
|
||||
onCalcStat?:
|
||||
| ((
|
||||
context: WarActionContext<TriggerState>,
|
||||
statName: WarStatName,
|
||||
value: number | [number, number],
|
||||
aux?: unknown
|
||||
) => number | [number, number])
|
||||
| undefined;
|
||||
| (<T extends WarStatName>(
|
||||
context: WarActionContext<TriggerState>,
|
||||
statName: T,
|
||||
value: WarStatBundleMap[T]['value'],
|
||||
aux?: WarStatBundleMap[T]['aux']
|
||||
) => WarStatBundleMap[T]['return'])
|
||||
| undefined;
|
||||
|
||||
onCalcOpposeStat?:
|
||||
| ((
|
||||
context: WarActionContext<TriggerState>,
|
||||
statName: WarStatName,
|
||||
value: number | [number, number],
|
||||
aux?: unknown
|
||||
) => number | [number, number])
|
||||
| undefined;
|
||||
| (<T extends WarStatName>(
|
||||
context: WarActionContext<TriggerState>,
|
||||
statName: T,
|
||||
value: WarStatBundleMap[T]['value'],
|
||||
aux?: WarStatBundleMap[T]['aux']
|
||||
) => WarStatBundleMap[T]['return'])
|
||||
| undefined;
|
||||
|
||||
getWarPowerMultiplier?:
|
||||
| ((
|
||||
context: WarActionContext<TriggerState>,
|
||||
unit: WarUnit<TriggerState>,
|
||||
oppose: WarUnit<TriggerState>
|
||||
) => [number, number])
|
||||
| undefined;
|
||||
| ((
|
||||
context: WarActionContext<TriggerState>,
|
||||
unit: WarUnit<TriggerState>,
|
||||
oppose: WarUnit<TriggerState>
|
||||
) => [number, number])
|
||||
| undefined;
|
||||
}
|
||||
|
||||
export class WarActionPipeline<TriggerState extends GeneralTriggerState = GeneralTriggerState> {
|
||||
@@ -80,36 +80,36 @@ export class WarActionPipeline<TriggerState extends GeneralTriggerState = Genera
|
||||
return caller;
|
||||
}
|
||||
|
||||
onCalcStat<T extends number | [number, number]>(
|
||||
onCalcStat<T extends WarStatName>(
|
||||
context: WarActionContext<TriggerState>,
|
||||
statName: WarStatName,
|
||||
value: T,
|
||||
aux?: unknown
|
||||
): T {
|
||||
let current: number | [number, number] = value;
|
||||
statName: T,
|
||||
value: WarStatBundleMap[T]['value'],
|
||||
aux?: WarStatBundleMap[T]['aux']
|
||||
): WarStatBundleMap[T]['return'] {
|
||||
let current = value;
|
||||
for (const module of this.modules) {
|
||||
if (!module.onCalcStat) {
|
||||
continue;
|
||||
}
|
||||
current = module.onCalcStat(context, statName, current, aux);
|
||||
current = module.onCalcStat(context, statName, current as never, aux as never) as never;
|
||||
}
|
||||
return current as T;
|
||||
return current;
|
||||
}
|
||||
|
||||
onCalcOpposeStat<T extends number | [number, number]>(
|
||||
onCalcOpposeStat<T extends WarStatName>(
|
||||
context: WarActionContext<TriggerState>,
|
||||
statName: WarStatName,
|
||||
value: T,
|
||||
aux?: unknown
|
||||
): T {
|
||||
let current: number | [number, number] = value;
|
||||
statName: T,
|
||||
value: WarStatBundleMap[T]['value'],
|
||||
aux?: WarStatBundleMap[T]['aux']
|
||||
): WarStatBundleMap[T]['return'] {
|
||||
let current = value;
|
||||
for (const module of this.modules) {
|
||||
if (!module.onCalcOpposeStat) {
|
||||
continue;
|
||||
}
|
||||
current = module.onCalcOpposeStat(context, statName, current, aux);
|
||||
current = module.onCalcOpposeStat(context, statName, current as never, aux as never) as never;
|
||||
}
|
||||
return current as T;
|
||||
return current;
|
||||
}
|
||||
|
||||
getWarPowerMultiplier(
|
||||
|
||||
@@ -466,8 +466,8 @@ export class WarUnitGeneral<
|
||||
const baseTurnTime = this.isAttacker()
|
||||
? getMetaString(this.general.meta, META_TURN_TIME)
|
||||
: oppose instanceof WarUnitGeneral
|
||||
? getMetaString(oppose.general.meta, META_TURN_TIME)
|
||||
: getMetaString(this.general.meta, META_TURN_TIME);
|
||||
? getMetaString(oppose.general.meta, META_TURN_TIME)
|
||||
: getMetaString(this.general.meta, META_TURN_TIME);
|
||||
if (!baseTurnTime) {
|
||||
return;
|
||||
}
|
||||
@@ -480,9 +480,8 @@ export class WarUnitGeneral<
|
||||
|
||||
public override getMaxPhase(): number {
|
||||
const base = this.getCrewType().speed;
|
||||
const aux = { isAttacker: this.isAttacker() };
|
||||
const context = this.getActionContext();
|
||||
const phase = this.actionPipeline.onCalcStat(context, 'initWarPhase', base, aux);
|
||||
const phase = this.actionPipeline.onCalcStat(context, 'initWarPhase', base, { isAttacker: this.isAttacker() });
|
||||
return phase + this.bonusPhase;
|
||||
}
|
||||
|
||||
@@ -507,12 +506,16 @@ export class WarUnitGeneral<
|
||||
return strength;
|
||||
}
|
||||
|
||||
private resolveOpposeStatValue(statName: WarStatName, value: number, aux?: Record<string, unknown>): number {
|
||||
private resolveOpposeStatValue(statName: WarStatName, value: number, aux?: any): number {
|
||||
const oppose = this.getOppose();
|
||||
if (!(oppose instanceof WarUnitGeneral)) {
|
||||
return value;
|
||||
}
|
||||
return oppose.getActionPipeline().onCalcOpposeStat(this.getActionContext(), statName, value, aux);
|
||||
const result = oppose.getActionPipeline().onCalcOpposeStat(this.getActionContext(), statName, value, aux);
|
||||
if (typeof result === 'number') {
|
||||
return result;
|
||||
}
|
||||
return value;
|
||||
}
|
||||
|
||||
public override getDex(crewType: WarCrewType): number {
|
||||
@@ -527,8 +530,10 @@ export class WarUnitGeneral<
|
||||
};
|
||||
const statName = toDexStatName(armType);
|
||||
let dex = this.actionPipeline.onCalcStat(this.getActionContext(), statName, base, aux);
|
||||
dex = this.resolveOpposeStatValue(statName, dex, aux);
|
||||
return dex;
|
||||
if (typeof dex === 'number') {
|
||||
dex = this.resolveOpposeStatValue(statName, dex, aux);
|
||||
}
|
||||
return typeof dex === 'number' ? dex : base;
|
||||
}
|
||||
|
||||
public override getComputedAttack(): number {
|
||||
@@ -578,8 +583,8 @@ export class WarUnitGeneral<
|
||||
const mainStat = this.resolveMainStat(armType);
|
||||
const coef =
|
||||
armType === this.config.armTypes.wizard ||
|
||||
armType === this.config.armTypes.siege ||
|
||||
armType === this.config.armTypes.misc
|
||||
armType === this.config.armTypes.siege ||
|
||||
armType === this.config.armTypes.misc
|
||||
? 0.4
|
||||
: 0.5;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user