Remove all obsolete BatteryComponent method calls (#25871)
Removed all obsolete, non-ECS method calls to BatteryComponent
This commit is contained in:
@@ -7,56 +7,34 @@ namespace Content.Server.Power.Components
|
||||
/// </summary>
|
||||
[RegisterComponent]
|
||||
[Virtual]
|
||||
[Access(typeof(BatterySystem))]
|
||||
public partial class BatteryComponent : Component
|
||||
{
|
||||
[Dependency] private readonly IEntityManager _entMan = default!;
|
||||
public string SolutionName = "battery";
|
||||
|
||||
/// <summary>
|
||||
/// Maximum charge of the battery in joules (ie. watt seconds)
|
||||
/// </summary>
|
||||
[ViewVariables(VVAccess.ReadWrite)]
|
||||
public float MaxCharge
|
||||
{
|
||||
get => _maxCharge;
|
||||
[Obsolete("Use system method")]
|
||||
set => _entMan.System<BatterySystem>().SetMaxCharge(Owner, value, this);
|
||||
}
|
||||
|
||||
[DataField("maxCharge")]
|
||||
[Access(typeof(BatterySystem))]
|
||||
public float _maxCharge;
|
||||
[DataField]
|
||||
public float MaxCharge;
|
||||
|
||||
/// <summary>
|
||||
/// Current charge of the battery in joules (ie. watt seconds)
|
||||
/// </summary>
|
||||
[ViewVariables(VVAccess.ReadWrite)]
|
||||
public float CurrentCharge
|
||||
{
|
||||
get => Charge;
|
||||
[Obsolete("Use system method")]
|
||||
set => _entMan.System<BatterySystem>().SetCharge(Owner, value, this);
|
||||
}
|
||||
|
||||
[DataField("startingCharge")]
|
||||
[Access(typeof(BatterySystem))]
|
||||
public float Charge;
|
||||
public float CurrentCharge;
|
||||
|
||||
/// <summary>
|
||||
/// True if the battery is fully charged.
|
||||
/// </summary>
|
||||
[ViewVariables] public bool IsFullyCharged => MathHelper.CloseToPercent(CurrentCharge, MaxCharge);
|
||||
[ViewVariables]
|
||||
public bool IsFullyCharged => MathHelper.CloseToPercent(CurrentCharge, MaxCharge);
|
||||
|
||||
/// <summary>
|
||||
/// The price per one joule. Default is 1 credit for 10kJ.
|
||||
/// </summary>
|
||||
[DataField("pricePerJoule")]
|
||||
[ViewVariables(VVAccess.ReadWrite)]
|
||||
[DataField]
|
||||
public float PricePerJoule = 0.0001f;
|
||||
|
||||
[Obsolete("Use system method")]
|
||||
public bool TryUseCharge(float value)
|
||||
=> _entMan.System<BatterySystem>().TryUseCharge(Owner, value, this);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -62,9 +62,9 @@ namespace Content.Server.Power.EntitySystems
|
||||
var enumerator = AllEntityQuery<PowerNetworkBatteryComponent, BatteryComponent>();
|
||||
while (enumerator.MoveNext(out var netBat, out var bat))
|
||||
{
|
||||
DebugTools.Assert(bat.Charge <= bat.MaxCharge && bat.Charge >= 0);
|
||||
DebugTools.Assert(bat.CurrentCharge <= bat.MaxCharge && bat.CurrentCharge >= 0);
|
||||
netBat.NetworkBattery.Capacity = bat.MaxCharge;
|
||||
netBat.NetworkBattery.CurrentStorage = bat.Charge;
|
||||
netBat.NetworkBattery.CurrentStorage = bat.CurrentCharge;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -108,10 +108,10 @@ namespace Content.Server.Power.EntitySystems
|
||||
if (value <= 0 || !Resolve(uid, ref battery) || battery.CurrentCharge == 0)
|
||||
return 0;
|
||||
|
||||
var newValue = Math.Clamp(0, battery.CurrentCharge - value, battery._maxCharge);
|
||||
var delta = newValue - battery.Charge;
|
||||
battery.Charge = newValue;
|
||||
var ev = new ChargeChangedEvent(battery.CurrentCharge, battery._maxCharge);
|
||||
var newValue = Math.Clamp(0, battery.CurrentCharge - value, battery.MaxCharge);
|
||||
var delta = newValue - battery.CurrentCharge;
|
||||
battery.CurrentCharge = newValue;
|
||||
var ev = new ChargeChangedEvent(battery.CurrentCharge, battery.MaxCharge);
|
||||
RaiseLocalEvent(uid, ref ev);
|
||||
return delta;
|
||||
}
|
||||
@@ -121,13 +121,13 @@ namespace Content.Server.Power.EntitySystems
|
||||
if (!Resolve(uid, ref battery))
|
||||
return;
|
||||
|
||||
var old = battery._maxCharge;
|
||||
battery._maxCharge = Math.Max(value, 0);
|
||||
battery.Charge = Math.Min(battery.Charge, battery._maxCharge);
|
||||
if (MathHelper.CloseTo(battery._maxCharge, old))
|
||||
var old = battery.MaxCharge;
|
||||
battery.MaxCharge = Math.Max(value, 0);
|
||||
battery.CurrentCharge = Math.Min(battery.CurrentCharge, battery.MaxCharge);
|
||||
if (MathHelper.CloseTo(battery.MaxCharge, old))
|
||||
return;
|
||||
|
||||
var ev = new ChargeChangedEvent(battery.CurrentCharge, battery._maxCharge);
|
||||
var ev = new ChargeChangedEvent(battery.CurrentCharge, battery.MaxCharge);
|
||||
RaiseLocalEvent(uid, ref ev);
|
||||
}
|
||||
|
||||
@@ -136,12 +136,12 @@ namespace Content.Server.Power.EntitySystems
|
||||
if (!Resolve(uid, ref battery))
|
||||
return;
|
||||
|
||||
var old = battery.Charge;
|
||||
battery.Charge = MathHelper.Clamp(value, 0, battery._maxCharge);
|
||||
if (MathHelper.CloseTo(battery.Charge, old))
|
||||
var old = battery.CurrentCharge;
|
||||
battery.CurrentCharge = MathHelper.Clamp(value, 0, battery.MaxCharge);
|
||||
if (MathHelper.CloseTo(battery.CurrentCharge, old))
|
||||
return;
|
||||
|
||||
var ev = new ChargeChangedEvent(battery.CurrentCharge, battery._maxCharge);
|
||||
var ev = new ChargeChangedEvent(battery.CurrentCharge, battery.MaxCharge);
|
||||
RaiseLocalEvent(uid, ref ev);
|
||||
}
|
||||
|
||||
@@ -150,7 +150,7 @@ namespace Content.Server.Power.EntitySystems
|
||||
/// </summary>
|
||||
public bool TryUseCharge(EntityUid uid, float value, BatteryComponent? battery = null)
|
||||
{
|
||||
if (!Resolve(uid, ref battery, false) || value > battery.Charge)
|
||||
if (!Resolve(uid, ref battery, false) || value > battery.CurrentCharge)
|
||||
return false;
|
||||
|
||||
UseCharge(uid, value, battery);
|
||||
|
||||
@@ -17,6 +17,7 @@ internal sealed class ChargerSystem : EntitySystem
|
||||
{
|
||||
[Dependency] private readonly ContainerSystem _container = default!;
|
||||
[Dependency] private readonly PowerCellSystem _powerCell = default!;
|
||||
[Dependency] private readonly BatterySystem _battery = default!;
|
||||
[Dependency] private readonly SharedAppearanceSystem _appearance = default!;
|
||||
|
||||
public override void Initialize()
|
||||
@@ -201,11 +202,11 @@ internal sealed class ChargerSystem : EntitySystem
|
||||
if (!SearchForBattery(targetEntity, out var heldBattery))
|
||||
return;
|
||||
|
||||
heldBattery.CurrentCharge += component.ChargeRate * frameTime;
|
||||
_battery.SetCharge(targetEntity, 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)
|
||||
{
|
||||
heldBattery.CurrentCharge = heldBattery.MaxCharge;
|
||||
_battery.SetCharge(targetEntity, heldBattery.MaxCharge, heldBattery);
|
||||
}
|
||||
|
||||
UpdateStatus(uid, component);
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
using Content.Server.Administration;
|
||||
using Content.Server.Power.Components;
|
||||
using Content.Server.Power.EntitySystems;
|
||||
using Content.Shared.Administration;
|
||||
using Robust.Shared.Console;
|
||||
|
||||
@@ -39,7 +40,8 @@ namespace Content.Server.Power
|
||||
shell.WriteLine($"No battery found with id {id}.");
|
||||
return;
|
||||
}
|
||||
battery.CurrentCharge = (battery.MaxCharge * percent) / 100;
|
||||
var system = IoCManager.Resolve<IEntitySystemManager>().GetEntitySystem<BatterySystem>();
|
||||
system.SetCharge(id.Value, battery.MaxCharge * percent / 100, battery);
|
||||
// Don't acknowledge b/c people WILL forall this
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user