]> git.smokeofanarchy.ru Git - space-station-14.git/commitdiff
Give throwing a cooldown (#23311)
authorNemanja <98561806+EmoGarbage404@users.noreply.github.com>
Mon, 1 Jan 2024 03:24:37 +0000 (22:24 -0500)
committerGitHub <noreply@github.com>
Mon, 1 Jan 2024 03:24:37 +0000 (14:24 +1100)
Content.Server/Hands/Systems/HandsSystem.cs
Content.Shared/Hands/Components/HandsComponent.cs

index ae5a99bf28cf210dd92fc8933defec27a78f2ab8..0b2180065321d0caa256a100be5c9c34fe315d03 100644 (file)
@@ -17,12 +17,14 @@ using Robust.Shared.GameStates;
 using Robust.Shared.Input.Binding;
 using Robust.Shared.Map;
 using Robust.Shared.Player;
+using Robust.Shared.Timing;
 using Robust.Shared.Utility;
 
 namespace Content.Server.Hands.Systems
 {
     public sealed class HandsSystem : SharedHandsSystem
     {
+        [Dependency] private readonly IGameTiming _timing = default!;
         [Dependency] private readonly StackSystem _stackSystem = default!;
         [Dependency] private readonly HandVirtualItemSystem _virtualItemSystem = default!;
         [Dependency] private readonly ActionBlockerSystem _actionBlockerSystem = default!;
@@ -43,6 +45,7 @@ namespace Content.Server.Hands.Systems
             SubscribeLocalEvent<HandsComponent, BodyPartRemovedEvent>(HandleBodyPartRemoved);
 
             SubscribeLocalEvent<HandsComponent, ComponentGetState>(GetComponentState);
+            SubscribeLocalEvent<HandsComponent, EntityUnpausedEvent>(OnUnpaused);
 
             SubscribeLocalEvent<HandsComponent, BeforeExplodeEvent>(OnExploded);
 
@@ -63,6 +66,11 @@ namespace Content.Server.Hands.Systems
             args.State = new HandsComponentState(hands);
         }
 
+        private void OnUnpaused(Entity<HandsComponent> ent, ref EntityUnpausedEvent args)
+        {
+            ent.Comp.NextThrowTime += args.PausedTime;
+        }
+
         private void OnExploded(Entity<HandsComponent> ent, ref BeforeExplodeEvent args)
         {
             foreach (var hand in ent.Comp.Hands.Values)
@@ -172,6 +180,10 @@ namespace Content.Server.Hands.Systems
                 !_actionBlockerSystem.CanThrow(player, throwEnt))
                 return false;
 
+            if (_timing.CurTime < hands.NextThrowTime)
+                return false;
+            hands.NextThrowTime = _timing.CurTime + hands.ThrowCooldown;
+
             if (EntityManager.TryGetComponent(throwEnt, out StackComponent? stack) && stack.Count > 1 && stack.ThrowIndividually)
             {
                 var splitStack = _stackSystem.Split(throwEnt, 1, EntityManager.GetComponent<TransformComponent>(player).Coordinates, stack);
@@ -201,7 +213,7 @@ namespace Content.Server.Hands.Systems
                 return true;
 
             // This can grief the above event so we raise it afterwards
-            if (!TryDrop(player, throwEnt, handsComp: hands))
+            if (IsHolding(player, throwEnt, out _, hands) && !TryDrop(player, throwEnt, handsComp: hands))
                 return false;
 
             _throwingSystem.TryThrow(ev.ItemUid, ev.Direction, ev.ThrowStrength, ev.PlayerUid);
index 0bece1d141ab528d1638bd83184d19e3a32e6c2f..ef3b2a6a0e6670897ae1cc8a25c40305344a1384 100644 (file)
@@ -57,6 +57,18 @@ public sealed partial class HandsComponent : Component
     ///     Used by the client.
     /// </summary>
     public readonly Dictionary<HandLocation, HashSet<string>> RevealedLayers = new();
+
+    /// <summary>
+    ///     The time at which throws will be allowed again.
+    /// </summary>
+    [DataField, ViewVariables(VVAccess.ReadWrite)]
+    public TimeSpan NextThrowTime;
+
+    /// <summary>
+    ///     The minimum time inbetween throws.
+    /// </summary>
+    [DataField, ViewVariables(VVAccess.ReadWrite)]
+    public TimeSpan ThrowCooldown = TimeSpan.FromSeconds(0.5f);
 }
 
 [Serializable, NetSerializable]