CatStation/Content.Shared/Weapons/Ranged/Systems/RechargeCycleAmmoSystem.cs
Pieter-Jan Briers 5168b5f3d4
IoC source gen compatibility (#43863)
* 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
2026-05-09 03:29:58 +00:00

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;
}
}