Harden sortie item assignment recovery
This commit is contained in:
@@ -274,6 +274,7 @@ const maxCampaignBattleObjectiveEntries = 24;
|
||||
const maxCampaignBattleUnitEntries = 96;
|
||||
const maxCampaignBattleBondEntries = 96;
|
||||
const maxCampaignReserveTrainingEntries = 96;
|
||||
const maxCampaignSortieAssignmentUnits = 96;
|
||||
const maxCampaignDisplayTextLength = 180;
|
||||
|
||||
export const campaignReserveTrainingFocusDefinitions: CampaignReserveTrainingFocusDefinition[] = [
|
||||
@@ -1176,24 +1177,33 @@ function normalizeReserveTrainingSnapshot(value: unknown): CampaignReserveTraini
|
||||
|
||||
export function normalizeCampaignSortieItemAssignments(assignments?: Record<string, unknown>, allowedUnitIds?: Set<string>) {
|
||||
return Object.entries(assignments ?? {}).reduce<CampaignSortieItemAssignments>((next, [unitId, stocks]) => {
|
||||
if (!unitId || (allowedUnitIds && !allowedUnitIds.has(unitId))) {
|
||||
const normalizedUnitId = normalizeKeyString(unitId);
|
||||
if (
|
||||
!normalizedUnitId ||
|
||||
(allowedUnitIds && !allowedUnitIds.has(normalizedUnitId)) ||
|
||||
(!allowedUnitIds && Object.keys(next).length >= maxCampaignSortieAssignmentUnits)
|
||||
) {
|
||||
return next;
|
||||
}
|
||||
|
||||
const unitStocks = Object.entries(recordOrEmpty(stocks)).reduce<Record<string, number>>((nextStocks, [itemId, amount]) => {
|
||||
const maxPerUnit = sortieSupplyMaxByUsableId[itemId];
|
||||
const normalizedItemId = normalizeKeyString(itemId);
|
||||
const maxPerUnit = sortieSupplyMaxByUsableId[normalizedItemId];
|
||||
if (!maxPerUnit) {
|
||||
return nextStocks;
|
||||
}
|
||||
const normalizedAmount = normalizeNonNegativeInteger(amount);
|
||||
if (itemId && normalizedAmount > 0) {
|
||||
nextStocks[itemId] = Math.min(maxPerUnit, normalizedAmount);
|
||||
if (normalizedItemId && normalizedAmount > 0) {
|
||||
nextStocks[normalizedItemId] = Math.min(maxPerUnit, normalizedAmount);
|
||||
}
|
||||
return nextStocks;
|
||||
}, {});
|
||||
|
||||
if (Object.keys(unitStocks).length > 0) {
|
||||
next[unitId] = unitStocks;
|
||||
next[normalizedUnitId] = {
|
||||
...(next[normalizedUnitId] ?? {}),
|
||||
...unitStocks
|
||||
};
|
||||
}
|
||||
return next;
|
||||
}, {});
|
||||
|
||||
Reference in New Issue
Block a user