fix: clone item inventory before nation level rewards

This commit is contained in:
2026-08-05 03:04:58 +00:00
parent 544168a76f
commit 65de2b30a3
2 changed files with 23 additions and 2 deletions
@@ -3,8 +3,10 @@ import {
LogCategory,
LogFormat,
LogScope,
cloneItemInventory,
countOccupiedUniqueItems,
createItemModuleRegistry,
ensureItemInventory,
equipNewItem,
resolveUniqueConfig,
type ItemModule,
@@ -105,10 +107,15 @@ const giveRandomUniqueItem = (options: {
}
const item = options.rng.choiceUsingWeightPair(available);
const nextGeneral = options.world.getGeneralById(options.general.id);
if (!nextGeneral) {
const currentGeneral = options.world.getGeneralById(options.general.id);
if (!currentGeneral) {
return false;
}
const nextGeneral: TurnGeneral = {
...currentGeneral,
role: { ...currentGeneral.role, items: { ...currentGeneral.role.items } },
itemInventory: cloneItemInventory(ensureItemInventory(currentGeneral)),
};
equipNewItem(nextGeneral, item.slot, item.key, {
...(item.initialCharges === undefined ? {} : { charges: item.initialCharges }),
});