Resolve server error inside removeRandomItemFromAssorts() when the item being processed has no upd object

This commit is contained in:
Dev 2024-04-20 13:05:44 +01:00
parent 225c44e594
commit ef65074dc3

View File

@ -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