]> git.smokeofanarchy.ru Git - space-station-14.git/commitdiff
Make failing to fire a gun that requires wielding not delay the next shot (#27973)
authorDrSmugleaf <10968691+DrSmugleaf@users.noreply.github.com>
Tue, 14 May 2024 04:53:47 +0000 (21:53 -0700)
committerGitHub <noreply@github.com>
Tue, 14 May 2024 04:53:47 +0000 (21:53 -0700)
Make failing to fire a wield-only gun not delay the next shot

Content.Shared/Weapons/Ranged/Components/GunRequiresWieldComponent.cs
Content.Shared/Weapons/Ranged/Events/ShotAttemptedEvent.cs
Content.Shared/Weapons/Ranged/Systems/SharedGunSystem.cs
Content.Shared/Wieldable/WieldableSystem.cs

index 2ae71334b47cfe6c6759b4344e6a62b61f5a1edc..fa3732209f5223c87b7fa8a12d9807cd74869e94 100644 (file)
@@ -6,8 +6,13 @@ namespace Content.Shared.Weapons.Ranged.Components;
 /// <summary>
 /// Indicates that this gun requires wielding to be useable.
 /// </summary>
-[RegisterComponent, NetworkedComponent, Access(typeof(WieldableSystem))]
+[RegisterComponent, NetworkedComponent, AutoGenerateComponentState]
+[Access(typeof(WieldableSystem))]
 public sealed partial class GunRequiresWieldComponent : Component
 {
+    [DataField, AutoNetworkedField]
+    public TimeSpan LastPopup;
 
+    [DataField, AutoNetworkedField]
+    public TimeSpan PopupCooldown = TimeSpan.FromSeconds(1);
 }
index 40925ad614c943a32706fa4cb8efb578a54f64c0..d61862bf1a0a3388c568cf7e3dc98dce1a82e804 100644 (file)
@@ -1,3 +1,5 @@
+using Content.Shared.Weapons.Ranged.Components;
+
 namespace Content.Shared.Weapons.Ranged.Events;
 
 /// <summary>
@@ -15,7 +17,7 @@ public record struct ShotAttemptedEvent
     /// <summary>
     /// The gun being shot.
     /// </summary>
-    public EntityUid Used;
+    public Entity<GunComponent> Used;
 
     public bool Cancelled { get; private set; }
 
index 4e51ca2b62dcb17a695bae56984d37b38e2e3f7c..4debc289be1f2ea845cc7173f2c35bedf2359c76 100644 (file)
@@ -239,7 +239,7 @@ public abstract partial class SharedGunSystem : EntitySystem
         var prevention = new ShotAttemptedEvent
         {
             User = user,
-            Used = gunUid
+            Used = (gunUid, gun)
         };
         RaiseLocalEvent(gunUid, ref prevention);
         if (prevention.Cancelled)
index 778a664e2cbc0999601fd495601d18ac5bd0db78..b765566f44af66de6a13ad2bd4eda1c0d41f40fd 100644 (file)
@@ -16,7 +16,7 @@ using Content.Shared.Weapons.Ranged.Events;
 using Content.Shared.Weapons.Ranged.Systems;
 using Content.Shared.Wieldable.Components;
 using Robust.Shared.Audio.Systems;
-using Robust.Shared.Player;
+using Robust.Shared.Timing;
 
 namespace Content.Shared.Wieldable;
 
@@ -30,6 +30,7 @@ public sealed class WieldableSystem : EntitySystem
     [Dependency] private readonly SharedAppearanceSystem _appearance = default!;
     [Dependency] private readonly UseDelaySystem _delay = default!;
     [Dependency] private readonly SharedGunSystem _gun = default!;
+    [Dependency] private readonly IGameTiming _timing = default!;
 
     public override void Initialize()
     {
@@ -42,7 +43,7 @@ public sealed class WieldableSystem : EntitySystem
         SubscribeLocalEvent<WieldableComponent, GetVerbsEvent<InteractionVerb>>(AddToggleWieldVerb);
 
         SubscribeLocalEvent<MeleeRequiresWieldComponent, AttemptMeleeEvent>(OnMeleeAttempt);
-        SubscribeLocalEvent<GunRequiresWieldComponent, AttemptShootEvent>(OnShootAttempt);
+        SubscribeLocalEvent<GunRequiresWieldComponent, ShotAttemptedEvent>(OnShootAttempt);
         SubscribeLocalEvent<GunWieldBonusComponent, ItemWieldedEvent>(OnGunWielded);
         SubscribeLocalEvent<GunWieldBonusComponent, ItemUnwieldedEvent>(OnGunUnwielded);
         SubscribeLocalEvent<GunWieldBonusComponent, GunRefreshModifiersEvent>(OnGunRefreshModifiers);
@@ -61,16 +62,21 @@ public sealed class WieldableSystem : EntitySystem
         }
     }
 
-    private void OnShootAttempt(EntityUid uid, GunRequiresWieldComponent component, ref AttemptShootEvent args)
+    private void OnShootAttempt(EntityUid uid, GunRequiresWieldComponent component, ref ShotAttemptedEvent args)
     {
         if (TryComp<WieldableComponent>(uid, out var wieldable) &&
             !wieldable.Wielded)
         {
-            args.Cancelled = true;
+            args.Cancel();
 
-            if (!HasComp<MeleeWeaponComponent>(uid) && !HasComp<MeleeRequiresWieldComponent>(uid))
+            var time = _timing.CurTime;
+            if (time > component.LastPopup + component.PopupCooldown &&
+                !HasComp<MeleeWeaponComponent>(uid) &&
+                !HasComp<MeleeRequiresWieldComponent>(uid))
             {
-                args.Message = Loc.GetString("wieldable-component-requires", ("item", uid));
+                component.LastPopup = time;
+                var message = Loc.GetString("wieldable-component-requires", ("item", uid));
+                _popupSystem.PopupClient(message, args.Used, args.User);
             }
         }
     }