using Content.Shared.Power.EntitySystems; using Content.Shared.Guidebook; using Robust.Shared.GameStates; using Robust.Shared.Serialization; using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom; namespace Content.Shared.Power.Components; /// /// Predicted equivalent to . /// Use this for electrical power storages that only have a constant charge rate or instantaneous power draw. /// Devices being directly charged by the power network do not fulfill that requirement as their power supply ramps up over time. /// /// /// We cannot simply network since it would get dirtied every single tick when it updates. /// This component solves this by requiring a constant charge rate and having the client infer the current charge from the rate /// and the timestamp the charge was last networked at. This can possibly be expanded in the future by adding a second time derivative. /// [RegisterComponent, NetworkedComponent, AutoGenerateComponentState, AutoGenerateComponentPause] [Access(typeof(PredictedBatterySystem))] public sealed partial class PredictedBatteryComponent : Component { /// /// Maximum charge of the battery in joules (ie. watt seconds) /// [DataField, AutoNetworkedField, ViewVariables] [GuidebookData] public float MaxCharge; /// /// The price per one joule. Default is 1 speso for 10kJ. /// [DataField] public float PricePerJoule = 0.0001f; /// /// Time stamp of the last networked update. /// [DataField(customTypeSerializer: typeof(TimeOffsetSerializer))] [AutoNetworkedField, AutoPausedField, ViewVariables] public TimeSpan LastUpdate = TimeSpan.Zero; /// /// The intial charge to be set on map init. /// [DataField] public float StartingCharge; /// /// The charge at the last update in joules (i.e. watt seconds). /// [DataField, AutoNetworkedField, ViewVariables] public float LastCharge; /// /// The current charge rate in watt. /// /// /// Not a datafield as this is only cached and recalculated on component startup. /// [ViewVariables, AutoNetworkedField] public float ChargeRate; /// /// The current charge state of the battery. /// Used to track state changes for raising . /// /// /// Not a datafield as this is only cached and recalculated in an update loop. /// [ViewVariables, AutoNetworkedField] public BatteryState State = BatteryState.Neither; } /// /// Charge level status of the battery. /// [Serializable, NetSerializable] public enum BatteryState : byte { /// /// Full charge. /// Full, /// /// No charge. /// Empty, /// /// Neither full nor empty. /// Neither, }