Skip to content

Commit

Permalink
Fix Insured item...is null error (#1110)
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

---------

Co-authored-by: DrakiaXYZ <[email protected]>
  • Loading branch information
DrakiaXYZ and DrakiaXYZ authored Feb 15, 2025
1 parent 78fb73d commit 2c29b4e
Show file tree
Hide file tree
Showing 2 changed files with 14 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
13 changes: 13 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,18 @@ 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 {
pmcProfile.InsuredItems = pmcProfile.InsuredItems.filter((insuredItem) => {
// Check if the player inventory contains this item
return pmcProfile.Inventory.items.some((item) => item._id === insuredItem.itemId);
});
}

/**
* 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 2c29b4e

Please sign in to comment.