using Content.Server.Power.NodeGroups;
using Content.Shared.APC;
using Robust.Shared.Audio;
using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom;
namespace Content.Server.Power.Components;
[RegisterComponent, AutoGenerateComponentPause]
public sealed partial class ApcComponent : BaseApcNetComponent
{
[DataField("onReceiveMessageSound")]
public SoundSpecifier OnReceiveMessageSound = new SoundPathSpecifier("/Audio/Machines/machine_switch.ogg");
public ApcChargeState LastChargeState;
public TimeSpan? LastChargeStateTime;
public ApcExternalPowerState LastExternalState;
///
/// Time the ui was last updated automatically.
/// Done after every to show the latest load.
/// If charge state changes it will be instantly updated.
///
public TimeSpan LastUiUpdate;
[DataField("enabled")]
public bool MainBreakerEnabled = true;
///
/// APC state needs to always be updated after first processing tick.
///
public bool NeedStateUpdate;
public const float HighPowerThreshold = 0.9f;
public static TimeSpan VisualsChangeDelay = TimeSpan.FromSeconds(1);
///
/// Maximum continuous load in Watts that this APC can supply to loads. Exceeding this starts a
/// timer, which after enough overloading causes the APC to "trip" off.
///
[DataField]
public float MaxLoad = 20e3f;
///
/// Time that the APC can be continuously overloaded before tripping off.
///
[DataField]
public TimeSpan TripTime = TimeSpan.FromSeconds(3);
///
/// Time that overloading began.
///
[DataField(customTypeSerializer: typeof(TimeOffsetSerializer)), AutoPausedField]
public TimeSpan? TripStartTime;
///
/// Set to true if the APC tripped off. Used to indicate problems in the UI. Reset by switching
/// APC on.
///
[DataField]
public bool TripFlag;
// TODO ECS power a little better!
// End the suffering
protected override void AddSelfToNet(IApcNet apcNet)
{
apcNet.AddApc(Owner, this);
}
protected override void RemoveSelfFromNet(IApcNet apcNet)
{
apcNet.RemoveApc(Owner, this);
}
}