From 67e16515fa09f730b03baace1a4711c00e773c63 Mon Sep 17 00:00:00 2001 From: DrakiaXYZ <565558+TheDgtl@users.noreply.github.com> Date: Sat, 15 Feb 2025 10:11:23 -0800 Subject: [PATCH] Fix `Insured item...is null` error - `mapInsuredItemsToTrader` should be using the pre-raid PMC profile, as the request profile isn't copied over after this method is run - Add a new profileFixer method to clean up old orphaned InsuredItems --- project/src/services/LocationLifecycleService.ts | 2 +- project/src/services/ProfileFixerService.ts | 16 ++++++++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/project/src/services/LocationLifecycleService.ts b/project/src/services/LocationLifecycleService.ts index 03fef351e..3965e3ea3 100644 --- a/project/src/services/LocationLifecycleService.ts +++ b/project/src/services/LocationLifecycleService.ts @@ -1004,7 +1004,7 @@ export class LocationLifecycleService { const mappedItems = this.insuranceService.mapInsuredItemsToTrader( sessionId, request.lostInsuredItems, - request.results.profile, + preRaidPmcProfile, ); // Is possible to have items in lostInsuredItems but removed before reaching mappedItems diff --git a/project/src/services/ProfileFixerService.ts b/project/src/services/ProfileFixerService.ts index 9ce28b3f9..45600b6a4 100644 --- a/project/src/services/ProfileFixerService.ts +++ b/project/src/services/ProfileFixerService.ts @@ -67,6 +67,7 @@ export class ProfileFixerService { this.removeOrphanedQuests(pmcProfile); this.verifyQuestProductionUnlocks(pmcProfile); this.fixFavorites(pmcProfile); + this.fixOrphanedInsurance(pmcProfile); if (pmcProfile.Hideout) { this.addHideoutEliteSlots(pmcProfile); @@ -406,6 +407,21 @@ export class ProfileFixerService { } } + /** + * Remove any entries from `pmcProfile.InsuredItems` that do not have a corresponding + * `pmcProfile.Inventory.items` entry + * @param pmcProfile + */ + protected fixOrphanedInsurance(pmcProfile: IPmcData): void { + const startTime = performance.now(); + pmcProfile.InsuredItems = pmcProfile.InsuredItems.filter((insuredItem) => { + // Check if the player inventory contains this item + return pmcProfile.Inventory.items.some((item) => item._id === insuredItem.itemId); + }); + const duration = performance.now() - startTime; + console.log(`Took ${duration}ms to filter insurance`); + } + /** * If the profile has elite Hideout Managment skill, add the additional slots from globals * NOTE: This seems redundant, but we will leave it here just incase.