using System.Threading;
using Content.Shared.FixedPoint;
using Robust.Shared.Serialization;
using Robust.Shared.Utility;
namespace Content.Shared.DoAfter;
//TODO: Merge into DoAfter
[Serializable, NetSerializable]
public sealed class DoAfterEventArgs
{
///
/// The entity invoking do_after
///
public EntityUid User;
///
/// How long does the do_after require to complete
///
public float Delay;
///
/// Applicable target (if relevant)
///
public EntityUid? Target;
///
/// Entity used by the User on the Target.
///
public EntityUid? Used;
public bool RaiseOnUser = true;
public bool RaiseOnTarget = true;
public bool RaiseOnUsed = true;
///
/// Manually cancel the do_after so it no longer runs
///
[NonSerialized]
public CancellationToken CancelToken;
// Break the chains
///
/// Whether we need to keep our active hand as is (i.e. can't change hand or change item).
/// This also covers requiring the hand to be free (if applicable).
///
public bool NeedHand;
///
/// If do_after stops when the user moves
///
public bool BreakOnUserMove;
///
/// If do_after stops when the target moves (if there is a target)
///
public bool BreakOnTargetMove;
///
/// Threshold for user and target movement
///
public float MovementThreshold;
public bool BreakOnDamage;
///
/// Threshold for user damage
///
public FixedPoint2? DamageThreshold;
public bool BreakOnStun;
///
/// Should the DoAfter event broadcast?
///
public bool Broadcast;
///
/// Threshold for distance user from the used OR target entities.
///
public float? DistanceThreshold;
///
/// Requires a function call once at the end (like InRangeUnobstructed).
///
///
/// Anything that needs a pre-check should do it itself so no DoAfterState is ever sent to the client.
///
[NonSerialized]
//TODO: Replace with eventbus
public Func? PostCheck;
///
/// Additional conditions that need to be met. Return false to cancel.
///
[NonSerialized]
//TODO Replace with eventbus
public Func? ExtraCheck;
public DoAfterEventArgs(
EntityUid user,
float delay,
CancellationToken cancelToken = default,
EntityUid? target = null,
EntityUid? used = null)
{
User = user;
Delay = delay;
CancelToken = cancelToken;
Target = target;
Used = used;
MovementThreshold = 0.1f;
DamageThreshold = 1.0;
if (Target == null)
{
DebugTools.Assert(!BreakOnTargetMove);
BreakOnTargetMove = false;
}
}
}