]> git.smokeofanarchy.ru Git - space-station-14.git/commitdiff
multi-gun nerf (#20194)
authorNemanja <98561806+EmoGarbage404@users.noreply.github.com>
Fri, 15 Sep 2023 04:15:42 +0000 (00:15 -0400)
committerGitHub <noreply@github.com>
Fri, 15 Sep 2023 04:15:42 +0000 (23:15 -0500)
Content.Shared/Weapons/Ranged/Components/GunComponent.cs
Content.Shared/Weapons/Ranged/Systems/SharedGunSystem.Interactions.cs
Content.Shared/Weapons/Ranged/Systems/SharedGunSystem.cs

index fd61fd70e64ef00d48b25aa3e7ec82f23e4a245e..515582b51b244fe0396a52916ae8359ed4a44e92 100644 (file)
@@ -104,6 +104,12 @@ public partial class GunComponent : Component
     [AutoNetworkedField]
     public float FireRate = 8f;
 
+    /// <summary>
+    /// Starts fire cooldown when equipped if true.
+    /// </summary>
+    [ViewVariables(VVAccess.ReadWrite), DataField("resetOnHandSelected")]
+    public bool ResetOnHandSelected = true;
+
     /// <summary>
     /// How fast the projectile moves.
     /// </summary>
index 659bc054f6bbf6cc25fbd908dbef692a77945f6b..1600dec0e48cad1a18efe3fd5116586651bc63dd 100644 (file)
@@ -1,5 +1,6 @@
 using Content.Shared.Actions;
 using Content.Shared.Examine;
+using Content.Shared.Hands;
 using Content.Shared.Verbs;
 using Content.Shared.Weapons.Ranged.Components;
 using Robust.Shared.Utility;
@@ -103,4 +104,27 @@ public abstract partial class SharedGunSystem
     {
         SelectFire(uid, component, args.Mode, args.Performer);
     }
+
+    private void OnGunSelected(EntityUid uid, GunComponent component, HandSelectedEvent args)
+    {
+        var fireDelay = 1f / component.FireRate;
+        if (fireDelay.Equals(0f))
+            return;
+
+        if (!component.ResetOnHandSelected)
+            return;
+
+        if (Paused(uid))
+            return;
+
+        // If someone swaps to this weapon then reset its cd.
+        var curTime = Timing.CurTime;
+        var minimum = curTime + TimeSpan.FromSeconds(fireDelay);
+
+        if (minimum < component.NextFire)
+            return;
+
+        component.NextFire = minimum;
+        Dirty(uid, component);
+    }
 }
index 1c80f73ad6d6fa665154df193cd77212b31d8ec3..6f764bb9f4e49b4ea237ad3efb42cde696e95199 100644 (file)
@@ -8,6 +8,7 @@ using Content.Shared.Containers.ItemSlots;
 using Content.Shared.Damage;
 using Content.Shared.Examine;
 using Content.Shared.Gravity;
+using Content.Shared.Hands;
 using Content.Shared.Hands.Components;
 using Content.Shared.Popups;
 using Content.Shared.Projectiles;
@@ -88,6 +89,7 @@ public abstract partial class SharedGunSystem : EntitySystem
         SubscribeLocalEvent<GunComponent, GetVerbsEvent<AlternativeVerb>>(OnAltVerb);
         SubscribeLocalEvent<GunComponent, ExaminedEvent>(OnExamine);
         SubscribeLocalEvent<GunComponent, CycleModeEvent>(OnCycleMode);
+        SubscribeLocalEvent<GunComponent, HandSelectedEvent>(OnGunSelected);
         SubscribeLocalEvent<GunComponent, EntityUnpausedEvent>(OnGunUnpaused);
 
 #if DEBUG