]> git.smokeofanarchy.ru Git - space-station-14.git/commitdiff
Another round of DoAfter fixes (#14295)
authorkeronshb <54602815+keronshb@users.noreply.github.com>
Wed, 1 Mar 2023 00:51:42 +0000 (19:51 -0500)
committerGitHub <noreply@github.com>
Wed, 1 Mar 2023 00:51:42 +0000 (11:51 +1100)
Content.IntegrationTests/Tests/DoAfter/DoAfterServerTest.cs
Content.Server/Construction/ConstructionSystem.Interactions.cs
Content.Server/Fluids/EntitySystems/MoppingSystem.cs
Content.Server/Kitchen/EntitySystems/KitchenSpikeSystem.cs
Content.Server/Resist/CanEscapeInventoryComponent.cs
Content.Server/Resist/EscapeInventorySystem.cs
Content.Server/Resist/ResistLockerComponent.cs
Content.Server/Resist/ResistLockerSystem.cs
Content.Server/Wires/WiresSystem.cs
Content.Shared/DoAfter/SharedDoAfterSystem.cs

index 186a6a6d8ca69b9ebc328da9b681e2659721e6ba..f9e6ddff39a83e049f3348ea2609830e12b043fe 100644 (file)
@@ -88,7 +88,7 @@ namespace Content.IntegrationTests.Tests.DoAfter
             });
 
             await server.WaitRunTicks(3);
-            Assert.That(data.Cancelled, Is.False);
+            Assert.That(data.Cancelled, Is.True);
 
             await pairTracker.CleanReturnAsync();
         }
index 5319047054f89ede8eefe56af24c97c7bdcc8c58..e39a4c3d39cc3a0f8a6094bc4ab9f610a31c5c89 100644 (file)
@@ -582,6 +582,7 @@ namespace Content.Server.Construction
             {
                 RaiseLocalEvent(args.Args.Target.Value, args.AdditionalData.CancelEvent);
                 args.Handled = true;
+                return;
             }
 
             RaiseLocalEvent(args.Args.Target.Value, args.AdditionalData.CompleteEvent);
index 627227920536d36d5f7911973756a0e9c5821d3e..eb98c103df7527857fd49e227e75c5645da52b07 100644 (file)
@@ -270,7 +270,17 @@ public sealed class MoppingSystem : SharedMoppingSystem
 
     private void OnDoAfter(EntityUid uid, AbsorbentComponent component, DoAfterEvent<AbsorbantData> args)
     {
-        if (args.Handled || args.Cancelled || args.Args.Target == null)
+        if (args.Args.Target == null)
+            return;
+
+        if (args.Cancelled)
+        {
+            //Remove the interacting entities or else it breaks the mop
+            component.InteractingEntities.Remove(args.Args.Target.Value);
+            return;
+        }
+
+        if (args.Handled)
             return;
 
         _audio.PlayPvs(args.AdditionalData.Sound, uid);
index 77b56bfa2f9c78d65d4b8bb1424c365d305d7d23..3b608ceb8739da72e12344b1df45f598caacc388 100644 (file)
@@ -77,12 +77,19 @@ namespace Content.Server.Kitchen.EntitySystems
             if (TryComp<ButcherableComponent>(args.Args.Target.Value, out var butcherable))
                 butcherable.BeingButchered = false;
 
-            if (args.Handled || args.Cancelled)
+            if (args.Cancelled)
+            {
+                component.InUse = false;
+                return;
+            }
+
+            if (args.Handled)
                 return;
 
             if (Spikeable(uid, args.Args.User, args.Args.Target.Value, component, butcherable))
                 Spike(uid, args.Args.User, args.Args.Target.Value, component);
 
+            component.InUse = false;
             args.Handled = true;
         }
 
index aff5a0b0e3896cb1efdd415b91601604d00de849..b67adfc203d3c8a1d8d46fc7b81b9a9ca42f3524 100644 (file)
@@ -1,3 +1,5 @@
+using System.Threading;
+
 namespace Content.Server.Resist;
 
 [RegisterComponent]
@@ -8,4 +10,9 @@ public sealed class CanEscapeInventoryComponent : Component
     /// </summary>
     [DataField("baseResistTime")]
     public float BaseResistTime = 5f;
+
+    [DataField("isEscaping")]
+    public bool IsEscaping;
+
+    public CancellationTokenSource? CancelToken;
 }
index 2e3fc66ea87ad544a226db72c4356ea4e2b18d11..6230b16fc6ab4e5e9ed00f5f2a3d578894f3a311 100644 (file)
@@ -1,3 +1,4 @@
+using System.Threading;
 using Content.Server.DoAfter;
 using Content.Server.Contests;
 using Robust.Shared.Containers;
@@ -65,11 +66,16 @@ public sealed class EscapeInventorySystem : EntitySystem
 
     private void AttemptEscape(EntityUid user, EntityUid container, CanEscapeInventoryComponent component, float multiplier = 1f)
     {
+        if (component.IsEscaping)
+            return;
+
+        component.CancelToken = new CancellationTokenSource();
+        component.IsEscaping = true;
         var escapeEvent = new EscapeInventoryEvent();
-        var doAfterEventArgs = new DoAfterEventArgs(user, component.BaseResistTime * multiplier, target:container)
+        var doAfterEventArgs = new DoAfterEventArgs(user, component.BaseResistTime * multiplier, cancelToken: component.CancelToken.Token, target:container)
         {
             BreakOnTargetMove = false,
-            BreakOnUserMove = false,
+            BreakOnUserMove = true,
             BreakOnDamage = true,
             BreakOnStun = true,
             NeedHand = false
@@ -82,17 +88,27 @@ public sealed class EscapeInventorySystem : EntitySystem
 
     private void OnEscape(EntityUid uid, CanEscapeInventoryComponent component, DoAfterEvent<EscapeInventoryEvent> args)
     {
-        if (args.Handled || args.Cancelled)
+        if (args.Cancelled)
+        {
+            component.CancelToken = null;
+            component.IsEscaping = false;
+            return;
+        }
+
+        if (args.Handled)
             return;
 
         Transform(uid).AttachParentToContainerOrGrid(EntityManager);
 
+        component.CancelToken = null;
+        component.IsEscaping = false;
         args.Handled = true;
     }
 
     private void OnDropped(EntityUid uid, CanEscapeInventoryComponent component, DroppedEvent args)
     {
-        //TODO: Enter cancel logic here
+        component.CancelToken?.Cancel();
+        component.CancelToken = null;
     }
 
     private sealed class EscapeInventoryEvent : EntityEventArgs
index 6cf4102d4509ea2c0ce97f8bed4ec6fc05ad7c53..7cb2149100d002b38466af2a4ae2df5538cf96ef 100644 (file)
@@ -18,8 +18,5 @@ public sealed class ResistLockerComponent : Component
     [ViewVariables]
     public bool IsResisting = false;
 
-    /// <summary>
-    /// Used to cancel the DoAfter when a locker is open
-    /// </summary>
-    public Shared.DoAfter.DoAfter? DoAfter;
+    public CancellationTokenSource? CancelToken;
 }
index 85b4176d9cf5e242c469d46b4ddb7d473858e355..c096d529f452ee08ecea12f4da3399a5bdbdd60b 100644 (file)
@@ -1,3 +1,4 @@
+using System.Threading;
 using Content.Server.DoAfter;
 using Content.Server.Popups;
 using Content.Server.Storage.Components;
@@ -44,7 +45,9 @@ public sealed class ResistLockerSystem : EntitySystem
         if (!Resolve(target, ref storageComponent, ref resistLockerComponent))
             return;
 
-        var doAfterEventArgs = new DoAfterEventArgs(user, resistLockerComponent.ResistTime, target:target)
+        resistLockerComponent.CancelToken = new CancellationTokenSource();
+
+        var doAfterEventArgs = new DoAfterEventArgs(user, resistLockerComponent.ResistTime, cancelToken:resistLockerComponent.CancelToken.Token, target:target)
         {
             BreakOnTargetMove = false,
             BreakOnUserMove = true,
@@ -55,13 +58,13 @@ public sealed class ResistLockerSystem : EntitySystem
 
         resistLockerComponent.IsResisting = true;
         _popupSystem.PopupEntity(Loc.GetString("resist-locker-component-start-resisting"), user, user, PopupType.Large);
-        resistLockerComponent.DoAfter = _doAfterSystem.DoAfter(doAfterEventArgs);
+        _doAfterSystem.DoAfter(doAfterEventArgs);
     }
 
     private void OnRemoved(EntityUid uid, ResistLockerComponent component, EntRemovedFromContainerMessage args)
     {
-        if (component.DoAfter != null)
-            _doAfterSystem.Cancel(uid, component.DoAfter);
+        component.CancelToken?.Cancel();
+        component.CancelToken = null;
     }
 
     private void OnDoAfter(EntityUid uid, ResistLockerComponent component, DoAfterEvent args)
@@ -69,6 +72,7 @@ public sealed class ResistLockerSystem : EntitySystem
         if (args.Cancelled)
         {
             component.IsResisting = false;
+            component.CancelToken = null;
             _popupSystem.PopupEntity(Loc.GetString("resist-locker-component-resist-interrupted"), args.Args.User, args.Args.User, PopupType.Medium);
             return;
         }
@@ -89,6 +93,7 @@ public sealed class ResistLockerSystem : EntitySystem
             _entityStorage.TryOpenStorage(args.Args.User, uid);
         }
 
+        component.CancelToken = null;
         args.Handled = true;
     }
 }
index 8be77f8a0edd0f1b26e690770026c9140fe6265a..6c6add46dbcd8cb6139936d1a95a2566df625c72 100644 (file)
@@ -467,7 +467,7 @@ public sealed class WiresSystem : EntitySystem
         }
         else if (!component.IsScrewing && _toolSystem.HasQuality(args.Used, "Screwing", tool))
         {
-            var toolEvData = new ToolEventData(new WireToolFinishedEvent(uid, args.User));
+            var toolEvData = new ToolEventData(new WireToolFinishedEvent(uid, args.User), cancelledEv: new WireToolCanceledEvent(uid));
 
             component.IsScrewing = _toolSystem.UseTool(args.Used, args.User, uid, ScrewTime, new[] { "Screwing" }, toolEvData, toolComponent: tool);
             args.Handled = component.IsScrewing;
index d83570d73b1a9a8612876d7135da242c54baea27..18c92cc7000f7e2aacf4332ca9515da57e1d3262 100644 (file)
@@ -179,19 +179,16 @@ public abstract class SharedDoAfterSystem : EntitySystem
     ///     Use this if you don't have any extra data to send with the DoAfter
     /// </summary>
     /// <param name="eventArgs">The DoAfterEventArgs</param>
-    public DoAfter DoAfter(DoAfterEventArgs eventArgs)
+    public void DoAfter(DoAfterEventArgs eventArgs)
     {
         var doAfter = CreateDoAfter(eventArgs);
 
         doAfter.Done = cancelled => { Send(cancelled, eventArgs); };
-
-        return doAfter;
     }
 
     private DoAfter CreateDoAfter(DoAfterEventArgs eventArgs)
     {
         // Setup
-        eventArgs.CancelToken = new CancellationToken();
         var doAfter = new DoAfter(eventArgs, EntityManager);
         // Caller's gonna be responsible for this I guess
         var doAfterComponent = Comp<DoAfterComponent>(eventArgs.User);