Only remove item from fence assort if he has items to remove
Add empty assort check to remove function too
This commit is contained in:
parent
e6d8e281ee
commit
285f65bb8d
@ -201,18 +201,25 @@ export class FenceService
|
|||||||
let itemCountToReplace = this.getCountOfItemsToReplace(this.traderConfig.fence.assortSize);
|
let itemCountToReplace = this.getCountOfItemsToReplace(this.traderConfig.fence.assortSize);
|
||||||
const discountItemCountToReplace = this.getCountOfItemsToReplace(this.traderConfig.fence.discountOptions.assortSize);
|
const discountItemCountToReplace = this.getCountOfItemsToReplace(this.traderConfig.fence.discountOptions.assortSize);
|
||||||
|
|
||||||
// Iterate x times to remove items
|
// Iterate x times to remove items (only remove if assort has items)
|
||||||
for (let index = 0; index < itemCountToReplace; index++)
|
if (this.fenceAssort?.items?.length > 0)
|
||||||
{
|
{
|
||||||
this.removeRandomItemFromAssorts(this.fenceAssort);
|
for (let index = 0; index < itemCountToReplace; index++)
|
||||||
|
{
|
||||||
|
this.removeRandomItemFromAssorts(this.fenceAssort);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Iterate x times to remove items
|
// Iterate x times to remove items (only remove if assort has items)
|
||||||
for (let index = 0; index < discountItemCountToReplace; index++)
|
if (this.fenceDiscountAssort?.items?.length > 0)
|
||||||
{
|
{
|
||||||
this.removeRandomItemFromAssorts(this.fenceDiscountAssort);
|
for (let index = 0; index < discountItemCountToReplace; index++)
|
||||||
|
{
|
||||||
|
this.removeRandomItemFromAssorts(this.fenceDiscountAssort);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
itemCountToReplace = this.getCountOfItemsToGenerate(itemCountToReplace);
|
itemCountToReplace = this.getCountOfItemsToGenerate(itemCountToReplace);
|
||||||
|
|
||||||
const newItems = this.createBaseTraderAssortItem();
|
const newItems = this.createBaseTraderAssortItem();
|
||||||
@ -286,6 +293,14 @@ export class FenceService
|
|||||||
*/
|
*/
|
||||||
protected removeRandomItemFromAssorts(assort: ITraderAssort): void
|
protected removeRandomItemFromAssorts(assort: ITraderAssort): void
|
||||||
{
|
{
|
||||||
|
// Only remove if assort has items
|
||||||
|
if (!assort.items.some(x => x.slotId === "hideout"))
|
||||||
|
{
|
||||||
|
this.logger.warning("Unable to remove random assort from trader as they have no assorts with a slotid of `hideout`");
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
let itemToRemove: Item;
|
let itemToRemove: Item;
|
||||||
while (!itemToRemove || itemToRemove.slotId !== "hideout")
|
while (!itemToRemove || itemToRemove.slotId !== "hideout")
|
||||||
{
|
{
|
||||||
@ -296,6 +311,7 @@ export class FenceService
|
|||||||
assort.items.splice(indexOfItemToRemove, 1);
|
assort.items.splice(indexOfItemToRemove, 1);
|
||||||
|
|
||||||
// Clean up any mods if item removed was a weapon
|
// Clean up any mods if item removed was a weapon
|
||||||
|
// TODO: also check for mods attached down the item chain
|
||||||
assort.items = assort.items.filter(x => x.parentId !== itemToRemove._id);
|
assort.items = assort.items.filter(x => x.parentId !== itemToRemove._id);
|
||||||
|
|
||||||
delete assort.barter_scheme[itemToRemove._id];
|
delete assort.barter_scheme[itemToRemove._id];
|
||||||
|
Loading…
x
Reference in New Issue
Block a user