From 2564ff8918c126a910fbe2a295cbb231b7e4194c Mon Sep 17 00:00:00 2001 From: AJCM-git <60196617+AJCM-git@users.noreply.github.com> Date: Sun, 30 Apr 2023 06:49:26 -0400 Subject: [PATCH] Tweaks to ContainerAmmoProvider (#15945) --- .../Components/ContainerAmmoProviderComponent.cs | 5 +++++ .../Ranged/Systems/SharedGunSystem.Container.cs | 10 ++++++---- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/Content.Shared/Weapons/Ranged/Components/ContainerAmmoProviderComponent.cs b/Content.Shared/Weapons/Ranged/Components/ContainerAmmoProviderComponent.cs index ee9158a6eb..8b5a6761a4 100644 --- a/Content.Shared/Weapons/Ranged/Components/ContainerAmmoProviderComponent.cs +++ b/Content.Shared/Weapons/Ranged/Components/ContainerAmmoProviderComponent.cs @@ -9,5 +9,10 @@ namespace Content.Shared.Weapons.Ranged.Components; public sealed class ContainerAmmoProviderComponent : AmmoProviderComponent { [DataField("container", required: true)] + [ViewVariables] public string Container = default!; + + [DataField("provider")] + [ViewVariables] + public EntityUid? ProviderUid; } diff --git a/Content.Shared/Weapons/Ranged/Systems/SharedGunSystem.Container.cs b/Content.Shared/Weapons/Ranged/Systems/SharedGunSystem.Container.cs index 204faecdb6..23e2d94e1f 100644 --- a/Content.Shared/Weapons/Ranged/Systems/SharedGunSystem.Container.cs +++ b/Content.Shared/Weapons/Ranged/Systems/SharedGunSystem.Container.cs @@ -11,7 +11,7 @@ public partial class SharedGunSystem [Dependency] private readonly INetManager _netMan = default!; [Dependency] private readonly SharedContainerSystem _container = default!; - public void InitializeContainer() + private void InitializeContainer() { SubscribeLocalEvent(OnContainerTakeAmmo); SubscribeLocalEvent(OnContainerAmmoCount); @@ -19,10 +19,11 @@ public partial class SharedGunSystem private void OnContainerTakeAmmo(EntityUid uid, ContainerAmmoProviderComponent component, TakeAmmoEvent args) { - if (!_container.TryGetContainer(uid, component.Container, out var container)) + component.ProviderUid ??= uid; + if (!_container.TryGetContainer(component.ProviderUid.Value, component.Container, out var container)) return; - for (int i = 0; i < args.Shots; i++) + for (var i = 0; i < args.Shots; i++) { if (!container.ContainedEntities.Any()) break; @@ -38,7 +39,8 @@ public partial class SharedGunSystem private void OnContainerAmmoCount(EntityUid uid, ContainerAmmoProviderComponent component, ref GetAmmoCountEvent args) { - if (!_container.TryGetContainer(uid, component.Container, out var container)) + component.ProviderUid ??= uid; + if (!_container.TryGetContainer(component.ProviderUid.Value, component.Container, out var container)) { args.Capacity = 0; args.Count = 0;