make apc events only affect single station APCs (#13708)
This commit is contained in:
@@ -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<ApcComponent>().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<ApcComponent>();
|
||||
foreach (var (apc, transform) in EntityQuery<ApcComponent, TransformComponent>())
|
||||
{
|
||||
if (apc.MainBreakerEnabled && CompOrNull<StationMemberComponent>(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]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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<ApcComponent>(true))
|
||||
if (StationSystem.Stations.Count == 0)
|
||||
return;
|
||||
var chosenStation = RobustRandom.Pick(StationSystem.Stations.ToList());
|
||||
|
||||
foreach (var (apc, transform) in EntityQuery<ApcComponent, TransformComponent>(true))
|
||||
{
|
||||
if (component.MainBreakerEnabled)
|
||||
_powered.Add(component.Owner);
|
||||
if (apc.MainBreakerEnabled && CompOrNull<StationMemberComponent>(transform.GridUid)?.Station == chosenStation)
|
||||
_powered.Add(apc.Owner);
|
||||
}
|
||||
|
||||
RobustRandom.Shuffle(_powered);
|
||||
|
||||
Reference in New Issue
Block a user