From f5af432ad999baa4d416ba9d17c332ef66165476 Mon Sep 17 00:00:00 2001 From: Joonas Rikkonen Date: Tue, 6 Mar 2018 11:25:25 +0200 Subject: [PATCH] Fixed item tags & aliases not being taken into account when determining target validity in StatusEffect.Apply. Closes #316 --- Barotrauma/BarotraumaShared/Source/Items/Item.cs | 10 ++++++++++ .../Source/Map/MapEntityPrefab.cs | 9 +++++++++ .../Source/StatusEffects/StatusEffect.cs | 15 ++++++++++++++- 3 files changed, 33 insertions(+), 1 deletion(-) diff --git a/Barotrauma/BarotraumaShared/Source/Items/Item.cs b/Barotrauma/BarotraumaShared/Source/Items/Item.cs index 1c2ff8a03..10be88838 100644 --- a/Barotrauma/BarotraumaShared/Source/Items/Item.cs +++ b/Barotrauma/BarotraumaShared/Source/Items/Item.cs @@ -694,6 +694,16 @@ namespace Barotrauma return (tags.Contains(tag) || tags.Contains(tag.ToLowerInvariant())); } + public bool HasTag(IEnumerable allowedTags) + { + if (allowedTags == null) return true; + + foreach (string tag in allowedTags) + { + if (tags.Contains(tag) || tags.Contains(tag.ToLowerInvariant())) return true; + } + return false; + } public void ApplyStatusEffects(ActionType type, float deltaTime, Character character = null, bool isNetworkEvent = false) { diff --git a/Barotrauma/BarotraumaShared/Source/Map/MapEntityPrefab.cs b/Barotrauma/BarotraumaShared/Source/Map/MapEntityPrefab.cs index c6b414315..a55a6d73c 100644 --- a/Barotrauma/BarotraumaShared/Source/Map/MapEntityPrefab.cs +++ b/Barotrauma/BarotraumaShared/Source/Map/MapEntityPrefab.cs @@ -228,6 +228,15 @@ namespace Barotrauma } } + public bool NameMatches(IEnumerable allowedNames, bool caseSensitive = false) + { + foreach (string name in allowedNames) + { + if (NameMatches(name, caseSensitive)) return true; + } + return false; + } + //a method that allows the GUIListBoxes to check through a delegate if the entityprefab is still selected public static object GetSelected() { diff --git a/Barotrauma/BarotraumaShared/Source/StatusEffects/StatusEffect.cs b/Barotrauma/BarotraumaShared/Source/StatusEffects/StatusEffect.cs index f98e1e3c1..f6c812812 100644 --- a/Barotrauma/BarotraumaShared/Source/StatusEffects/StatusEffect.cs +++ b/Barotrauma/BarotraumaShared/Source/StatusEffects/StatusEffect.cs @@ -299,7 +299,20 @@ namespace Barotrauma //remove invalid targets if (targetNames != null) { - targets.RemoveAll(t => !targetNames.Contains(t.Name)); + targets.RemoveAll(t => + { + Item item = t as Item; + if (item == null) + { + return !targetNames.Contains(t.Name); + } + else + { + if (item.HasTag(targetNames)) return false; + if (item.Prefab.NameMatches(targetNames)) return false; + } + return true; + }); if (targets.Count == 0) return; }