From a9ad6d05042fc72b100f4a4dbd3db85e9b8ea35d Mon Sep 17 00:00:00 2001 From: Joonas Rikkonen Date: Mon, 15 Apr 2019 12:05:34 +0300 Subject: [PATCH] (02db081a3) Fixed treatment suggestions not working correctly for some items because they were using incorrect affliction identifiers (there's no affliction with the identifier "damage"). Now the treatments can be defined using either the identifier or type of the affliction. --- .../AI/Objectives/AIObjectiveFindSafety.cs | 4 ++-- .../Source/Items/ItemPrefab.cs | 21 ++++++++++++++++--- 2 files changed, 20 insertions(+), 5 deletions(-) diff --git a/Barotrauma/BarotraumaShared/Source/Characters/AI/Objectives/AIObjectiveFindSafety.cs b/Barotrauma/BarotraumaShared/Source/Characters/AI/Objectives/AIObjectiveFindSafety.cs index 6b735f0f5..ae793f08f 100644 --- a/Barotrauma/BarotraumaShared/Source/Characters/AI/Objectives/AIObjectiveFindSafety.cs +++ b/Barotrauma/BarotraumaShared/Source/Characters/AI/Objectives/AIObjectiveFindSafety.cs @@ -60,8 +60,8 @@ namespace Barotrauma else { divingGearObjective = null; - // Reduce the timer so that we get a safe hull target faster. - searchHullTimer = Math.Min(1, searchHullTimer); + // Reset the timer so that we get a safe hull target. + searchHullTimer = 0; } } diff --git a/Barotrauma/BarotraumaShared/Source/Items/ItemPrefab.cs b/Barotrauma/BarotraumaShared/Source/Items/ItemPrefab.cs index c9b04ad1c..09bb91532 100644 --- a/Barotrauma/BarotraumaShared/Source/Items/ItemPrefab.cs +++ b/Barotrauma/BarotraumaShared/Source/Items/ItemPrefab.cs @@ -615,10 +615,25 @@ namespace Barotrauma string treatmentIdentifier = subElement.GetAttributeString("identifier", "").ToLowerInvariant(); - var matchingAffliction = AfflictionPrefab.List.Find(a => a.Identifier == treatmentIdentifier); - if (matchingAffliction != null) + List matchingAfflictions = AfflictionPrefab.List.FindAll(a => a.Identifier == treatmentIdentifier || a.AfflictionType == treatmentIdentifier); + if (matchingAfflictions.Count == 0) { - matchingAffliction.TreatmentSuitability.Add(identifier, subElement.GetAttributeFloat("suitability", 0.0f)); + DebugConsole.ThrowError("Error in item prefab \"" + Name + "\" - couldn't define as a treatment, no treatments with the identifier or type \"" + treatmentIdentifier + "\" were found."); + continue; + } + + float suitability = subElement.GetAttributeFloat("suitability", 0.0f); + foreach (AfflictionPrefab matchingAffliction in matchingAfflictions) + { + if (matchingAffliction.TreatmentSuitability.ContainsKey(identifier)) + { + matchingAffliction.TreatmentSuitability[identifier] = + Math.Max(matchingAffliction.TreatmentSuitability[identifier], suitability); + } + else + { + matchingAffliction.TreatmentSuitability.Add(identifier, suitability); + } } break; }