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>
This commit is contained in:
81
Content.Shared/DoAfter/DoAfterEvent.cs
Normal file
81
Content.Shared/DoAfter/DoAfterEvent.cs
Normal file
@@ -0,0 +1,81 @@
|
||||
using Robust.Shared.Serialization;
|
||||
|
||||
namespace Content.Shared.DoAfter;
|
||||
|
||||
/// <summary>
|
||||
/// Base type for events that get raised when a do-after is canceled or finished.
|
||||
/// </summary>
|
||||
[Serializable, NetSerializable]
|
||||
[ImplicitDataDefinitionForInheritors]
|
||||
public abstract class DoAfterEvent : HandledEntityEventArgs
|
||||
{
|
||||
/// <summary>
|
||||
/// The do after that triggered this event. This will be set by the do after system before the event is raised.
|
||||
/// </summary>
|
||||
[NonSerialized]
|
||||
public DoAfter DoAfter = default!;
|
||||
|
||||
/// <summary>
|
||||
/// Duplicate the current event. This is used by state handling, and should copy by value unless the reference
|
||||
/// types are immutable.
|
||||
/// </summary>
|
||||
public abstract DoAfterEvent Clone();
|
||||
|
||||
#region Convenience properties
|
||||
public bool Cancelled => DoAfter.Cancelled;
|
||||
public EntityUid User => DoAfter.Args.User;
|
||||
public EntityUid? Target => DoAfter.Args.Target;
|
||||
public EntityUid? Used => DoAfter.Args.Used;
|
||||
public DoAfterArgs Args => DoAfter.Args;
|
||||
#endregion
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Blank / empty event for simple do afters that carry no information.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// This just exists as a convenience to avoid having to re-implement Clone() for every simply DoAfterEvent.
|
||||
/// If an event actually contains data, it should actually override Clone().
|
||||
/// </remarks>
|
||||
[Serializable, NetSerializable]
|
||||
public abstract class SimpleDoAfterEvent : DoAfterEvent
|
||||
{
|
||||
// TODO: Find some way to enforce that inheritors don't store data?
|
||||
// Alternatively, I just need to allow generics to be networked.
|
||||
// E.g., then a SimpleDoAfter<TEvent> would just raise a TEvent event.
|
||||
// But afaik generic event types currently can't be serialized for networking or YAML.
|
||||
|
||||
public override DoAfterEvent Clone() => this;
|
||||
}
|
||||
|
||||
// Placeholder for obsolete async do afters
|
||||
[Serializable, NetSerializable]
|
||||
[Obsolete("Dont use async DoAfters")]
|
||||
public sealed class AwaitedDoAfterEvent : SimpleDoAfterEvent
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// This event will optionally get raised every tick while a do-after is in progress to check whether the do-after
|
||||
/// should be canceled.
|
||||
/// </summary>
|
||||
public sealed class DoAfterAttemptEvent<TEvent> : CancellableEntityEventArgs where TEvent : DoAfterEvent
|
||||
{
|
||||
/// <summary>
|
||||
/// The do after that triggered this event.
|
||||
/// </summary>
|
||||
public readonly DoAfter DoAfter;
|
||||
|
||||
/// <summary>
|
||||
/// The event that the DoAfter will raise after sucesfully finishing. Given that this event has the data
|
||||
/// required to perform the interaction, it should also contain the data required to validate/attempt the
|
||||
/// interaction.
|
||||
/// </summary>
|
||||
public readonly TEvent Event;
|
||||
|
||||
public DoAfterAttemptEvent(DoAfter doAfter, TEvent @event)
|
||||
{
|
||||
DoAfter = doAfter;
|
||||
Event = @event;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user