From: metalgearsloth <31366439+metalgearsloth@users.noreply.github.com> Date: Fri, 9 Aug 2024 07:39:27 +0000 (+1000) Subject: Add access to gun components (#30688) X-Git-Url: https://git.smokeofanarchy.ru/gitweb.cgi?a=commitdiff_plain;h=1649ed45bd395c850bd531752f7146ca073b04cd;p=space-station-14.git Add access to gun components (#30688) * 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. --- diff --git a/Content.Server/Administration/Systems/AdminVerbSystem.Tools.cs b/Content.Server/Administration/Systems/AdminVerbSystem.Tools.cs index 328fa74484..a00424a741 100644 --- a/Content.Server/Administration/Systems/AdminVerbSystem.Tools.cs +++ b/Content.Server/Administration/Systems/AdminVerbSystem.Tools.cs @@ -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); }); }, diff --git a/Content.Shared/Weapons/Ranged/Components/BallisticAmmoProviderComponent.cs b/Content.Shared/Weapons/Ranged/Components/BallisticAmmoProviderComponent.cs index eb04d3227d..f825f10550 100644 --- a/Content.Shared/Weapons/Ranged/Components/BallisticAmmoProviderComponent.cs +++ b/Content.Shared/Weapons/Ranged/Components/BallisticAmmoProviderComponent.cs @@ -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 Entities = new(); diff --git a/Content.Shared/Weapons/Ranged/Components/ChamberMagazineAmmoProviderComponent.cs b/Content.Shared/Weapons/Ranged/Components/ChamberMagazineAmmoProviderComponent.cs index e64ec0d68d..37517c1371 100644 --- a/Content.Shared/Weapons/Ranged/Components/ChamberMagazineAmmoProviderComponent.cs +++ b/Content.Shared/Weapons/Ranged/Components/ChamberMagazineAmmoProviderComponent.cs @@ -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 /// [RegisterComponent, AutoGenerateComponentState] +[Access(typeof(SharedGunSystem))] public sealed partial class ChamberMagazineAmmoProviderComponent : MagazineAmmoProviderComponent { /// diff --git a/Content.Shared/Weapons/Ranged/Components/ContainerAmmoProviderComponent.cs b/Content.Shared/Weapons/Ranged/Components/ContainerAmmoProviderComponent.cs index 0f2884bf58..f49cc812c2 100644 --- a/Content.Shared/Weapons/Ranged/Components/ContainerAmmoProviderComponent.cs +++ b/Content.Shared/Weapons/Ranged/Components/ContainerAmmoProviderComponent.cs @@ -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. /// [RegisterComponent] +[Access(typeof(SharedGunSystem))] public sealed partial class ContainerAmmoProviderComponent : AmmoProviderComponent { [DataField("container", required: true)] diff --git a/Content.Shared/Weapons/Ranged/Components/MagazineAmmoProviderComponent.cs b/Content.Shared/Weapons/Ranged/Components/MagazineAmmoProviderComponent.cs index 9aff60fd3a..56d09ceaa5 100644 --- a/Content.Shared/Weapons/Ranged/Components/MagazineAmmoProviderComponent.cs +++ b/Content.Shared/Weapons/Ranged/Components/MagazineAmmoProviderComponent.cs @@ -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. /// [RegisterComponent, Virtual] +[Access(typeof(SharedGunSystem))] public partial class MagazineAmmoProviderComponent : AmmoProviderComponent { [ViewVariables(VVAccess.ReadWrite), DataField("soundAutoEject")] diff --git a/Content.Shared/Weapons/Ranged/Systems/SharedGunSystem.Ballistic.cs b/Content.Shared/Weapons/Ranged/Systems/SharedGunSystem.Ballistic.cs index 4c5712c509..9ef5cbd702 100644 --- a/Content.Shared/Weapons/Ranged/Systems/SharedGunSystem.Ballistic.cs +++ b/Content.Shared/Weapons/Ranged/Systems/SharedGunSystem.Ballistic.cs @@ -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 entity, int count) + { + if (entity.Comp.UnspawnedCount == count) + return; + + entity.Comp.UnspawnedCount = count; + UpdateBallisticAppearance(entity.Owner, entity.Comp); + UpdateAmmoCount(entity.Owner); + Dirty(entity); + } } ///