Use AllEntityQuery<> In power systems (#15336)
This commit is contained in:
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user