Files
OldThink/Content.Server/Conveyor/ConveyorSystem.cs

76 lines
2.9 KiB
C#
Raw Normal View History

using Content.Server.MachineLinking.Events;
using Content.Server.MachineLinking.System;
using Content.Server.Power.Components;
using Content.Server.Power.EntitySystems;
using Content.Server.Recycling;
using Content.Server.Recycling.Components;
using Content.Shared.Conveyor;
get that crap outta here (completely rewrites inventorysystem) (#5807) * some work * equip: done unequip: todo * unequipping done & refactored events * workin * movin * reee namespaces * stun * mobstate * fixes * some work on events * removes serverside itemcomp & misc fixes * work * smol merge fix * ports template to prototype & finishes ui * moves relay & adds containerenumerator * actions & cuffs * my god what is actioncode * more fixes * im loosing my grasp on reality * more fixes * more work * explosions * yes * more work * more fixes * merge master & misc fixed because i forgot to commit before merging master * more fixes * fixes * moar * more work * moar fixes * suffixmap * more work on client * motivation low * no. no containers * mirroring client to server * fixes * move serverinvcomp * serverinventorycomponent is dead * gaming * only strippable & ai left... * only ai and richtext left * fixes ai * fixes * fixes sprite layers * more fixes * resolves optional * yes * stable:tm: * fixes * moar fixes * moar * fix some tests * lmao * no comment * good to merge:tm: * fixes build but for real * adresses some reviews * adresses some more reviews * nullables, yo * fixes lobbyscreen * timid refactor to differentiate actor & target * adresses more reviews * more * my god what a mess * removed the rest of duplicates * removed duplicate slotflags and renamed shoes to feet * removes another unused one * yes * fixes lobby & makes tryunequip return unequipped item * fixes * some funny renames * fixes * misc improvements to attemptevents * fixes * merge fixes Co-authored-by: Paul Ritter <ritter.paul1@gmail.com>
2021-12-30 22:56:10 +01:00
using Content.Shared.Item;
namespace Content.Server.Conveyor
{
public sealed class ConveyorSystem : EntitySystem
{
[Dependency] private RecyclerSystem _recycler = default!;
[Dependency] private readonly SignalLinkerSystem _signalSystem = default!;
public override void Initialize()
{
base.Initialize();
2022-04-04 01:13:03 -05:00
SubscribeLocalEvent<ConveyorComponent, ComponentInit>(OnInit);
SubscribeLocalEvent<ConveyorComponent, SignalReceivedEvent>(OnSignalReceived);
SubscribeLocalEvent<ConveyorComponent, PowerChangedEvent>(OnPowerChanged);
}
2022-04-04 01:13:03 -05:00
private void OnInit(EntityUid uid, ConveyorComponent component, ComponentInit args)
{
_signalSystem.EnsureReceiverPorts(uid, component.ReversePort, component.ForwardPort, component.OffPort);
2022-04-04 01:13:03 -05:00
}
private void OnPowerChanged(EntityUid uid, ConveyorComponent component, PowerChangedEvent args)
{
UpdateAppearance(component);
}
private void UpdateAppearance(ConveyorComponent component)
{
if (!EntityManager.TryGetComponent<AppearanceComponent?>(component.Owner, out var appearance)) return;
var isPowered = this.IsPowered(component.Owner, EntityManager);
appearance.SetData(ConveyorVisuals.State, isPowered ? component.State : ConveyorState.Off);
}
private void OnSignalReceived(EntityUid uid, ConveyorComponent component, SignalReceivedEvent args)
{
if (args.Port == component.OffPort)
SetState(component, ConveyorState.Off);
else if (args.Port == component.ForwardPort)
SetState(component, ConveyorState.Forward);
else if (args.Port == component.ReversePort)
SetState(component, ConveyorState.Reverse);
}
2022-04-04 01:13:03 -05:00
private void SetState(ConveyorComponent component, ConveyorState state)
{
2022-04-04 01:13:03 -05:00
component.State = state;
if (TryComp<RecyclerComponent>(component.Owner, out var recycler))
{
if (component.State != ConveyorState.Off)
_recycler.EnableRecycler(recycler);
else
_recycler.DisableRecycler(recycler);
}
UpdateAppearance(component);
}
public bool CanRun(ConveyorComponent component)
{
return component.State != ConveyorState.Off &&
!EntityManager.HasComponent<SharedItemComponent>(component.Owner) &&
this.IsPowered(component.Owner, EntityManager);
}
}
}