Adds signal control to portable generators (#24157)
* added signal control to portable generators * added documentation * Discard changes to Content.Server/Radio/EntitySystems/HeadsetSystem.cs * added DeviceNetworkComponent and WirelessNetworkConnectionComponent to generator prototype * made GeneratorSignalControlComponent nicer * implemented auto-revving * added back necessary dependency * can't send do-after event manually * repeat now works with auto revving * fixed * removed vv * stopping generating when it is revving now makes it stop revving * Update Content.Shared/Power/Generator/ActiveGeneratorRevvingComponent.cs Co-authored-by: Kara <lunarautomaton6@gmail.com> * used resolve instead of TryComp --------- Co-authored-by: Julian Giebel <juliangiebel@live.de> Co-authored-by: Kara <lunarautomaton6@gmail.com>
This commit is contained in:
@@ -0,0 +1,48 @@
|
||||
using System.ComponentModel;
|
||||
using Content.Server.DeviceLinking.Events;
|
||||
using Content.Shared.Power.Generator;
|
||||
|
||||
namespace Content.Server.Power.Generator;
|
||||
|
||||
public sealed class GeneratorSignalControlSystem: EntitySystem
|
||||
{
|
||||
[Dependency] private readonly GeneratorSystem _generator = default!;
|
||||
[Dependency] private readonly ActiveGeneratorRevvingSystem _revving = default!;
|
||||
|
||||
public override void Initialize()
|
||||
{
|
||||
base.Initialize();
|
||||
SubscribeLocalEvent<GeneratorSignalControlComponent, SignalReceivedEvent>(OnSignalReceived);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Change the state of the generator depending on what signal is sent.
|
||||
/// </summary>
|
||||
private void OnSignalReceived(EntityUid uid, GeneratorSignalControlComponent component, SignalReceivedEvent args)
|
||||
{
|
||||
if (!TryComp<FuelGeneratorComponent>(uid, out var generator))
|
||||
return;
|
||||
|
||||
if (args.Port == component.OnPort)
|
||||
{
|
||||
_revving.StartAutoRevving(uid);
|
||||
}
|
||||
else if (args.Port == component.OffPort)
|
||||
{
|
||||
_generator.SetFuelGeneratorOn(uid, false, generator);
|
||||
_revving.StopAutoRevving(uid);
|
||||
}
|
||||
else if (args.Port == component.TogglePort)
|
||||
{
|
||||
if (generator.On)
|
||||
{
|
||||
_generator.SetFuelGeneratorOn(uid, false, generator);
|
||||
_revving.StopAutoRevving(uid);
|
||||
}
|
||||
else
|
||||
{
|
||||
_revving.StartAutoRevving(uid);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user