1
0

AdjustAlert.cs 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. using Content.Shared.Alert;
  2. using Content.Shared.EntityEffects;
  3. using Robust.Shared.Prototypes;
  4. using Robust.Shared.Timing;
  5. namespace Content.Server.EntityEffects.Effects;
  6. public sealed partial class AdjustAlert : EntityEffect
  7. {
  8. /// <summary>
  9. /// The specific Alert that will be adjusted
  10. /// </summary>
  11. [DataField(required: true)]
  12. public ProtoId<AlertPrototype> AlertType;
  13. /// <summary>
  14. /// If true, the alert is removed after Time seconds. If Time was not specified the alert is removed immediately.
  15. /// </summary>
  16. [DataField]
  17. public bool Clear;
  18. /// <summary>
  19. /// Visually display cooldown progress over the alert icon.
  20. /// </summary>
  21. [DataField]
  22. public bool ShowCooldown;
  23. /// <summary>
  24. /// The length of the cooldown or delay before removing the alert (in seconds).
  25. /// </summary>
  26. [DataField]
  27. public float Time;
  28. //JUSTIFICATION: This just changes some visuals, doesn't need to be documented.
  29. protected override string? ReagentEffectGuidebookText(IPrototypeManager prototype, IEntitySystemManager entSys) => null;
  30. public override void Effect(EntityEffectBaseArgs args)
  31. {
  32. var alertSys = args.EntityManager.EntitySysManager.GetEntitySystem<AlertsSystem>();
  33. if (!args.EntityManager.HasComponent<AlertsComponent>(args.TargetEntity))
  34. return;
  35. if (Clear && Time <= 0)
  36. {
  37. alertSys.ClearAlert(args.TargetEntity, AlertType);
  38. }
  39. else
  40. {
  41. var timing = IoCManager.Resolve<IGameTiming>();
  42. (TimeSpan, TimeSpan)? cooldown = null;
  43. if ((ShowCooldown || Clear) && Time > 0)
  44. cooldown = (timing.CurTime, timing.CurTime + TimeSpan.FromSeconds(Time));
  45. alertSys.ShowAlert(args.TargetEntity, AlertType, cooldown: cooldown, autoRemove: Clear, showCooldown: ShowCooldown);
  46. }
  47. }
  48. }