1
0

UseDelayComponent.cs 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. using Robust.Shared.GameStates;
  2. using Robust.Shared.Serialization;
  3. namespace Content.Shared.Timing;
  4. /// <summary>
  5. /// Timer that creates a cooldown each time an object is activated/used.
  6. /// Can support additional, separate cooldown timers on the object by passing a unique ID with the system methods.
  7. /// </summary>
  8. [RegisterComponent]
  9. [NetworkedComponent]
  10. [Access(typeof(UseDelaySystem))]
  11. public sealed partial class UseDelayComponent : Component
  12. {
  13. [DataField]
  14. public Dictionary<string, UseDelayInfo> Delays = [];
  15. /// <summary>
  16. /// Default delay time.
  17. /// </summary>
  18. /// <remarks>
  19. /// This is only used at MapInit and should not be expected
  20. /// to reflect the length of the default delay after that.
  21. /// Use <see cref="UseDelaySystem.TryGetDelayInfo"/> instead.
  22. /// </remarks>
  23. [DataField]
  24. public TimeSpan Delay = TimeSpan.FromSeconds(1);
  25. }
  26. [Serializable, NetSerializable]
  27. public sealed class UseDelayComponentState : IComponentState
  28. {
  29. public Dictionary<string, UseDelayInfo> Delays = new();
  30. }
  31. [Serializable, NetSerializable]
  32. [DataDefinition]
  33. public sealed partial class UseDelayInfo
  34. {
  35. [DataField]
  36. public TimeSpan Length { get; set; }
  37. [DataField]
  38. public TimeSpan StartTime { get; set; }
  39. [DataField]
  40. public TimeSpan EndTime { get; set; }
  41. public UseDelayInfo(TimeSpan length, TimeSpan startTime = default, TimeSpan endTime = default)
  42. {
  43. Length = length;
  44. StartTime = startTime;
  45. EndTime = endTime;
  46. }
  47. }