From d7ce092a4a21e2b2889187de1e4b6db573037888 Mon Sep 17 00:00:00 2001 From: Dev Date: Thu, 29 Aug 2024 17:36:31 +0100 Subject: [PATCH] Added code to clean up insured items data post-raid --- project/src/services/InsuranceService.ts | 10 ++++++++++ project/src/services/LocationLifecycleService.ts | 2 ++ 2 files changed, 12 insertions(+) diff --git a/project/src/services/InsuranceService.ts b/project/src/services/InsuranceService.ts index aaa714e5..b5f946a8 100644 --- a/project/src/services/InsuranceService.ts +++ b/project/src/services/InsuranceService.ts @@ -324,4 +324,14 @@ export class InsuranceService { // Try to use the equipment id from the profile. I'm not sure this is strictly required, but it feels neat. return this.saveServer.getProfile(sessionID)?.characters?.pmc?.Inventory?.equipment ?? this.hashUtil.generate(); } + + /** + * Remove lost insurance items from profiles insuredItems array + * @param profile Profile to remove from + * @param itemsToRemove Items to remove + */ + public removeLostInsuranceFromProfile(profile: IPmcData, itemsToRemove: Item[]) { + const itemIdsToRemove = new Set(itemsToRemove.map((item) => item._id)); + profile.InsuredItems = profile.InsuredItems.filter((insuredItem) => !itemIdsToRemove.has(insuredItem.itemId)); + } } diff --git a/project/src/services/LocationLifecycleService.ts b/project/src/services/LocationLifecycleService.ts index d9c37003..201bc878 100644 --- a/project/src/services/LocationLifecycleService.ts +++ b/project/src/services/LocationLifecycleService.ts @@ -589,6 +589,8 @@ export class LocationLifecycleService { this.insuranceService.storeGearLostInRaidToSendLater(sessionId, mappedItems); this.insuranceService.sendInsuredItems(preRaidPmcProfile, sessionId, locationName); + + this.insuranceService.removeLostInsuranceFromProfile(preRaidPmcProfile, request.lostInsuredItems); } }