From 170e5594174b648cac122d7e3e9278f51c5fed93 Mon Sep 17 00:00:00 2001 From: Nemanja <98561806+EmoGarbage404@users.noreply.github.com> Date: Fri, 15 Sep 2023 00:15:42 -0400 Subject: [PATCH] multi-gun nerf (#20194) --- .../Weapons/Ranged/Components/GunComponent.cs | 6 +++++ .../Systems/SharedGunSystem.Interactions.cs | 24 +++++++++++++++++++ .../Weapons/Ranged/Systems/SharedGunSystem.cs | 2 ++ 3 files changed, 32 insertions(+) diff --git a/Content.Shared/Weapons/Ranged/Components/GunComponent.cs b/Content.Shared/Weapons/Ranged/Components/GunComponent.cs index fd61fd70e6..515582b51b 100644 --- a/Content.Shared/Weapons/Ranged/Components/GunComponent.cs +++ b/Content.Shared/Weapons/Ranged/Components/GunComponent.cs @@ -104,6 +104,12 @@ public partial class GunComponent : Component [AutoNetworkedField] public float FireRate = 8f; + /// + /// Starts fire cooldown when equipped if true. + /// + [ViewVariables(VVAccess.ReadWrite), DataField("resetOnHandSelected")] + public bool ResetOnHandSelected = true; + /// /// How fast the projectile moves. /// diff --git a/Content.Shared/Weapons/Ranged/Systems/SharedGunSystem.Interactions.cs b/Content.Shared/Weapons/Ranged/Systems/SharedGunSystem.Interactions.cs index 659bc054f6..1600dec0e4 100644 --- a/Content.Shared/Weapons/Ranged/Systems/SharedGunSystem.Interactions.cs +++ b/Content.Shared/Weapons/Ranged/Systems/SharedGunSystem.Interactions.cs @@ -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); + } } diff --git a/Content.Shared/Weapons/Ranged/Systems/SharedGunSystem.cs b/Content.Shared/Weapons/Ranged/Systems/SharedGunSystem.cs index 1c80f73ad6..6f764bb9f4 100644 --- a/Content.Shared/Weapons/Ranged/Systems/SharedGunSystem.cs +++ b/Content.Shared/Weapons/Ranged/Systems/SharedGunSystem.cs @@ -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>(OnAltVerb); SubscribeLocalEvent(OnExamine); SubscribeLocalEvent(OnCycleMode); + SubscribeLocalEvent(OnGunSelected); SubscribeLocalEvent(OnGunUnpaused); #if DEBUG -- 2.51.2