diff --git a/Content.Server/Body/Systems/BodySystem.cs b/Content.Server/Body/Systems/BodySystem.cs index a9d0e0be50..f7635157d7 100644 --- a/Content.Server/Body/Systems/BodySystem.cs +++ b/Content.Server/Body/Systems/BodySystem.cs @@ -47,18 +47,22 @@ namespace Content.Server.Body.Systems /// The entity to check for the component on. /// The body to check for mechanisms on. /// The component to check for. - public IEnumerable<(T Comp, MechanismComponent Mech)> GetComponentsOnMechanisms(EntityUid uid, + public List<(T Comp, MechanismComponent Mech)> GetComponentsOnMechanisms(EntityUid uid, SharedBodyComponent? body=null) where T : Component { if (!Resolve(uid, ref body)) - yield break; + return new(); + var query = EntityManager.GetEntityQuery(); + var list = new List<(T Comp, MechanismComponent Mech)>(3); foreach (var (part, _) in body.Parts) foreach (var mechanism in part.Mechanisms) { - if (EntityManager.TryGetComponent((mechanism).Owner, out var comp)) - yield return (comp, mechanism); + if (query.TryGetComponent(mechanism.Owner, out var comp)) + list.Add((comp, mechanism)); } + + return list; } /// @@ -71,7 +75,7 @@ namespace Content.Server.Body.Systems /// The component to check for. /// Whether any were found. public bool TryGetComponentsOnMechanisms(EntityUid uid, - [NotNullWhen(true)] out IEnumerable<(T Comp, MechanismComponent Mech)>? comps, + [NotNullWhen(true)] out List<(T Comp, MechanismComponent Mech)>? comps, SharedBodyComponent? body=null) where T: Component { if (!Resolve(uid, ref body)) @@ -80,9 +84,9 @@ namespace Content.Server.Body.Systems return false; } - comps = GetComponentsOnMechanisms(uid, body).ToArray(); + comps = GetComponentsOnMechanisms(uid, body); - if (!comps.Any()) + if (comps.Count == 0) { comps = null; return false; diff --git a/Content.Server/Body/Systems/RespiratorSystem.cs b/Content.Server/Body/Systems/RespiratorSystem.cs index 1b016dd298..17e52c7b36 100644 --- a/Content.Server/Body/Systems/RespiratorSystem.cs +++ b/Content.Server/Body/Systems/RespiratorSystem.cs @@ -99,7 +99,7 @@ namespace Content.Server.Body.Systems if (!Resolve(uid, ref body, false)) return; - var organs = _bodySystem.GetComponentsOnMechanisms(uid, body).ToArray(); + var organs = _bodySystem.GetComponentsOnMechanisms(uid, body); // Inhale gas var ev = new InhaleLocationEvent(); @@ -114,8 +114,8 @@ namespace Content.Server.Body.Systems var ratio = (Atmospherics.BreathVolume / ev.Gas.Volume); var actualGas = ev.Gas.RemoveRatio(ratio); - var lungRatio = 1.0f / organs.Length; - var gas = organs.Length == 1 ? actualGas : actualGas.RemoveRatio(lungRatio); + var lungRatio = 1.0f / organs.Count; + var gas = organs.Count == 1 ? actualGas : actualGas.RemoveRatio(lungRatio); foreach (var (lung, _) in organs) { // Merge doesn't remove gas from the giver.