From c37c39fe3c975b1fb472c8c70e3c3e77c727c46a Mon Sep 17 00:00:00 2001 From: DrSmugleaf Date: Sat, 29 Aug 2020 13:13:08 +0200 Subject: [PATCH] Fix not checking both perspectives of a disposals tube connection (#1947) * Fix not checking both perspectives of a disposals tube connection * Good night LINQ Switch to Reactive whence * by god --- .../Disposal/DisposalTubeComponent.cs | 26 +++++++++++++++---- 1 file changed, 21 insertions(+), 5 deletions(-) diff --git a/Content.Server/GameObjects/Components/Disposal/DisposalTubeComponent.cs b/Content.Server/GameObjects/Components/Disposal/DisposalTubeComponent.cs index 5055312f56..f03abfd8b0 100644 --- a/Content.Server/GameObjects/Components/Disposal/DisposalTubeComponent.cs +++ b/Content.Server/GameObjects/Components/Disposal/DisposalTubeComponent.cs @@ -69,12 +69,28 @@ namespace Content.Server.GameObjects.Components.Disposal var nextDirection = NextDirection(holder); var snapGrid = Owner.GetComponent(); var oppositeDirection = new Angle(nextDirection.ToAngle().Theta + Math.PI).GetDir(); - var tube = snapGrid - .GetInDir(nextDirection) - .Select(x => x.TryGetComponent(out IDisposalTubeComponent? c) ? c : null) - .FirstOrDefault(x => x != null && x != this && x.CanConnect(oppositeDirection, this)); - return tube; + foreach (var entity in snapGrid.GetInDir(nextDirection)) + { + if (!entity.TryGetComponent(out IDisposalTubeComponent? tube)) + { + continue; + } + + if (!tube.CanConnect(oppositeDirection, this)) + { + continue; + } + + if (!CanConnect(nextDirection, tube)) + { + continue; + } + + return tube; + } + + return null; } public bool Remove(DisposalHolderComponent holder)