using Content.Shared.Power.EntitySystems; using Content.Shared.PowerCell.Components; using Content.Shared.Guidebook; using Robust.Shared.GameStates; using Robust.Shared.Serialization; using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom; namespace Content.Shared.Power.Components; /// /// Used for any sort of battery that stores electical power. /// Can be used as a battery node on the pow3r network. Needs other components to connect to actual networks, see PowerNetworkBatteryComponent. /// Also used for power cells using or battery powered guns with intrinsic battery. /// /// /// IMPORTANT: If your battery has an update loop setting the charge every single tick you should set to false /// in your prototype to prevent it from getting networked every single tick. However, this will disable prediction. /// This is mostly needed for anything connected to the power network (APCs, SMES, turrets with battery), as their power supply ramps up over time. /// Everything else that only has a constant charge rate (e.g. charging/discharging a battery at a certain wattage) or instantaneous power draw (e.g. shooting a gun) is fine being networked. /// However, you should write your systems to avoid using update loops and instead change the battery's charge rate using and /// the current charge will automatically be inferred if you use . /// [RegisterComponent, NetworkedComponent, AutoGenerateComponentState, AutoGenerateComponentPause] [Access(typeof(SharedBatterySystem))] public sealed partial class BatteryComponent : 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, }