Files
tbd-station-14/Content.Server/Conveyor/ConveyorSystem.cs
Paul Ritter e11a9b282a machine linking refactor to ecs (#4323)
* started work

* some more work, ui working (somewhat)

* stuff

* reorganization

* some more reorg

* conveyors

* conveyors working

* finalized (dis)connection
added linkattempt
added feedback text
work on conveyors

* removed command
add rangecheck

* fixed inrange check

* handling

* ui no longer kanser, ship it

* adresses reviews

* reformats file

* reformats file

Co-authored-by: Paul <ritter.paul1+git@googlemail.com>
2021-08-27 17:46:02 +02:00

52 lines
1.9 KiB
C#

using Content.Server.MachineLinking.Events;
using Content.Server.MachineLinking.Models;
using Content.Server.Stunnable.Components;
using Content.Shared.MachineLinking;
using Content.Shared.Notification.Managers;
using Robust.Shared.GameObjects;
using Robust.Shared.Localization;
namespace Content.Server.Conveyor
{
public class ConveyorSystem : EntitySystem
{
public override void Initialize()
{
base.Initialize();
SubscribeLocalEvent<ConveyorComponent, SignalReceivedEvent>(OnSignalReceived);
SubscribeLocalEvent<ConveyorComponent, PortDisconnectedEvent>(OnPortDisconnected);
SubscribeLocalEvent<ConveyorComponent, LinkAttemptEvent>(OnLinkAttempt);
}
private void OnLinkAttempt(EntityUid uid, ConveyorComponent component, LinkAttemptEvent args)
{
if (args.TransmitterComponent.Outputs.GetPort(args.TransmitterPort).Signal is TwoWayLeverSignal signal &&
signal != TwoWayLeverSignal.Middle)
{
args.Cancel();
if (args.Attemptee.TryGetComponent<StunnableComponent>(out var stunnableComponent))
{
stunnableComponent.Paralyze(2);
component.Owner.PopupMessage(args.Attemptee, Loc.GetString("conveyor-component-failed-link"));
}
}
}
private void OnPortDisconnected(EntityUid uid, ConveyorComponent component, PortDisconnectedEvent args)
{
component.SetState(TwoWayLeverSignal.Middle);
}
private void OnSignalReceived(EntityUid uid, ConveyorComponent component, SignalReceivedEvent args)
{
switch (args.Port)
{
case "state":
component.SetState((TwoWayLeverSignal) args.Value!);
break;
}
}
}
}