1
0

DoAfter.cs 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. using Robust.Shared.Map;
  2. using Robust.Shared.Serialization;
  3. using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom;
  4. using Robust.Shared.Utility;
  5. namespace Content.Shared.DoAfter;
  6. [Serializable, NetSerializable]
  7. [DataDefinition]
  8. [Access(typeof(SharedDoAfterSystem))]
  9. public sealed partial class DoAfter
  10. {
  11. [DataField("index", required:true)]
  12. public ushort Index;
  13. public DoAfterId Id => new(Args.User, Index);
  14. [IncludeDataField]
  15. public DoAfterArgs Args = default!;
  16. /// <summary>
  17. /// Time at which this do after was started.
  18. /// </summary>
  19. [DataField("startTime", customTypeSerializer: typeof(TimeOffsetSerializer), required:true)]
  20. public TimeSpan StartTime;
  21. /// <summary>
  22. /// The time at which this do after was canceled
  23. /// </summary>
  24. [DataField("cancelledTime", customTypeSerializer: typeof(TimeOffsetSerializer), required:true)]
  25. public TimeSpan? CancelledTime;
  26. /// <summary>
  27. /// If true, this do after has finished, passed the final checks, and has raised its events.
  28. /// </summary>
  29. [DataField("completed")]
  30. public bool Completed;
  31. /// <summary>
  32. /// Whether the do after has been canceled.
  33. /// </summary>
  34. public bool Cancelled => CancelledTime != null;
  35. /// <summary>
  36. /// Position of the user relative to their parent when the do after was started.
  37. /// </summary>
  38. [NonSerialized]
  39. [DataField("userPosition")]
  40. public EntityCoordinates UserPosition;
  41. public NetCoordinates NetUserPosition;
  42. /// <summary>
  43. /// Distance from the user to the target when the do after was started.
  44. /// </summary>
  45. [DataField("targetDistance")]
  46. public float TargetDistance;
  47. /// <summary>
  48. /// If <see cref="DoAfterArgs.NeedHand"/> is true, this is the hand that was selected when the doafter started.
  49. /// </summary>
  50. [DataField("activeHand")]
  51. public string? InitialHand;
  52. /// <summary>
  53. /// If <see cref="NeedHand"/> is true, this is the entity that was in the active hand when the doafter started.
  54. /// </summary>
  55. [NonSerialized]
  56. [DataField("activeItem")]
  57. public EntityUid? InitialItem;
  58. public NetEntity? NetInitialItem;
  59. // cached attempt event for the sake of avoiding unnecessary reflection every time this needs to be raised.
  60. [NonSerialized] public object? AttemptEvent;
  61. private DoAfter()
  62. {
  63. }
  64. public DoAfter(ushort index, DoAfterArgs args, TimeSpan startTime)
  65. {
  66. Index = index;
  67. Args = args;
  68. StartTime = startTime;
  69. }
  70. public DoAfter(IEntityManager entManager, DoAfter other)
  71. {
  72. Index = other.Index;
  73. Args = new(other.Args);
  74. StartTime = other.StartTime;
  75. CancelledTime = other.CancelledTime;
  76. Completed = other.Completed;
  77. UserPosition = other.UserPosition;
  78. TargetDistance = other.TargetDistance;
  79. InitialHand = other.InitialHand;
  80. InitialItem = other.InitialItem;
  81. NetUserPosition = other.NetUserPosition;
  82. NetInitialItem = other.NetInitialItem;
  83. }
  84. }
  85. /// <summary>
  86. /// Simple struct that contains data required to uniquely identify a doAfter.
  87. /// </summary>
  88. /// <remarks>
  89. /// Can be used to track currently active do-afters to prevent simultaneous do-afters.
  90. /// </remarks>
  91. public record struct DoAfterId(EntityUid Uid, ushort Index);