Normalize sortie supply assignments
This commit is contained in:
@@ -254,6 +254,12 @@ const defaultEquipmentBySlot: Record<EquipmentSlot, string> = {
|
||||
accessory: 'grain-pouch'
|
||||
};
|
||||
|
||||
const sortieSupplyMaxByUsableId: Record<string, number> = {
|
||||
bean: 2,
|
||||
wine: 1,
|
||||
salve: 1
|
||||
};
|
||||
|
||||
const campaignInventoryCaps: Record<string, number> = {
|
||||
['\uCF69']: 120,
|
||||
['\uC0C1\uCC98\uC57D']: 80,
|
||||
@@ -826,7 +832,7 @@ function normalizeCampaignState(state: Partial<CampaignState>): CampaignState {
|
||||
normalized.selectedSortieUnitIds = uniqueStrings(normalized.selectedSortieUnitIds)
|
||||
.filter((unitId) => !sortieUnitFilter || sortieUnitFilter.has(unitId));
|
||||
normalized.sortieFormationAssignments = normalizeSortieFormationAssignments(recordOrEmpty(normalized.sortieFormationAssignments), sortieUnitFilter);
|
||||
normalized.sortieItemAssignments = normalizeSortieItemAssignments(recordOrEmpty(normalized.sortieItemAssignments), sortieUnitFilter);
|
||||
normalized.sortieItemAssignments = normalizeCampaignSortieItemAssignments(recordOrEmpty(normalized.sortieItemAssignments), sortieUnitFilter);
|
||||
normalized.reserveTrainingFocus = normalizeReserveTrainingFocusId(normalized.reserveTrainingFocus);
|
||||
normalized.battleHistory = normalizeBattleHistory(normalized.battleHistory);
|
||||
normalized.latestBattleId = normalizeLatestBattleId(normalized.latestBattleId, normalized.battleHistory);
|
||||
@@ -1022,16 +1028,20 @@ function normalizeReserveTrainingSnapshot(value: unknown): CampaignReserveTraini
|
||||
};
|
||||
}
|
||||
|
||||
function normalizeSortieItemAssignments(assignments?: Record<string, unknown>, allowedUnitIds?: Set<string>) {
|
||||
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))) {
|
||||
return next;
|
||||
}
|
||||
|
||||
const unitStocks = Object.entries(recordOrEmpty(stocks)).reduce<Record<string, number>>((nextStocks, [itemId, amount]) => {
|
||||
const maxPerUnit = sortieSupplyMaxByUsableId[itemId];
|
||||
if (!maxPerUnit) {
|
||||
return nextStocks;
|
||||
}
|
||||
const normalizedAmount = normalizeNonNegativeInteger(amount);
|
||||
if (itemId && normalizedAmount > 0) {
|
||||
nextStocks[itemId] = normalizedAmount;
|
||||
nextStocks[itemId] = Math.min(maxPerUnit, normalizedAmount);
|
||||
}
|
||||
return nextStocks;
|
||||
}, {});
|
||||
|
||||
Reference in New Issue
Block a user