From 386b93e7e6b067ddbeb02b819339d39611dfc792 Mon Sep 17 00:00:00 2001 From: TetrisGG Date: Fri, 23 Aug 2024 16:35:17 +0000 Subject: [PATCH] Handle Softinsertslots when insuring armor (!401) fixes SPT/Issues#765 Tested with Uptodate Bleedingedge Reviewed-on: https://dev.sp-tarkov.com/SPT/Server/pulls/401 Co-authored-by: TetrisGG Co-committed-by: TetrisGG --- .../src/controllers/InsuranceController.ts | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/project/src/controllers/InsuranceController.ts b/project/src/controllers/InsuranceController.ts index 8f976c44..af88dc49 100644 --- a/project/src/controllers/InsuranceController.ts +++ b/project/src/controllers/InsuranceController.ts @@ -643,6 +643,10 @@ export class InsuranceController { // add items to InsuredItems list once money has been paid for (const key of body.items) { pmcData.InsuredItems.push({ tid: body.tid, itemId: inventoryItemsHash[key]._id }); + // If Item is Helmet or Body Armour -> Handle insurance of Softinserts + if (this.itemHelper.armorItemHasRemovableOrSoftInsertSlots(inventoryItemsHash[key]._tpl)) { + this.insureSoftInserts(inventoryItemsHash[key], pmcData, body); + } } this.profileHelper.addSkillPointsToPlayer(pmcData, SkillTypes.CHARISMA, itemsToInsureCount * 0.01); @@ -650,6 +654,22 @@ export class InsuranceController { return output; } + /** + * Insure softinserts of Armor that has softinsert slots + * @param item Armor item to be insured + * @param pmcData Player profile + * @param body Insurance request data + */ + public insureSoftInserts(item: Item, pmcData: IPmcData, body: IInsureRequestData): void { + const softInsertIds = this.itemHelper.getSoftInsertSlotIds(); + const softInsertSlots = pmcData.Inventory.items.filter((x) => x.parentId === item._id && softInsertIds.includes(x.slotId.toLowerCase())); + + for (const softInsertSlot of softInsertSlots) { + this.logger.debug(`SoftInsertSlots: ${softInsertSlot.slotId}`); + pmcData.InsuredItems.push({ tid: body.tid, itemId: softInsertSlot._id }); + } + } + /** * Handle client/insurance/items/list/cost * Calculate insurance cost