Use AllEntityQuery<> In power systems (#15336)

This commit is contained in:
Leon Friedrich
2023-04-15 07:45:02 +12:00
committed by GitHub
parent 9b8b844386
commit 5b09ee3102
3 changed files with 31 additions and 15 deletions

View File

@@ -57,7 +57,9 @@ namespace Content.Server.Power.EntitySystems
private void PreSync(NetworkBatteryPreSync ev)
{
foreach (var (netBat, bat) in EntityManager.EntityQuery<PowerNetworkBatteryComponent, BatteryComponent>())
// Ignoring entity pausing. If the entity was paused, neither component's data should have been changed.
var enumerator = AllEntityQuery<PowerNetworkBatteryComponent, BatteryComponent>();
while (enumerator.MoveNext(out var netBat, out var bat))
{
netBat.NetworkBattery.Capacity = bat.MaxCharge;
netBat.NetworkBattery.CurrentStorage = bat.CurrentCharge;
@@ -66,9 +68,15 @@ namespace Content.Server.Power.EntitySystems
private void PostSync(NetworkBatteryPostSync ev)
{
foreach (var (netBat, bat) in EntityManager.EntityQuery<PowerNetworkBatteryComponent, BatteryComponent>())
// Ignoring entity pausing. If the entity was paused, neither component's data should have been changed.
var enumerator = AllEntityQuery<PowerNetworkBatteryComponent, BatteryComponent>();
while (enumerator.MoveNext(out var uid, out var netBat, out var bat))
{
bat.CurrentCharge = netBat.NetworkBattery.CurrentStorage;
var netCharge = netBat.NetworkBattery.CurrentStorage;
if (MathHelper.CloseTo(bat.CurrentCharge, netCharge))
continue;
bat.CurrentCharge = netCharge;
}
}
@@ -93,7 +101,7 @@ namespace Content.Server.Power.EntitySystems
private void OnEmpPulse(EntityUid uid, BatteryComponent component, ref EmpPulseEvent args)
{
args.Affected = true;
component.UseCharge(args.EnergyConsumption);
component.UseCharge(args.EnergyConsumption);
}
}
}