Files
tbd-station-14/Content.Shared/DoAfter/DoAfter.cs
Leon Friedrich 19277a2276 More DoAfter Changes (#14609)
* DoAfters

* Compact Clone()

* Fix mice and cuffables

* Try generalize attempt events

* moves climbabledoafter event to shared, fixes issue with climbable target

* Fix merge (cuffing)

* Make all events netserializable

* handful of doafter events moved

* moves the rest of the events to their respective shared folders

* Changes all mentions of server doafter to shared

* stop stripping cancellation

* fix merge errors

* draw paused doafters

* handle unpausing

* missing netserializable ref

* removes break on stun reference

* removes cuffing state reference

* Fix tools

* Fix door prying.

* Fix construction

* Fix dumping

* Fix wielding assert

* fix rev

* Fix test

* more test fixes

---------

Co-authored-by: keronshb <keronshb@live.com>
2023-04-02 21:13:48 -04:00

110 lines
3.3 KiB
C#

using Robust.Shared.Map;
using Robust.Shared.Serialization;
using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom;
using Robust.Shared.Utility;
namespace Content.Shared.DoAfter;
[Serializable, NetSerializable]
[DataDefinition]
[Access(typeof(SharedDoAfterSystem))]
public sealed class DoAfter
{
[DataField("index", required:true)]
public ushort Index;
public DoAfterId Id => new(Args.User, Index);
[IncludeDataField]
public readonly DoAfterArgs Args = default!;
/// <summary>
/// Time at which this do after was started.
/// </summary>
[DataField("startTime", customTypeSerializer: typeof(TimeOffsetSerializer), required:true)]
public TimeSpan StartTime;
/// <summary>
/// The time at which this do after was canceled
/// </summary>
[DataField("cancelledTime", customTypeSerializer: typeof(TimeOffsetSerializer), required:true)]
public TimeSpan? CancelledTime;
/// <summary>
/// If true, this do after has finished, passed the final checks, and has raised its events.
/// </summary>
[DataField("completed")]
public bool Completed;
/// <summary>
/// Whether the do after has been canceled.
/// </summary>
public bool Cancelled => CancelledTime != null;
/// <summary>
/// Position of the user relative to their parent when the do after was started.
/// </summary>
[DataField("userPosition")]
public EntityCoordinates UserPosition;
/// <summary>
/// Position of the target relative to their parent when the do after was started.
/// </summary>
[DataField("targetPosition")]
public EntityCoordinates TargetPosition;
/// <summary>
/// If <see cref="DoAfterArgs.NeedHand"/> is true, this is the hand that was selected when the doafter started.
/// </summary>
[DataField("activeHand")]
public string? InitialHand;
/// <summary>
/// If <see cref="NeedHand"/> is true, this is the entity that was in the active hand when the doafter started.
/// </summary>
[DataField("activeItem")]
public EntityUid? InitialItem;
// cached attempt event for the sake of avoiding unnecessary reflection every time this needs to be raised.
[NonSerialized] public object? AttemptEvent;
private DoAfter()
{
}
public DoAfter(ushort index, DoAfterArgs args, TimeSpan startTime)
{
Index = index;
if (args.Target == null)
{
DebugTools.Assert(!args.BreakOnTargetMove);
args.BreakOnTargetMove = false;
}
Args = args;
StartTime = startTime;
}
public DoAfter(DoAfter other)
{
Index = other.Index;
Args = new(other.Args);
StartTime = other.StartTime;
CancelledTime = other.CancelledTime;
Completed = other.Completed;
UserPosition = other.UserPosition;
TargetPosition = other.TargetPosition;
InitialHand = other.InitialHand;
InitialItem = other.InitialItem;
}
}
/// <summary>
/// Simple struct that contains data required to uniquely identify a doAfter.
/// </summary>
/// <remarks>
/// Can be used to track currently active do-afters to prevent simultaneous do-afters.
/// </remarks>
public record struct DoAfterId(EntityUid Uid, ushort Index);