From 9d9edd8322cac50230211a6e9d2cb29820ed8318 Mon Sep 17 00:00:00 2001 From: Slava0135 <40753025+Slava0135@users.noreply.github.com> Date: Sat, 28 Jan 2023 17:07:18 +0300 Subject: [PATCH] make apc events only affect single station APCs (#13708) --- .../StationEvents/Events/BreakerFlip.cs | 21 +++++++++++++++---- .../StationEvents/Events/PowerGridCheck.cs | 13 +++++++++--- 2 files changed, 27 insertions(+), 7 deletions(-) diff --git a/Content.Server/StationEvents/Events/BreakerFlip.cs b/Content.Server/StationEvents/Events/BreakerFlip.cs index 3a14f5c3cc..2df721b7cc 100644 --- a/Content.Server/StationEvents/Events/BreakerFlip.cs +++ b/Content.Server/StationEvents/Events/BreakerFlip.cs @@ -1,6 +1,7 @@ using System.Linq; using Content.Server.Power.Components; using Content.Server.Power.EntitySystems; +using Content.Server.Station.Components; using JetBrains.Annotations; using Robust.Shared.Random; @@ -25,16 +26,28 @@ public sealed class BreakerFlip : StationEventSystem { base.Started(); - var allApcs = EntityQuery().ToList(); - var toDisable = Math.Min(RobustRandom.Next(3, 7), allApcs.Count); + if (StationSystem.Stations.Count == 0) + return; + var chosenStation = RobustRandom.Pick(StationSystem.Stations.ToList()); + + var stationApcs = new List(); + foreach (var (apc, transform) in EntityQuery()) + { + if (apc.MainBreakerEnabled && CompOrNull(transform.GridUid)?.Station == chosenStation) + { + stationApcs.Add(apc); + } + } + + var toDisable = Math.Min(RobustRandom.Next(3, 7), stationApcs.Count); if (toDisable == 0) return; - RobustRandom.Shuffle(allApcs); + RobustRandom.Shuffle(stationApcs); for (var i = 0; i < toDisable; i++) { - _apcSystem.ApcToggleBreaker(allApcs[i].Owner, allApcs[i]); + _apcSystem.ApcToggleBreaker(stationApcs[i].Owner, stationApcs[i]); } } } diff --git a/Content.Server/StationEvents/Events/PowerGridCheck.cs b/Content.Server/StationEvents/Events/PowerGridCheck.cs index b27afcf24b..b1f21af12c 100644 --- a/Content.Server/StationEvents/Events/PowerGridCheck.cs +++ b/Content.Server/StationEvents/Events/PowerGridCheck.cs @@ -6,6 +6,9 @@ using Robust.Shared.Utility; using System.Threading; using Content.Server.Power.EntitySystems; using Timer = Robust.Shared.Timing.Timer; +using System.Linq; +using Robust.Shared.Random; +using Content.Server.Station.Components; namespace Content.Server.StationEvents.Events { @@ -37,10 +40,14 @@ namespace Content.Server.StationEvents.Events public override void Started() { - foreach (var component in EntityManager.EntityQuery(true)) + if (StationSystem.Stations.Count == 0) + return; + var chosenStation = RobustRandom.Pick(StationSystem.Stations.ToList()); + + foreach (var (apc, transform) in EntityQuery(true)) { - if (component.MainBreakerEnabled) - _powered.Add(component.Owner); + if (apc.MainBreakerEnabled && CompOrNull(transform.GridUid)?.Station == chosenStation) + _powered.Add(apc.Owner); } RobustRandom.Shuffle(_powered);