diff --git a/Content.Server/Containers/ContainerExt.cs b/Content.Server/Containers/ContainerExt.cs deleted file mode 100644 index 9245b58375..0000000000 --- a/Content.Server/Containers/ContainerExt.cs +++ /dev/null @@ -1,42 +0,0 @@ -using Robust.Shared.Containers; - -namespace Content.Server.Containers -{ - public static class ContainerExt - { - /// - /// Searches the entity, and the entities containers recursively for a prototypeId - /// - /// The entity to search - /// The prototypeId to find - /// Optional entity manager - /// True if entity is, or contains a prototype Id - public static bool ContainsPrototypeRecursive(this EntityUid entityUid, string prototypeId, IEntityManager? entityManager = null) - { - IoCManager.Resolve(ref entityManager); - var metaQuery = entityManager.GetEntityQuery(); - var managerQuery = entityManager.GetEntityQuery(); - var stack = new Stack(); - if (metaQuery.GetComponent(entityUid).EntityPrototype?.ID == prototypeId) - return true; - if (!managerQuery.TryGetComponent(entityUid, out var currentManager)) - return false; - do - { - foreach (var container in currentManager.Containers.Values) - { - foreach (var entity in container.ContainedEntities) - { - if (metaQuery.GetComponent(entity).EntityPrototype?.ID == prototypeId) - return true; - if (!managerQuery.TryGetComponent(entity, out var containerManager)) - continue; - stack.Push(containerManager); - } - } - } while (stack.TryPop(out currentManager)); - - return false; - } - } -} diff --git a/Content.Server/Objectives/Conditions/StealCondition.cs b/Content.Server/Objectives/Conditions/StealCondition.cs index 98758cfccb..a5ac6160c5 100644 --- a/Content.Server/Objectives/Conditions/StealCondition.cs +++ b/Content.Server/Objectives/Conditions/StealCondition.cs @@ -1,12 +1,14 @@ using Content.Server.Containers; using Content.Server.Objectives.Interfaces; using JetBrains.Annotations; +using Robust.Shared.Containers; using Robust.Shared.Prototypes; using Robust.Shared.Serialization; using Robust.Shared.Utility; namespace Content.Server.Objectives.Conditions { + // Oh god my eyes [UsedImplicitly] [DataDefinition] public sealed class StealCondition : IObjectiveCondition, ISerializationHooks @@ -46,9 +48,41 @@ namespace Content.Server.Objectives.Conditions { get { - if (_mind?.OwnedEntity is not {Valid: true} owned) - return 0f; - return owned.ContainsPrototypeRecursive(_prototypeId)? 1f : 0f; + var uid = _mind?.OwnedEntity; + var entMan = IoCManager.Resolve(); + + // TODO make this a container system function + // or: just iterate through transform children, instead of containers? + + var metaQuery = entMan.GetEntityQuery(); + var managerQuery = entMan.GetEntityQuery(); + var stack = new Stack(); + + if (!metaQuery.TryGetComponent(_mind?.OwnedEntity, out var meta)) + return 0; + + if (meta.EntityPrototype?.ID == _prototypeId) + return 1; + + if (!managerQuery.TryGetComponent(uid, out var currentManager)) + return 0; + + do + { + foreach (var container in currentManager.Containers.Values) + { + foreach (var entity in container.ContainedEntities) + { + if (metaQuery.GetComponent(entity).EntityPrototype?.ID == _prototypeId) + return 1; + if (!managerQuery.TryGetComponent(entity, out var containerManager)) + continue; + stack.Push(containerManager); + } + } + } while (stack.TryPop(out currentManager)); + + return 0; } }