From e783f268159832ed2e2b60d33e078ea2529d52d5 Mon Sep 17 00:00:00 2001 From: Chris Adamson Date: Sun, 18 May 2025 13:37:31 -0500 Subject: [PATCH] Fix: Insurance items lost in labyrinth should not be returned (#256) * labyrinth insurance fix * fix copypasta --- .../54cb50c76803fa8b248b4571/dialogue.json | 6 +++- .../54cb57776803fa99248b456e/dialogue.json | 8 +++-- .../Controllers/InsuranceController.cs | 35 +++++++++++++++++++ 3 files changed, 46 insertions(+), 3 deletions(-) diff --git a/Libraries/SPTarkov.Server.Assets/Assets/database/traders/54cb50c76803fa8b248b4571/dialogue.json b/Libraries/SPTarkov.Server.Assets/Assets/database/traders/54cb50c76803fa8b248b4571/dialogue.json index fa595912..f5833557 100644 --- a/Libraries/SPTarkov.Server.Assets/Assets/database/traders/54cb50c76803fa8b248b4571/dialogue.json +++ b/Libraries/SPTarkov.Server.Assets/Assets/database/traders/54cb50c76803fa8b248b4571/dialogue.json @@ -20,6 +20,10 @@ "5c1a3e0686f77445b95c29b3 1", "5c1a3e0686f77445b95c29b3 2" ], + "insuranceFailedLabyrinth": [ + "5c1a3e0686f77445b95c29b3 0", + "5c1a3e0686f77445b95c29b3 1" + ], "insuranceExpired": [ "5900a71886f7742d9a47454c 0", "5900a71886f7742d9a47454c 1", @@ -33,4 +37,4 @@ "59008bca86f7745cb11ae67b 3", "59008bca86f7745cb11ae67b 4" ] -} \ No newline at end of file +} diff --git a/Libraries/SPTarkov.Server.Assets/Assets/database/traders/54cb57776803fa99248b456e/dialogue.json b/Libraries/SPTarkov.Server.Assets/Assets/database/traders/54cb57776803fa99248b456e/dialogue.json index df6f675a..639d5ea9 100644 --- a/Libraries/SPTarkov.Server.Assets/Assets/database/traders/54cb57776803fa99248b456e/dialogue.json +++ b/Libraries/SPTarkov.Server.Assets/Assets/database/traders/54cb57776803fa99248b456e/dialogue.json @@ -31,5 +31,9 @@ "5c1a3e1886f77445b74fb8b0 1", "5c1a3e1886f77445b74fb8b0 2", "5c1a3e2a86f77476ad6d23b0 0" - ] -} \ No newline at end of file + ], + "insuranceFailedLabyrinth": [ + "5c1a3e1886f77445b74fb8b0 1", + "5c1a3e2a86f77476ad6d23b0 0" + ] +} diff --git a/Libraries/SPTarkov.Server.Core/Controllers/InsuranceController.cs b/Libraries/SPTarkov.Server.Core/Controllers/InsuranceController.cs index 7d942623..c276363b 100644 --- a/Libraries/SPTarkov.Server.Core/Controllers/InsuranceController.cs +++ b/Libraries/SPTarkov.Server.Core/Controllers/InsuranceController.cs @@ -582,6 +582,10 @@ public class InsuranceController( { HandleLabsInsurance(traderDialogMessages, insurance); } + else if (IsMapLabyrinthAndInsuranceDisabled(insurance)) + { + HandleLabyrinthInsurance(traderDialogMessages, insurance); + } else if (insurance.Items?.Count == 0) // Not labs and no items to return { @@ -615,6 +619,18 @@ public class InsuranceController( !(_databaseService.GetLocation(labsId)?.Base?.Insurance.GetValueOrDefault(false) ?? false); } + /// + /// Edge case - labyrinth doesn't allow for insurance returns unless location config is edited + /// + /// The insured items to process + /// OPTIONAL - id of labs location + /// + protected bool IsMapLabyrinthAndInsuranceDisabled(Insurance insurance, string labyrinthId = "labyrinth") + { + return string.Equals(insurance.SystemData?.Location, labyrinthId, StringComparison.OrdinalIgnoreCase) && + !(_databaseService.GetLocation(labyrinthId)?.Base?.Insurance.GetValueOrDefault(false) ?? false); + } + /// /// Update IInsurance object with new messageTemplateId and wipe out items array data /// @@ -634,6 +650,25 @@ public class InsuranceController( insurance.Items = []; } + /// + /// Update IInsurance object with new messageTemplateId and wipe out items array data + /// + /// + /// + protected void HandleLabyrinthInsurance(Dictionary?>? traderDialogMessages, Insurance insurance) + { + // Use labs specific messages if available, otherwise use default + var responseMessageIds = + traderDialogMessages["insuranceFailedLabyrinth"]?.Count > 0 + ? traderDialogMessages["insuranceFailedLabyrinth"] + : traderDialogMessages["insuranceFailed"]; + + insurance.MessageTemplateId = _randomUtil.GetArrayValue(responseMessageIds); + + // Remove all insured items taken into labs + insurance.Items = []; + } + /// /// Roll for chance of item being 'lost'