2021-07-17 02:37:09 +02:00
|
|
|
|
using System;
|
2020-08-09 02:16:13 +10:00
|
|
|
|
using System.Threading;
|
2021-02-11 01:13:03 -08:00
|
|
|
|
using Robust.Shared.GameObjects;
|
2020-08-13 14:40:27 +02:00
|
|
|
|
|
2021-06-09 22:19:39 +02:00
|
|
|
|
namespace Content.Server.DoAfter
|
2020-08-09 02:16:13 +10:00
|
|
|
|
{
|
|
|
|
|
|
public sealed class DoAfterEventArgs
|
|
|
|
|
|
{
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// The entity invoking do_after
|
|
|
|
|
|
/// </summary>
|
2021-09-28 11:33:33 +02:00
|
|
|
|
public EntityUid User { get; }
|
2020-08-09 01:44:17 +02:00
|
|
|
|
|
2020-08-09 02:16:13 +10:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// How long does the do_after require to complete
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
public float Delay { get; }
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Applicable target (if relevant)
|
|
|
|
|
|
/// </summary>
|
2021-09-28 11:33:33 +02:00
|
|
|
|
public EntityUid? Target { get; }
|
2020-08-09 01:44:17 +02:00
|
|
|
|
|
2020-08-09 02:16:13 +10:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Manually cancel the do_after so it no longer runs
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
public CancellationToken CancelToken { get; }
|
2020-08-09 01:44:17 +02:00
|
|
|
|
|
2020-08-09 02:16:13 +10:00
|
|
|
|
// Break the chains
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 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).
|
|
|
|
|
|
/// </summary>
|
2020-08-09 02:04:15 +02:00
|
|
|
|
public bool NeedHand { get; set; }
|
2020-08-09 01:44:17 +02:00
|
|
|
|
|
2020-08-09 02:16:13 +10:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// If do_after stops when the user moves
|
|
|
|
|
|
/// </summary>
|
2020-08-09 02:04:15 +02:00
|
|
|
|
public bool BreakOnUserMove { get; set; }
|
2020-08-09 01:44:17 +02:00
|
|
|
|
|
2020-08-09 02:16:13 +10:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// If do_after stops when the target moves (if there is a target)
|
|
|
|
|
|
/// </summary>
|
2020-08-09 02:04:15 +02:00
|
|
|
|
public bool BreakOnTargetMove { get; set; }
|
2020-08-09 01:44:17 +02:00
|
|
|
|
|
2020-11-22 03:58:31 +01:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Threshold for user and target movement
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
public float MovementThreshold { get; set; }
|
|
|
|
|
|
|
2020-08-09 02:04:15 +02:00
|
|
|
|
public bool BreakOnDamage { get; set; }
|
|
|
|
|
|
public bool BreakOnStun { get; set; }
|
2020-08-09 01:44:17 +02:00
|
|
|
|
|
2020-08-29 21:35:03 +10:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Requires a function call once at the end (like InRangeUnobstructed).
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <remarks>
|
|
|
|
|
|
/// Anything that needs a pre-check should do it itself so no DoAfterState is ever sent to the client.
|
|
|
|
|
|
/// </remarks>
|
|
|
|
|
|
public Func<bool>? PostCheck { get; set; } = null;
|
2020-08-30 11:37:06 +02:00
|
|
|
|
|
2020-08-09 02:16:13 +10:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Additional conditions that need to be met. Return false to cancel.
|
|
|
|
|
|
/// </summary>
|
2020-08-09 02:04:15 +02:00
|
|
|
|
public Func<bool>? ExtraCheck { get; set; }
|
2020-08-09 01:44:17 +02:00
|
|
|
|
|
2021-07-04 13:32:24 +02:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Event to be raised directed to the <see cref="User"/> entity when the DoAfter is cancelled.
|
|
|
|
|
|
/// </summary>
|
2021-09-17 07:16:11 -07:00
|
|
|
|
public object? UserCancelledEvent { get; set; }
|
2021-07-04 13:32:24 +02:00
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Event to be raised directed to the <see cref="User"/> entity when the DoAfter is finished successfully.
|
|
|
|
|
|
/// </summary>
|
2021-09-17 07:16:11 -07:00
|
|
|
|
public object? UserFinishedEvent { get; set; }
|
2021-07-04 13:32:24 +02:00
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
2021-07-13 08:02:27 +02:00
|
|
|
|
/// Event to be raised directed to the <see cref="Target"/> entity when the DoAfter is cancelled.
|
2021-07-04 13:32:24 +02:00
|
|
|
|
/// </summary>
|
2021-09-17 07:16:11 -07:00
|
|
|
|
public object? TargetCancelledEvent { get; set; }
|
2021-07-04 13:32:24 +02:00
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
2021-07-13 08:02:27 +02:00
|
|
|
|
/// Event to be raised directed to the <see cref="Target"/> entity when the DoAfter is finished successfully.
|
2021-07-04 13:32:24 +02:00
|
|
|
|
/// </summary>
|
2021-09-17 07:16:11 -07:00
|
|
|
|
public object? TargetFinishedEvent { get; set; }
|
2021-07-04 13:32:24 +02:00
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Event to be broadcast when the DoAfter is cancelled.
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
public object? BroadcastCancelledEvent { get; set; }
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Event to be broadcast when the DoAfter is finished successfully.
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
public object? BroadcastFinishedEvent { get; set; }
|
|
|
|
|
|
|
2021-09-28 11:33:33 +02:00
|
|
|
|
public DoAfterEventArgs(
|
|
|
|
|
|
EntityUid user,
|
|
|
|
|
|
float delay,
|
|
|
|
|
|
CancellationToken cancelToken = default,
|
|
|
|
|
|
EntityUid? target = null)
|
2020-08-09 02:16:13 +10:00
|
|
|
|
{
|
|
|
|
|
|
User = user;
|
|
|
|
|
|
Delay = delay;
|
|
|
|
|
|
CancelToken = cancelToken;
|
|
|
|
|
|
Target = target;
|
2020-11-22 03:58:31 +01:00
|
|
|
|
MovementThreshold = 0.1f;
|
2020-08-09 01:44:17 +02:00
|
|
|
|
|
2020-08-09 02:16:13 +10:00
|
|
|
|
if (Target == null)
|
|
|
|
|
|
{
|
|
|
|
|
|
BreakOnTargetMove = false;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2020-08-09 01:44:17 +02:00
|
|
|
|
}
|