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.