From 0b1ed3ec7e79e78e27ad193526db95351bfa263c Mon Sep 17 00:00:00 2001 From: Errant <35878406+Errant-4@users.noreply.github.com> Date: Fri, 10 Jan 2025 07:54:55 +0100 Subject: [PATCH] Fix battery charging stopping just short of being full (#34028) --- .../Light/EntitySystems/EmergencyLightSystem.cs | 2 +- Content.Server/Ninja/Systems/BatteryDrainerSystem.cs | 2 +- Content.Server/Power/Components/BatteryComponent.cs | 6 ------ Content.Server/Power/EntitySystems/BatterySystem.cs | 8 ++++---- Content.Server/Power/EntitySystems/ChargerSystem.cs | 10 ++-------- 5 files changed, 8 insertions(+), 20 deletions(-) diff --git a/Content.Server/Light/EntitySystems/EmergencyLightSystem.cs b/Content.Server/Light/EntitySystems/EmergencyLightSystem.cs index 6bd5750460..1b7b614665 100644 --- a/Content.Server/Light/EntitySystems/EmergencyLightSystem.cs +++ b/Content.Server/Light/EntitySystems/EmergencyLightSystem.cs @@ -153,7 +153,7 @@ public sealed class EmergencyLightSystem : SharedEmergencyLightSystem else { _battery.SetCharge(entity.Owner, battery.CurrentCharge + entity.Comp.ChargingWattage * frameTime * entity.Comp.ChargingEfficiency, battery); - if (battery.IsFullyCharged) + if (_battery.IsFull(entity, battery)) { if (TryComp(entity.Owner, out var receiver)) { diff --git a/Content.Server/Ninja/Systems/BatteryDrainerSystem.cs b/Content.Server/Ninja/Systems/BatteryDrainerSystem.cs index 4baf0913ce..8e707cf3fc 100644 --- a/Content.Server/Ninja/Systems/BatteryDrainerSystem.cs +++ b/Content.Server/Ninja/Systems/BatteryDrainerSystem.cs @@ -106,6 +106,6 @@ public sealed class BatteryDrainerSystem : SharedBatteryDrainerSystem _popup.PopupEntity(Loc.GetString("battery-drainer-success", ("battery", target)), uid, uid); // repeat the doafter until battery is full - return !battery.IsFullyCharged; + return !_battery.IsFull(ent, battery); } } diff --git a/Content.Server/Power/Components/BatteryComponent.cs b/Content.Server/Power/Components/BatteryComponent.cs index 113106ed18..4ef8891333 100644 --- a/Content.Server/Power/Components/BatteryComponent.cs +++ b/Content.Server/Power/Components/BatteryComponent.cs @@ -24,12 +24,6 @@ namespace Content.Server.Power.Components [DataField("startingCharge")] public float CurrentCharge; - /// - /// True if the battery is fully charged. - /// - [ViewVariables] - public bool IsFullyCharged => MathHelper.CloseToPercent(CurrentCharge, MaxCharge); - /// /// The price per one joule. Default is 1 credit for 10kJ. /// diff --git a/Content.Server/Power/EntitySystems/BatterySystem.cs b/Content.Server/Power/EntitySystems/BatterySystem.cs index eac31ecef7..6e636622e6 100644 --- a/Content.Server/Power/EntitySystems/BatterySystem.cs +++ b/Content.Server/Power/EntitySystems/BatterySystem.cs @@ -87,8 +87,8 @@ namespace Content.Server.Power.EntitySystems var query = EntityQueryEnumerator(); while (query.MoveNext(out var uid, out var comp, out var batt)) { - if (!comp.AutoRecharge) continue; - if (batt.IsFullyCharged) continue; + if (!comp.AutoRecharge || IsFull(uid, batt)) + continue; if (comp.AutoRechargePause) { @@ -212,14 +212,14 @@ namespace Content.Server.Power.EntitySystems } /// - /// Returns whether the battery is at least 99% charged, basically full. + /// Returns whether the battery is full. /// public bool IsFull(EntityUid uid, BatteryComponent? battery = null) { if (!Resolve(uid, ref battery)) return false; - return battery.CurrentCharge / battery.MaxCharge >= 0.99f; + return battery.CurrentCharge >= battery.MaxCharge; } } } diff --git a/Content.Server/Power/EntitySystems/ChargerSystem.cs b/Content.Server/Power/EntitySystems/ChargerSystem.cs index 40b998a95d..c128c846fb 100644 --- a/Content.Server/Power/EntitySystems/ChargerSystem.cs +++ b/Content.Server/Power/EntitySystems/ChargerSystem.cs @@ -223,10 +223,10 @@ internal sealed class ChargerSystem : EntitySystem if (container.ContainedEntities.Count == 0) return CellChargerStatus.Empty; - if (!SearchForBattery(container.ContainedEntities[0], out _, out var heldBattery)) + if (!SearchForBattery(container.ContainedEntities[0], out var heldEnt, out var heldBattery)) return CellChargerStatus.Off; - if (Math.Abs(heldBattery.MaxCharge - heldBattery.CurrentCharge) < 0.01) + if (_battery.IsFull(heldEnt.Value, heldBattery)) return CellChargerStatus.Charged; return CellChargerStatus.Charging; @@ -247,12 +247,6 @@ internal sealed class ChargerSystem : EntitySystem return; _battery.SetCharge(batteryUid.Value, heldBattery.CurrentCharge + component.ChargeRate * frameTime, heldBattery); - // Just so the sprite won't be set to 99.99999% visibility - if (heldBattery.MaxCharge - heldBattery.CurrentCharge < 0.01) - { - _battery.SetCharge(batteryUid.Value, heldBattery.MaxCharge, heldBattery); - } - UpdateStatus(uid, component); } -- 2.51.2