}
else
{
- battery.CurrentCharge += component.ChargingWattage * frameTime * component.ChargingEfficiency;
+ _battery.SetCharge(uid, battery.CurrentCharge + component.ChargingWattage * frameTime * component.ChargingEfficiency, battery);
if (battery.IsFullyCharged)
{
if (TryComp<ApcPowerReceiverComponent>(uid, out var receiver))
using Content.Server.Actions;
using Content.Server.Popups;
+using Content.Server.Power.EntitySystems;
using Content.Server.PowerCell;
using Content.Shared.Actions;
using Content.Shared.Examine;
[Dependency] private readonly ActionContainerSystem _actionContainer = default!;
[Dependency] private readonly PopupSystem _popup = default!;
[Dependency] private readonly PowerCellSystem _powerCell = default!;
+ [Dependency] private readonly BatterySystem _battery = default!;
[Dependency] private readonly SharedAppearanceSystem _appearance = default!;
[Dependency] private readonly SharedAudioSystem _audio = default!;
[Dependency] private readonly SharedPointLightSystem _lights = default!;
_appearance.SetData(uid, HandheldLightVisuals.Power, HandheldLightPowerStates.Dying, appearanceComponent);
}
- if (component.Activated && !battery.TryUseCharge(component.Wattage * frameTime))
+ if (component.Activated && !_battery.TryUseCharge(uid, component.Wattage * frameTime, battery))
TurnOff(uid, false);
UpdateLevel(uid);
/// </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>
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;
}
}
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;
}
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);
}
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);
}
/// </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);
{
[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()
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);
using Content.Server.Administration;
using Content.Server.Power.Components;
+using Content.Server.Power.EntitySystems;
using Content.Shared.Administration;
using Robust.Shared.Console;
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
}
}
return false;
}
- _sharedAppearanceSystem.SetData(uid, PowerCellSlotVisuals.Enabled, battery.Charge > 0);
+ _sharedAppearanceSystem.SetData(uid, PowerCellSlotVisuals.Enabled, battery.CurrentCharge > 0);
return true;
}
using Robust.Shared.Timing;
using Robust.Shared.Audio;
using Robust.Shared.Audio.Systems;
+using Content.Server.Power.EntitySystems;
namespace Content.Server.PowerSink
{
[Dependency] private readonly ExplosionSystem _explosionSystem = default!;
[Dependency] private readonly SharedAudioSystem _audio = default!;
[Dependency] private readonly StationSystem _station = default!;
+ [Dependency] private readonly BatterySystem _battery = default!;
public override void Initialize()
{
if (!transform.Anchored)
continue;
- battery.CurrentCharge += networkLoad.NetworkLoad.ReceivingPower / 1000;
+ _battery.SetCharge(entity, battery.CurrentCharge + networkLoad.NetworkLoad.ReceivingPower / 1000, battery);
var currentBatteryThreshold = battery.CurrentCharge / battery.MaxCharge;
using Content.Server.Popups;
+using Content.Server.Power.EntitySystems;
using Content.Server.PowerCell;
using Content.Server.Radio.Components;
using Content.Shared.Examine;
public sealed class JammerSystem : EntitySystem
{
[Dependency] private readonly PowerCellSystem _powerCell = default!;
+ [Dependency] private readonly BatterySystem _battery = default!;
[Dependency] private readonly PopupSystem _popup = default!;
[Dependency] private readonly SharedTransformSystem _transform = default!;
while (query.MoveNext(out var uid, out var _, out var jam))
{
if (_powerCell.TryGetBatteryFromSlot(uid, out var battery) &&
- !battery.TryUseCharge(jam.Wattage * frameTime))
+ !_battery.TryUseCharge(uid, jam.Wattage * frameTime, battery))
{
RemComp<ActiveRadioJammerComponent>(uid);
}
private void OnActivate(EntityUid uid, RadioJammerComponent comp, ActivateInWorldEvent args)
{
- var activated = !HasComp<ActiveRadioJammerComponent>(uid) &&
+ var activated = !HasComp<ActiveRadioJammerComponent>(uid) &&
_powerCell.TryGetBatteryFromSlot(uid, out var battery) &&
battery.CurrentCharge > comp.Wattage;
if (activated)
{
[DeviceNetworkConstants.Command] = DeviceNetworkCommandSyncData,
[DeviceNetworkCommandSyncData] = new BatterySensorData(
- battery.Charge,
+ battery.CurrentCharge,
battery.MaxCharge,
netBattery.CurrentReceiving,
netBattery.MaxChargeRate,
if (_powerCell.TryGetBatteryFromSlot(uid, out var battery))
{
hasBattery = true;
- chargePercent = battery.Charge / battery.MaxCharge;
+ chargePercent = battery.CurrentCharge / battery.MaxCharge;
}
var state = new BorgBuiState(chargePercent, hasBattery);
if (!TryComp<BatteryComponent>(uid, out var battery))
return;
- UpdateShots(uid, component, battery.Charge, battery.MaxCharge);
+ UpdateShots(uid, component, battery.CurrentCharge, battery.MaxCharge);
}
private void UpdateShots(EntityUid uid, BatteryAmmoProviderComponent component, float charge, float maxCharge)