]> git.smokeofanarchy.ru Git - space-station-14.git/commitdiff
Gun + PKA fixes (#16244)
authormetalgearsloth <31366439+metalgearsloth@users.noreply.github.com>
Mon, 8 May 2023 12:37:40 +0000 (22:37 +1000)
committerGitHub <noreply@github.com>
Mon, 8 May 2023 12:37:40 +0000 (22:37 +1000)
Content.Client/Weapons/Ranged/Systems/GunSystem.AmmoCounter.cs
Content.Server/Weapons/Ranged/Components/RechargeBasicEntityAmmoComponent.cs [deleted file]
Content.Server/Weapons/Ranged/Systems/RechargeBasicEntityAmmoSystem.cs [deleted file]
Content.Shared/Weapons/Ranged/Components/BasicEntityAmmoProviderComponent.cs
Content.Shared/Weapons/Ranged/Components/RechargeBasicEntityAmmoComponent.cs [new file with mode: 0644]
Content.Shared/Weapons/Ranged/Systems/RechargeBasicEntityAmmoSystem.cs [new file with mode: 0644]
Content.Shared/Weapons/Ranged/Systems/SharedGunSystem.BasicEntity.cs
Content.Shared/Weapons/Ranged/Systems/SharedGunSystem.cs
Resources/Prototypes/Entities/Objects/Weapons/Guns/Basic/base_pka.yml
Resources/Prototypes/Entities/Objects/Weapons/Guns/Basic/base_staff.yml

index 10f789b42a187769b728e1a2314eddcfdb76e82d..f9914df470144de586515deabab5538b75d22161 100644 (file)
@@ -62,7 +62,9 @@ public sealed partial class GunSystem
         // share as much code as possible
         if (!Timing.IsFirstTimePredicted ||
             !TryComp<AmmoCounterComponent>(uid, out var clientComp))
+        {
             return;
+        }
 
         UpdateAmmoCount(uid, clientComp);
     }
diff --git a/Content.Server/Weapons/Ranged/Components/RechargeBasicEntityAmmoComponent.cs b/Content.Server/Weapons/Ranged/Components/RechargeBasicEntityAmmoComponent.cs
deleted file mode 100644 (file)
index 61f4815..0000000
+++ /dev/null
@@ -1,32 +0,0 @@
-using Robust.Shared.Audio;
-
-namespace Content.Server.Weapons.Ranged.Components;
-
-/// <summary>
-///     Responsible for handling recharging a basic entity ammo provider over time.
-/// </summary>
-[RegisterComponent]
-public sealed class RechargeBasicEntityAmmoComponent : Component
-{
-    [ViewVariables(VVAccess.ReadWrite)]
-    [DataField("minRechargeCooldown")]
-    public float MinRechargeCooldown = 30f;
-
-    [ViewVariables(VVAccess.ReadWrite)]
-    [DataField("maxRechargeCooldown")]
-    public float MaxRechargeCooldown = 45f;
-
-    [DataField("rechargeSound")]
-    public SoundSpecifier RechargeSound = new SoundPathSpecifier("/Audio/Magic/forcewall.ogg")
-    {
-        Params = AudioParams.Default.WithVolume(-5f)
-    };
-
-    [DataField("accumulatedFrametime")]
-    public float AccumulatedFrameTime;
-    /// <summary>
-    ///     Number of seconds until the next recharge.
-    /// </summary>
-    [ViewVariables(VVAccess.ReadWrite)]
-    public float NextRechargeTime = 0f;
-}
diff --git a/Content.Server/Weapons/Ranged/Systems/RechargeBasicEntityAmmoSystem.cs b/Content.Server/Weapons/Ranged/Systems/RechargeBasicEntityAmmoSystem.cs
deleted file mode 100644 (file)
index 0f29aab..0000000
+++ /dev/null
@@ -1,73 +0,0 @@
-using Content.Server.Weapons.Ranged.Components;
-using Content.Shared.Examine;
-using Content.Shared.Weapons.Ranged.Components;
-using Content.Shared.Weapons.Ranged.Systems;
-using Robust.Shared.Audio;
-using Robust.Shared.Player;
-using Robust.Shared.Random;
-
-namespace Content.Server.Weapons.Ranged.Systems;
-
-public sealed class RechargeBasicEntityAmmoSystem : EntitySystem
-{
-    [Dependency] private readonly IRobustRandom _random = default!;
-    [Dependency] private readonly SharedGunSystem _gun = default!;
-
-    public override void Initialize()
-    {
-        base.Initialize();
-
-        SubscribeLocalEvent<RechargeBasicEntityAmmoComponent, ComponentInit>(OnInit);
-        SubscribeLocalEvent<RechargeBasicEntityAmmoComponent, ExaminedEvent>(OnExamined);
-    }
-
-    public override void Update(float frameTime)
-    {
-        base.Update(frameTime);
-
-        foreach (var (recharge, ammo) in
-                 EntityQuery<RechargeBasicEntityAmmoComponent, BasicEntityAmmoProviderComponent>())
-        {
-            if (ammo.Count is null || ammo.Count == ammo.Capacity)
-                continue;
-
-            recharge.AccumulatedFrameTime += frameTime;
-
-            if (recharge.AccumulatedFrameTime < recharge.NextRechargeTime)
-                continue;
-
-            recharge.AccumulatedFrameTime -= recharge.NextRechargeTime;
-            UpdateCooldown(recharge);
-
-
-            if (_gun.UpdateBasicEntityAmmoCount(ammo.Owner, ammo.Count.Value + 1, ammo))
-            {
-                SoundSystem.Play(recharge.RechargeSound.GetSound(), Filter.Pvs(recharge.Owner), recharge.Owner,
-                    recharge.RechargeSound.Params);
-            }
-        }
-    }
-
-    private void OnInit(EntityUid uid, RechargeBasicEntityAmmoComponent component, ComponentInit args)
-    {
-        UpdateCooldown(component);
-    }
-
-    private void OnExamined(EntityUid uid, RechargeBasicEntityAmmoComponent component, ExaminedEvent args)
-    {
-        if (!TryComp<BasicEntityAmmoProviderComponent>(uid, out var ammo)
-            || ammo.Count == ammo.Capacity)
-        {
-            args.PushMarkup(Loc.GetString("recharge-basic-entity-ammo-full"));
-            return;
-        }
-
-        var timeLeft = component.NextRechargeTime - component.AccumulatedFrameTime;
-        args.PushMarkup(Loc.GetString("recharge-basic-entity-ammo-can-recharge", ("seconds", Math.Round(timeLeft, 1))));
-    }
-
-    private void UpdateCooldown(RechargeBasicEntityAmmoComponent component)
-    {
-        component.NextRechargeTime = _random.NextFloat(component.MinRechargeCooldown, component.MaxRechargeCooldown);
-    }
-}
index d0c6c4487e494206ba24e4e2002f21960fa95173..3b2131d3a6de50fc3d8e1cbebd1f74a71c8102d4 100644 (file)
@@ -1,6 +1,5 @@
 using Robust.Shared.GameStates;
 using Robust.Shared.Prototypes;
-using Robust.Shared.Serialization;
 using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom.Prototype;
 
 namespace Content.Shared.Weapons.Ranged.Components;
@@ -9,7 +8,7 @@ namespace Content.Shared.Weapons.Ranged.Components;
 ///     Simply provides a certain capacity of entities that cannot be reloaded through normal means and have
 ///     no special behavior like cycling, magazine
 /// </summary>
-[RegisterComponent, AutoGenerateComponentState]
+[RegisterComponent, NetworkedComponent, AutoGenerateComponentState]
 public sealed partial class BasicEntityAmmoProviderComponent : AmmoProviderComponent
 {
     [ViewVariables(VVAccess.ReadWrite)]
diff --git a/Content.Shared/Weapons/Ranged/Components/RechargeBasicEntityAmmoComponent.cs b/Content.Shared/Weapons/Ranged/Components/RechargeBasicEntityAmmoComponent.cs
new file mode 100644 (file)
index 0000000..923f95e
--- /dev/null
@@ -0,0 +1,29 @@
+using Robust.Shared.Audio;
+using Robust.Shared.GameStates;
+using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom;
+
+namespace Content.Shared.Weapons.Ranged.Components;
+
+/// <summary>
+///     Responsible for handling recharging a basic entity ammo provider over time.
+/// </summary>
+[RegisterComponent, NetworkedComponent, AutoGenerateComponentState]
+public sealed partial class RechargeBasicEntityAmmoComponent : Component
+{
+    [ViewVariables(VVAccess.ReadWrite)]
+    [DataField("rechargeCooldown")]
+    [AutoNetworkedField]
+    public float RechargeCooldown = 1.5f;
+
+    [DataField("rechargeSound")]
+    [AutoNetworkedField]
+    public SoundSpecifier RechargeSound = new SoundPathSpecifier("/Audio/Magic/forcewall.ogg")
+    {
+        Params = AudioParams.Default.WithVolume(-5f)
+    };
+
+    [ViewVariables(VVAccess.ReadWrite),
+     DataField("nextCharge", customTypeSerializer:typeof(TimeOffsetSerializer)),
+    AutoNetworkedField]
+    public TimeSpan? NextCharge;
+}
diff --git a/Content.Shared/Weapons/Ranged/Systems/RechargeBasicEntityAmmoSystem.cs b/Content.Shared/Weapons/Ranged/Systems/RechargeBasicEntityAmmoSystem.cs
new file mode 100644 (file)
index 0000000..9b72136
--- /dev/null
@@ -0,0 +1,97 @@
+using Content.Shared.Examine;
+using Content.Shared.Weapons.Ranged.Components;
+using Robust.Shared.Network;
+using Robust.Shared.Player;
+using Robust.Shared.Timing;
+using Robust.Shared.Utility;
+
+namespace Content.Shared.Weapons.Ranged.Systems;
+
+public sealed class RechargeBasicEntityAmmoSystem : EntitySystem
+{
+    [Dependency] private readonly IGameTiming _timing = default!;
+    [Dependency] private readonly INetManager _netManager = default!;
+    [Dependency] private readonly SharedAudioSystem _audio = default!;
+    [Dependency] private readonly SharedGunSystem _gun = default!;
+    [Dependency] private readonly MetaDataSystem _metadata = default!;
+
+    public override void Initialize()
+    {
+        base.Initialize();
+
+        SubscribeLocalEvent<RechargeBasicEntityAmmoComponent, EntityUnpausedEvent>(OnUnpaused);
+        SubscribeLocalEvent<RechargeBasicEntityAmmoComponent, MapInitEvent>(OnInit);
+        SubscribeLocalEvent<RechargeBasicEntityAmmoComponent, ExaminedEvent>(OnExamined);
+    }
+
+    private void OnUnpaused(EntityUid uid, RechargeBasicEntityAmmoComponent component, ref EntityUnpausedEvent args)
+    {
+        if (component.NextCharge == null)
+            return;
+
+        component.NextCharge = component.NextCharge.Value + args.PausedTime;
+    }
+
+    public override void Update(float frameTime)
+    {
+        base.Update(frameTime);
+        var query = EntityQueryEnumerator<RechargeBasicEntityAmmoComponent, BasicEntityAmmoProviderComponent>();
+
+        while (query.MoveNext(out var uid, out var recharge, out var ammo))
+        {
+            if (ammo.Count is null || ammo.Count == ammo.Capacity || recharge.NextCharge == null)
+                continue;
+
+            if (recharge.NextCharge > _timing.CurTime)
+                continue;
+
+            if (_gun.UpdateBasicEntityAmmoCount(uid, ammo.Count.Value + 1, ammo))
+            {
+                if (_netManager.IsClient && _timing.IsFirstTimePredicted)
+                    _audio.Play(recharge.RechargeSound, Filter.Local(), uid, true);
+            }
+
+            if (ammo.Count == ammo.Capacity)
+            {
+                recharge.NextCharge = null;
+                Dirty(recharge);
+                continue;
+            }
+
+            recharge.NextCharge = recharge.NextCharge.Value + TimeSpan.FromSeconds(recharge.RechargeCooldown);
+            Dirty(recharge);
+        }
+    }
+
+    private void OnInit(EntityUid uid, RechargeBasicEntityAmmoComponent component, MapInitEvent args)
+    {
+        component.NextCharge = _timing.CurTime;
+        Dirty(component);
+    }
+
+    private void OnExamined(EntityUid uid, RechargeBasicEntityAmmoComponent component, ExaminedEvent args)
+    {
+        if (!TryComp<BasicEntityAmmoProviderComponent>(uid, out var ammo)
+            || ammo.Count == ammo.Capacity ||
+            component.NextCharge == null)
+        {
+            args.PushMarkup(Loc.GetString("recharge-basic-entity-ammo-full"));
+            return;
+        }
+
+        var timeLeft = component.NextCharge + _metadata.GetPauseTime(uid) - _timing.CurTime;
+        args.PushMarkup(Loc.GetString("recharge-basic-entity-ammo-can-recharge", ("seconds", Math.Round(timeLeft.Value.TotalSeconds, 1))));
+    }
+
+    public void Reset(EntityUid uid, RechargeBasicEntityAmmoComponent? recharge = null)
+    {
+        if (!Resolve(uid, ref recharge, false))
+            return;
+
+        if (recharge.NextCharge == null || recharge.NextCharge < _timing.CurTime)
+        {
+            recharge.NextCharge = _timing.CurTime + TimeSpan.FromSeconds(recharge.RechargeCooldown);
+            Dirty(recharge);
+        }
+    }
+}
index e530b21e3277b84e42eb1c3dac9de9dc2f54ba6d..7e459169d89637a097f08a646f7c887f9f1df71d 100644 (file)
@@ -8,12 +8,12 @@ public abstract partial class SharedGunSystem
 {
     protected virtual void InitializeBasicEntity()
     {
-        SubscribeLocalEvent<BasicEntityAmmoProviderComponent, ComponentInit>(OnBasicEntityInit);
+        SubscribeLocalEvent<BasicEntityAmmoProviderComponent, MapInitEvent>(OnBasicEntityMapInit);
         SubscribeLocalEvent<BasicEntityAmmoProviderComponent, TakeAmmoEvent>(OnBasicEntityTakeAmmo);
         SubscribeLocalEvent<BasicEntityAmmoProviderComponent, GetAmmoCountEvent>(OnBasicEntityAmmoCount);
     }
 
-    private void OnBasicEntityInit(EntityUid uid, BasicEntityAmmoProviderComponent component, ComponentInit args)
+    private void OnBasicEntityMapInit(EntityUid uid, BasicEntityAmmoProviderComponent component, MapInitEvent args)
     {
         if (component.Count is null)
         {
@@ -26,7 +26,7 @@ public abstract partial class SharedGunSystem
 
     private void OnBasicEntityTakeAmmo(EntityUid uid, BasicEntityAmmoProviderComponent component, TakeAmmoEvent args)
     {
-        for (int i = 0; i < args.Shots; i++)
+        for (var i = 0; i < args.Shots; i++)
         {
             if (component.Count <= 0)
                 return;
@@ -40,6 +40,7 @@ public abstract partial class SharedGunSystem
             args.Ammo.Add((ent, EnsureComp<AmmoComponent>(ent)));
         }
 
+        _recharge.Reset(uid);
         UpdateBasicEntityAppearance(uid, component);
         Dirty(component);
     }
@@ -73,6 +74,7 @@ public abstract partial class SharedGunSystem
         component.Count = count;
         Dirty(component);
         UpdateBasicEntityAppearance(uid, component);
+        UpdateAmmoCount(uid);
 
         return true;
     }
index 6baa6c38ec9bea8a12d3ebc4f7abc3ea5a214036..47688489728bf255413a3a46d329b4179b4e6888 100644 (file)
@@ -41,6 +41,7 @@ public abstract partial class SharedGunSystem : EntitySystem
     [Dependency] protected readonly DamageableSystem Damageable = default!;
     [Dependency] protected readonly ExamineSystemShared Examine = default!;
     [Dependency] private   readonly ItemSlotsSystem _slots = default!;
+    [Dependency] private   readonly RechargeBasicEntityAmmoSystem _recharge = default!;
     [Dependency] protected readonly SharedActionsSystem Actions = default!;
     [Dependency] protected readonly SharedAppearanceSystem Appearance = default!;
     [Dependency] private   readonly SharedCombatModeSystem _combatMode = default!;
@@ -243,6 +244,9 @@ public abstract partial class SharedGunSystem : EntitySystem
             shots++;
         }
 
+        // NextFire has been touched regardless so need to dirty the gun.
+        Dirty(gun);
+
         // Get how many shots we're actually allowed to make, due to clip size or otherwise.
         // Don't do this in the loop so we still reset NextFire.
         switch (gun.SelectedMode)
@@ -288,7 +292,6 @@ public abstract partial class SharedGunSystem : EntitySystem
                 // May cause prediction issues? Needs more tweaking
                 gun.NextFire = TimeSpan.FromSeconds(Math.Max(lastFire.TotalSeconds + SafetyNextFire, gun.NextFire.TotalSeconds));
                 Audio.PlayPredicted(gun.SoundEmpty, gunUid, user);
-                Dirty(gun);
                 return;
             }
 
index d9c1315ccbb9a04bed83bc8bb0fa9876bccd873a..34dac2a80e48f80c04440184febd608a62c46cc7 100644 (file)
@@ -9,7 +9,7 @@
     sprite: Objects/Weapons/Guns/Basic/kinetic_accelerator.rsi
     size: 30
   - type: Gun
-    fireRate: 1
+    fireRate: 0.75
     selectedMode: SemiAuto
     availableModes:
     - SemiAuto
@@ -24,8 +24,7 @@
           True: { visible: False }
           False: { visible: True }
   - type: RechargeBasicEntityAmmo
-    minRechargeCooldown: 1.5
-    maxRechargeCooldown: 1.5
+    rechargeCooldown: 1
     rechargeSound:
       path: /Audio/Weapons/Guns/MagIn/kinetic_reload.ogg
   - type: BasicEntityAmmoProvider
index 302641c2d520e46e53d7dfabb246145951abb6a3..76bd0b9e75029d251bcd17b494baecce9f9acf53 100644 (file)
@@ -16,6 +16,7 @@
   - type: AmmoCounter
   # All staves recharge. Wands are not.
   - type: RechargeBasicEntityAmmo
+    rechargeCooldown: 30
   - type: Tag
     tags:
     - WizardStaff