2022-06-01 19:59:58 +10:00
|
|
|
using Content.Shared.Weapons.Ranged.Components;
|
2023-05-27 14:15:15 +10:00
|
|
|
using Content.Shared.Weapons.Ranged.Events;
|
2022-06-01 19:59:58 +10:00
|
|
|
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);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2023-05-27 14:15:15 +10:00
|
|
|
protected override void Cycle(EntityUid uid, BallisticAmmoProviderComponent component, MapCoordinates coordinates)
|
2022-06-01 19:59:58 +10:00
|
|
|
{
|
2023-05-27 14:15:15 +10:00
|
|
|
if (!Timing.IsFirstTimePredicted)
|
|
|
|
|
return;
|
2022-06-01 19:59:58 +10:00
|
|
|
|
|
|
|
|
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);
|
2023-05-27 14:15:15 +10:00
|
|
|
|
|
|
|
|
var cycledEvent = new GunCycledEvent();
|
|
|
|
|
RaiseLocalEvent(uid, ref cycledEvent);
|
2022-06-01 19:59:58 +10:00
|
|
|
}
|
|
|
|
|
}
|