diff --git a/Content.Shared/Weapons/Ranged/Components/RevolverAmmoProviderComponent.cs b/Content.Shared/Weapons/Ranged/Components/RevolverAmmoProviderComponent.cs index 9dbba734b4..f591fbbebf 100644 --- a/Content.Shared/Weapons/Ranged/Components/RevolverAmmoProviderComponent.cs +++ b/Content.Shared/Weapons/Ranged/Components/RevolverAmmoProviderComponent.cs @@ -30,8 +30,9 @@ public sealed class RevolverAmmoProviderComponent : AmmoProviderComponent // Like BallisticAmmoProvider we defer spawning until necessary // AmmoSlots is the instantiated ammo and Chambers is the unspawned ammo (that may or may not have been shot). + // TODO: Using an array would be better but this throws! [DataField("ammoSlots")] - public EntityUid?[] AmmoSlots = Array.Empty(); + public List AmmoSlots = new(); [DataField("chambers")] public bool?[] Chambers = Array.Empty(); diff --git a/Content.Shared/Weapons/Ranged/Systems/SharedGunSystem.Revolver.cs b/Content.Shared/Weapons/Ranged/Systems/SharedGunSystem.Revolver.cs index 1ecdc4e53c..7dff724148 100644 --- a/Content.Shared/Weapons/Ranged/Systems/SharedGunSystem.Revolver.cs +++ b/Content.Shared/Weapons/Ranged/Systems/SharedGunSystem.Revolver.cs @@ -55,13 +55,14 @@ public partial class SharedGunSystem var oldIndex = component.CurrentIndex; component.CurrentIndex = state.CurrentIndex; - component.AmmoSlots = new EntityUid?[state.AmmoSlots.Length]; + component.AmmoSlots.EnsureCapacity(state.AmmoSlots.Count); + component.AmmoSlots.Clear(); component.Chambers = new bool?[state.Chambers.Length]; - DebugTools.Assert(component.AmmoSlots.Length == component.Chambers.Length); + DebugTools.Assert(component.AmmoSlots.Count == component.Chambers.Length); // Need to copy across the state rather than the ref. - for (var i = 0; i < component.AmmoSlots.Length; i++) + for (var i = 0; i < component.AmmoSlots.Count; i++) { component.AmmoSlots[i] = state.AmmoSlots[i]; component.Chambers[i] = state.Chambers[i]; @@ -298,7 +299,14 @@ public partial class SharedGunSystem private void OnRevolverInit(EntityUid uid, RevolverAmmoProviderComponent component, ComponentInit args) { component.AmmoContainer = Containers.EnsureContainer(uid, RevolverContainer); - component.AmmoSlots = new EntityUid?[component.Capacity]; + component.AmmoSlots.EnsureCapacity(component.Capacity); + var remainder = component.Capacity - component.AmmoSlots.Count; + + for (var i = 0; i < remainder; i++) + { + component.AmmoSlots.Add(null); + } + component.Chambers = new bool?[component.Capacity]; if (component.FillPrototype != null) @@ -320,7 +328,7 @@ public partial class SharedGunSystem protected sealed class RevolverAmmoProviderComponentState : ComponentState { public int CurrentIndex; - public EntityUid?[] AmmoSlots = default!; + public List AmmoSlots = default!; public bool?[] Chambers = default!; }