CHE 아이템 상태 동결로 인한 턴 정지 수정
This commit is contained in:
@@ -40,6 +40,7 @@ import { simpleSerialize } from '@sammo-ts/logic/war/utils.js';
|
||||
import type { MapDefinition, UnitSetDefinition } from '@sammo-ts/logic/world/types.js';
|
||||
import type { ActionContextBuilder } from '@sammo-ts/logic/actions/turn/actionContext.js';
|
||||
import { tryApplyUniqueLottery } from '@sammo-ts/logic/rewards/uniqueLottery.js';
|
||||
import { cloneItemInventory } from '@sammo-ts/logic/items/inventory.js';
|
||||
import { buildNationFrontStatePatches } from '../../../diplomacy/frontState.js';
|
||||
import type { TracePort } from '../../../ports/trace.js';
|
||||
import { formatDestCityConstraintFailure } from '../constraintFailure.js';
|
||||
@@ -343,6 +344,7 @@ const cloneGeneral = <TriggerState extends GeneralTriggerState>(
|
||||
general: General<TriggerState>
|
||||
): General<TriggerState> => ({
|
||||
...general,
|
||||
...(general.itemInventory ? { itemInventory: cloneItemInventory(general.itemInventory) } : {}),
|
||||
stats: { ...general.stats },
|
||||
role: {
|
||||
...general.role,
|
||||
|
||||
@@ -2,6 +2,7 @@ import { describe, expect, it } from 'vitest';
|
||||
|
||||
import type { General } from '../src/domain/entities.js';
|
||||
import {
|
||||
cloneItemInventory,
|
||||
consumeEquippedItemCharge,
|
||||
createItemInventoryFromSlots,
|
||||
equipNewItem,
|
||||
@@ -110,4 +111,23 @@ describe('GeneralItemInventory', () => {
|
||||
|
||||
expect(getEquippedItemInstance({ ...general, itemInventory: parsed }, 'item')?.state.charges).toBe(-1);
|
||||
});
|
||||
|
||||
it('clones an Immer-frozen inventory into mutable next-turn state', () => {
|
||||
const general = makeGeneral();
|
||||
equipNewItem(general, 'item', 'che_치료_환약', { charges: 3 });
|
||||
const inventory = general.itemInventory!;
|
||||
const instance = getEquippedItemInstance(general, 'item')!;
|
||||
Object.freeze(instance.state);
|
||||
Object.freeze(instance);
|
||||
Object.freeze(inventory.instances);
|
||||
Object.freeze(inventory.equipped);
|
||||
Object.freeze(inventory);
|
||||
|
||||
const cloned = cloneItemInventory(inventory);
|
||||
const nextGeneral = { ...general, itemInventory: cloned };
|
||||
|
||||
expect(consumeEquippedItemCharge(nextGeneral, 'item', 'che_치료_환약')).toBe(false);
|
||||
expect(getEquippedItemInstance(nextGeneral, 'item')?.state.charges).toBe(2);
|
||||
expect(instance.state.charges).toBe(3);
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user