Fixed edge case where custom traders without labs-specific failure messages would still return insured items

This commit is contained in:
Dev 2024-10-28 11:17:19 +00:00
parent 844616e3c4
commit 4346fadcbc

View File

@ -538,7 +538,7 @@ export class InsuranceController {
if (this.IsMapLabsAndInsuranceDisabled(insurance)) {
// Trader has labs-specific messages
// Wipe out returnable items
this.handleLabsInsuranceMessaging(traderDialogMessages, insurance);
this.handleLabsInsurance(traderDialogMessages, insurance);
} else if (insurance.items.length === 0) {
// Not labs and no items to return
const insuranceFailedTemplates = traderDialogMessages.insuranceFailed;
@ -564,18 +564,20 @@ export class InsuranceController {
);
}
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);
/**
* Update IInsurance object with new messageTemplateId and wipe out items array data
*/
protected handleLabsInsurance(traderDialogMessages: Record<string, string[]>, insurance: IInsurance): void {
// Use labs specific messages if available, otherwise use default
const responseMesageIds =
traderDialogMessages.insuranceFailedLabs?.length > 0
? traderDialogMessages.insuranceFailedLabs
: traderDialogMessages.insuranceFailed;
// Remove all insured items taken into labs
insurance.items = [];
}
insurance.messageTemplateId = this.randomUtil.getArrayValue(responseMesageIds);
// Remove all insured items taken into labs
insurance.items = [];
}
/**