diff --git a/Content.Shared/Body/Systems/SharedBodySystem.Organs.cs b/Content.Shared/Body/Systems/SharedBodySystem.Organs.cs index ed67e88da1..0ccc18120a 100644 --- a/Content.Shared/Body/Systems/SharedBodySystem.Organs.cs +++ b/Content.Shared/Body/Systems/SharedBodySystem.Organs.cs @@ -174,7 +174,7 @@ public partial class SharedBodySystem /// Returns a list of ValueTuples of and OrganComponent on each organ /// in the given body. /// - /// The entity to check for the component on. + /// The body entity id to check on. /// The body to check for organs on. /// The component to check for. public List<(T Comp, OrganComponent Organ)> GetBodyOrganComponents( @@ -185,7 +185,7 @@ public partial class SharedBodySystem if (!Resolve(uid, ref body)) return new List<(T Comp, OrganComponent Organ)>(); - var query = EntityManager.GetEntityQuery(); + var query = GetEntityQuery(); var list = new List<(T Comp, OrganComponent Organ)>(3); foreach (var organ in GetBodyOrgans(uid, body)) { @@ -200,7 +200,7 @@ public partial class SharedBodySystem /// Tries to get a list of ValueTuples of and OrganComponent on each organs /// in the given body. /// - /// The entity to check for the component on. + /// The body entity id to check on. /// The list of components. /// The body to check for organs on. /// The component to check for. @@ -219,12 +219,10 @@ public partial class SharedBodySystem comps = GetBodyOrganComponents(uid, body); - if (comps.Count == 0) - { - comps = null; - return false; - } + if (comps.Count != 0) + return true; - return true; + comps = null; + return false; } } diff --git a/Content.Shared/Body/Systems/SharedBodySystem.Parts.cs b/Content.Shared/Body/Systems/SharedBodySystem.Parts.cs index 2f1a7fec46..f6951f0024 100644 --- a/Content.Shared/Body/Systems/SharedBodySystem.Parts.cs +++ b/Content.Shared/Body/Systems/SharedBodySystem.Parts.cs @@ -350,4 +350,118 @@ public partial class SharedBodySystem return child.ParentSlot?.Child == parentId; } + + public IEnumerable GetBodyPartAdjacentParts(EntityUid partId, BodyPartComponent? part = null) + { + if (!Resolve(partId, ref part, false)) + yield break; + + if (part.ParentSlot != null) + yield return part.ParentSlot.Parent; + + foreach (var slot in part.Children.Values) + { + if (slot.Child != null) + yield return slot.Child.Value; + } + } + + public IEnumerable<(EntityUid AdjacentId, T Component)> GetBodyPartAdjacentPartsComponents( + EntityUid partId, + BodyPartComponent? part = null) + where T : Component + { + if (!Resolve(partId, ref part, false)) + yield break; + + var query = GetEntityQuery(); + foreach (var adjacentId in GetBodyPartAdjacentParts(partId, part)) + { + if (query.TryGetComponent(adjacentId, out var component)) + yield return (adjacentId, component); + } + } + + public bool TryGetBodyPartAdjacentPartsComponents( + EntityUid partId, + [NotNullWhen(true)] out List<(EntityUid AdjacentId, T Component)>? comps, + BodyPartComponent? part = null) + where T : Component + { + if (!Resolve(partId, ref part, false)) + { + comps = null; + return false; + } + + var query = GetEntityQuery(); + comps = new List<(EntityUid AdjacentId, T Component)>(); + foreach (var adjacentId in GetBodyPartAdjacentParts(partId, part)) + { + if (query.TryGetComponent(adjacentId, out var component)) + comps.Add((adjacentId, component)); + } + + if (comps.Count != 0) + return true; + + comps = null; + return false; + } + + /// + /// Returns a list of ValueTuples of and OrganComponent on each organ + /// in the given part. + /// + /// The part entity id to check on. + /// The part to check for organs on. + /// The component to check for. + public List<(T Comp, OrganComponent Organ)> GetBodyPartOrganComponents( + EntityUid uid, + BodyPartComponent? part = null) + where T : Component + { + if (!Resolve(uid, ref part)) + return new List<(T Comp, OrganComponent Organ)>(); + + var query = GetEntityQuery(); + var list = new List<(T Comp, OrganComponent Organ)>(); + foreach (var organ in GetPartOrgans(uid, part)) + { + if (query.TryGetComponent(organ.Id, out var comp)) + list.Add((comp, organ.Component)); + } + + return list; + } + + /// + /// Tries to get a list of ValueTuples of and OrganComponent on each organs + /// in the given part. + /// + /// The part entity id to check on. + /// The list of components. + /// The part to check for organs on. + /// The component to check for. + /// Whether any were found. + public bool TryGetBodyPartOrganComponents( + EntityUid uid, + [NotNullWhen(true)] out List<(T Comp, OrganComponent Organ)>? comps, + BodyPartComponent? part = null) + where T : Component + { + if (!Resolve(uid, ref part)) + { + comps = null; + return false; + } + + comps = GetBodyPartOrganComponents(uid, part); + + if (comps.Count != 0) + return true; + + comps = null; + return false; + } }