Machine Linking Overhaul (#7160)

This commit is contained in:
Jack Fox
2022-04-04 01:13:03 -05:00
committed by GitHub
parent fd7ea3f1e7
commit f957c58906
40 changed files with 605 additions and 696 deletions

View File

@@ -1,19 +1,16 @@
using System;
using System.Collections.Generic;
using Content.Server.MachineLinking.Components;
using Content.Server.MachineLinking.Events;
using Content.Server.MachineLinking.Models;
using Content.Server.Power.Components;
using Content.Server.Recycling;
using Content.Server.Recycling.Components;
using Content.Server.Stunnable;
using Content.Shared.Conveyor;
using Content.Shared.Item;
using Content.Shared.MachineLinking;
using Content.Shared.Movement.Components;
using Content.Shared.Popups;
using Robust.Shared.Containers;
using Robust.Shared.GameObjects;
using Robust.Shared.IoC;
using Robust.Shared.Localization;
using Robust.Shared.Maths;
using Robust.Shared.Physics;
@@ -23,18 +20,24 @@ namespace Content.Server.Conveyor
public sealed class ConveyorSystem : EntitySystem
{
[Dependency] private RecyclerSystem _recycler = default!;
[Dependency] private StunSystem _stunSystem = default!;
public override void Initialize()
{
base.Initialize();
SubscribeLocalEvent<ConveyorComponent, ComponentInit>(OnInit);
SubscribeLocalEvent<ConveyorComponent, SignalReceivedEvent>(OnSignalReceived);
SubscribeLocalEvent<ConveyorComponent, PortDisconnectedEvent>(OnPortDisconnected);
SubscribeLocalEvent<ConveyorComponent, LinkAttemptEvent>(OnLinkAttempt);
SubscribeLocalEvent<ConveyorComponent, PowerChangedEvent>(OnPowerChanged);
}
private void OnInit(EntityUid uid, ConveyorComponent component, ComponentInit args)
{
var receiver = EnsureComp<SignalReceiverComponent>(uid);
foreach (string port in Enum.GetNames<ConveyorState>())
if (!receiver.Inputs.ContainsKey(port))
receiver.AddPort(port);
}
private void OnPowerChanged(EntityUid uid, ConveyorComponent component, PowerChangedEvent args)
{
UpdateAppearance(component);
@@ -55,41 +58,15 @@ namespace Content.Server.Conveyor
}
}
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();
_stunSystem.TryParalyze(uid, TimeSpan.FromSeconds(2f), true);
component.Owner.PopupMessage(args.Attemptee, Loc.GetString("conveyor-component-failed-link"));
}
}
private void OnPortDisconnected(EntityUid uid, ConveyorComponent component, PortDisconnectedEvent args)
{
SetState(component, TwoWayLeverSignal.Middle);
}
private void OnSignalReceived(EntityUid uid, ConveyorComponent component, SignalReceivedEvent args)
{
switch (args.Port)
{
case "state":
SetState(component, (TwoWayLeverSignal) args.Value!);
break;
}
if (Enum.TryParse(args.Port, out ConveyorState state))
SetState(component, state);
}
private void SetState(ConveyorComponent component, TwoWayLeverSignal signal)
private void SetState(ConveyorComponent component, ConveyorState state)
{
component.State = signal switch
{
TwoWayLeverSignal.Left => ConveyorState.Reversed,
TwoWayLeverSignal.Middle => ConveyorState.Off,
TwoWayLeverSignal.Right => ConveyorState.Forward,
_ => ConveyorState.Off
};
component.State = state;
if (TryComp<RecyclerComponent>(component.Owner, out var recycler))
{