Cap campaign inventory recovery
This commit is contained in:
@@ -209,7 +209,16 @@ try {
|
||||
],
|
||||
completedCampDialogues: ['dialogue-a', 17, 'dialogue-a', '', 'x'.repeat(97)],
|
||||
completedCampVisits: 'visit-a',
|
||||
inventory: { bean: '3', ' bean ': '4', ['\uCF69']: '200', [' \uCF69 ']: '20', wine: -2, empty: 0 },
|
||||
inventory: {
|
||||
bean: '3',
|
||||
' bean ': '4',
|
||||
['\uCF69']: '200',
|
||||
[' \uCF69 ']: '20',
|
||||
rareSupply: '2000',
|
||||
['x'.repeat(97)]: 5,
|
||||
wine: -2,
|
||||
empty: 0
|
||||
},
|
||||
selectedSortieUnitIds: { corrupted: true },
|
||||
sortieFormationAssignments: 'front',
|
||||
sortieItemAssignments: {
|
||||
@@ -242,8 +251,10 @@ try {
|
||||
assert(
|
||||
malformed.inventory.bean === 7 &&
|
||||
malformed.inventory['\uCF69'] === 120 &&
|
||||
malformed.inventory.rareSupply === 999 &&
|
||||
malformed.inventory[' bean '] === undefined &&
|
||||
malformed.inventory[' \uCF69 '] === undefined &&
|
||||
malformed.inventory['x'.repeat(97)] === undefined &&
|
||||
malformed.inventory.wine === undefined &&
|
||||
malformed.sortieItemAssignments['liu-bei']?.bean === 2 &&
|
||||
malformed.sortieItemAssignments['liu-bei']?.salve === 1 &&
|
||||
|
||||
@@ -268,6 +268,7 @@ const campaignInventoryCaps: Record<string, number> = {
|
||||
|
||||
const maxCampaignStringListEntries = 128;
|
||||
const maxCampaignStringListLength = 96;
|
||||
const maxCampaignUnknownInventoryAmount = 999;
|
||||
const maxCampaignRewardNoteLength = 180;
|
||||
const maxCampaignBattleObjectiveEntries = 24;
|
||||
const maxCampaignBattleUnitEntries = 96;
|
||||
@@ -967,10 +968,10 @@ function normalizeInventory(value: unknown) {
|
||||
return Object.entries(recordOrEmpty(value)).reduce<Record<string, number>>((inventory, [itemId, amount]) => {
|
||||
const normalizedItemId = itemId.replace(/\s+/g, ' ').trim();
|
||||
const normalizedAmount = normalizeNonNegativeInteger(amount);
|
||||
if (normalizedItemId && normalizedAmount > 0) {
|
||||
if (normalizedItemId && normalizedItemId.length <= maxCampaignStringListLength && normalizedAmount > 0) {
|
||||
const nextAmount = (inventory[normalizedItemId] ?? 0) + normalizedAmount;
|
||||
const cap = campaignInventoryCaps[normalizedItemId];
|
||||
inventory[normalizedItemId] = cap ? Math.min(nextAmount, cap) : nextAmount;
|
||||
const cap = campaignInventoryCaps[normalizedItemId] ?? maxCampaignUnknownInventoryAmount;
|
||||
inventory[normalizedItemId] = Math.min(nextAmount, cap);
|
||||
}
|
||||
return inventory;
|
||||
}, {});
|
||||
|
||||
Reference in New Issue
Block a user