mirror of
https://github.com/corvax-team/ss14-wl.git
synced 2026-09-15 14:52:26 +02:00
* IoC source gen compatibility Can be merged before or after https://github.com/space-wizards/RobustToolbox/pull/6549 doesn't really matter. * Missed a spot
33 lines
1023 B
C#
33 lines
1023 B
C#
using Content.Shared.DeviceLinking.Components;
|
|
using Content.Shared.DeviceLinking.Events;
|
|
using Content.Shared.DeviceLinking.Systems;
|
|
using Robust.Shared.Random;
|
|
|
|
namespace Content.Server.DeviceLinking.Systems;
|
|
|
|
public sealed partial class RandomGateSystem : SharedRandomGateSystem
|
|
{
|
|
[Dependency] private DeviceLinkSystem _deviceLink = default!;
|
|
[Dependency] private IRobustRandom _random = default!;
|
|
|
|
public override void Initialize()
|
|
{
|
|
base.Initialize();
|
|
SubscribeLocalEvent<RandomGateComponent, SignalReceivedEvent>(OnSignalReceived);
|
|
}
|
|
|
|
private void OnSignalReceived(Entity<RandomGateComponent> ent, ref SignalReceivedEvent args)
|
|
{
|
|
if (args.Port != ent.Comp.InputPort)
|
|
return;
|
|
|
|
var output = _random.Prob(ent.Comp.SuccessProbability);
|
|
if (output != ent.Comp.LastOutput)
|
|
{
|
|
ent.Comp.LastOutput = output;
|
|
Dirty(ent);
|
|
_deviceLink.SendSignal(ent.Owner, ent.Comp.OutputPort, output);
|
|
}
|
|
}
|
|
}
|