diff --git a/Content.Server/GameObjects/Components/NodeContainer/Nodes/AdjacentNode.cs b/Content.Server/GameObjects/Components/NodeContainer/Nodes/AdjacentNode.cs index 3bb66265ea..3badc4fe7f 100644 --- a/Content.Server/GameObjects/Components/NodeContainer/Nodes/AdjacentNode.cs +++ b/Content.Server/GameObjects/Components/NodeContainer/Nodes/AdjacentNode.cs @@ -1,5 +1,4 @@ -using System.Collections.Generic; -using System.Linq; +using System.Collections.Generic; using Robust.Shared.GameObjects.Components.Transform; namespace Content.Server.GameObjects.Components.NodeContainer.Nodes @@ -11,13 +10,25 @@ namespace Content.Server.GameObjects.Components.NodeContainer.Nodes { protected override IEnumerable GetReachableNodes() { - return Owner.GetComponent() - .GetCardinalNeighborCells() - .SelectMany(sgc => sgc.GetLocal()) - .Select(entity => entity.TryGetComponent(out var container) ? container : null) - .Where(container => container != null) - .SelectMany(container => container.Nodes) - .Where(node => node != null && node != this); + var cells = Owner.GetComponent() + .GetCardinalNeighborCells(); + + foreach (var cell in cells) + { + foreach (var entity in cell.GetLocal()) + { + if (entity.TryGetComponent(out var container)) + { + foreach (var node in container.Nodes) + { + if (node != null && node != this) + { + yield return node; + } + } + } + } + } } } } diff --git a/Content.Server/GameObjects/Components/NodeContainer/Nodes/PipeNode.cs b/Content.Server/GameObjects/Components/NodeContainer/Nodes/PipeNode.cs index 46ed4f00c4..cc4c25207d 100644 --- a/Content.Server/GameObjects/Components/NodeContainer/Nodes/PipeNode.cs +++ b/Content.Server/GameObjects/Components/NodeContainer/Nodes/PipeNode.cs @@ -1,6 +1,4 @@ -using System; using System.Collections.Generic; -using System.Linq; using Content.Server.Atmos; using Content.Server.GameObjects.Components.NodeContainer.NodeGroups; using Content.Server.Interfaces; @@ -107,17 +105,30 @@ namespace Content.Server.GameObjects.Components.NodeContainer.Nodes var ownNeededConnection = pipeDirection; var theirNeededConnection = ownNeededConnection.GetOpposite(); - if (!_pipeDirection.HasFlag(ownNeededConnection)) + if (!_pipeDirection.HasDirection(ownNeededConnection)) { continue; } - var pipeNodesInDirection = Owner.GetComponent() - .GetInDir(pipeDirection.ToDirection()) - .Select(entity => entity.TryGetComponent(out var container) ? container : null) - .Where(container => container != null) - .SelectMany(container => container.Nodes) - .OfType() - .Where(pipeNode => pipeNode._pipeDirection.HasFlag(theirNeededConnection)); + + var pipeNodesInDirection = new List(); + + var entities = Owner.GetComponent() + .GetInDir(pipeDirection.ToDirection()); + + foreach (var entity in entities) + { + if (entity.TryGetComponent(out var container)) + { + foreach (var node in container.Nodes) + { + if (node is PipeNode pipeNode && pipeNode._pipeDirection.HasDirection(theirNeededConnection)) + { + pipeNodesInDirection.Add(pipeNode); + } + } + } + } + foreach (var pipeNode in pipeNodesInDirection) { yield return pipeNode; diff --git a/Content.Server/GameObjects/Components/Power/ApcNetComponents/PowerProviderComponent.cs b/Content.Server/GameObjects/Components/Power/ApcNetComponents/PowerProviderComponent.cs index 570357c3bc..2284963d5a 100644 --- a/Content.Server/GameObjects/Components/Power/ApcNetComponents/PowerProviderComponent.cs +++ b/Content.Server/GameObjects/Components/Power/ApcNetComponents/PowerProviderComponent.cs @@ -1,6 +1,5 @@ using System; using System.Collections.Generic; -using System.Linq; using Content.Server.GameObjects.Components.NodeContainer.NodeGroups; using Robust.Shared.GameObjects; using Robust.Shared.Interfaces.GameObjects; @@ -109,12 +108,21 @@ namespace Content.Server.GameObjects.Components.Power.ApcNetComponents { var nearbyEntities = Owner.EntityManager .GetEntitiesInRange(Owner, PowerTransferRange); - return nearbyEntities.Select(entity => entity.TryGetComponent(out var receiver) ? receiver : null) - .Where(receiver => receiver != null) - .Where(receiver => receiver.Connectable) - .Where(receiver => receiver.NeedsProvider) - .Where(receiver => receiver.Owner.Transform.Coordinates.TryDistance(Owner.EntityManager, Owner.Transform.Coordinates, out var distance) && distance < Math.Min(PowerTransferRange, receiver.PowerReceptionRange)) - .ToList(); + + var receivers = new List(); + + foreach (var entity in nearbyEntities) + { + if (entity.TryGetComponent(out var receiver) && + receiver.Connectable && + receiver.NeedsProvider && + receiver.Owner.Transform.Coordinates.TryDistance(Owner.EntityManager, Owner.Transform.Coordinates, out var distance) && + distance < Math.Min(PowerTransferRange, receiver.PowerReceptionRange)) + { + receivers.Add(receiver); + } + } + return receivers; } protected override void AddSelfToNet(IApcNet apcNet) diff --git a/Content.Shared/GameObjects/Components/Atmos/SharedPipeComponent.cs b/Content.Shared/GameObjects/Components/Atmos/SharedPipeComponent.cs index 25301171ab..b5c4f222a6 100644 --- a/Content.Shared/GameObjects/Components/Atmos/SharedPipeComponent.cs +++ b/Content.Shared/GameObjects/Components/Atmos/SharedPipeComponent.cs @@ -1,6 +1,6 @@ -using System; using Robust.Shared.Maths; using Robust.Shared.Serialization; +using System; namespace Content.Shared.GameObjects.Components.Atmos { @@ -76,6 +76,11 @@ namespace Content.Shared.GameObjects.Components.Atmos { public const int PipeDirections = 4; + public static bool HasDirection(this PipeDirection pipeDirection, PipeDirection other) + { + return (pipeDirection & other) == other; + } + public static Angle ToAngle(this PipeDirection pipeDirection) { return pipeDirection switch