Files
space-station-14/Content.Shared/Weapons/Ranged/Systems/RechargeCycleAmmoSystem.cs
mq 4920c9e907 Update (MOST) instances of EntityUid, Component in GunSystem to Entity<T> (#41966)
* Entity<T>, skipping Magazine and ChamberMagazine

* missed some

* AUGH!!

* ballistic examine

* dotnet hates me

* WHY ARE YOU CALLED THAT!!!!

* cheers aada
2026-01-01 19:00:49 +00:00

35 lines
1014 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 class RechargeCycleAmmoSystem : EntitySystem
{
[Dependency] private readonly 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;
}
}