Skip to content

Commit

Permalink
Fix Insured item...is null error
Browse files Browse the repository at this point in the history
- `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
  • Loading branch information
DrakiaXYZ committed Feb 15, 2025
1 parent 78fb73d commit 67e1651
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
2 changes: 1 addition & 1 deletion project/src/services/LocationLifecycleService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
16 changes: 16 additions & 0 deletions project/src/services/ProfileFixerService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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.
Expand Down

0 comments on commit 67e1651

Please sign in to comment.