Fix Sloth's power crime (#6443)

This commit is contained in:
metalgearsloth
2022-02-03 07:10:31 +11:00
committed by GitHub
parent 80727f7fa4
commit aaea5dd2d8
2 changed files with 9 additions and 19 deletions

View File

@@ -15,6 +15,8 @@ namespace Content.Server.Power.Components
[RegisterComponent] [RegisterComponent]
public sealed class PowerNetworkBatteryComponent : Component public sealed class PowerNetworkBatteryComponent : Component
{ {
[ViewVariables] public float LastSupply = 0f;
[DataField("maxChargeRate")] [DataField("maxChargeRate")]
[ViewVariables(VVAccess.ReadWrite)] [ViewVariables(VVAccess.ReadWrite)]
public float MaxChargeRate public float MaxChargeRate

View File

@@ -1,5 +1,6 @@
using System.Linq; using System.Linq;
using System.Collections.Generic; using System.Collections.Generic;
using System.Diagnostics;
using Content.Server.NodeContainer.EntitySystems; using Content.Server.NodeContainer.EntitySystems;
using Content.Server.Power.Components; using Content.Server.Power.Components;
using Content.Server.Power.NodeGroups; using Content.Server.Power.NodeGroups;
@@ -7,6 +8,7 @@ using Content.Server.Power.Pow3r;
using JetBrains.Annotations; using JetBrains.Annotations;
using Robust.Shared.GameObjects; using Robust.Shared.GameObjects;
using Robust.Shared.IoC; using Robust.Shared.IoC;
using Robust.Shared.Log;
using Robust.Shared.Maths; using Robust.Shared.Maths;
namespace Content.Server.Power.EntitySystems namespace Content.Server.Power.EntitySystems
@@ -21,8 +23,6 @@ namespace Content.Server.Power.EntitySystems
private readonly HashSet<PowerNet> _powerNetReconnectQueue = new(); private readonly HashSet<PowerNet> _powerNetReconnectQueue = new();
private readonly HashSet<ApcNet> _apcNetReconnectQueue = new(); private readonly HashSet<ApcNet> _apcNetReconnectQueue = new();
private readonly Dictionary<PowerNetworkBatteryComponent, float> _lastSupply = new();
private readonly BatteryRampPegSolver _solver = new(); private readonly BatteryRampPegSolver _solver = new();
public override void Initialize() public override void Initialize()
@@ -208,14 +208,6 @@ namespace Content.Server.Power.EntitySystems
{ {
base.Update(frameTime); base.Update(frameTime);
// Setup for events.
{
foreach (var powerNetBattery in EntityManager.EntityQuery<PowerNetworkBatteryComponent>())
{
_lastSupply[powerNetBattery] = powerNetBattery.CurrentSupply;
}
}
// Reconnect networks. // Reconnect networks.
{ {
foreach (var apcNet in _apcNetReconnectQueue) foreach (var apcNet in _apcNetReconnectQueue)
@@ -276,24 +268,20 @@ namespace Content.Server.Power.EntitySystems
foreach (var powerNetBattery in EntityManager.EntityQuery<PowerNetworkBatteryComponent>()) foreach (var powerNetBattery in EntityManager.EntityQuery<PowerNetworkBatteryComponent>())
{ {
if (!_lastSupply.TryGetValue(powerNetBattery, out var lastPowerSupply)) var lastSupply = powerNetBattery.LastSupply;
{
lastPowerSupply = 0f;
}
var currentSupply = powerNetBattery.CurrentSupply; var currentSupply = powerNetBattery.CurrentSupply;
if (lastPowerSupply == 0f && currentSupply != 0f) if (lastSupply == 0f && currentSupply != 0f)
{ {
RaiseLocalEvent(powerNetBattery.Owner, new PowerNetBatterySupplyEvent {Supply = true}); RaiseLocalEvent(powerNetBattery.Owner, new PowerNetBatterySupplyEvent {Supply = true});
} }
else if (lastPowerSupply > 0f && currentSupply == 0f) else if (lastSupply > 0f && currentSupply == 0f)
{ {
RaiseLocalEvent(powerNetBattery.Owner, new PowerNetBatterySupplyEvent {Supply = false}); RaiseLocalEvent(powerNetBattery.Owner, new PowerNetBatterySupplyEvent {Supply = false});
} }
}
_lastSupply.Clear(); powerNetBattery.LastSupply = currentSupply;
}
} }
} }