]> git.smokeofanarchy.ru Git - space-station-14.git/commitdiff
DoAfter & misc interaction fixes (#15144)
authorLeon Friedrich <60421075+ElectroJr@users.noreply.github.com>
Wed, 5 Apr 2023 00:19:28 +0000 (12:19 +1200)
committerGitHub <noreply@github.com>
Wed, 5 Apr 2023 00:19:28 +0000 (10:19 +1000)
Content.Server/Construction/ConstructionSystem.Interactions.cs
Content.Server/Wires/WiresSystem.cs
Content.Shared/Clothing/EntitySystems/ToggleableClothingSystem.cs
Content.Shared/Radio/EntitySystems/EncryptionKeySystem.cs

index bfe8f7e04df83a96cf13cfb33721b1e6e5fd3b8b..0a9d3c543bd8ccb33e7c839d95766bb46cd907ff 100644 (file)
@@ -7,6 +7,7 @@ using Content.Shared.Construction;
 using Content.Shared.Construction.Steps;
 using Content.Shared.DoAfter;
 using Content.Shared.Interaction;
+using Content.Shared.Radio.EntitySystems;
 using Content.Shared.Tools.Components;
 using Robust.Shared.Containers;
 using Robust.Shared.Map;
@@ -30,13 +31,20 @@ namespace Content.Server.Construction
 
         private void InitializeInteractions()
         {
-            SubscribeLocalEvent<ConstructionComponent, ConstructionInteractDoAfterEvent>(EnqueueEvent);
+            SubscribeLocalEvent<ConstructionComponent, ConstructionInteractDoAfterEvent>(OnDoAfterComplete);
 
             // Event handling. Add your subscriptions here! Just make sure they're all handled by EnqueueEvent.
-            SubscribeLocalEvent<ConstructionComponent, InteractUsingEvent>(EnqueueEvent, new []{typeof(AnchorableSystem)});
+            SubscribeLocalEvent<ConstructionComponent, InteractUsingEvent>(EnqueueEvent, new []{typeof(AnchorableSystem), typeof(EncryptionKeySystem)});
             SubscribeLocalEvent<ConstructionComponent, OnTemperatureChangeEvent>(EnqueueEvent);
         }
 
+        private void OnDoAfterComplete(EntityUid uid, ConstructionComponent component, ConstructionInteractDoAfterEvent args)
+        {
+            component.DoAfter = null;
+            if (!args.Cancelled)
+                EnqueueEvent(uid, component, args);
+        }
+
         /// <summary>
         ///     Takes in an entity with <see cref="ConstructionComponent"/> and an object event, and handles any
         ///     possible construction interactions, depending on the construction's state.
@@ -223,11 +231,8 @@ namespace Content.Server.Construction
             // The DoAfter events can only perform special logic when we're not validating events.
             if (ev is ConstructionInteractDoAfterEvent interactDoAfter)
             {
-                if (!validation)
-                    construction.DoAfter = null;
-
-                if (interactDoAfter.Cancelled)
-                    return HandleResult.False;
+                // cancelled events should not reach this point.
+                DebugTools.Assert(!interactDoAfter.Cancelled);
 
                 ev = new InteractUsingEvent(
                     interactDoAfter.User,
@@ -256,12 +261,6 @@ namespace Content.Server.Construction
                     if (ev is not InteractUsingEvent interactUsing)
                         break;
 
-                    if (construction.DoAfter != null && !validation)
-                    {
-                        _doAfterSystem.Cancel(construction.DoAfter);
-                        return HandleResult.False;
-                    }
-
                     // TODO: Sanity checks.
 
                     user = interactUsing.User;
@@ -343,12 +342,6 @@ namespace Content.Server.Construction
                     if (ev is not InteractUsingEvent interactUsing)
                         break;
 
-                    if (construction.DoAfter != null && !validation)
-                    {
-                        _doAfterSystem.Cancel(construction.DoAfter);
-                        return HandleResult.False;
-                    }
-
                     // TODO: Sanity checks.
 
                     user = interactUsing.User;
index 2199ee16432b3b3017d21d52de23afb9475d8c34..304a63b049cb3bb19558407362db0fbf3ca7fd53 100644 (file)
@@ -463,12 +463,16 @@ public sealed class WiresSystem : SharedWiresSystem
             _toolSystem.HasQuality(args.Used, "Pulsing", tool)))
         {
             if (TryComp(args.User, out ActorComponent? actor))
+            {
                 _uiSystem.TryOpen(uid, WiresUiKey.Key, actor.PlayerSession);
+                args.Handled = true;
+            }
         }
         else if (_toolSystem.UseTool(args.Used, args.User, uid, ScrewTime, "Screwing", new WirePanelDoAfterEvent(), toolComponent: tool))
         {
             _adminLogger.Add(LogType.Action, LogImpact.Low,
                 $"{ToPrettyString(args.User):user} is screwing {ToPrettyString(uid):target}'s {(panel.Open ? "open" : "closed")} maintenance panel at {Transform(uid).Coordinates:targetlocation}");
+            args.Handled = true;
         }
     }
 
index 0f69dafbed0f9f41625eb46b1e0267a991c66fd8..fa5c2f647cb1b59b55ce9a957ca9410a4434e5ef 100644 (file)
@@ -245,14 +245,14 @@ public sealed class ToggleableClothingSystem : EntitySystem
 
         var parent = Transform(target).ParentUid;
         if (component.Container.ContainedEntity == null)
-            _inventorySystem.TryUnequip(parent, component.Slot);
+            _inventorySystem.TryUnequip(user, parent, component.Slot);
         else if (_inventorySystem.TryGetSlotEntity(parent, component.Slot, out var existing))
         {
             _popupSystem.PopupEntity(Loc.GetString("toggleable-clothing-remove-first", ("entity", existing)),
                 user, user);
         }
         else
-            _inventorySystem.TryEquip(parent, component.ClothingUid.Value, component.Slot);
+            _inventorySystem.TryEquip(user, parent, component.ClothingUid.Value, component.Slot);
     }
 
     private void OnGetActions(EntityUid uid, ToggleableClothingComponent component, GetItemActionsEvent args)
index a69438c354161f1f6a24b20a9bd9eee6412cbc8e..16d6960d99bb3c4d064e61b1fe7d2b4374d0c08f 100644 (file)
@@ -92,27 +92,27 @@ public sealed class EncryptionKeySystem : EntitySystem
         if ( args.Handled || !TryComp<ContainerManagerComponent>(uid, out var storage))
             return;
 
-        args.Handled = true;
-
-        if (!component.KeysUnlocked)
-        {
-            if (_net.IsClient && _timing.IsFirstTimePredicted)
-                _popup.PopupEntity(Loc.GetString("encryption-keys-are-locked"), uid, args.User);
-            return;
-        }
-
-        if (TryComp<EncryptionKeyComponent>(args.Used, out var key))
+        if (HasComp<EncryptionKeyComponent>(args.Used))
         {
+            args.Handled = true;
             TryInsertKey(uid, component, args);
         }
-        else
+        else if (TryComp<ToolComponent>(args.Used, out var tool) && tool.Qualities.Contains(component.KeysExtractionMethod))
         {
-            TryRemoveKey(uid, component, args);
+            args.Handled = true;
+            TryRemoveKey(uid, component, args, tool);
         }
     }
 
     private void TryInsertKey(EntityUid uid, EncryptionKeyHolderComponent component, InteractUsingEvent args)
     {
+        if (!component.KeysUnlocked)
+        {
+            if (_net.IsClient && _timing.IsFirstTimePredicted)
+                _popup.PopupEntity(Loc.GetString("encryption-keys-are-locked"), uid, args.User);
+            return;
+        }
+
         if (TryComp<WiresPanelComponent>(uid, out var panel) && !panel.Open)
         {
             if (_net.IsClient && _timing.IsFirstTimePredicted)
@@ -137,10 +137,15 @@ public sealed class EncryptionKeySystem : EntitySystem
         }
     }
 
-    private void TryRemoveKey(EntityUid uid, EncryptionKeyHolderComponent component, InteractUsingEvent args)
+    private void TryRemoveKey(EntityUid uid, EncryptionKeyHolderComponent component, InteractUsingEvent args,
+        ToolComponent? tool)
     {
-        if (!TryComp<ToolComponent>(args.Used, out var tool) || !tool.Qualities.Contains(component.KeysExtractionMethod))
+        if (!component.KeysUnlocked)
+        {
+            if (_net.IsClient && _timing.IsFirstTimePredicted)
+                _popup.PopupEntity(Loc.GetString("encryption-keys-are-locked"), uid, args.User);
             return;
+        }
 
         if (TryComp<WiresPanelComponent>(uid, out var panel) && !panel.Open)
         {