Attempted to fix issue with calculateItemWorth() failing on child items without a upd object

Clone children when returned to prevent modification + add missing upd object to child before calculating price
This commit is contained in:
Dev 2024-08-18 09:52:13 +01:00
parent 1b9a3c46f9
commit 5ffedfa91a

View File

@ -8,6 +8,7 @@ import { BonusType } from "@spt/models/enums/BonusType";
import { ILogger } from "@spt/models/spt/utils/ILogger";
import { DatabaseService } from "@spt/services/DatabaseService";
import { RagfairPriceService } from "@spt/services/RagfairPriceService";
import { ICloner } from "@spt/utils/cloners/ICloner";
import { inject, injectable } from "tsyringe";
@injectable()
@ -20,6 +21,7 @@ export class RagfairTaxService {
@inject("RagfairPriceService") protected ragfairPriceService: RagfairPriceService,
@inject("ItemHelper") protected itemHelper: ItemHelper,
@inject("ProfileHelper") protected profileHelper: ProfileHelper,
@inject("PrimaryCloner") protected cloner: ICloner,
) {}
public storeClientOfferTaxValue(sessionId: string, offer: IStorePlayerOfferTaxAmountRequestData): void {
@ -120,15 +122,20 @@ export class RagfairTaxService {
// Since we get a flat list of all child items, we only want to recurse from parent item
const itemChildren = this.itemHelper.findAndReturnChildrenAsItems(pmcData.Inventory.items, item._id);
if (itemChildren.length > 1) {
for (const child of itemChildren) {
const itemChildrenClone = this.cloner.clone(itemChildren); // Clone is expensive, only run if necessary
for (const child of itemChildrenClone) {
if (child._id === item._id) {
continue;
}
if (!child.upd) {
child.upd = {};
}
worth += this.calculateItemWorth(
child,
this.itemHelper.getItem(child._tpl)[1],
child.upd?.StackObjectsCount ?? 1,
child.upd.StackObjectsCount ?? 1,
pmcData,
false,
);