Files
tbd-station-14/Content.Server/DeviceLinking/Systems/AutoLinkSystem.cs
Julian Giebel 6ebd784cb6 Device Linking and better linking ui (#13645)
Co-authored-by: AJCM-git <60196617+AJCM-git@users.noreply.github.com>
Co-authored-by: Visne <39844191+Visne@users.noreply.github.com>
Co-authored-by: ElectroJr <leonsfriedrich@gmail.com>
Co-authored-by: metalgearsloth <comedian_vs_clown@hotmail.com>
2023-05-07 16:07:24 +10:00

38 lines
1.1 KiB
C#

using Content.Server.DeviceLinking.Components;
using Content.Server.MachineLinking.System;
namespace Content.Server.DeviceLinking.Systems;
/// <summary>
/// This handles automatically linking autolinked entities at round-start.
/// </summary>
public sealed class AutoLinkSystem : EntitySystem
{
[Dependency] private readonly DeviceLinkSystem _deviceLinkSystem = default!;
/// <inheritdoc/>
public override void Initialize()
{
SubscribeLocalEvent<AutoLinkTransmitterComponent, MapInitEvent>(OnAutoLinkMapInit);
}
private void OnAutoLinkMapInit(EntityUid uid, AutoLinkTransmitterComponent component, MapInitEvent args)
{
var xform = Transform(uid);
foreach (var receiver in EntityQuery<AutoLinkReceiverComponent>())
{
if (receiver.AutoLinkChannel != component.AutoLinkChannel)
continue; // Not ours.
var rxXform = Transform(receiver.Owner);
if (rxXform.GridUid != xform.GridUid)
continue;
_deviceLinkSystem.LinkDefaults(null, uid, receiver.Owner);
}
}
}