From 844616e3c49d914e69df74cd3c23f0a3f7188ce2 Mon Sep 17 00:00:00 2001 From: Dev Date: Mon, 28 Oct 2024 10:31:29 +0000 Subject: [PATCH] Further improvements to `sendMail()` --- .../src/controllers/InsuranceController.ts | 23 +++++++++++++------ 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/project/src/controllers/InsuranceController.ts b/project/src/controllers/InsuranceController.ts index c34e3814..6eddf442 100644 --- a/project/src/controllers/InsuranceController.ts +++ b/project/src/controllers/InsuranceController.ts @@ -538,11 +538,7 @@ export class InsuranceController { if (this.IsMapLabsAndInsuranceDisabled(insurance)) { // Trader has labs-specific messages // Wipe out returnable items - if (traderDialogMessages.insuranceFailedLabs?.length > 0) { - const insuranceFailedLabTemplates = traderDialogMessages.insuranceFailedLabs; - insurance.messageTemplateId = this.randomUtil.getArrayValue(insuranceFailedLabTemplates); - insurance.items = []; - } + this.handleLabsInsuranceMessaging(traderDialogMessages, insurance); } else if (insurance.items.length === 0) { // Not labs and no items to return const insuranceFailedTemplates = traderDialogMessages.insuranceFailed; @@ -561,14 +557,27 @@ export class InsuranceController { ); } - protected IsMapLabsAndInsuranceDisabled(insurance: IInsurance) { - const labsId = "laboratory"; + protected IsMapLabsAndInsuranceDisabled(insurance: IInsurance, labsId = "laboratory"): boolean { return ( insurance.systemData?.location?.toLowerCase() === labsId && !this.databaseService.getLocation(labsId).base.Insurance ); } + protected handleLabsInsuranceMessaging( + traderDialogMessages: Record, + insurance: IInsurance, + ): void { + if (traderDialogMessages.insuranceFailedLabs?.length > 0) { + // Change message template id to a labs-specific one + const insuranceFailedLabTemplates = traderDialogMessages.insuranceFailedLabs; + insurance.messageTemplateId = this.randomUtil.getArrayValue(insuranceFailedLabTemplates); + + // Remove all insured items taken into labs + insurance.items = []; + } + } + /** * Determines whether an insured item should be removed from the player's inventory based on a random roll and * trader-specific return chance.