Improved handling of a missing upd
object inside removeRandomItemFromAssorts()
This commit is contained in:
parent
fe7d09e075
commit
be841fbe3f
@ -387,8 +387,8 @@ export class FenceService
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Choose an item at random and remove it + mods from assorts
|
* Choose an item at random and remove it + mods from assorts
|
||||||
* @param assort Items to remove from
|
* @param assort Trader assort to remove item from
|
||||||
* @param rootItems Assort root items to pick from to remove
|
* @param rootItems Pool of root items to pick from to remove
|
||||||
*/
|
*/
|
||||||
protected removeRandomItemFromAssorts(assort: ITraderAssort, rootItems: Item[]): void
|
protected removeRandomItemFromAssorts(assort: ITraderAssort, rootItems: Item[]): void
|
||||||
{
|
{
|
||||||
@ -399,24 +399,34 @@ export class FenceService
|
|||||||
|
|
||||||
// Get a random count of the chosen item to remove
|
// Get a random count of the chosen item to remove
|
||||||
const itemCountToRemove = this.randomUtil.getInt(1, stackSize);
|
const itemCountToRemove = this.randomUtil.getInt(1, stackSize);
|
||||||
if (itemCountToRemove > 1 && itemCountToRemove < rootItemToAdjust.upd.StackObjectsCount)
|
|
||||||
{ // More than 1 + less then full stack
|
const isEntireStackToBeRemoved = itemCountToRemove === stackSize;
|
||||||
// Reduce stack size but keep stack
|
|
||||||
rootItemToAdjust.upd.StackObjectsCount -= itemCountToRemove;
|
// Partial stack reduction
|
||||||
}
|
if (!isEntireStackToBeRemoved)
|
||||||
else
|
|
||||||
{
|
{
|
||||||
// Remove up item + any mods
|
if (!rootItemToAdjust.upd)
|
||||||
const itemWithChildren = this.itemHelper.findAndReturnChildrenAsItems(assort.items, rootItemToAdjust._id);
|
|
||||||
for (const itemToDelete of itemWithChildren)
|
|
||||||
{
|
{
|
||||||
// Delete item from assort items array
|
rootItemToAdjust.upd = {};
|
||||||
assort.items.splice(assort.items.indexOf(itemToDelete), 1);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
delete assort.barter_scheme[rootItemToAdjust._id];
|
// Reduce stack to at smallest, 1
|
||||||
delete assort.loyal_level_items[rootItemToAdjust._id];
|
rootItemToAdjust.upd.StackObjectsCount -= Math.max(1, itemCountToRemove);
|
||||||
|
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Remove item + child mods (if any)
|
||||||
|
const itemWithChildren = this.itemHelper.findAndReturnChildrenAsItems(assort.items, rootItemToAdjust._id);
|
||||||
|
for (const itemToDelete of itemWithChildren)
|
||||||
|
{
|
||||||
|
// Delete item from assort items array
|
||||||
|
assort.items.splice(assort.items.indexOf(itemToDelete), 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Need to remove item from all areas of trader assort
|
||||||
|
delete assort.barter_scheme[rootItemToAdjust._id];
|
||||||
|
delete assort.loyal_level_items[rootItemToAdjust._id];
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Loading…
Reference in New Issue
Block a user