Fixed ammo boxes again. location starts at highest count instead of lowest

This commit is contained in:
Kaeno 2024-02-11 17:31:52 +00:00
parent 9e70b1135c
commit 28ab029ef3

View File

@ -1047,11 +1047,10 @@ export class ItemHelper
// Add new stack-size-correct items to ammo box // Add new stack-size-correct items to ammo box
let currentStoredCartridgeCount = 0; let currentStoredCartridgeCount = 0;
// Location in ammoBox cartridges will be placed
let location = 0;
const maxPerStack = Math.min(ammoBoxMaxCartridgeCount, cartridgeMaxStackSize); const maxPerStack = Math.min(ammoBoxMaxCartridgeCount, cartridgeMaxStackSize);
// Find location based on Max ammo box size
let location = Math.ceil(ammoBoxMaxCartridgeCount / maxPerStack) - 1;
const ammoStacksToAdd: Item[] = [];
while (currentStoredCartridgeCount < ammoBoxMaxCartridgeCount) while (currentStoredCartridgeCount < ammoBoxMaxCartridgeCount)
{ {
const remainingSpace = ammoBoxMaxCartridgeCount - currentStoredCartridgeCount; const remainingSpace = ammoBoxMaxCartridgeCount - currentStoredCartridgeCount;
@ -1072,15 +1071,11 @@ export class ItemHelper
delete cartridgeItemToAdd.location; delete cartridgeItemToAdd.location;
} }
ammoStacksToAdd.push(cartridgeItemToAdd); ammoBox.push(cartridgeItemToAdd);
currentStoredCartridgeCount += cartridgeCountToAdd; currentStoredCartridgeCount += cartridgeCountToAdd;
location++; location--;
} }
// Ammo must be reversed so location 2 goes first, then location 1 etc, prevents being unable to open ammo boxes in live in one click
ammoStacksToAdd.reverse();
ammoBox.push(...ammoStacksToAdd);
} }
/** /**