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>
This commit is contained in:
metalgearsloth
2022-06-01 19:59:58 +10:00
committed by GitHub
parent 1ced3c5002
commit fb943a61dc
1051 changed files with 8230 additions and 99090 deletions

View File

@@ -0,0 +1,48 @@
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);
}
}