diff --git a/Content.Server/GameObjects/Components/Disposal/DisposalBendComponent.cs b/Content.Server/GameObjects/Components/Disposal/DisposalBendComponent.cs
index fbf3ecc73d..b53c63a5dc 100644
--- a/Content.Server/GameObjects/Components/Disposal/DisposalBendComponent.cs
+++ b/Content.Server/GameObjects/Components/Disposal/DisposalBendComponent.cs
@@ -1,5 +1,4 @@
-using System.Collections.Generic;
-using Robust.Shared.GameObjects;
+using Robust.Shared.GameObjects;
using Robust.Shared.Maths;
using Robust.Shared.Serialization;
@@ -26,13 +25,13 @@ namespace Content.Server.GameObjects.Components.Disposal
var directions = ConnectableDirections();
var previousTube = holder.PreviousTube;
- if (previousTube == null || !Connected.ContainsValue(previousTube))
+ if (previousTube == null)
{
return directions[0];
}
- var first = Connected.GetValueOrDefault(directions[0]);
- return previousTube == first ? directions[1] : directions[0];
+ var previousDirection = DirectionTo(previousTube);
+ return previousDirection == directions[0] ? directions[1] : directions[0];
}
public override void ExposeData(ObjectSerializer serializer)
diff --git a/Content.Server/GameObjects/Components/Disposal/DisposalEntryComponent.cs b/Content.Server/GameObjects/Components/Disposal/DisposalEntryComponent.cs
index 9835f339d3..80765abd10 100644
--- a/Content.Server/GameObjects/Components/Disposal/DisposalEntryComponent.cs
+++ b/Content.Server/GameObjects/Components/Disposal/DisposalEntryComponent.cs
@@ -26,7 +26,7 @@ namespace Content.Server.GameObjects.Components.Disposal
return TryInsert(holderComponent);
}
- public bool TryInsert(DisposalHolderComponent holder)
+ private bool TryInsert(DisposalHolderComponent holder)
{
if (!Contents.Insert(holder.Owner))
{
diff --git a/Content.Server/GameObjects/Components/Disposal/DisposalJunctionComponent.cs b/Content.Server/GameObjects/Components/Disposal/DisposalJunctionComponent.cs
index ecb818abfd..f4ad5530fa 100644
--- a/Content.Server/GameObjects/Components/Disposal/DisposalJunctionComponent.cs
+++ b/Content.Server/GameObjects/Components/Disposal/DisposalJunctionComponent.cs
@@ -35,16 +35,16 @@ namespace Content.Server.GameObjects.Components.Disposal
public override Direction NextDirection(DisposalHolderComponent holder)
{
- var next = Owner.Transform.LocalRotation;
+ var next = Owner.Transform.LocalRotation.GetDir();
var directions = ConnectableDirections().Skip(1).ToArray();
- if (Connected.TryGetValue(next.GetDir(), out var forwardTube) &&
- holder.PreviousTube == forwardTube)
+ if (holder.PreviousTube == null ||
+ DirectionTo(holder.PreviousTube) == next)
{
return _random.Pick(directions);
}
- return next.GetDir();
+ return next;
}
public override void ExposeData(ObjectSerializer serializer)
diff --git a/Content.Server/GameObjects/Components/Disposal/DisposalTransitComponent.cs b/Content.Server/GameObjects/Components/Disposal/DisposalTransitComponent.cs
index e25610c28a..b4cbc1731c 100644
--- a/Content.Server/GameObjects/Components/Disposal/DisposalTransitComponent.cs
+++ b/Content.Server/GameObjects/Components/Disposal/DisposalTransitComponent.cs
@@ -1,5 +1,4 @@
using System;
-using System.Collections.Generic;
using Robust.Shared.GameObjects;
using Robust.Shared.Maths;
@@ -25,14 +24,14 @@ namespace Content.Server.GameObjects.Components.Disposal
var directions = ConnectableDirections();
var previousTube = holder.PreviousTube;
var forward = directions[0];
- if (previousTube == null || !Connected.ContainsValue(previousTube))
+
+ if (previousTube == null)
{
return forward;
}
- var forwardTube = Connected.GetValueOrDefault(forward);
var backward = directions[1];
- return previousTube == forwardTube ? backward : forward;
+ return DirectionTo(previousTube) == forward ? backward : forward;
}
}
}
diff --git a/Content.Server/GameObjects/Components/Disposal/DisposalTubeComponent.cs b/Content.Server/GameObjects/Components/Disposal/DisposalTubeComponent.cs
index b1b75b7b94..ed953b4e70 100644
--- a/Content.Server/GameObjects/Components/Disposal/DisposalTubeComponent.cs
+++ b/Content.Server/GameObjects/Components/Disposal/DisposalTubeComponent.cs
@@ -1,5 +1,5 @@
-using System;
-using System.Collections.Generic;
+#nullable enable
+using System;
using System.Linq;
using Content.Server.Interfaces.GameObjects.Components.Interaction;
using Content.Shared.GameObjects;
@@ -34,20 +34,13 @@ namespace Content.Server.GameObjects.Components.Disposal
private bool _connected;
private bool _broken;
- private string _clangSound;
+ private string _clangSound = default!;
///
/// Container of entities that are currently inside this tube
///
[ViewVariables]
- public Container Contents { get; private set; }
-
- ///
- /// Dictionary of tubes connecting to this one mapped by their direction
- ///
- [ViewVariables]
- protected Dictionary Connected { get; } =
- new Dictionary();
+ public Container Contents { get; private set; } = default!;
[ViewVariables]
private bool Anchored =>
@@ -67,10 +60,32 @@ namespace Content.Server.GameObjects.Components.Disposal
return NextDirection(holder).ToVec();
}
- public IDisposalTubeComponent NextTube(DisposalHolderComponent holder)
+ protected Direction DirectionTo(IDisposalTubeComponent other)
+ {
+ return (other.Owner.Transform.WorldPosition - Owner.Transform.WorldPosition).GetDir();
+ }
+
+ public IDisposalTubeComponent? NextTube(DisposalHolderComponent holder)
{
var nextDirection = NextDirection(holder);
- return Connected.GetValueOrDefault(nextDirection);
+ var snapGrid = Owner.GetComponent();
+ var tube = snapGrid
+ .GetInDir(nextDirection)
+ .Select(x => x.TryGetComponent(out IDisposalTubeComponent c) ? c : null)
+ .FirstOrDefault(x => x != null && x != this);
+
+ if (tube == null)
+ {
+ return null;
+ }
+
+ var oppositeDirection = new Angle(nextDirection.ToAngle().Theta + Math.PI).GetDir();
+ if (!tube.CanConnect(oppositeDirection, this))
+ {
+ return null;
+ }
+
+ return tube;
}
public bool Remove(DisposalHolderComponent holder)
@@ -105,45 +120,25 @@ namespace Content.Server.GameObjects.Components.Disposal
}
_connected = true;
-
- var snapGrid = Owner.GetComponent();
-
- foreach (var direction in ConnectableDirections())
- {
- var tube = snapGrid
- .GetInDir(direction)
- .Select(x => x.TryGetComponent(out IDisposalTubeComponent c) ? c : null)
- .FirstOrDefault(x => x != null && x != this);
-
- if (tube == null)
- {
- continue;
- }
-
- var oppositeDirection = new Angle(direction.ToAngle().Theta + Math.PI).GetDir();
- if (!tube.AdjacentConnected(oppositeDirection, this))
- {
- continue;
- }
-
- Connected.Add(direction, tube);
- }
}
- public bool AdjacentConnected(Direction direction, IDisposalTubeComponent tube)
+ public bool CanConnect(Direction direction, IDisposalTubeComponent with)
{
+ if (!_connected)
+ {
+ return false;
+ }
+
if (_broken)
{
return false;
}
- if (Connected.ContainsKey(direction) ||
- !ConnectableDirections().Contains(direction))
+ if (!ConnectableDirections().Contains(direction))
{
return false;
}
- Connected.Add(direction, tube);
return true;
}
@@ -165,64 +160,6 @@ namespace Content.Server.GameObjects.Components.Disposal
holder.ExitDisposals();
}
-
- foreach (var connected in Connected.Values)
- {
- connected.AdjacentDisconnected(this);
- }
-
- Connected.Clear();
- }
-
- public void AdjacentDisconnected(IDisposalTubeComponent adjacent)
- {
- foreach (var pair in Connected)
- {
- foreach (var entity in Contents.ContainedEntities)
- {
- if (!entity.TryGetComponent(out DisposalHolderComponent holder))
- {
- continue;
- }
-
- if (holder.PreviousTube == adjacent)
- {
- holder.PreviousTube = null;
- }
-
- if (holder.NextTube == adjacent)
- {
- holder.NextTube = null;
- }
- }
-
- if (pair.Value == adjacent)
- {
- Connected.Remove(pair.Key);
- }
- }
- }
-
- public void MoveEvent(MoveEvent moveEvent)
- {
- if (!_connected)
- {
- return;
- }
-
- foreach (var tube in Connected.Values)
- {
- var distance = (tube.Owner.Transform.WorldPosition - Owner.Transform.WorldPosition).Length;
-
- // Disconnect distance threshold
- if (distance < 1.25)
- {
- continue;
- }
-
- AdjacentDisconnected(tube);
- tube.AdjacentDisconnected(this);
- }
}
public void PopupDirections(IEntity entity)
@@ -299,7 +236,7 @@ namespace Content.Server.GameObjects.Components.Disposal
{
base.Startup();
- if (!Owner.GetComponent().Anchored)
+ if (!Owner.EnsureComponent().Anchored)
{
return;
}
@@ -318,7 +255,7 @@ namespace Content.Server.GameObjects.Components.Disposal
Disconnect();
}
- public override void HandleMessage(ComponentMessage message, IComponent component)
+ public override void HandleMessage(ComponentMessage message, IComponent? component)
{
base.HandleMessage(message, component);
diff --git a/Content.Server/GameObjects/Components/Disposal/IDisposalTubeComponent.cs b/Content.Server/GameObjects/Components/Disposal/IDisposalTubeComponent.cs
index ee6c8787e4..5077e7abbb 100644
--- a/Content.Server/GameObjects/Components/Disposal/IDisposalTubeComponent.cs
+++ b/Content.Server/GameObjects/Components/Disposal/IDisposalTubeComponent.cs
@@ -1,6 +1,5 @@
#nullable enable
using Robust.Server.GameObjects.Components.Container;
-using Robust.Shared.GameObjects.Components.Transform;
using Robust.Shared.Interfaces.GameObjects;
using Robust.Shared.Maths;
@@ -15,9 +14,7 @@ namespace Content.Server.GameObjects.Components.Disposal
IDisposalTubeComponent? NextTube(DisposalHolderComponent holder);
bool Remove(DisposalHolderComponent holder);
bool TransferTo(DisposalHolderComponent holder, IDisposalTubeComponent to);
- bool AdjacentConnected(Direction direction, IDisposalTubeComponent tube);
- void AdjacentDisconnected(IDisposalTubeComponent adjacent);
- void MoveEvent(MoveEvent moveEvent);
+ bool CanConnect(Direction direction, IDisposalTubeComponent with);
void PopupDirections(IEntity entity);
}
}
diff --git a/Content.Server/GameObjects/EntitySystems/DisposalTubeSystem.cs b/Content.Server/GameObjects/EntitySystems/DisposalTubeSystem.cs
deleted file mode 100644
index 4a8a108867..0000000000
--- a/Content.Server/GameObjects/EntitySystems/DisposalTubeSystem.cs
+++ /dev/null
@@ -1,33 +0,0 @@
-using Content.Server.GameObjects.Components.Disposal;
-using JetBrains.Annotations;
-using Robust.Shared.GameObjects.Components.Transform;
-using Robust.Shared.GameObjects.Systems;
-
-namespace Content.Server.GameObjects.EntitySystems
-{
- [UsedImplicitly]
- public class DisposalTubeSystem : EntitySystem
- {
- private void MoveEvent(MoveEvent moveEvent)
- {
- if (moveEvent.Sender.TryGetComponent(out IDisposalTubeComponent tube))
- {
- tube.MoveEvent(moveEvent);
- }
- }
-
- public override void Initialize()
- {
- base.Initialize();
-
- SubscribeLocalEvent(MoveEvent);
- }
-
- public override void Shutdown()
- {
- base.Shutdown();
-
- UnsubscribeLocalEvent();
- }
- }
-}