Further improvements to sendMail()

This commit is contained in:
Dev 2024-10-28 10:31:29 +00:00
parent 564fb7f4ca
commit 844616e3c4

View File

@ -538,11 +538,7 @@ export class InsuranceController {
if (this.IsMapLabsAndInsuranceDisabled(insurance)) { if (this.IsMapLabsAndInsuranceDisabled(insurance)) {
// Trader has labs-specific messages // Trader has labs-specific messages
// Wipe out returnable items // Wipe out returnable items
if (traderDialogMessages.insuranceFailedLabs?.length > 0) { this.handleLabsInsuranceMessaging(traderDialogMessages, insurance);
const insuranceFailedLabTemplates = traderDialogMessages.insuranceFailedLabs;
insurance.messageTemplateId = this.randomUtil.getArrayValue(insuranceFailedLabTemplates);
insurance.items = [];
}
} else if (insurance.items.length === 0) { } else if (insurance.items.length === 0) {
// Not labs and no items to return // Not labs and no items to return
const insuranceFailedTemplates = traderDialogMessages.insuranceFailed; const insuranceFailedTemplates = traderDialogMessages.insuranceFailed;
@ -561,14 +557,27 @@ export class InsuranceController {
); );
} }
protected IsMapLabsAndInsuranceDisabled(insurance: IInsurance) { protected IsMapLabsAndInsuranceDisabled(insurance: IInsurance, labsId = "laboratory"): boolean {
const labsId = "laboratory";
return ( return (
insurance.systemData?.location?.toLowerCase() === labsId && insurance.systemData?.location?.toLowerCase() === labsId &&
!this.databaseService.getLocation(labsId).base.Insurance !this.databaseService.getLocation(labsId).base.Insurance
); );
} }
protected handleLabsInsuranceMessaging(
traderDialogMessages: Record<string, string[]>,
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 * Determines whether an insured item should be removed from the player's inventory based on a random roll and
* trader-specific return chance. * trader-specific return chance.