]> git.smokeofanarchy.ru Git - space-station-14.git/commitdiff
Fix UseDelay issues (#27336)
authormetalgearsloth <31366439+metalgearsloth@users.noreply.github.com>
Fri, 26 Apr 2024 07:58:06 +0000 (17:58 +1000)
committerGitHub <noreply@github.com>
Fri, 26 Apr 2024 07:58:06 +0000 (17:58 +1000)
* Fix UseDelay issues

- Fix it not predicting properly by deep-copying the classes (realistically they should be structs).
- Fix the `z` path not applying UseDelay similarly to the `e` path.

* click

Content.Shared/Interaction/SharedInteractionSystem.cs
Content.Shared/Timing/UseDelayComponent.cs
Content.Shared/Timing/UseDelaySystem.cs

index 8d49ce31f0a91558102b731b67a5bd215832e843..2eabe14d2365bc7fb47edd32cf9b0c970636eb64 100644 (file)
@@ -973,8 +973,8 @@ namespace Content.Shared.Interaction
                 return false;
 
             DoContactInteraction(user, used, activateMsg);
-            if (delayComponent != null)
-                _useDelay.TryResetDelay((used, delayComponent));
+            // Still need to call this even without checkUseDelay in case this gets relayed from Activate.
+            _useDelay.TryResetDelay(used, component: delayComponent);
             if (!activateMsg.WasLogged)
                 _adminLogger.Add(LogType.InteractActivate, LogImpact.Low, $"{ToPrettyString(user):user} activated {ToPrettyString(used):used}");
             return true;
index c7b21bd1feb6219b7a8a1b494eee61b87a7ebf3e..aa6c66eb81aa8b606f3a37099c78a052abda1d90 100644 (file)
@@ -8,11 +8,11 @@ namespace Content.Shared.Timing;
 /// Can support additional, separate cooldown timers on the object by passing a unique ID with the system methods.
 /// </summary>
 [RegisterComponent]
-[NetworkedComponent, AutoGenerateComponentState]
+[NetworkedComponent]
 [Access(typeof(UseDelaySystem))]
 public sealed partial class UseDelayComponent : Component
 {
-    [DataField, AutoNetworkedField]
+    [DataField]
     public Dictionary<string, UseDelayInfo> Delays = [];
 
     /// <summary>
@@ -27,6 +27,12 @@ public sealed partial class UseDelayComponent : Component
     public TimeSpan Delay = TimeSpan.FromSeconds(1);
 }
 
+[Serializable, NetSerializable]
+public sealed class UseDelayComponentState : IComponentState
+{
+    public Dictionary<string, UseDelayInfo> Delays = new();
+}
+
 [Serializable, NetSerializable]
 [DataDefinition]
 public sealed partial class UseDelayInfo
index 3d2498203c62be9bad2ef041a084763aee3c0c25..bc2a709175441206cc8b48a7ce13aab9f2d4c22a 100644 (file)
@@ -1,4 +1,5 @@
 using System.Diagnostics.CodeAnalysis;
+using Robust.Shared.GameStates;
 using Robust.Shared.Timing;
 
 namespace Content.Shared.Timing;
@@ -16,6 +17,30 @@ public sealed class UseDelaySystem : EntitySystem
 
         SubscribeLocalEvent<UseDelayComponent, MapInitEvent>(OnMapInit);
         SubscribeLocalEvent<UseDelayComponent, EntityUnpausedEvent>(OnUnpaused);
+        SubscribeLocalEvent<UseDelayComponent, ComponentGetState>(OnDelayGetState);
+        SubscribeLocalEvent<UseDelayComponent, ComponentHandleState>(OnDelayHandleState);
+    }
+
+    private void OnDelayHandleState(Entity<UseDelayComponent> ent, ref ComponentHandleState args)
+    {
+        if (args.Current is not UseDelayComponentState state)
+            return;
+
+        ent.Comp.Delays.Clear();
+
+        // At time of writing sourcegen networking doesn't deep copy so this will mispredict if you try.
+        foreach (var (key, delay) in state.Delays)
+        {
+            ent.Comp.Delays[key] = new UseDelayInfo(delay.Length, delay.StartTime, delay.EndTime);
+        }
+    }
+
+    private void OnDelayGetState(Entity<UseDelayComponent> ent, ref ComponentGetState args)
+    {
+        args.State = new UseDelayComponentState()
+        {
+            Delays = ent.Comp.Delays
+        };
     }
 
     private void OnMapInit(Entity<UseDelayComponent> ent, ref MapInitEvent args)