RechargeCycleAmmoSystem.cs 1021 B

12345678910111213141516171819202122232425262728293031323334
  1. using Content.Shared.Interaction;
  2. using Content.Shared.Weapons.Ranged.Components;
  3. namespace Content.Shared.Weapons.Ranged.Systems;
  4. /// <summary>
  5. /// Recharges ammo whenever the gun is cycled.
  6. /// </summary>
  7. public sealed class RechargeCycleAmmoSystem : EntitySystem
  8. {
  9. [Dependency] private readonly SharedGunSystem _gun = default!;
  10. public override void Initialize()
  11. {
  12. base.Initialize();
  13. SubscribeLocalEvent<RechargeCycleAmmoComponent, ActivateInWorldEvent>(OnRechargeCycled);
  14. }
  15. private void OnRechargeCycled(EntityUid uid, RechargeCycleAmmoComponent component, ActivateInWorldEvent args)
  16. {
  17. if (!args.Complex)
  18. return;
  19. if (!TryComp<BasicEntityAmmoProviderComponent>(uid, out var basic) || args.Handled)
  20. return;
  21. if (basic.Count >= basic.Capacity || basic.Count == null)
  22. return;
  23. _gun.UpdateBasicEntityAmmoCount(uid, basic.Count.Value + 1, basic);
  24. Dirty(uid, basic);
  25. args.Handled = true;
  26. }
  27. }