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.
This commit is contained in:
metalgearsloth
2024-08-09 17:39:27 +10:00
committed by GitHub
parent b8fc879cd7
commit 1649ed45bd
6 changed files with 22 additions and 11 deletions

View File

@@ -724,15 +724,7 @@ public sealed partial class AdminVerbSystem
if (!int.TryParse(amount, out var result)) if (!int.TryParse(amount, out var result))
return; return;
if (result > 0) _gun.SetBallisticUnspawned((args.Target, ballisticAmmo), result);
{
ballisticAmmo.UnspawnedCount = result;
}
else
{
ballisticAmmo.UnspawnedCount = 0;
}
_gun.UpdateBallisticAppearance(args.Target, ballisticAmmo); _gun.UpdateBallisticAppearance(args.Target, ballisticAmmo);
}); });
}, },

View File

@@ -1,3 +1,4 @@
using Content.Shared.Weapons.Ranged.Systems;
using Content.Shared.Whitelist; using Content.Shared.Whitelist;
using Robust.Shared.Audio; using Robust.Shared.Audio;
using Robust.Shared.Containers; using Robust.Shared.Containers;
@@ -6,7 +7,7 @@ using Robust.Shared.Prototypes;
namespace Content.Shared.Weapons.Ranged.Components; namespace Content.Shared.Weapons.Ranged.Components;
[RegisterComponent, NetworkedComponent, AutoGenerateComponentState] [RegisterComponent, NetworkedComponent, AutoGenerateComponentState, Access(typeof(SharedGunSystem))]
public sealed partial class BallisticAmmoProviderComponent : Component public sealed partial class BallisticAmmoProviderComponent : Component
{ {
[ViewVariables(VVAccess.ReadWrite), DataField] [ViewVariables(VVAccess.ReadWrite), DataField]
@@ -32,6 +33,7 @@ public sealed partial class BallisticAmmoProviderComponent : Component
public Container Container = default!; public Container Container = default!;
// TODO: Make this use stacks when the typeserializer is done. // TODO: Make this use stacks when the typeserializer is done.
// Realistically just point to the container.
[DataField, AutoNetworkedField] [DataField, AutoNetworkedField]
public List<EntityUid> Entities = new(); public List<EntityUid> Entities = new();

View File

@@ -1,3 +1,4 @@
using Content.Shared.Weapons.Ranged.Systems;
using Robust.Shared.Audio; using Robust.Shared.Audio;
namespace Content.Shared.Weapons.Ranged.Components; 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"/> /// Chamber + mags in one package. If you need just magazine then use <see cref="MagazineAmmoProviderComponent"/>
/// </summary> /// </summary>
[RegisterComponent, AutoGenerateComponentState] [RegisterComponent, AutoGenerateComponentState]
[Access(typeof(SharedGunSystem))]
public sealed partial class ChamberMagazineAmmoProviderComponent : MagazineAmmoProviderComponent public sealed partial class ChamberMagazineAmmoProviderComponent : MagazineAmmoProviderComponent
{ {
/// <summary> /// <summary>

View 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; 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. /// Handles pulling entities from the given container to use as ammunition.
/// </summary> /// </summary>
[RegisterComponent] [RegisterComponent]
[Access(typeof(SharedGunSystem))]
public sealed partial class ContainerAmmoProviderComponent : AmmoProviderComponent public sealed partial class ContainerAmmoProviderComponent : AmmoProviderComponent
{ {
[DataField("container", required: true)] [DataField("container", required: true)]

View File

@@ -1,4 +1,5 @@
using Content.Shared.Weapons.Ranged.Components; using Content.Shared.Weapons.Ranged.Components;
using Content.Shared.Weapons.Ranged.Systems;
using Robust.Shared.Audio; using Robust.Shared.Audio;
namespace Content.Shared.Weapons.Ranged; 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. /// Wrapper around a magazine (handled via ItemSlot). Passes all AmmoProvider logic onto it.
/// </summary> /// </summary>
[RegisterComponent, Virtual] [RegisterComponent, Virtual]
[Access(typeof(SharedGunSystem))]
public partial class MagazineAmmoProviderComponent : AmmoProviderComponent public partial class MagazineAmmoProviderComponent : AmmoProviderComponent
{ {
[ViewVariables(VVAccess.ReadWrite), DataField("soundAutoEject")] [ViewVariables(VVAccess.ReadWrite), DataField("soundAutoEject")]

View File

@@ -277,6 +277,17 @@ public abstract partial class SharedGunSystem
Appearance.SetData(uid, AmmoVisuals.AmmoCount, GetBallisticShots(component), appearance); Appearance.SetData(uid, AmmoVisuals.AmmoCount, GetBallisticShots(component), appearance);
Appearance.SetData(uid, AmmoVisuals.AmmoMax, component.Capacity, 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> /// <summary>