Files
Borsh 6fc13a5875 Adding a random gate (#41627)
* Added random gate

* minor edit

* cleaning up my shit after trying to do something faster

* new lines

* some changes

* joke

* UI

* Long Division

* Dont use ctrl + x in 3 am

* I hope these are the final touches

* One thing, I don't know why

* noname commit

* no way, 1kk of code lines edit

* sudo rm -rf ... and something there...

* update

* sometimes its sad
2025-12-14 19:15:22 +00:00

33 lines
1.0 KiB
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 class RandomGateSystem : SharedRandomGateSystem
{
[Dependency] private readonly DeviceLinkSystem _deviceLink = default!;
[Dependency] private readonly 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);
}
}
}