diff --git a/project/src/controllers/InraidController.ts b/project/src/controllers/InraidController.ts index 71ae5ed0..019feb44 100644 --- a/project/src/controllers/InraidController.ts +++ b/project/src/controllers/InraidController.ts @@ -153,24 +153,20 @@ export class InraidController this.healthHelper.saveVitality(serverPmcProfile, postRaidRequest.health, sessionID); - // Remove inventory if player died and send insurance items - let insuredItemsLostCount = 0; - if (mapHasInsuranceEnabled) + // Get array of insured items+child that were lost in raid + const gearToStore = this.insuranceService.getGearLostInRaid( + serverPmcProfile, + postRaidRequest, + preRaidGear, + sessionID, + isDead, + ); + + if (gearToStore.length > 0) { - insuredItemsLostCount = this.insuranceService.storeLostGear( - serverPmcProfile, - postRaidRequest, - preRaidGear, - sessionID, - isDead, - ); - } - else - { - if (insuredItemsLostCount > 0) - { - this.insuranceService.sendLostInsuranceMessage(sessionID, locationName); - } + mapHasInsuranceEnabled + ? this.insuranceService.storeGearLostInRaidToSendLater(gearToStore) + : this.insuranceService.sendLostInsuranceMessage(sessionID, locationName); } // Edge case - Handle usec players leaving lighthouse with Rogues angry at them diff --git a/project/src/services/InsuranceService.ts b/project/src/services/InsuranceService.ts index d95a4517..3f37ab6e 100644 --- a/project/src/services/InsuranceService.ts +++ b/project/src/services/InsuranceService.ts @@ -138,7 +138,7 @@ export class InsuranceService } /** - * Send a message to player informing them gear was lost + * Send a message to player informing them gear was completely lost * @param sessionId Session id * @param locationName name of map insurance was lost on */ @@ -212,23 +212,22 @@ export class InsuranceService } /** - * Store lost gear post-raid inside profile, ready for later code to pick it up and mail it - * @param pmcData player profile to store gear in - * @param offraidData post-raid request object - * @param preRaidGear gear player wore prior to raid + * Create an array of insured items lost in a raid player has just exited + * @param pmcData Player profile + * @param offraidData Post-raid data + * @param preRaidGear Pre-raid data * @param sessionID Session id - * @param playerDied did the player die in raid - * @returns Count of insured items lost in raid + * @param playerDied Did player die in raid + * @returns Array of insured items lost in raid */ - public storeLostGear( + public getGearLostInRaid( pmcData: IPmcData, offraidData: ISaveProgressRequestData, preRaidGear: Item[], sessionID: string, playerDied: boolean, - ): number + ): any[] { - let itemsLostCount = 0; const preRaidGearHash = this.createItemHashTable(preRaidGear); const offRaidGearHash = this.createItemHashTable(offraidData.profile.Inventory.items); @@ -275,14 +274,21 @@ export class InsuranceService } } + return equipmentToSendToPlayer; + } + + /** + * Store lost gear post-raid inside profile, ready for later code to pick it up and mail it + * @param equipmentToSendToPlayer Gear to store - generated by getGearLostInRaid() + * TODO: add type to equipmentToSendToPlayer + */ + public storeGearLostInRaidToSendLater(equipmentToSendToPlayer: any[]): void + { // Process all insured items lost in-raid for (const gear of equipmentToSendToPlayer) { this.addGearToSend(gear); - itemsLostCount++; } - - return itemsLostCount; } /**