Apc device network and apc based light switch (#4908)
* Remove WireNet node group from cables Implement extension cable components and system Remove connection over distance logic from ApcPower... components * Add extension cable components to prototypes * Implement ApcNetwork Implement ApcNetSwitch * Fix ignoredComponents.cs * Add friend attribute to new components * Add construction graph for a light switch * Address reviews * Fix broken test * Move ConnectionType enum to DeviceNetworkComponent Change netId data definition to use the ConnectionType enum values Co-authored-by: Julian Giebel <j.giebel@netrocks.info>
This commit is contained in:
56
Content.Server/DeviceNetwork/Systems/ApcNetworkSystem.cs
Normal file
56
Content.Server/DeviceNetwork/Systems/ApcNetworkSystem.cs
Normal file
@@ -0,0 +1,56 @@
|
||||
using Content.Server.DeviceNetwork.Components;
|
||||
using Content.Server.NodeContainer;
|
||||
using JetBrains.Annotations;
|
||||
using Robust.Shared.GameObjects;
|
||||
using Content.Server.Power.EntitySystems;
|
||||
using Content.Server.Power.Nodes;
|
||||
|
||||
namespace Content.Server.DeviceNetwork.Systems
|
||||
{
|
||||
[UsedImplicitly]
|
||||
public class ApcNetworkSystem : EntitySystem
|
||||
{
|
||||
public override void Initialize()
|
||||
{
|
||||
base.Initialize();
|
||||
|
||||
SubscribeLocalEvent<ApcNetworkComponent, BeforePacketSentEvent>(OnBeforePacketSent);
|
||||
|
||||
SubscribeLocalEvent<ApcNetworkComponent, ExtensionCableSystem.ProviderConnectedEvent>(OnProviderConnected);
|
||||
SubscribeLocalEvent<ApcNetworkComponent, ExtensionCableSystem.ProviderDisconnectedEvent>(OnProviderDisconnected);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Checks if both devices are connected to the same apc
|
||||
/// </summary>
|
||||
private void OnBeforePacketSent(EntityUid uid, ApcNetworkComponent receiver, BeforePacketSentEvent args)
|
||||
{
|
||||
if (!EntityManager.TryGetComponent(args.Sender, out ApcNetworkComponent? sender)) return;
|
||||
|
||||
if (sender.ConnectedNode?.NodeGroup == null || !sender.ConnectedNode.NodeGroup.Equals(receiver.ConnectedNode?.NodeGroup))
|
||||
{
|
||||
args.Cancel();
|
||||
}
|
||||
}
|
||||
|
||||
private void OnProviderConnected(EntityUid uid, ApcNetworkComponent component, ExtensionCableSystem.ProviderConnectedEvent args)
|
||||
{
|
||||
if (!args.Provider.Owner.TryGetComponent(out NodeContainerComponent? nodeContainer)) return;
|
||||
|
||||
if (nodeContainer.TryGetNode("power", out CableNode? node))
|
||||
{
|
||||
component.ConnectedNode = node;
|
||||
}
|
||||
else if (nodeContainer.TryGetNode("output", out CableDeviceNode? deviceNode))
|
||||
{
|
||||
component.ConnectedNode = deviceNode;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private void OnProviderDisconnected(EntityUid uid, ApcNetworkComponent component, ExtensionCableSystem.ProviderDisconnectedEvent args)
|
||||
{
|
||||
component.ConnectedNode = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user