GeneratorSignalControlSystem.cs 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. using System.ComponentModel;
  2. using Content.Server.DeviceLinking.Events;
  3. using Content.Shared.Power.Generator;
  4. namespace Content.Server.Power.Generator;
  5. public sealed class GeneratorSignalControlSystem: EntitySystem
  6. {
  7. [Dependency] private readonly GeneratorSystem _generator = default!;
  8. [Dependency] private readonly ActiveGeneratorRevvingSystem _revving = default!;
  9. public override void Initialize()
  10. {
  11. base.Initialize();
  12. SubscribeLocalEvent<GeneratorSignalControlComponent, SignalReceivedEvent>(OnSignalReceived);
  13. }
  14. /// <summary>
  15. /// Change the state of the generator depending on what signal is sent.
  16. /// </summary>
  17. private void OnSignalReceived(EntityUid uid, GeneratorSignalControlComponent component, SignalReceivedEvent args)
  18. {
  19. if (!TryComp<FuelGeneratorComponent>(uid, out var generator))
  20. return;
  21. if (args.Port == component.OnPort)
  22. {
  23. _revving.StartAutoRevving(uid);
  24. }
  25. else if (args.Port == component.OffPort)
  26. {
  27. _generator.SetFuelGeneratorOn(uid, false, generator);
  28. _revving.StopAutoRevving(uid);
  29. }
  30. else if (args.Port == component.TogglePort)
  31. {
  32. if (generator.On)
  33. {
  34. _generator.SetFuelGeneratorOn(uid, false, generator);
  35. _revving.StopAutoRevving(uid);
  36. }
  37. else
  38. {
  39. _revving.StartAutoRevving(uid);
  40. }
  41. }
  42. }
  43. }