ECS BatteryComponent (#15337)

This commit is contained in:
Leon Friedrich
2023-04-19 22:10:08 +12:00
committed by GitHub
parent e95cd6e412
commit 9513ea66e4
6 changed files with 128 additions and 112 deletions

View File

@@ -32,9 +32,9 @@ public sealed partial class GunSystem
UpdateShots(uid, component);
}
private void OnBatteryChargeChange(EntityUid uid, BatteryAmmoProviderComponent component, ChargeChangedEvent args)
private void OnBatteryChargeChange(EntityUid uid, BatteryAmmoProviderComponent component, ref ChargeChangedEvent args)
{
UpdateShots(uid, component);
UpdateShots(uid, component, args.Charge, args.MaxCharge);
}
private void UpdateShots(EntityUid uid, BatteryAmmoProviderComponent component)
@@ -42,13 +42,13 @@ public sealed partial class GunSystem
if (!TryComp<BatteryComponent>(uid, out var battery))
return;
UpdateShots(uid, component, battery);
UpdateShots(uid, component, battery.Charge, battery.MaxCharge);
}
private void UpdateShots(EntityUid uid, BatteryAmmoProviderComponent component, BatteryComponent battery)
private void UpdateShots(EntityUid uid, BatteryAmmoProviderComponent component, float charge, float maxCharge)
{
var shots = (int) (battery.CurrentCharge / component.FireCost);
var maxShots = (int) (battery.MaxCharge / component.FireCost);
var shots = (int) (charge / component.FireCost);
var maxShots = (int) (maxCharge / component.FireCost);
if (component.Shots != shots || component.Capacity != maxShots)
{
@@ -128,10 +128,7 @@ public sealed partial class GunSystem
protected override void TakeCharge(EntityUid uid, BatteryAmmoProviderComponent component)
{
if (!TryComp<BatteryComponent>(uid, out var battery))
return;
battery.CurrentCharge -= component.FireCost;
UpdateShots(uid, component, battery);
// Will raise ChargeChangedEvent
_battery.UseCharge(uid, component.FireCost);
}
}