signaller can be used as a payload (#14827)
Co-authored-by: deltanedas <@deltanedas:kde.org>
This commit is contained in:
@@ -1,31 +1,49 @@
|
|||||||
|
using Content.Server.Explosion.EntitySystems;
|
||||||
using Content.Server.MachineLinking.Components;
|
using Content.Server.MachineLinking.Components;
|
||||||
using JetBrains.Annotations;
|
|
||||||
using Content.Shared.Interaction.Events;
|
using Content.Shared.Interaction.Events;
|
||||||
|
using Content.Shared.Timing;
|
||||||
|
|
||||||
|
namespace Content.Server.MachineLinking.System;
|
||||||
|
|
||||||
namespace Content.Server.MachineLinking.System
|
|
||||||
{
|
|
||||||
[UsedImplicitly]
|
|
||||||
public sealed class SignallerSystem : EntitySystem
|
public sealed class SignallerSystem : EntitySystem
|
||||||
{
|
{
|
||||||
[Dependency] private readonly SignalLinkerSystem _signalSystem = default!;
|
[Dependency] private readonly SignalLinkerSystem _signal = default!;
|
||||||
|
[Dependency] private readonly UseDelaySystem _useDelay = default!;
|
||||||
|
|
||||||
public override void Initialize()
|
public override void Initialize()
|
||||||
{
|
{
|
||||||
base.Initialize();
|
base.Initialize();
|
||||||
|
|
||||||
SubscribeLocalEvent<SignallerComponent, ComponentInit>(OnInit);
|
SubscribeLocalEvent<SignallerComponent, ComponentInit>(OnInit);
|
||||||
SubscribeLocalEvent<SignallerComponent, UseInHandEvent>(OnUseInHand);
|
SubscribeLocalEvent<SignallerComponent, UseInHandEvent>(OnUseInHand);
|
||||||
|
SubscribeLocalEvent<SignallerComponent, TriggerEvent>(OnTrigger);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void OnInit(EntityUid uid, SignallerComponent component, ComponentInit args)
|
private void OnInit(EntityUid uid, SignallerComponent component, ComponentInit args)
|
||||||
{
|
{
|
||||||
_signalSystem.EnsureTransmitterPorts(uid, component.Port);
|
_signal.EnsureTransmitterPorts(uid, component.Port);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void OnUseInHand(EntityUid uid, SignallerComponent component, UseInHandEvent args)
|
private void OnUseInHand(EntityUid uid, SignallerComponent component, UseInHandEvent args)
|
||||||
{
|
{
|
||||||
if (args.Handled)
|
if (args.Handled)
|
||||||
return;
|
return;
|
||||||
_signalSystem.InvokePort(uid, component.Port);
|
_signal.InvokePort(uid, component.Port);
|
||||||
|
args.Handled = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void OnTrigger(EntityUid uid, SignallerComponent component, TriggerEvent args)
|
||||||
|
{
|
||||||
|
// if on cooldown, do nothing
|
||||||
|
var hasUseDelay = TryComp<UseDelayComponent>(uid, out var useDelay);
|
||||||
|
if (hasUseDelay && _useDelay.ActiveDelay(uid, useDelay))
|
||||||
|
return;
|
||||||
|
|
||||||
|
// set cooldown to prevent clocks
|
||||||
|
if (hasUseDelay)
|
||||||
|
_useDelay.BeginDelay(uid, useDelay);
|
||||||
|
|
||||||
|
_signal.InvokePort(uid, component.Port);
|
||||||
args.Handled = true;
|
args.Handled = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|||||||
@@ -16,3 +16,6 @@
|
|||||||
- type: SignalTransmitter
|
- type: SignalTransmitter
|
||||||
outputs:
|
outputs:
|
||||||
Pressed: []
|
Pressed: []
|
||||||
|
- type: Tag
|
||||||
|
tags:
|
||||||
|
- Payload
|
||||||
|
|||||||
Reference in New Issue
Block a user