Files
tbd-station-14/Content.Shared/DoAfter/DoAfterComponent.cs
keronshb f885075d2e DoAfter support for Actions (#38253)
* Adds Action DoAfter Events

* Adds DoAfterArgs fields to DoAfterComp

* Adds a base doafter action

* Adds Attempt action doafter logic

* Adds doafter logic to actions

* Changes Action Attempt Doafter and action doafter to take in Performer and the original use delay. Use delay now triggers when a repeated action  is cancelled.

* Readds the TryPerformAction method and readds request perform action into the action doafter events

* Adds a force skip to DoAfter Cancel so we can skip the complete check

* Adds a Delay Reduction field to the comp and to the comp state

* Fixes doafter mispredict, changes doafter comp check to a guard clause, sets delay reduction if it exists.

* Cancels ActionDoAfter if charges is 0

* Serializes Attempt Frequency

* Comment for rework

* Changes todo into a comment

* Moves doafterargs to doafterargscomp

* Adds DoAfterArgs comp to BaseDoAfterAction

* Removes unused trycomp with actionDoAfter

* Replaces DoAfterRepateUseDelay const with timespan.zero

* Removes unused usings

* Makes SharedActionsSystem partial, adds DoAfter partial class to ActionSystem, moves ActionDoAfter logic to the SharedActionsSystem.DoAfter class

* Cleanup and prediction

* Renames OnActionDoAfterAttempt to OnActionDoAfter, moves both to Shared Action DoAfter

* Removes ActionAttemptDoAfterEvent and moves its summaries to ActionDoAfterEvent. Converts OnActionDoAfterAttempt into TryStartActionDoAfter

* Removes Extra check for charges and actiondoafters

* Sloptimization

* Cleanup

* Cleanup

* Adds param descs

---------

Co-authored-by: Princess Cheeseballs <66055347+Pronana@users.noreply.github.com>
2025-09-08 12:55:13 +03:00

63 lines
1.8 KiB
C#

using System.Threading.Tasks;
using Content.Shared.FixedPoint;
using Robust.Shared.GameStates;
using Robust.Shared.Serialization;
namespace Content.Shared.DoAfter;
[RegisterComponent, NetworkedComponent]
[Access(typeof(SharedDoAfterSystem))]
public sealed partial class DoAfterComponent : Component
{
/// <summary>
/// The id of the next doafter
/// </summary>
[DataField]
public ushort NextId;
/// <summary>
/// collection of id + doafter
/// </summary>
[DataField]
public Dictionary<ushort, DoAfter> DoAfters = new();
// Used by obsolete async do afters
public readonly Dictionary<ushort, TaskCompletionSource<DoAfterStatus>> AwaitedDoAfters = new();
}
[Serializable, NetSerializable]
public sealed class DoAfterComponentState : ComponentState
{
public readonly ushort NextId;
public readonly Dictionary<ushort, DoAfter> DoAfters;
public DoAfterComponentState(IEntityManager entManager, DoAfterComponent component)
{
NextId = component.NextId;
// Cursed test bugs - See CraftingTests.CancelCraft
// The following is wrapped in an if DEBUG. This is tests don't (de)serialize net messages and just copy objects
// by reference. This means that the server will directly modify cached server states on the client's end.
// Crude fix at the moment is to used modified state handling while in debug mode Otherwise, this test cannot work.
#if !DEBUG
DoAfters = component.DoAfters;
#else
DoAfters = new();
foreach (var (id, doAfter) in component.DoAfters)
{
var newDoAfter = new DoAfter(entManager, doAfter);
DoAfters.Add(id, newDoAfter);
}
#endif
}
}
[Serializable, NetSerializable]
public enum DoAfterStatus : byte
{
Invalid,
Running,
Cancelled,
Finished,
}