2021-07-04 18:11:52 +02:00
|
|
|
using Content.Server.Power.NodeGroups;
|
|
|
|
|
using Content.Server.Power.Pow3r;
|
2024-05-29 23:46:22 -07:00
|
|
|
using Content.Shared.Power.Components;
|
2020-06-28 09:23:26 -06:00
|
|
|
|
2021-06-09 22:19:39 +02:00
|
|
|
namespace Content.Server.Power.Components
|
2020-06-28 09:23:26 -06:00
|
|
|
{
|
|
|
|
|
/// <summary>
|
2021-07-04 18:11:52 +02:00
|
|
|
/// Attempts to link with a nearby <see cref="ApcPowerProviderComponent"/>s
|
|
|
|
|
/// so that it can receive power from a <see cref="IApcNet"/>.
|
2020-06-28 09:23:26 -06:00
|
|
|
/// </summary>
|
|
|
|
|
[RegisterComponent]
|
2024-05-29 23:46:22 -07:00
|
|
|
public sealed partial class ApcPowerReceiverComponent : SharedApcPowerReceiverComponent
|
2020-06-28 09:23:26 -06:00
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Amount of charge this needs from an APC per second to function.
|
|
|
|
|
/// </summary>
|
2020-07-26 04:14:03 -06:00
|
|
|
[ViewVariables(VVAccess.ReadWrite)]
|
2021-03-05 01:08:38 +01:00
|
|
|
[DataField("powerLoad")]
|
2021-07-04 18:11:52 +02:00
|
|
|
public float Load { get => NetworkLoad.DesiredPower; set => NetworkLoad.DesiredPower = value; }
|
2020-06-28 09:23:26 -06:00
|
|
|
|
2021-10-25 21:55:00 +02:00
|
|
|
public ApcPowerProviderComponent? Provider = null;
|
|
|
|
|
|
2020-06-28 09:23:26 -06:00
|
|
|
/// <summary>
|
2020-09-13 06:08:23 -06:00
|
|
|
/// When false, causes this to appear powered even if not receiving power from an Apc.
|
2020-06-28 09:23:26 -06:00
|
|
|
/// </summary>
|
|
|
|
|
[ViewVariables(VVAccess.ReadWrite)]
|
2021-07-04 18:11:52 +02:00
|
|
|
public bool NeedsPower
|
|
|
|
|
{
|
|
|
|
|
get => _needsPower;
|
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
_needsPower = value;
|
|
|
|
|
// Reset this so next tick will do a power update.
|
2024-05-29 23:46:22 -07:00
|
|
|
Recalculate = true;
|
2021-07-04 18:11:52 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2021-03-05 01:08:38 +01:00
|
|
|
[DataField("needsPower")]
|
|
|
|
|
private bool _needsPower = true;
|
2020-06-28 09:23:26 -06:00
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// When true, causes this to never appear powered.
|
|
|
|
|
/// </summary>
|
2020-09-13 06:08:23 -06:00
|
|
|
[ViewVariables(VVAccess.ReadWrite)]
|
2021-03-05 01:08:38 +01:00
|
|
|
[DataField("powerDisabled")]
|
2022-05-05 19:35:06 -07:00
|
|
|
public bool PowerDisabled {
|
|
|
|
|
get => !NetworkLoad.Enabled;
|
|
|
|
|
set => NetworkLoad.Enabled = !value;
|
|
|
|
|
}
|
2021-07-04 18:11:52 +02:00
|
|
|
|
2024-05-29 23:46:22 -07:00
|
|
|
// TODO Is this needed? It forces a PowerChangedEvent when NeedsPower is toggled even if it changes to the same state.
|
|
|
|
|
public bool Recalculate;
|
2021-07-04 18:11:52 +02:00
|
|
|
|
|
|
|
|
[ViewVariables]
|
|
|
|
|
public PowerState.Load NetworkLoad { get; } = new PowerState.Load
|
|
|
|
|
{
|
|
|
|
|
DesiredPower = 5
|
|
|
|
|
};
|
2020-06-28 09:23:26 -06:00
|
|
|
|
2021-11-02 01:12:55 +01:00
|
|
|
public float PowerReceived => NetworkLoad.ReceivingPower;
|
2020-06-28 09:23:26 -06:00
|
|
|
}
|
|
|
|
|
}
|