diff --git a/Content.Server/Power/EntitySystems/ApcSystem.cs b/Content.Server/Power/EntitySystems/ApcSystem.cs index c1d864e845..a5516d9e15 100644 --- a/Content.Server/Power/EntitySystems/ApcSystem.cs +++ b/Content.Server/Power/EntitySystems/ApcSystem.cs @@ -143,7 +143,7 @@ namespace Content.Server.Power.EntitySystems var state = new ApcBoundInterfaceState(apc.MainBreakerEnabled, apc.HasAccess, (int) MathF.Ceiling(battery.CurrentSupply), apc.LastExternalState, - battery.AvailableSupply / battery.Capacity); + battery.CurrentStorage / battery.Capacity); _ui.TrySetUiState(uid, ApcUiKey.Key, state, ui: ui); } diff --git a/Content.Server/Power/EntitySystems/BatterySystem.cs b/Content.Server/Power/EntitySystems/BatterySystem.cs index 479d07c26a..410aa30bba 100644 --- a/Content.Server/Power/EntitySystems/BatterySystem.cs +++ b/Content.Server/Power/EntitySystems/BatterySystem.cs @@ -32,7 +32,7 @@ namespace Content.Server.Power.EntitySystems private void OnBatteryRejuvenate(EntityUid uid, BatteryComponent component, RejuvenateEvent args) { - component.CurrentCharge = component.MaxCharge; + SetCharge(uid, component.MaxCharge, component); } private void OnExamine(EntityUid uid, ExaminableBatteryComponent component, ExaminedEvent args) @@ -74,28 +74,18 @@ namespace Content.Server.Power.EntitySystems var enumerator = AllEntityQuery(); while (enumerator.MoveNext(out var uid, out var netBat, out var bat)) { - var netCharge = netBat.NetworkBattery.CurrentStorage; - - bat.Charge = netCharge; - DebugTools.Assert(bat.Charge <= bat.MaxCharge && bat.Charge >= 0); - - // TODO maybe decrease tolerance & track the charge at the time the event was most recently raised. - // Ensures that events aren't skipped when there are many tiny power changes. - if (MathHelper.CloseTo(bat.CurrentCharge, netCharge)) - continue; - - var changeEv = new ChargeChangedEvent(netCharge, bat.MaxCharge); - RaiseLocalEvent(uid, ref changeEv); + SetCharge(uid, netBat.NetworkBattery.CurrentStorage, bat); } } public override void Update(float frameTime) { - foreach (var (comp, batt) in EntityManager.EntityQuery()) + var query = EntityQueryEnumerator(); + while (query.MoveNext(out var uid, out var comp, out var batt)) { if (!comp.AutoRecharge) continue; if (batt.IsFullyCharged) continue; - batt.CurrentCharge += comp.AutoRechargeRate * frameTime; + SetCharge(uid, batt.CurrentCharge + comp.AutoRechargeRate * frameTime, batt); } } diff --git a/Content.Server/Power/Pow3r/PowerState.cs b/Content.Server/Power/Pow3r/PowerState.cs index 1d35af254b..5b9949a7f2 100644 --- a/Content.Server/Power/Pow3r/PowerState.cs +++ b/Content.Server/Power/Pow3r/PowerState.cs @@ -437,7 +437,7 @@ namespace Content.Server.Power.Pow3r public bool LoadingMarked; /// - /// Amount of supply that the battery can provider this tick. + /// Amount of supply that the battery can provide this tick. /// [ViewVariables(VVAccess.ReadWrite)] [JsonIgnore] public float AvailableSupply;