add breakers to power batteries (#16903)
Co-authored-by: deltanedas <@deltanedas:kde.org>
This commit is contained in:
14
Content.Server/Power/Components/BreakerComponent.cs
Normal file
14
Content.Server/Power/Components/BreakerComponent.cs
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
using Content.Server.Power.EntitySystems;
|
||||||
|
|
||||||
|
namespace Content.Server.Power.Components;
|
||||||
|
|
||||||
|
[RegisterComponent]
|
||||||
|
[Access(typeof(BreakerSystem))]
|
||||||
|
public sealed class BreakerComponent : Component
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Once power supplied exceeds this limit the breaker will pop.
|
||||||
|
/// </summary>
|
||||||
|
[DataField("limit", required: true), ViewVariables(VVAccess.ReadWrite)]
|
||||||
|
public float Limit;
|
||||||
|
}
|
||||||
@@ -1,6 +1,7 @@
|
|||||||
using Content.Server.Emp;
|
using Content.Server.Emp;
|
||||||
using Content.Server.Popups;
|
using Content.Server.Popups;
|
||||||
using Content.Server.Power.Components;
|
using Content.Server.Power.Components;
|
||||||
|
using Content.Server.Power.Events;
|
||||||
using Content.Server.Power.Pow3r;
|
using Content.Server.Power.Pow3r;
|
||||||
using Content.Shared.Access.Components;
|
using Content.Shared.Access.Components;
|
||||||
using Content.Shared.Access.Systems;
|
using Content.Shared.Access.Systems;
|
||||||
@@ -36,6 +37,7 @@ namespace Content.Server.Power.EntitySystems
|
|||||||
SubscribeLocalEvent<ApcComponent, ChargeChangedEvent>(OnBatteryChargeChanged);
|
SubscribeLocalEvent<ApcComponent, ChargeChangedEvent>(OnBatteryChargeChanged);
|
||||||
SubscribeLocalEvent<ApcComponent, ApcToggleMainBreakerMessage>(OnToggleMainBreaker);
|
SubscribeLocalEvent<ApcComponent, ApcToggleMainBreakerMessage>(OnToggleMainBreaker);
|
||||||
SubscribeLocalEvent<ApcComponent, GotEmaggedEvent>(OnEmagged);
|
SubscribeLocalEvent<ApcComponent, GotEmaggedEvent>(OnEmagged);
|
||||||
|
SubscribeLocalEvent<ApcComponent, BreakerPoppedEvent>(OnBreakerPopped);
|
||||||
|
|
||||||
SubscribeLocalEvent<ApcComponent, EmpPulseEvent>(OnEmpPulse);
|
SubscribeLocalEvent<ApcComponent, EmpPulseEvent>(OnEmpPulse);
|
||||||
}
|
}
|
||||||
@@ -111,6 +113,18 @@ namespace Content.Server.Power.EntitySystems
|
|||||||
args.Handled = true;
|
args.Handled = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void OnBreakerPopped(EntityUid uid, ApcComponent comp, BreakerPoppedEvent args)
|
||||||
|
{
|
||||||
|
// already disabled, do nothing
|
||||||
|
if (!comp.MainBreakerEnabled)
|
||||||
|
return;
|
||||||
|
|
||||||
|
ApcToggleBreaker(uid, comp);
|
||||||
|
|
||||||
|
// popup so its clear what happened
|
||||||
|
_popup.PopupEntity(Loc.GetString("apc-component-breaker-popped"), uid);
|
||||||
|
}
|
||||||
|
|
||||||
public void UpdateApcState(EntityUid uid,
|
public void UpdateApcState(EntityUid uid,
|
||||||
ApcComponent? apc=null,
|
ApcComponent? apc=null,
|
||||||
PowerNetworkBatteryComponent? battery = null)
|
PowerNetworkBatteryComponent? battery = null)
|
||||||
|
|||||||
30
Content.Server/Power/EntitySystems/BreakerSystem.cs
Normal file
30
Content.Server/Power/EntitySystems/BreakerSystem.cs
Normal file
@@ -0,0 +1,30 @@
|
|||||||
|
using Content.Server.Administration.Logs;
|
||||||
|
using Content.Server.Power.Components;
|
||||||
|
using Content.Server.Power.Events;
|
||||||
|
using Content.Shared.Database;
|
||||||
|
|
||||||
|
namespace Content.Server.Power.EntitySystems;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Handles raising BreakerPopEvent when a power provider exceeds its maximum power.
|
||||||
|
/// </summary>
|
||||||
|
public sealed class BreakerSystem : EntitySystem
|
||||||
|
{
|
||||||
|
[Dependency] private readonly IAdminLogManager _adminLogger = default!;
|
||||||
|
|
||||||
|
/// <inheritdoc/>
|
||||||
|
public override void Update(float frameTime)
|
||||||
|
{
|
||||||
|
base.Update(frameTime);
|
||||||
|
|
||||||
|
var query = EntityQueryEnumerator<BreakerComponent, PowerNetworkBatteryComponent>();
|
||||||
|
while (query.MoveNext(out var uid, out var breaker, out var battery))
|
||||||
|
{
|
||||||
|
if (battery.CurrentSupply > breaker.Limit)
|
||||||
|
{
|
||||||
|
_adminLogger.Add(LogType.Action, LogImpact.Low, $"Breaker of {ToPrettyString(uid):battery)} popped from supplying {battery.CurrentSupply} with a breaker limit of {breaker.Limit}");
|
||||||
|
RaiseLocalEvent(uid, new BreakerPoppedEvent());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
8
Content.Server/Power/Events/BreakerPoppedEvent.cs
Normal file
8
Content.Server/Power/Events/BreakerPoppedEvent.cs
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
namespace Content.Server.Power.Events;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Invoked on a target power provider when its power exceeds BreakerComponent MaxPower, popping the breaker or blowing the fuse.
|
||||||
|
/// </summary>
|
||||||
|
public sealed class BreakerPoppedEvent : EntityEventArgs
|
||||||
|
{
|
||||||
|
}
|
||||||
@@ -2,3 +2,4 @@ apc-component-insufficient-access = Insufficient access!
|
|||||||
apc-component-on-examine-panel-open = The [color=lightgray]APC electronics panel[/color] is [color=red]open[/color].
|
apc-component-on-examine-panel-open = The [color=lightgray]APC electronics panel[/color] is [color=red]open[/color].
|
||||||
apc-component-on-examine-panel-closed = The [color=lightgray]APC electronics panel[/color] is [color=darkgreen]closed[/color].
|
apc-component-on-examine-panel-closed = The [color=lightgray]APC electronics panel[/color] is [color=darkgreen]closed[/color].
|
||||||
apc-component-on-toggle-cancel = It does nothing!
|
apc-component-on-toggle-cancel = It does nothing!
|
||||||
|
apc-component-breaker-popped = The APC's breaker popped!
|
||||||
|
|||||||
@@ -70,6 +70,9 @@
|
|||||||
voltage: Medium
|
voltage: Medium
|
||||||
- type: PowerProvider
|
- type: PowerProvider
|
||||||
voltage: Apc
|
voltage: Apc
|
||||||
|
- type: Breaker
|
||||||
|
# 100A at 240V - 24kW
|
||||||
|
limit: 24000
|
||||||
- type: Apc
|
- type: Apc
|
||||||
voltage: Apc
|
voltage: Apc
|
||||||
- type: ExtensionCableProvider
|
- type: ExtensionCableProvider
|
||||||
|
|||||||
Reference in New Issue
Block a user