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 partial class DoAfter
{
[DataField("index", required:true)]
public ushort Index;
public DoAfterId Id => new(Args.User, Index);
[IncludeDataField]
public DoAfterArgs Args = default!;
///
/// Time at which this do after was started.
///
[DataField("startTime", customTypeSerializer: typeof(TimeOffsetSerializer), required:true)]
public TimeSpan StartTime;
///
/// The time at which this do after was canceled
///
[DataField("cancelledTime", customTypeSerializer: typeof(TimeOffsetSerializer), required:true)]
public TimeSpan? CancelledTime;
///
/// If true, this do after has finished, passed the final checks, and has raised its events.
///
[DataField("completed")]
public bool Completed;
///
/// Whether the do after has been canceled.
///
public bool Cancelled => CancelledTime != null;
///
/// Position of the user relative to their parent when the do after was started.
///
[NonSerialized]
[DataField("userPosition")]
public EntityCoordinates UserPosition;
public NetCoordinates NetUserPosition;
///
/// Distance from the user to the target when the do after was started.
///
[DataField("targetDistance")]
public float TargetDistance;
///
/// If is true, this is the hand that was selected when the doafter started.
///
[DataField("activeHand")]
public string? InitialHand;
///
/// If is true, this is the entity that was in the active hand when the doafter started.
///
[NonSerialized]
[DataField("activeItem")]
public EntityUid? InitialItem;
public NetEntity? NetInitialItem;
// 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(IEntityManager entManager, DoAfter other)
{
Index = other.Index;
Args = new(other.Args);
StartTime = other.StartTime;
CancelledTime = other.CancelledTime;
Completed = other.Completed;
UserPosition = other.UserPosition;
TargetDistance = other.TargetDistance;
InitialHand = other.InitialHand;
InitialItem = other.InitialItem;
NetUserPosition = other.NetUserPosition;
NetInitialItem = other.NetInitialItem;
}
}
///
/// Simple struct that contains data required to uniquely identify a doAfter.
///
///
/// Can be used to track currently active do-afters to prevent simultaneous do-afters.
///
public record struct DoAfterId(EntityUid Uid, ushort Index);