committed by
GitHub
parent
ea60a81fdf
commit
103bc19508
@@ -44,7 +44,7 @@ namespace Content.Server.Singularity.Components
|
||||
private PowerConsumerComponent _powerConsumer = default!;
|
||||
|
||||
// whether the power switch is in "on"
|
||||
[ViewVariables] private bool _isOn;
|
||||
[ViewVariables] public bool IsOn { get; private set; }
|
||||
// Whether the power switch is on AND the machine has enough power (so is actively firing)
|
||||
[ViewVariables] private bool _isPowered;
|
||||
[ViewVariables] private bool _isLocked;
|
||||
@@ -64,32 +64,6 @@ namespace Content.Server.Singularity.Components
|
||||
[ViewVariables(VVAccess.ReadWrite)] [DataField("fireBurstDelayMin")] private TimeSpan _fireBurstDelayMin = TimeSpan.FromSeconds(2);
|
||||
[ViewVariables(VVAccess.ReadWrite)] [DataField("fireBurstDelayMax")] private TimeSpan _fireBurstDelayMax = TimeSpan.FromSeconds(10);
|
||||
|
||||
protected override void Initialize()
|
||||
{
|
||||
base.Initialize();
|
||||
|
||||
Owner.EnsureComponent<PowerConsumerComponent>(out _powerConsumer);
|
||||
|
||||
_powerConsumer.OnReceivedPowerChanged += OnReceivedPowerChanged;
|
||||
}
|
||||
|
||||
private void OnReceivedPowerChanged(object? sender, ReceivedPowerChangedEventArgs e)
|
||||
{
|
||||
if (!_isOn)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (e.ReceivedPower < e.DrawRate)
|
||||
{
|
||||
PowerOff();
|
||||
}
|
||||
else
|
||||
{
|
||||
PowerOn();
|
||||
}
|
||||
}
|
||||
|
||||
void IActivate.Activate(ActivateEventArgs eventArgs)
|
||||
{
|
||||
if (_isLocked)
|
||||
@@ -100,7 +74,7 @@ namespace Content.Server.Singularity.Components
|
||||
|
||||
if (Owner.TryGetComponent(out PhysicsComponent? phys) && phys.BodyType == BodyType.Static)
|
||||
{
|
||||
if (!_isOn)
|
||||
if (!IsOn)
|
||||
{
|
||||
SwitchOn();
|
||||
Owner.PopupMessage(eventArgs.User, Loc.GetString("comp-emitter-turned-on", ("target", Owner)));
|
||||
@@ -149,7 +123,7 @@ namespace Content.Server.Singularity.Components
|
||||
|
||||
public void SwitchOff()
|
||||
{
|
||||
_isOn = false;
|
||||
IsOn = false;
|
||||
_powerConsumer.DrawRate = 0;
|
||||
PowerOff();
|
||||
UpdateAppearance();
|
||||
@@ -157,14 +131,14 @@ namespace Content.Server.Singularity.Components
|
||||
|
||||
public void SwitchOn()
|
||||
{
|
||||
_isOn = true;
|
||||
IsOn = true;
|
||||
_powerConsumer.DrawRate = _powerUseActive;
|
||||
// Do not directly PowerOn().
|
||||
// OnReceivedPowerChanged will get fired due to DrawRate change which will turn it on.
|
||||
UpdateAppearance();
|
||||
}
|
||||
|
||||
private void PowerOff()
|
||||
public void PowerOff()
|
||||
{
|
||||
if (!_isPowered)
|
||||
{
|
||||
@@ -180,7 +154,7 @@ namespace Content.Server.Singularity.Components
|
||||
UpdateAppearance();
|
||||
}
|
||||
|
||||
private void PowerOn()
|
||||
public void PowerOn()
|
||||
{
|
||||
if (_isPowered)
|
||||
{
|
||||
@@ -202,7 +176,7 @@ namespace Content.Server.Singularity.Components
|
||||
// Any power-off condition should result in the timer for this method being cancelled
|
||||
// and thus not firing
|
||||
DebugTools.Assert(_isPowered);
|
||||
DebugTools.Assert(_isOn);
|
||||
DebugTools.Assert(IsOn);
|
||||
DebugTools.Assert(_powerConsumer.DrawRate <= _powerConsumer.ReceivedPower);
|
||||
|
||||
Fire();
|
||||
@@ -269,7 +243,7 @@ namespace Content.Server.Singularity.Components
|
||||
{
|
||||
state = EmitterVisualState.On;
|
||||
}
|
||||
else if (_isOn)
|
||||
else if (IsOn)
|
||||
{
|
||||
state = EmitterVisualState.Underpowered;
|
||||
}
|
||||
|
||||
@@ -1,9 +1,7 @@
|
||||
#nullable enable
|
||||
using System;
|
||||
using Content.Server.Battery.Components;
|
||||
using Content.Server.Power.Components;
|
||||
using Content.Shared.Interaction;
|
||||
using Content.Shared.Notification;
|
||||
using Content.Shared.Notification.Managers;
|
||||
using Content.Shared.Radiation;
|
||||
using Content.Shared.Singularity.Components;
|
||||
@@ -37,7 +35,6 @@ namespace Content.Server.Singularity.Components
|
||||
}
|
||||
|
||||
[ComponentDependency] private readonly BatteryComponent? _batteryComponent = default!;
|
||||
[ComponentDependency] private readonly BatteryDischargerComponent? _batteryDischargerComponent = default!;
|
||||
|
||||
bool IInteractHand.InteractHand(InteractHandEventArgs eventArgs)
|
||||
{
|
||||
@@ -74,12 +71,6 @@ namespace Content.Server.Singularity.Components
|
||||
if (_batteryComponent != null)
|
||||
{
|
||||
_batteryComponent!.CurrentCharge += frameTime * radiation.RadsPerSecond * 3000f;
|
||||
if (_batteryDischargerComponent != null)
|
||||
{
|
||||
// The battery discharger is controlled like this to ensure it won't drain the entire battery in a single tick.
|
||||
// If that occurs then the battery discharger ends up shutting down.
|
||||
_batteryDischargerComponent!.ActiveSupplyRate = (int) Math.Max(1, _batteryComponent!.CurrentCharge);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
38
Content.Server/Singularity/EntitySystems/EmitterSystem.cs
Normal file
38
Content.Server/Singularity/EntitySystems/EmitterSystem.cs
Normal file
@@ -0,0 +1,38 @@
|
||||
using Content.Server.Power.EntitySystems;
|
||||
using Content.Server.Singularity.Components;
|
||||
using JetBrains.Annotations;
|
||||
using Robust.Shared.GameObjects;
|
||||
|
||||
namespace Content.Server.Singularity.EntitySystems
|
||||
{
|
||||
[UsedImplicitly]
|
||||
public class EmitterSystem : EntitySystem
|
||||
{
|
||||
public override void Initialize()
|
||||
{
|
||||
base.Initialize();
|
||||
|
||||
SubscribeLocalEvent<EmitterComponent, PowerConsumerReceivedChanged>(ReceivedChanged);
|
||||
}
|
||||
|
||||
private static void ReceivedChanged(
|
||||
EntityUid uid,
|
||||
EmitterComponent component,
|
||||
PowerConsumerReceivedChanged args)
|
||||
{
|
||||
if (!component.IsOn)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (args.ReceivedPower < args.DrawRate)
|
||||
{
|
||||
component.PowerOff();
|
||||
}
|
||||
else
|
||||
{
|
||||
component.PowerOn();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user