using Content.Server.Power.EntitySystems;
namespace Content.Server.Power.Components
{
///
/// Battery node on the pow3r network. Needs other components to connect to actual networks.
///
[RegisterComponent]
[Virtual]
public partial class BatteryComponent : Component
{
[Dependency] private readonly IEntityManager _entMan = default!;
public string SolutionName = "battery";
///
/// Maximum charge of the battery in joules (ie. watt seconds)
///
[ViewVariables(VVAccess.ReadWrite)]
public float MaxCharge
{
get => _maxCharge;
[Obsolete("Use system method")]
set => _entMan.System().SetMaxCharge(Owner, value, this);
}
[DataField("maxCharge")]
[Access(typeof(BatterySystem))]
public float _maxCharge;
///
/// Current charge of the battery in joules (ie. watt seconds)
///
[ViewVariables(VVAccess.ReadWrite)]
public float CurrentCharge
{
get => Charge;
[Obsolete("Use system method")]
set => _entMan.System().SetCharge(Owner, value, this);
}
[DataField("startingCharge")]
[Access(typeof(BatterySystem))]
public float Charge;
///
/// 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.
///
[DataField("pricePerJoule")]
[ViewVariables(VVAccess.ReadWrite)]
public float PricePerJoule = 0.0001f;
[Obsolete("Use system method")]
public bool TryUseCharge(float value)
=> _entMan.System().TryUseCharge(Owner, value, this);
}
///
/// Raised when a battery's charge or capacity changes (capacity affects relative charge percentage).
///
[ByRefEvent]
public readonly record struct ChargeChangedEvent(float Charge, float MaxCharge);
}