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);
|
|
|
|
|
|
2023-12-27 21:30:03 -08:00
|
|
|
Containers.Remove(existing, component.Container);
|
2023-09-01 07:33:28 +10:00
|
|
|
EnsureShootable(existing);
|
2022-06-01 19:59:58 +10:00
|
|
|
}
|
|
|
|
|
else if (component.UnspawnedCount > 0)
|
|
|
|
|
{
|
|
|
|
|
component.UnspawnedCount--;
|
2023-09-28 16:20:29 -07:00
|
|
|
ent = Spawn(component.Proto, coordinates);
|
2023-09-01 07:33:28 +10:00
|
|
|
EnsureShootable(ent.Value);
|
2022-06-01 19:59:58 +10:00
|
|
|
}
|
|
|
|
|
|
2023-09-11 09:42:41 +10:00
|
|
|
if (ent != null && IsClientSide(ent.Value))
|
2022-06-01 19:59:58 +10:00
|
|
|
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
|
|
|
}
|
|
|
|
|
}
|