2022-02-26 21:04:01 -06:00
|
|
|
using Content.Server.Power.Components;
|
|
|
|
|
using Content.Server.Power.EntitySystems;
|
2023-04-25 20:23:14 -04:00
|
|
|
using Content.Server.StationEvents.Components;
|
2024-07-22 21:32:30 +02:00
|
|
|
using Content.Shared.GameTicking.Components;
|
|
|
|
|
using Content.Shared.Station.Components;
|
2022-02-26 21:04:01 -06:00
|
|
|
using JetBrains.Annotations;
|
|
|
|
|
|
|
|
|
|
namespace Content.Server.StationEvents.Events;
|
|
|
|
|
|
|
|
|
|
[UsedImplicitly]
|
2023-04-25 20:23:14 -04:00
|
|
|
public sealed class BreakerFlipRule : StationEventSystem<BreakerFlipRuleComponent>
|
2022-02-26 21:04:01 -06:00
|
|
|
{
|
2022-07-10 18:48:41 -07:00
|
|
|
[Dependency] private readonly ApcSystem _apcSystem = default!;
|
|
|
|
|
|
2023-04-25 20:23:14 -04:00
|
|
|
protected override void Added(EntityUid uid, BreakerFlipRuleComponent component, GameRuleComponent gameRule, GameRuleAddedEvent args)
|
2022-07-10 18:48:41 -07:00
|
|
|
{
|
2024-06-01 23:34:58 +03:00
|
|
|
if (!TryComp<StationEventComponent>(uid, out var stationEvent))
|
|
|
|
|
return;
|
2022-07-10 18:48:41 -07:00
|
|
|
|
|
|
|
|
var str = Loc.GetString("station-event-breaker-flip-announcement", ("data", Loc.GetString(Loc.GetString($"random-sentience-event-data-{RobustRandom.Next(1, 6)}"))));
|
2024-06-01 23:34:58 +03:00
|
|
|
stationEvent.StartAnnouncement = str;
|
|
|
|
|
|
|
|
|
|
base.Added(uid, component, gameRule, args);
|
|
|
|
|
|
2022-07-10 18:48:41 -07:00
|
|
|
}
|
|
|
|
|
|
2023-04-25 20:23:14 -04:00
|
|
|
protected override void Started(EntityUid uid, BreakerFlipRuleComponent component, GameRuleComponent gameRule, GameRuleStartedEvent args)
|
2022-02-26 21:04:01 -06:00
|
|
|
{
|
2023-04-25 20:23:14 -04:00
|
|
|
base.Started(uid, component, gameRule, args);
|
2022-02-26 21:04:01 -06:00
|
|
|
|
2023-05-19 15:45:09 -05:00
|
|
|
if (!TryGetRandomStation(out var chosenStation))
|
2023-01-28 17:07:18 +03:00
|
|
|
return;
|
|
|
|
|
|
2023-10-19 12:34:31 -07:00
|
|
|
var stationApcs = new List<Entity<ApcComponent>>();
|
|
|
|
|
var query = EntityQueryEnumerator<ApcComponent, TransformComponent>();
|
|
|
|
|
while (query.MoveNext(out var apcUid, out var apc, out var xform))
|
2023-01-28 17:07:18 +03:00
|
|
|
{
|
2023-10-19 12:34:31 -07:00
|
|
|
if (apc.MainBreakerEnabled && CompOrNull<StationMemberComponent>(xform.GridUid)?.Station == chosenStation)
|
2023-01-28 17:07:18 +03:00
|
|
|
{
|
2023-10-19 12:34:31 -07:00
|
|
|
stationApcs.Add((apcUid, apc));
|
2023-01-28 17:07:18 +03:00
|
|
|
}
|
|
|
|
|
}
|
2023-04-25 20:23:14 -04:00
|
|
|
|
2023-01-28 17:07:18 +03:00
|
|
|
var toDisable = Math.Min(RobustRandom.Next(3, 7), stationApcs.Count);
|
2022-02-26 21:04:01 -06:00
|
|
|
if (toDisable == 0)
|
|
|
|
|
return;
|
|
|
|
|
|
2023-01-28 17:07:18 +03:00
|
|
|
RobustRandom.Shuffle(stationApcs);
|
2022-02-26 21:04:01 -06:00
|
|
|
|
|
|
|
|
for (var i = 0; i < toDisable; i++)
|
|
|
|
|
{
|
2023-10-19 12:34:31 -07:00
|
|
|
_apcSystem.ApcToggleBreaker(stationApcs[i], stationApcs[i]);
|
2022-02-26 21:04:01 -06:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|