ECS BatteryComponent (#15337)
This commit is contained in:
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user