From ef65074dc3b095bc4e5b918feb5d4985fa0040c7 Mon Sep 17 00:00:00 2001 From: Dev Date: Sat, 20 Apr 2024 13:05:44 +0100 Subject: [PATCH] Resolve server error inside `removeRandomItemFromAssorts()` when the item being processed has no `upd` object --- project/src/services/FenceService.ts | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/project/src/services/FenceService.ts b/project/src/services/FenceService.ts index 6d538d0d..9cef446a 100644 --- a/project/src/services/FenceService.ts +++ b/project/src/services/FenceService.ts @@ -393,7 +393,12 @@ export class FenceService protected removeRandomItemFromAssorts(assort: ITraderAssort, rootItems: Item[]): void { const rootItemToAdjust = this.randomUtil.getArrayValue(rootItems); - const itemCountToRemove = this.randomUtil.getInt(1, rootItemToAdjust.upd.StackObjectsCount); + + // Items added by mods may not have a upd object, assume item stack size is 1 + const stackSize = rootItemToAdjust.upd?.StackObjectsCount ?? 1; + + // Get a random count of the chosen item to remove + const itemCountToRemove = this.randomUtil.getInt(1, stackSize); if (itemCountToRemove > 1 && itemCountToRemove < rootItemToAdjust.upd.StackObjectsCount) { // More than 1 + less then full stack // Reduce stack size but keep stack