Fix battery charging stopping just short of being full (#34028)
This commit is contained in:
@@ -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<ApcPowerReceiverComponent>(entity.Owner, out var receiver))
|
||||
{
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -24,12 +24,6 @@ namespace Content.Server.Power.Components
|
||||
[DataField("startingCharge")]
|
||||
public float CurrentCharge;
|
||||
|
||||
/// <summary>
|
||||
/// True if the battery is fully charged.
|
||||
/// </summary>
|
||||
[ViewVariables]
|
||||
public bool IsFullyCharged => MathHelper.CloseToPercent(CurrentCharge, MaxCharge);
|
||||
|
||||
/// <summary>
|
||||
/// The price per one joule. Default is 1 credit for 10kJ.
|
||||
/// </summary>
|
||||
|
||||
@@ -87,8 +87,8 @@ namespace Content.Server.Power.EntitySystems
|
||||
var query = EntityQueryEnumerator<BatterySelfRechargerComponent, BatteryComponent>();
|
||||
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
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns whether the battery is at least 99% charged, basically full.
|
||||
/// Returns whether the battery is full.
|
||||
/// </summary>
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user