CatStation/Content.Shared/Power/Components/BatteryComponent.cs
Samuka 838984971c
Xenoborg guided missile (#45247)
* update math

* target finder system

* ports

* guns with projectiles

* make sure

* custom sprites for the laser

* add auto link

* add module

* sprite for the missile

* update animation speed

* ops

* make it glow

* overlay sprite

* stuff that doesn't work

* update launcher

* fix it

* make it see from far

* make it work

* sprite for the module

* 30 seconds is too much

* sprite for the range finder

* why was that here?

* update sprite of the missile

* update module icon

* ops

* update missile and missile launcher

* make it look like the launcher item

* remove ammo counter from range finder

* increase to 15 seconds

* no longer show the battery percentage

* use comp

* change summary

* ops

* new line

* make it last longer

* commentary

* acme moment

* fix bug when shooter was also the target and the projectile wouldn't move

* empty commit

* fix test fail

* replace with global behavior

* forgot to remove from the yml

* important

* check to see if the target exists

* fix autorefill bug

* remove unused system

* make it reload a tad slower

---------

Co-authored-by: beck-thompson <beck314159@hotmail.com>
2026-08-16 05:10:57 +00:00

104 lines
3.8 KiB
C#

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;
/// <summary>
/// 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 <see cref="PowerCellComponent"/> or battery powered guns with intrinsic battery.
/// </summary>
/// <remarks>
/// IMPORTANT: If your battery has an update loop setting the charge every single tick you should set <see cref="Component.NetSyncEnabled"> 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 <see cref="SharedBatterySystem.RefreshChargeRate"/> and
/// the current charge will automatically be inferred if you use <see cref="SharedBatterySystem.GetCharge"/>.
/// </remarks>
[RegisterComponent, NetworkedComponent, AutoGenerateComponentState, AutoGenerateComponentPause]
[Access(typeof(SharedBatterySystem))]
public sealed partial class BatteryComponent : Component
{
/// <summary>
/// Maximum charge of the battery in joules (ie. watt seconds)
/// </summary>
[DataField, AutoNetworkedField, ViewVariables]
[GuidebookData]
public float MaxCharge;
/// <summary>
/// The price per one joule. Default is 1 speso for 10kJ.
/// </summary>
[DataField]
public float PricePerJoule = 0.0001f;
/// <summary>
/// Time stamp of the last networked update.
/// </summary>
[DataField(customTypeSerializer: typeof(TimeOffsetSerializer))]
[AutoNetworkedField, AutoPausedField, ViewVariables]
public TimeSpan LastUpdate = TimeSpan.Zero;
/// <summary>
/// The intial charge to be set on map init.
/// </summary>
[DataField]
public float StartingCharge;
/// <summary>
/// The charge at the last update in joules (i.e. watt seconds).
/// </summary>
[DataField, AutoNetworkedField, ViewVariables]
public float LastCharge;
/// <summary>
/// The current charge rate in watt.
/// </summary>
/// <remarks>
/// Not a datafield as this is only cached and recalculated on component startup.
/// </remarks>
[ViewVariables, AutoNetworkedField]
public float ChargeRate;
/// <summary>
/// The current charge state of the battery.
/// Used to track state changes for raising <see cref="BatteryStateChangedEvent"/>.
/// </summary>
/// <remarks>
/// Not a datafield as this is only cached and recalculated in an update loop.
/// </remarks>
[ViewVariables, AutoNetworkedField]
public BatteryState State = BatteryState.Neither;
/// <summary>
/// If it should show the battery percentage in the item status.
/// </summary>
[DataField]
public bool ShowItemStatus = true;
}
/// <summary>
/// Charge level status of the battery.
/// </summary>
[Serializable, NetSerializable]
public enum BatteryState : byte
{
/// <summary>
/// Full charge.
/// </summary>
Full,
/// <summary>
/// No charge.
/// </summary>
Empty,
/// <summary>
/// Neither full nor empty.
/// </summary>
Neither,
}