using Content.Server.Power.NodeGroups; using Content.Server.Power.Pow3r; namespace Content.Server.Power.Components { /// /// Attempts to link with a nearby s /// so that it can receive power from a . /// [RegisterComponent] public sealed partial class ApcPowerReceiverComponent : Component { [ViewVariables] public bool Powered => (MathHelper.CloseToPercent(NetworkLoad.ReceivingPower, Load) || !NeedsPower) && !PowerDisabled; /// /// Amount of charge this needs from an APC per second to function. /// [ViewVariables(VVAccess.ReadWrite)] [DataField("powerLoad")] public float Load { get => NetworkLoad.DesiredPower; set => NetworkLoad.DesiredPower = value; } public ApcPowerProviderComponent? Provider = null; /// /// When false, causes this to appear powered even if not receiving power from an Apc. /// [ViewVariables(VVAccess.ReadWrite)] public bool NeedsPower { get => _needsPower; set { _needsPower = value; // Reset this so next tick will do a power update. PoweredLastUpdate = null; } } [DataField("needsPower")] private bool _needsPower = true; /// /// When true, causes this to never appear powered. /// [ViewVariables(VVAccess.ReadWrite)] [DataField("powerDisabled")] public bool PowerDisabled { get => !NetworkLoad.Enabled; set => NetworkLoad.Enabled = !value; } public bool? PoweredLastUpdate; [ViewVariables] public PowerState.Load NetworkLoad { get; } = new PowerState.Load { DesiredPower = 5 }; public float PowerReceived => NetworkLoad.ReceivingPower; } /// /// Raised whenever an ApcPowerReceiver becomes powered / unpowered. /// Does nothing on the client. /// [ByRefEvent] public readonly record struct PowerChangedEvent(bool Powered, float ReceivingPower) { public readonly bool Powered = Powered; public readonly float ReceivingPower = ReceivingPower; } }