From a56cbdb821951811b02ef008bfbd6c9f60d96f3e Mon Sep 17 00:00:00 2001 From: Jade-Harleyy <67431770+Jade-Harleyy@users.noreply.github.com> Date: Wed, 11 Sep 2024 03:33:41 -0500 Subject: [PATCH 1/2] Extensions to the StatusEffect container heirarchy system. --- .../SharedSource/Characters/Attack.cs | 14 +-- .../SharedSource/Characters/Character.cs | 3 +- .../Health/Afflictions/Affliction.cs | 3 +- .../SharedSource/Characters/Limb.cs | 3 +- .../Extensions/GenericExtensions.cs | 40 +++++++ .../Extensions/IEnumerableExtensions.cs | 18 ++- .../Items/Components/ItemContainer.cs | 7 +- .../Items/Components/Projectile.cs | 3 +- .../SharedSource/Items/Item.cs | 22 ++-- .../Map/Levels/LevelObjects/LevelTrigger.cs | 13 +-- .../StatusEffects/StatusEffect.cs | 104 +++++++++++++++++- 11 files changed, 181 insertions(+), 49 deletions(-) create mode 100644 Barotrauma/BarotraumaShared/SharedSource/Extensions/GenericExtensions.cs diff --git a/Barotrauma/BarotraumaShared/SharedSource/Characters/Attack.cs b/Barotrauma/BarotraumaShared/SharedSource/Characters/Attack.cs index 92f4d98976..c287a18009 100644 --- a/Barotrauma/BarotraumaShared/SharedSource/Characters/Attack.cs +++ b/Barotrauma/BarotraumaShared/SharedSource/Characters/Attack.cs @@ -569,8 +569,7 @@ public AttackResult DoDamage(Character attacker, IDamageable target, Vector2 wor } if (target is Entity targetEntity) { - if (effect.HasTargetType(StatusEffect.TargetType.NearbyItems) || - effect.HasTargetType(StatusEffect.TargetType.NearbyCharacters)) + if (effect.HasTargetType(StatusEffect.TargetType.NearbyEntities)) { targets.Clear(); effect.AddNearbyTargets(worldPosition, targets); @@ -589,10 +588,10 @@ public AttackResult DoDamage(Character attacker, IDamageable target, Vector2 wor effect.Apply(additionalEffectType, deltaTime, targetEntity, targetEntity as ISerializableEntity, worldPosition); } } - if (effect.HasTargetType(StatusEffect.TargetType.Contained)) + if (effect.HasTargetType(StatusEffect.TargetType.Descendants)) { targets.Clear(); - targets.AddRange(attacker.Inventory.AllItems); + targets.AddRange(effect.GetContainedItems(attacker)); if (additionalEffectType != ActionType.OnEating) { effect.Apply(conditionalEffectType, deltaTime, attacker, targets); @@ -668,18 +667,17 @@ public AttackResult DoDamageToLimb(Character attacker, Limb targetLimb, Vector2 effect.Apply(conditionalEffectType, deltaTime, targetLimb.character, targets); effect.Apply(ActionType.OnUse, deltaTime, targetLimb.character, targets); } - if (effect.HasTargetType(StatusEffect.TargetType.NearbyItems) || - effect.HasTargetType(StatusEffect.TargetType.NearbyCharacters)) + if (effect.HasTargetType(StatusEffect.TargetType.NearbyEntities)) { targets.Clear(); effect.AddNearbyTargets(worldPosition, targets); effect.Apply(conditionalEffectType, deltaTime, targetLimb.character, targets); effect.Apply(ActionType.OnUse, deltaTime, targetLimb.character, targets); } - if (effect.HasTargetType(StatusEffect.TargetType.Contained)) + if (effect.HasTargetType(StatusEffect.TargetType.Descendants)) { targets.Clear(); - targets.AddRange(attacker.Inventory.AllItems); + targets.AddRange(effect.GetContainedItems(attacker)); effect.Apply(conditionalEffectType, deltaTime, attacker, targets); effect.Apply(ActionType.OnUse, deltaTime, attacker, targets); } diff --git a/Barotrauma/BarotraumaShared/SharedSource/Characters/Character.cs b/Barotrauma/BarotraumaShared/SharedSource/Characters/Character.cs index 6e2a69bc8d..0cd20bf06c 100644 --- a/Barotrauma/BarotraumaShared/SharedSource/Characters/Character.cs +++ b/Barotrauma/BarotraumaShared/SharedSource/Characters/Character.cs @@ -4673,8 +4673,7 @@ public void ApplyStatusEffects(ActionType actionType, float deltaTime) } } } - if (statusEffect.HasTargetType(StatusEffect.TargetType.NearbyItems) || - statusEffect.HasTargetType(StatusEffect.TargetType.NearbyCharacters)) + if (statusEffect.HasTargetType(StatusEffect.TargetType.NearbyEntities)) { targets.Clear(); statusEffect.AddNearbyTargets(WorldPosition, targets); diff --git a/Barotrauma/BarotraumaShared/SharedSource/Characters/Health/Afflictions/Affliction.cs b/Barotrauma/BarotraumaShared/SharedSource/Characters/Health/Afflictions/Affliction.cs index baa030c313..ee3d497111 100644 --- a/Barotrauma/BarotraumaShared/SharedSource/Characters/Health/Afflictions/Affliction.cs +++ b/Barotrauma/BarotraumaShared/SharedSource/Characters/Health/Afflictions/Affliction.cs @@ -487,8 +487,7 @@ public void ApplyStatusEffect(ActionType type, StatusEffect statusEffect, float { statusEffect.Apply(type, deltaTime, characterHealth.Character, targets: characterHealth.Character.AnimController.Limbs); } - if (statusEffect.HasTargetType(StatusEffect.TargetType.NearbyItems) || - statusEffect.HasTargetType(StatusEffect.TargetType.NearbyCharacters)) + if (statusEffect.HasTargetType(StatusEffect.TargetType.NearbyEntities)) { targets.Clear(); statusEffect.AddNearbyTargets(characterHealth.Character.WorldPosition, targets); diff --git a/Barotrauma/BarotraumaShared/SharedSource/Characters/Limb.cs b/Barotrauma/BarotraumaShared/SharedSource/Characters/Limb.cs index b6de960f53..76e43177da 100644 --- a/Barotrauma/BarotraumaShared/SharedSource/Characters/Limb.cs +++ b/Barotrauma/BarotraumaShared/SharedSource/Characters/Limb.cs @@ -1279,8 +1279,7 @@ public void ApplyStatusEffects(ActionType actionType, float deltaTime) } } } - if (statusEffect.HasTargetType(StatusEffect.TargetType.NearbyItems) || - statusEffect.HasTargetType(StatusEffect.TargetType.NearbyCharacters)) + if (statusEffect.HasTargetType(StatusEffect.TargetType.NearbyEntities)) { targets.Clear(); statusEffect.AddNearbyTargets(WorldPosition, targets); diff --git a/Barotrauma/BarotraumaShared/SharedSource/Extensions/GenericExtensions.cs b/Barotrauma/BarotraumaShared/SharedSource/Extensions/GenericExtensions.cs new file mode 100644 index 0000000000..58032bf6ce --- /dev/null +++ b/Barotrauma/BarotraumaShared/SharedSource/Extensions/GenericExtensions.cs @@ -0,0 +1,40 @@ +using System; +using System.Collections.Generic; +using System.Linq; + +namespace Barotrauma.Extensions +{ + public static class GenericExtensions + { + public static IEnumerable SelectManyRecursive(this T source, Func selector) + { + IEnumerable result = new List(); + T child = selector.Invoke(source); + + while (child != null) + { + result.Append(child); + child = selector.Invoke(child); + } + return result; + } + + public static IEnumerable SelectManyRecursive(this T source, Func selector, int maxDepth, int minDepth = 1) + { + minDepth = Math.Max(minDepth, 1); + maxDepth = Math.Max(maxDepth, minDepth); + + IEnumerable result = new List(); + T child = selector.Invoke(source); + + int depth = 1; + while (child != null && depth <= maxDepth) + { + if (depth >= minDepth) { result.Append(child); } + child = selector.Invoke(child); + depth++; + } + return result; + } + } +} \ No newline at end of file diff --git a/Barotrauma/BarotraumaShared/SharedSource/Extensions/IEnumerableExtensions.cs b/Barotrauma/BarotraumaShared/SharedSource/Extensions/IEnumerableExtensions.cs index 4a12a67c60..1ca7e84ad1 100644 --- a/Barotrauma/BarotraumaShared/SharedSource/Extensions/IEnumerableExtensions.cs +++ b/Barotrauma/BarotraumaShared/SharedSource/Extensions/IEnumerableExtensions.cs @@ -172,12 +172,22 @@ public static IEnumerable ToEnumerable(this T item) // source: https://stackoverflow.com/questions/19237868/get-all-children-to-one-list-recursive-c-sharp public static IEnumerable SelectManyRecursive(this IEnumerable source, Func> selector) { - var result = source.SelectMany(selector); - if (!result.Any()) + IEnumerable result = source.SelectMany(selector); + return result.Any() ? result.Concat(result.SelectManyRecursive(selector)) : result; + } + + public static IEnumerable SelectManyRecursive(this IEnumerable source, Func> selector, int maxDepth, int minDepth = 1) + { + minDepth = Math.Max(minDepth, 1); + maxDepth = Math.Max(maxDepth, minDepth); + + return RecursiveSearch(source, selector, minDepth, maxDepth, 1); + + static IEnumerable RecursiveSearch(IEnumerable source, Func> selector, int minDepth, int maxDepth, int depth) { - return result; + IEnumerable result = source.SelectMany(selector); + return result.Any() && depth <= maxDepth ? depth < minDepth ? RecursiveSearch(result, selector, minDepth, maxDepth, depth + 1) : result.Concat(RecursiveSearch(result, selector, minDepth, maxDepth, depth + 1)) : result; } - return result.Concat(result.SelectManyRecursive(selector)); } public static void AddIfNotNull(this IList source, T value) diff --git a/Barotrauma/BarotraumaShared/SharedSource/Items/Components/ItemContainer.cs b/Barotrauma/BarotraumaShared/SharedSource/Items/Components/ItemContainer.cs index a8a73f35a7..32083417b2 100644 --- a/Barotrauma/BarotraumaShared/SharedSource/Items/Components/ItemContainer.cs +++ b/Barotrauma/BarotraumaShared/SharedSource/Items/Components/ItemContainer.cs @@ -671,16 +671,15 @@ void Inject(Item item) { targets.AddRange(item.AllPropertyObjects); } - if (effect.HasTargetType(StatusEffect.TargetType.Contained)) + if (effect.HasTargetType(StatusEffect.TargetType.Descendants)) { - targets.AddRange(contained.AllPropertyObjects); + targets.AddRange(effect.GetContainedItems(contained, true).SelectMany(item => item.AllPropertyObjects)); } if (effect.HasTargetType(StatusEffect.TargetType.Character) && item.ParentInventory?.Owner is Character character) { targets.Add(character); } - if (effect.HasTargetType(StatusEffect.TargetType.NearbyItems) || - effect.HasTargetType(StatusEffect.TargetType.NearbyCharacters)) + if (effect.HasTargetType(StatusEffect.TargetType.NearbyEntities)) { effect.AddNearbyTargets(item.WorldPosition, targets); } diff --git a/Barotrauma/BarotraumaShared/SharedSource/Items/Components/Projectile.cs b/Barotrauma/BarotraumaShared/SharedSource/Items/Components/Projectile.cs index a2a0a573f5..797ce86867 100644 --- a/Barotrauma/BarotraumaShared/SharedSource/Items/Components/Projectile.cs +++ b/Barotrauma/BarotraumaShared/SharedSource/Items/Components/Projectile.cs @@ -1111,8 +1111,7 @@ private bool HandleProjectileCollision(Fixture target, Vector2 collisionNormal, { effect.Apply(effect.type, 1.0f, targetLimb.character, targetLimb); } - if (effect.HasTargetType(StatusEffect.TargetType.NearbyItems) || - effect.HasTargetType(StatusEffect.TargetType.NearbyCharacters)) + if (effect.HasTargetType(StatusEffect.TargetType.NearbyEntities)) { targets.Clear(); effect.AddNearbyTargets(targetLimb.WorldPosition, targets); diff --git a/Barotrauma/BarotraumaShared/SharedSource/Items/Item.cs b/Barotrauma/BarotraumaShared/SharedSource/Items/Item.cs index 35b3a877e9..a9f272ceac 100644 --- a/Barotrauma/BarotraumaShared/SharedSource/Items/Item.cs +++ b/Barotrauma/BarotraumaShared/SharedSource/Items/Item.cs @@ -1977,28 +1977,21 @@ public void ApplyStatusEffect(StatusEffect effect, ActionType type, float deltaT targets.Clear(); - if (effect.HasTargetType(StatusEffect.TargetType.Contained)) + if (effect.HasTargetType(StatusEffect.TargetType.Descendants)) { - foreach (Item containedItem in ContainedItems) + foreach (Item containedItem in effect.GetContainedItems(this)) { - if (effect.TargetIdentifiers != null && - !effect.TargetIdentifiers.Contains(((MapEntity)containedItem).Prefab.Identifier) && - !effect.TargetIdentifiers.Any(id => containedItem.HasTag(id))) + if (effect.TargetIdentifiers != null && !effect.TargetIdentifiers.Contains(containedItem.Prefab.Identifier) && !effect.TargetIdentifiers.Any(containedItem.HasTag)) { continue; } - if (effect.TargetSlot > -1) - { - if (!OwnInventory.GetItemsAt(effect.TargetSlot).Contains(containedItem)) { continue; } - } - hasTargets = true; targets.Add(containedItem); } } - if (effect.HasTargetType(StatusEffect.TargetType.NearbyCharacters) || effect.HasTargetType(StatusEffect.TargetType.NearbyItems)) + if (effect.HasTargetType(StatusEffect.TargetType.NearbyEntities)) { effect.AddNearbyTargets(WorldPosition, targets); if (targets.Count > 0) @@ -2058,8 +2051,11 @@ public void ApplyStatusEffect(StatusEffect effect, ActionType type, float deltaT targets.Add(limb); } - if (Container != null && effect.HasTargetType(StatusEffect.TargetType.Parent)) { targets.AddRange(Container.AllPropertyObjects); } - + if (effect.HasTargetType(StatusEffect.TargetType.Parents)) + { + targets.AddRange(effect.GetParentItems(this).SelectMany(item => item.AllPropertyObjects)); + } + effect.Apply(type, deltaTime, this, targets, worldPosition); } diff --git a/Barotrauma/BarotraumaShared/SharedSource/Map/Levels/LevelObjects/LevelTrigger.cs b/Barotrauma/BarotraumaShared/SharedSource/Map/Levels/LevelObjects/LevelTrigger.cs index d7c70391f4..8ec8debf33 100644 --- a/Barotrauma/BarotraumaShared/SharedSource/Map/Levels/LevelObjects/LevelTrigger.cs +++ b/Barotrauma/BarotraumaShared/SharedSource/Map/Levels/LevelObjects/LevelTrigger.cs @@ -662,16 +662,9 @@ public static void ApplyStatusEffects(List statusEffects, Vector2 if (triggerer is Character character) { effect.Apply(effect.type, deltaTime, triggerer, character, position); - if (effect.HasTargetType(StatusEffect.TargetType.Contained) && character.Inventory != null) + if (effect.HasTargetType(StatusEffect.TargetType.Descendants)) { - foreach (Item item in character.Inventory.AllItemsMod) - { - if (item.ContainedItems == null) { continue; } - foreach (Item containedItem in item.ContainedItems) - { - effect.Apply(effect.type, deltaTime, triggerer, containedItem.AllPropertyObjects, position); - } - } + effect.Apply(effect.type, deltaTime, triggerer, effect.GetContainedItems(character).SelectMany(item => item.AllPropertyObjects).ToList(), position); } } else if (triggerer is Item item) @@ -682,7 +675,7 @@ public static void ApplyStatusEffects(List statusEffects, Vector2 { effect.Apply(effect.type, deltaTime, sub, Array.Empty(), position); } - if (effect.HasTargetType(StatusEffect.TargetType.NearbyItems) || effect.HasTargetType(StatusEffect.TargetType.NearbyCharacters)) + if (effect.HasTargetType(StatusEffect.TargetType.NearbyEntities)) { targets.Clear(); effect.AddNearbyTargets(worldPosition, targets); diff --git a/Barotrauma/BarotraumaShared/SharedSource/StatusEffects/StatusEffect.cs b/Barotrauma/BarotraumaShared/SharedSource/StatusEffects/StatusEffect.cs index e7d287f790..88d11fa8be 100644 --- a/Barotrauma/BarotraumaShared/SharedSource/StatusEffects/StatusEffect.cs +++ b/Barotrauma/BarotraumaShared/SharedSource/StatusEffects/StatusEffect.cs @@ -122,7 +122,31 @@ public enum TargetType /// /// Last limb of the character the effect is being used on. /// - LastLimb = 1024 + LastLimb = 1024, + /// + /// The container of the container the item is inside (if any). + /// + GrandParent = 2048, + /// + /// The item(s) contained in the inventories of the item(s) contained in the inventory of the entity the StatusEffect is defined in. + /// + GrandChildren = 4096, + /// + /// Same as NearbyCharacters and NearbyItems. + /// + NearbyEntities = NearbyCharacters | NearbyItems, + /// + /// Same as Parent with RecursiveSearch. + /// + Parents = Parent | GrandParent, + /// + /// Same as Contained with RecursiveSearch. + /// + Descendants = Contained | GrandChildren, + /// + /// Same as This, Parents, and Descendants. + /// + Heirarchy = This | Parents | Descendants } /// @@ -531,6 +555,15 @@ public AITrigger(XElement element) /// public int TargetSlot = -1; + /// + /// Whether to search recursively when finding parent/child items. + /// + private readonly bool RecursiveSearch; + /// + /// Controls the depth at which the recursive search will take place. Requires . + /// + private readonly int MinSearchDepth, MaxSearchDepth; + private readonly List requiredItems; public readonly ImmutableArray<(Identifier propertyName, object value)> PropertyEffects; @@ -807,6 +840,9 @@ protected StatusEffect(ContentXElement element, string parentDebugName) TargetItemComponent = element.GetAttributeString("targetitemcomponent", string.Empty); TargetSlot = element.GetAttributeInt("targetslot", -1); + RecursiveSearch = element.GetAttributeBool("recursive", element.GetAttributeBool("recursivesearch", false)); + MinSearchDepth = element.GetAttributeInt("minsearchdepth", 1); + MaxSearchDepth = element.GetAttributeInt("maxsearchdepth", int.MaxValue); Range = element.GetAttributeFloat("range", 0.0f); Offset = element.GetAttributeVector2("offset", Vector2.Zero); @@ -835,6 +871,10 @@ protected StatusEffect(ContentXElement element, string parentDebugName) else { targetTypes |= targetType; + if (targetType is TargetType.Parents or TargetType.Descendants or TargetType.Heirarchy) + { + RecursiveSearch = true; + } } } if (targetTypes == 0) @@ -880,6 +920,8 @@ protected StatusEffect(ContentXElement element, string parentDebugName) case "targetlimb": case "delay": case "interval": + case "recursivesearch": + case "recursive": //aliases for fields we're already reading above, and which shouldn't be interpreted as values we're trying to set break; case "allowedafflictions": @@ -903,7 +945,7 @@ protected StatusEffect(ContentXElement element, string parentDebugName) DebugConsole.ThrowError($"Error in StatusEffect ({parentDebugName}): sounds should be defined as child elements of the StatusEffect, not as attributes.", contentPackage: element.ContentPackage); break; case "range": - if (!HasTargetType(TargetType.NearbyCharacters) && !HasTargetType(TargetType.NearbyItems)) + if (!HasTargetType(TargetType.NearbyEntities)) { propertyAttributes.Add(attribute); } @@ -1267,6 +1309,64 @@ bool CheckDistance(ISpatialEntity e) } } + public List GetContainedItems(Character character) => (TargetSlot > -1 ? character.Inventory.GetItemsAt(TargetSlot) : character.Inventory.AllItems).SelectMany(item => GetContainedItems(item, true)).ToList(); + + public List GetContainedItems(Item item, bool isChild = false) + { + List targets = new List(); + IEnumerable children = isChild ? new List { item } : (TargetSlot > -1 ? item.OwnInventory.GetItemsAt(TargetSlot) : item.ContainedItems); + + if (HasTargetType(TargetType.Contained)) + { + if (ProcessChildren()) { return targets; } + } + if (HasTargetType(TargetType.GrandChildren)) + { + children = children.SelectMany(item => item.ContainedItems); + if (ProcessChildren()) { return targets; } + } + return targets; + + bool ProcessChildren() + { + targets.AddRange(children); + if (RecursiveSearch) + { + targets.AddRange(children.SelectManyRecursive(item => item.ContainedItems, MinSearchDepth, MaxSearchDepth)); + return true; + } + return false; + } + } + + public List GetParentItems(Item item) + { + List targets = new List(); + Item parent = item.Container; + + if (HasTargetType(TargetType.Parent) && parent != null) + { + if (ProcessParent()) { return targets; } + } + if (HasTargetType(TargetType.GrandParent) && parent?.Container != null) + { + parent = parent.Container; + if (ProcessParent()) { return targets; } + } + return targets; + + bool ProcessParent() + { + targets.Add(parent); + if (RecursiveSearch) + { + targets.AddRange(parent.SelectManyRecursive(item => item.Container, MaxSearchDepth, MinSearchDepth)); + return true; + } + return false; + } + } + public bool HasRequiredConditions(IReadOnlyList targets) { return HasRequiredConditions(targets, propertyConditionals); From bc62fcef746c608e8339a7beab8665821f891356 Mon Sep 17 00:00:00 2001 From: Jade-Harleyy <67431770+Jade-Harleyy@users.noreply.github.com> Date: Wed, 11 Sep 2024 03:59:03 -0500 Subject: [PATCH 2/2] Remove redundancies. --- .../SharedSource/Characters/Attack.cs | 4 +- .../Items/Components/ItemContainer.cs | 2 +- .../SharedSource/Items/Item.cs | 4 +- .../Map/Levels/LevelObjects/LevelTrigger.cs | 2 +- .../StatusEffects/StatusEffect.cs | 54 ++----------------- 5 files changed, 9 insertions(+), 57 deletions(-) diff --git a/Barotrauma/BarotraumaShared/SharedSource/Characters/Attack.cs b/Barotrauma/BarotraumaShared/SharedSource/Characters/Attack.cs index c287a18009..8e6b7e47d7 100644 --- a/Barotrauma/BarotraumaShared/SharedSource/Characters/Attack.cs +++ b/Barotrauma/BarotraumaShared/SharedSource/Characters/Attack.cs @@ -588,7 +588,7 @@ public AttackResult DoDamage(Character attacker, IDamageable target, Vector2 wor effect.Apply(additionalEffectType, deltaTime, targetEntity, targetEntity as ISerializableEntity, worldPosition); } } - if (effect.HasTargetType(StatusEffect.TargetType.Descendants)) + if (effect.HasTargetType(StatusEffect.TargetType.Contained)) { targets.Clear(); targets.AddRange(effect.GetContainedItems(attacker)); @@ -674,7 +674,7 @@ public AttackResult DoDamageToLimb(Character attacker, Limb targetLimb, Vector2 effect.Apply(conditionalEffectType, deltaTime, targetLimb.character, targets); effect.Apply(ActionType.OnUse, deltaTime, targetLimb.character, targets); } - if (effect.HasTargetType(StatusEffect.TargetType.Descendants)) + if (effect.HasTargetType(StatusEffect.TargetType.Contained)) { targets.Clear(); targets.AddRange(effect.GetContainedItems(attacker)); diff --git a/Barotrauma/BarotraumaShared/SharedSource/Items/Components/ItemContainer.cs b/Barotrauma/BarotraumaShared/SharedSource/Items/Components/ItemContainer.cs index 32083417b2..c3a7aab8e2 100644 --- a/Barotrauma/BarotraumaShared/SharedSource/Items/Components/ItemContainer.cs +++ b/Barotrauma/BarotraumaShared/SharedSource/Items/Components/ItemContainer.cs @@ -671,7 +671,7 @@ void Inject(Item item) { targets.AddRange(item.AllPropertyObjects); } - if (effect.HasTargetType(StatusEffect.TargetType.Descendants)) + if (effect.HasTargetType(StatusEffect.TargetType.Contained)) { targets.AddRange(effect.GetContainedItems(contained, true).SelectMany(item => item.AllPropertyObjects)); } diff --git a/Barotrauma/BarotraumaShared/SharedSource/Items/Item.cs b/Barotrauma/BarotraumaShared/SharedSource/Items/Item.cs index a9f272ceac..f80785c32f 100644 --- a/Barotrauma/BarotraumaShared/SharedSource/Items/Item.cs +++ b/Barotrauma/BarotraumaShared/SharedSource/Items/Item.cs @@ -1977,7 +1977,7 @@ public void ApplyStatusEffect(StatusEffect effect, ActionType type, float deltaT targets.Clear(); - if (effect.HasTargetType(StatusEffect.TargetType.Descendants)) + if (effect.HasTargetType(StatusEffect.TargetType.Contained)) { foreach (Item containedItem in effect.GetContainedItems(this)) { @@ -2051,7 +2051,7 @@ public void ApplyStatusEffect(StatusEffect effect, ActionType type, float deltaT targets.Add(limb); } - if (effect.HasTargetType(StatusEffect.TargetType.Parents)) + if (effect.HasTargetType(StatusEffect.TargetType.Parent)) { targets.AddRange(effect.GetParentItems(this).SelectMany(item => item.AllPropertyObjects)); } diff --git a/Barotrauma/BarotraumaShared/SharedSource/Map/Levels/LevelObjects/LevelTrigger.cs b/Barotrauma/BarotraumaShared/SharedSource/Map/Levels/LevelObjects/LevelTrigger.cs index 8ec8debf33..c2888c0653 100644 --- a/Barotrauma/BarotraumaShared/SharedSource/Map/Levels/LevelObjects/LevelTrigger.cs +++ b/Barotrauma/BarotraumaShared/SharedSource/Map/Levels/LevelObjects/LevelTrigger.cs @@ -662,7 +662,7 @@ public static void ApplyStatusEffects(List statusEffects, Vector2 if (triggerer is Character character) { effect.Apply(effect.type, deltaTime, triggerer, character, position); - if (effect.HasTargetType(StatusEffect.TargetType.Descendants)) + if (effect.HasTargetType(StatusEffect.TargetType.Contained)) { effect.Apply(effect.type, deltaTime, triggerer, effect.GetContainedItems(character).SelectMany(item => item.AllPropertyObjects).ToList(), position); } diff --git a/Barotrauma/BarotraumaShared/SharedSource/StatusEffects/StatusEffect.cs b/Barotrauma/BarotraumaShared/SharedSource/StatusEffects/StatusEffect.cs index 88d11fa8be..082a0964a2 100644 --- a/Barotrauma/BarotraumaShared/SharedSource/StatusEffects/StatusEffect.cs +++ b/Barotrauma/BarotraumaShared/SharedSource/StatusEffects/StatusEffect.cs @@ -124,29 +124,9 @@ public enum TargetType /// LastLimb = 1024, /// - /// The container of the container the item is inside (if any). - /// - GrandParent = 2048, - /// - /// The item(s) contained in the inventories of the item(s) contained in the inventory of the entity the StatusEffect is defined in. - /// - GrandChildren = 4096, - /// /// Same as NearbyCharacters and NearbyItems. /// - NearbyEntities = NearbyCharacters | NearbyItems, - /// - /// Same as Parent with RecursiveSearch. - /// - Parents = Parent | GrandParent, - /// - /// Same as Contained with RecursiveSearch. - /// - Descendants = Contained | GrandChildren, - /// - /// Same as This, Parents, and Descendants. - /// - Heirarchy = This | Parents | Descendants + NearbyEntities = NearbyCharacters | NearbyItems } /// @@ -871,10 +851,6 @@ protected StatusEffect(ContentXElement element, string parentDebugName) else { targetTypes |= targetType; - if (targetType is TargetType.Parents or TargetType.Descendants or TargetType.Heirarchy) - { - RecursiveSearch = true; - } } } if (targetTypes == 0) @@ -1317,26 +1293,14 @@ public List GetContainedItems(Item item, bool isChild = false) IEnumerable children = isChild ? new List { item } : (TargetSlot > -1 ? item.OwnInventory.GetItemsAt(TargetSlot) : item.ContainedItems); if (HasTargetType(TargetType.Contained)) - { - if (ProcessChildren()) { return targets; } - } - if (HasTargetType(TargetType.GrandChildren)) - { - children = children.SelectMany(item => item.ContainedItems); - if (ProcessChildren()) { return targets; } - } - return targets; - - bool ProcessChildren() { targets.AddRange(children); if (RecursiveSearch) { targets.AddRange(children.SelectManyRecursive(item => item.ContainedItems, MinSearchDepth, MaxSearchDepth)); - return true; } - return false; } + return targets; } public List GetParentItems(Item item) @@ -1345,26 +1309,14 @@ public List GetParentItems(Item item) Item parent = item.Container; if (HasTargetType(TargetType.Parent) && parent != null) - { - if (ProcessParent()) { return targets; } - } - if (HasTargetType(TargetType.GrandParent) && parent?.Container != null) - { - parent = parent.Container; - if (ProcessParent()) { return targets; } - } - return targets; - - bool ProcessParent() { targets.Add(parent); if (RecursiveSearch) { targets.AddRange(parent.SelectManyRecursive(item => item.Container, MaxSearchDepth, MinSearchDepth)); - return true; } - return false; } + return targets; } public bool HasRequiredConditions(IReadOnlyList targets)