2023-05-27 14:15:15 +10:00
|
|
|
using Content.Shared.Interaction;
|
|
|
|
|
using Content.Shared.Weapons.Ranged.Components;
|
|
|
|
|
|
|
|
|
|
namespace Content.Shared.Weapons.Ranged.Systems;
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Recharges ammo whenever the gun is cycled.
|
|
|
|
|
/// </summary>
|
|
|
|
|
public sealed class RechargeCycleAmmoSystem : EntitySystem
|
|
|
|
|
{
|
|
|
|
|
[Dependency] private readonly SharedGunSystem _gun = default!;
|
|
|
|
|
|
|
|
|
|
public override void Initialize()
|
|
|
|
|
{
|
|
|
|
|
base.Initialize();
|
|
|
|
|
SubscribeLocalEvent<RechargeCycleAmmoComponent, ActivateInWorldEvent>(OnRechargeCycled);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void OnRechargeCycled(EntityUid uid, RechargeCycleAmmoComponent component, ActivateInWorldEvent args)
|
|
|
|
|
{
|
2024-05-31 16:26:19 -04:00
|
|
|
if (!args.Complex)
|
|
|
|
|
return;
|
|
|
|
|
|
2023-05-27 14:15:15 +10:00
|
|
|
if (!TryComp<BasicEntityAmmoProviderComponent>(uid, out var basic) || args.Handled)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
if (basic.Count >= basic.Capacity || basic.Count == null)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
_gun.UpdateBasicEntityAmmoCount(uid, basic.Count.Value + 1, basic);
|
2024-03-19 23:27:02 -04:00
|
|
|
Dirty(uid, basic);
|
2023-05-27 14:15:15 +10:00
|
|
|
args.Handled = true;
|
|
|
|
|
}
|
|
|
|
|
}
|