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:
SpeltIncorrectyl
2024-01-29 14:56:29 +00:00
committed by GitHub
parent 7bd22762ff
commit 5d2ddc0d8b
8 changed files with 240 additions and 7 deletions

View File

@@ -27,6 +27,7 @@ public sealed class PortableGeneratorSystem : SharedPortableGeneratorSystem
[Dependency] private readonly IRobustRandom _random = default!;
[Dependency] private readonly GeneratorSystem _generator = default!;
[Dependency] private readonly PowerSwitchableSystem _switchable = default!;
[Dependency] private readonly ActiveGeneratorRevvingSystem _revving = default!;
[Dependency] private readonly PowerNetSystem _powerNet = default!;
public override void Initialize()
@@ -38,7 +39,8 @@ public sealed class PortableGeneratorSystem : SharedPortableGeneratorSystem
UpdatesAfter.Add(typeof(PowerNetSystem));
SubscribeLocalEvent<PortableGeneratorComponent, GetVerbsEvent<AlternativeVerb>>(GetAlternativeVerb);
SubscribeLocalEvent<PortableGeneratorComponent, GeneratorStartedEvent>(GeneratorTugged);
SubscribeLocalEvent<PortableGeneratorComponent, GeneratorStartedEvent>(OnGeneratorStarted);
SubscribeLocalEvent<PortableGeneratorComponent, AutoGeneratorStartedEvent>(OnAutoGeneratorStarted);
SubscribeLocalEvent<PortableGeneratorComponent, PortableGeneratorStartMessage>(GeneratorStartMessage);
SubscribeLocalEvent<PortableGeneratorComponent, PortableGeneratorStopMessage>(GeneratorStopMessage);
SubscribeLocalEvent<PortableGeneratorComponent, PortableGeneratorSwitchOutputMessage>(GeneratorSwitchOutputMessage);
@@ -92,9 +94,30 @@ public sealed class PortableGeneratorSystem : SharedPortableGeneratorSystem
_generator.SetFuelGeneratorOn(uid, false);
}
private void GeneratorTugged(EntityUid uid, PortableGeneratorComponent component, GeneratorStartedEvent args)
private void OnGeneratorStarted(EntityUid uid, PortableGeneratorComponent component, GeneratorStartedEvent args)
{
if (args.Cancelled || !Transform(uid).Anchored)
if (args.Cancelled)
return;
GeneratorTugged(uid, component, args.User, out args.Repeat);
}
private void OnAutoGeneratorStarted(EntityUid uid, PortableGeneratorComponent component, ref AutoGeneratorStartedEvent args)
{
GeneratorTugged(uid, component, null, out var repeat);
// restart the auto rev if it should be repeated
if (repeat)
_revving.StartAutoRevving(uid);
else
args.Started = true;
}
private void GeneratorTugged(EntityUid uid, PortableGeneratorComponent component, EntityUid? user, out bool repeat)
{
repeat = false;
if (!Transform(uid).Anchored)
return;
var fuelGenerator = Comp<FuelGeneratorComponent>(uid);
@@ -107,14 +130,23 @@ public sealed class PortableGeneratorSystem : SharedPortableGeneratorSystem
if (!clogged && !empty && _random.Prob(component.StartChance))
{
_popup.PopupEntity(Loc.GetString("portable-generator-start-success"), uid, args.User);
_generator.SetFuelGeneratorOn(uid, true, fuelGenerator);
if (user is null)
return;
_popup.PopupEntity(Loc.GetString("portable-generator-start-success"), uid, user.Value);
}
else
{
_popup.PopupEntity(Loc.GetString("portable-generator-start-fail"), uid, args.User);
// Try again bozo
args.Repeat = true;
// try again bozo
repeat = true;
if (user is null)
return;
_popup.PopupEntity(Loc.GetString("portable-generator-start-fail"), uid, user.Value);
}
}