AntiRotOnBuckleSystem.cs 1.0 KB

123456789101112131415161718192021222324252627282930
  1. using Content.Server.Power.Components;
  2. using Content.Shared.Atmos.Rotting;
  3. using Content.Shared.Buckle.Components;
  4. using Content.Shared.Power;
  5. namespace Content.Server.Buckle.Systems;
  6. public sealed class AntiRotOnBuckleSystem : EntitySystem
  7. {
  8. public override void Initialize()
  9. {
  10. base.Initialize();
  11. SubscribeLocalEvent<BuckleComponent, IsRottingEvent>(OnIsRotting);
  12. SubscribeLocalEvent<AntiRotOnBuckleComponent, PowerChangedEvent>(OnPowerChanged);
  13. }
  14. private void OnIsRotting(EntityUid uid, BuckleComponent buckle, ref IsRottingEvent args)
  15. {
  16. if (args.Handled)
  17. return;
  18. args.Handled = buckle is { Buckled: true, BuckledTo: not null } &&
  19. TryComp<AntiRotOnBuckleComponent>(buckle.BuckledTo.Value, out var antiRot) &&
  20. antiRot.Enabled;
  21. }
  22. private void OnPowerChanged(EntityUid uid, AntiRotOnBuckleComponent component, ref PowerChangedEvent args)
  23. {
  24. component.Enabled = !component.RequiresPower || args.Powered;
  25. }
  26. }