]> git.smokeofanarchy.ru Git - space-station-14.git/commitdiff
Add access to gun components (#30688)
authormetalgearsloth <31366439+metalgearsloth@users.noreply.github.com>
Fri, 9 Aug 2024 07:39:27 +0000 (17:39 +1000)
committerGitHub <noreply@github.com>
Fri, 9 Aug 2024 07:39:27 +0000 (17:39 +1000)
* Add access to gun components

Found from an rmc14 PR.

* Admin verbs proving why access needs to exist

* Someone is probably going to post this pr to le reddit and complain about self-merges.

Content.Server/Administration/Systems/AdminVerbSystem.Tools.cs
Content.Shared/Weapons/Ranged/Components/BallisticAmmoProviderComponent.cs
Content.Shared/Weapons/Ranged/Components/ChamberMagazineAmmoProviderComponent.cs
Content.Shared/Weapons/Ranged/Components/ContainerAmmoProviderComponent.cs
Content.Shared/Weapons/Ranged/Components/MagazineAmmoProviderComponent.cs
Content.Shared/Weapons/Ranged/Systems/SharedGunSystem.Ballistic.cs

index 328fa74484644fbeb74b2ddd36bd6202194debfb..a00424a74125bf1b2aef053e9c875ca7fe243ac5 100644 (file)
@@ -724,15 +724,7 @@ public sealed partial class AdminVerbSystem
                         if (!int.TryParse(amount, out var result))
                             return;
 
-                        if (result > 0)
-                        {
-                            ballisticAmmo.UnspawnedCount = result;
-                        }
-                        else
-                        {
-                            ballisticAmmo.UnspawnedCount = 0;
-                        }
-
+                        _gun.SetBallisticUnspawned((args.Target, ballisticAmmo), result);
                         _gun.UpdateBallisticAppearance(args.Target, ballisticAmmo);
                     });
                 },
index eb04d3227db629128ccc3a5128e7485059407a4d..f825f10550d4d2e54ac116321794f4c5a6f16fc6 100644 (file)
@@ -1,3 +1,4 @@
+using Content.Shared.Weapons.Ranged.Systems;
 using Content.Shared.Whitelist;
 using Robust.Shared.Audio;
 using Robust.Shared.Containers;
@@ -6,7 +7,7 @@ using Robust.Shared.Prototypes;
 
 namespace Content.Shared.Weapons.Ranged.Components;
 
-[RegisterComponent, NetworkedComponent, AutoGenerateComponentState]
+[RegisterComponent, NetworkedComponent, AutoGenerateComponentState, Access(typeof(SharedGunSystem))]
 public sealed partial class BallisticAmmoProviderComponent : Component
 {
     [ViewVariables(VVAccess.ReadWrite), DataField]
@@ -32,6 +33,7 @@ public sealed partial class BallisticAmmoProviderComponent : Component
     public Container Container = default!;
 
     // TODO: Make this use stacks when the typeserializer is done.
+    // Realistically just point to the container.
     [DataField, AutoNetworkedField]
     public List<EntityUid> Entities = new();
 
index e64ec0d68de91f3140a56c47e82e6dd5706fc414..37517c13711015ef04f9858c96a8f44cc426bbbc 100644 (file)
@@ -1,3 +1,4 @@
+using Content.Shared.Weapons.Ranged.Systems;
 using Robust.Shared.Audio;
 
 namespace Content.Shared.Weapons.Ranged.Components;
@@ -6,6 +7,7 @@ namespace Content.Shared.Weapons.Ranged.Components;
 /// Chamber + mags in one package. If you need just magazine then use <see cref="MagazineAmmoProviderComponent"/>
 /// </summary>
 [RegisterComponent, AutoGenerateComponentState]
+[Access(typeof(SharedGunSystem))]
 public sealed partial class ChamberMagazineAmmoProviderComponent : MagazineAmmoProviderComponent
 {
     /// <summary>
index 0f2884bf58ac8b714c57d9753bb937c394aea7b6..f49cc812c24c0ee3929271f5c9ef96c9b63a5b62 100644 (file)
@@ -1,4 +1,5 @@
-using Robust.Shared.GameStates;
+using Content.Shared.Weapons.Ranged.Systems;
+using Robust.Shared.GameStates;
 
 namespace Content.Shared.Weapons.Ranged.Components;
 
@@ -6,6 +7,7 @@ namespace Content.Shared.Weapons.Ranged.Components;
 ///     Handles pulling entities from the given container to use as ammunition.
 /// </summary>
 [RegisterComponent]
+[Access(typeof(SharedGunSystem))]
 public sealed partial class ContainerAmmoProviderComponent : AmmoProviderComponent
 {
     [DataField("container", required: true)]
index 9aff60fd3ae30f5bd8696a5a5eac30b2c813ae14..56d09ceaa5d7904c57cfec7c16ab6b815f101971 100644 (file)
@@ -1,4 +1,5 @@
 using Content.Shared.Weapons.Ranged.Components;
+using Content.Shared.Weapons.Ranged.Systems;
 using Robust.Shared.Audio;
 
 namespace Content.Shared.Weapons.Ranged;
@@ -7,6 +8,7 @@ namespace Content.Shared.Weapons.Ranged;
 /// Wrapper around a magazine (handled via ItemSlot). Passes all AmmoProvider logic onto it.
 /// </summary>
 [RegisterComponent, Virtual]
+[Access(typeof(SharedGunSystem))]
 public partial class MagazineAmmoProviderComponent : AmmoProviderComponent
 {
     [ViewVariables(VVAccess.ReadWrite), DataField("soundAutoEject")]
index 4c5712c5093bcdebf4b382119782aee60ab0e4ad..9ef5cbd70285d6d0ad30032c3e89aaaeaf3a59a0 100644 (file)
@@ -277,6 +277,17 @@ public abstract partial class SharedGunSystem
         Appearance.SetData(uid, AmmoVisuals.AmmoCount, GetBallisticShots(component), appearance);
         Appearance.SetData(uid, AmmoVisuals.AmmoMax, component.Capacity, appearance);
     }
+
+    public void SetBallisticUnspawned(Entity<BallisticAmmoProviderComponent> entity, int count)
+    {
+        if (entity.Comp.UnspawnedCount == count)
+            return;
+
+        entity.Comp.UnspawnedCount = count;
+        UpdateBallisticAppearance(entity.Owner, entity.Comp);
+        UpdateAmmoCount(entity.Owner);
+        Dirty(entity);
+    }
 }
 
 /// <summary>