mirror of
https://github.com/space-syndicate/space-station-14.git
synced 2026-10-14 12:51:10 +03:00
* IoC source gen compatibility Can be merged before or after https://github.com/space-wizards/RobustToolbox/pull/6549 doesn't really matter. * Missed a spot
34 lines
1,013 B
C#
34 lines
1,013 B
C#
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 partial class RechargeCycleAmmoSystem : EntitySystem
|
|
{
|
|
[Dependency] private SharedGunSystem _gun = default!;
|
|
|
|
public override void Initialize()
|
|
{
|
|
base.Initialize();
|
|
SubscribeLocalEvent<RechargeCycleAmmoComponent, ActivateInWorldEvent>(OnRechargeCycled);
|
|
}
|
|
|
|
private void OnRechargeCycled(Entity<RechargeCycleAmmoComponent> ent, ref ActivateInWorldEvent args)
|
|
{
|
|
if (!args.Complex)
|
|
return;
|
|
|
|
if (!TryComp<BasicEntityAmmoProviderComponent>(ent, out var basic) || args.Handled)
|
|
return;
|
|
|
|
if (basic.Count >= basic.Capacity || basic.Count == null)
|
|
return;
|
|
|
|
_gun.UpdateBasicEntityAmmoCount((ent, basic), basic.Count.Value + 1);
|
|
Dirty(ent, basic);
|
|
args.Handled = true;
|
|
}
|
|
}
|