Files
tbd-station-14/Content.Client/Weapons/Ranged/Systems/GunSystem.Ballistic.cs
metalgearsloth fb943a61dc Gun refactor (#8301)
Co-authored-by: Kara <lunarautomaton6@gmail.com>
Co-authored-by: T-Stalker <le0nel_1van@hotmail.com>
Co-authored-by: T-Stalker <43253663+DogZeroX@users.noreply.github.com>
Co-authored-by: ElectroJr <leonsfriedrich@gmail.com>
Co-authored-by: metalgearsloth <metalgearsloth@gmail.com>
2022-06-01 19:59:58 +10:00

49 lines
1.5 KiB
C#

using Content.Shared.Weapons.Ranged.Components;
using Robust.Shared.Map;
namespace Content.Client.Weapons.Ranged.Systems;
public sealed partial class GunSystem
{
protected override void InitializeBallistic()
{
base.InitializeBallistic();
SubscribeLocalEvent<BallisticAmmoProviderComponent, UpdateAmmoCounterEvent>(OnBallisticAmmoCount);
}
private void OnBallisticAmmoCount(EntityUid uid, BallisticAmmoProviderComponent component, UpdateAmmoCounterEvent args)
{
if (args.Control is DefaultStatusControl control)
{
control.Update(GetBallisticShots(component), component.Capacity);
return;
}
}
protected override void Cycle(BallisticAmmoProviderComponent component, MapCoordinates coordinates)
{
if (!Timing.IsFirstTimePredicted) return;
EntityUid? ent = null;
// TODO: Combine with TakeAmmo
if (component.Entities.Count > 0)
{
var existing = component.Entities[^1];
component.Entities.RemoveAt(component.Entities.Count - 1);
component.Container.Remove(existing);
EnsureComp<AmmoComponent>(existing);
}
else if (component.UnspawnedCount > 0)
{
component.UnspawnedCount--;
ent = Spawn(component.FillProto, coordinates);
EnsureComp<AmmoComponent>(ent.Value);
}
if (ent != null && ent.Value.IsClientSide())
Del(ent.Value);
}
}