From b2497ded19debfab337a24a1b9ceae177ebcd0d5 Mon Sep 17 00:00:00 2001 From: Sainan <63328889+Sainan@users.noreply.github.com> Date: Sun, 6 Apr 2025 06:04:30 -0700 Subject: [PATCH] fix: refuse to add items non-fatally (#1476) This is needed to complete to the railjack quest when already owning a railjack Reviewed-on: https://onlyg.it/OpenWF/SpaceNinjaServer/pulls/1476 Co-authored-by: Sainan <63328889+Sainan@users.noreply.github.com> Co-committed-by: Sainan <63328889+Sainan@users.noreply.github.com> --- src/services/inventoryService.ts | 27 +++++++++++++++------------ 1 file changed, 15 insertions(+), 12 deletions(-) diff --git a/src/services/inventoryService.ts b/src/services/inventoryService.ts index 9a841453..904c90fa 100644 --- a/src/services/inventoryService.ts +++ b/src/services/inventoryService.ts @@ -1060,11 +1060,12 @@ const addCrewShip = ( inventoryChanges: IInventoryChanges = {} ): IInventoryChanges => { if (inventory.CrewShips.length != 0) { - throw new Error("refusing to add CrewShip because account already has one"); + logger.warn("refusing to add CrewShip because account already has one"); + } else { + const index = inventory.CrewShips.push({ ItemType: typeName }) - 1; + inventoryChanges.CrewShips ??= []; + inventoryChanges.CrewShips.push(inventory.CrewShips[index].toJSON()); } - const index = inventory.CrewShips.push({ ItemType: typeName }) - 1; - inventoryChanges.CrewShips ??= []; - inventoryChanges.CrewShips.push(inventory.CrewShips[index].toJSON()); return inventoryChanges; }; @@ -1074,11 +1075,12 @@ const addCrewShipHarness = ( inventoryChanges: IInventoryChanges = {} ): IInventoryChanges => { if (inventory.CrewShipHarnesses.length != 0) { - throw new Error("refusing to add CrewShipHarness because account already has one"); + logger.warn("refusing to add CrewShipHarness because account already has one"); + } else { + const index = inventory.CrewShipHarnesses.push({ ItemType: typeName }) - 1; + inventoryChanges.CrewShipHarnesses ??= []; + inventoryChanges.CrewShipHarnesses.push(inventory.CrewShipHarnesses[index].toJSON()); } - const index = inventory.CrewShipHarnesses.push({ ItemType: typeName }) - 1; - inventoryChanges.CrewShipHarnesses ??= []; - inventoryChanges.CrewShipHarnesses.push(inventory.CrewShipHarnesses[index].toJSON()); return inventoryChanges; }; @@ -1088,11 +1090,12 @@ const addMotorcycle = ( inventoryChanges: IInventoryChanges = {} ): IInventoryChanges => { if (inventory.Motorcycles.length != 0) { - throw new Error("refusing to add Motorcycle because account already has one"); + logger.warn("refusing to add Motorcycle because account already has one"); + } else { + const index = inventory.Motorcycles.push({ ItemType: typeName }) - 1; + inventoryChanges.Motorcycles ??= []; + inventoryChanges.Motorcycles.push(inventory.Motorcycles[index].toJSON()); } - const index = inventory.Motorcycles.push({ ItemType: typeName }) - 1; - inventoryChanges.Motorcycles ??= []; - inventoryChanges.Motorcycles.push(inventory.Motorcycles[index].toJSON()); return inventoryChanges; };