* move MinMax to shared * cleanup MinMax * move other ticking components to shared just because * remove unused prototype file * update everything to use shared components * test * test 2 * test 3 --------- Co-authored-by: deltanedas <@deltanedas:kde.org>
56 lines
2.0 KiB
C#
56 lines
2.0 KiB
C#
using Content.Server.Power.Components;
|
||
using Content.Server.Power.EntitySystems;
|
||
using Content.Server.Station.Components;
|
||
using Content.Server.StationEvents.Components;
|
||
using Content.Shared.GameTicking.Components;
|
||
using JetBrains.Annotations;
|
||
|
||
namespace Content.Server.StationEvents.Events;
|
||
|
||
[UsedImplicitly]
|
||
public sealed class BreakerFlipRule : StationEventSystem<BreakerFlipRuleComponent>
|
||
{
|
||
[Dependency] private readonly ApcSystem _apcSystem = default!;
|
||
|
||
protected override void Added(EntityUid uid, BreakerFlipRuleComponent component, GameRuleComponent gameRule, GameRuleAddedEvent args)
|
||
{
|
||
if (!TryComp<StationEventComponent>(uid, out var stationEvent))
|
||
return;
|
||
|
||
var str = Loc.GetString("station-event-breaker-flip-announcement", ("data", Loc.GetString(Loc.GetString($"random-sentience-event-data-{RobustRandom.Next(1, 6)}"))));
|
||
stationEvent.StartAnnouncement = str;
|
||
|
||
base.Added(uid, component, gameRule, args);
|
||
|
||
}
|
||
|
||
protected override void Started(EntityUid uid, BreakerFlipRuleComponent component, GameRuleComponent gameRule, GameRuleStartedEvent args)
|
||
{
|
||
base.Started(uid, component, gameRule, args);
|
||
|
||
if (!TryGetRandomStation(out var chosenStation))
|
||
return;
|
||
|
||
var stationApcs = new List<Entity<ApcComponent>>();
|
||
var query = EntityQueryEnumerator<ApcComponent, TransformComponent>();
|
||
while (query.MoveNext(out var apcUid, out var apc, out var xform))
|
||
{
|
||
if (apc.MainBreakerEnabled && CompOrNull<StationMemberComponent>(xform.GridUid)?.Station == chosenStation)
|
||
{
|
||
stationApcs.Add((apcUid, apc));
|
||
}
|
||
}
|
||
|
||
var toDisable = Math.Min(RobustRandom.Next(3, 7), stationApcs.Count);
|
||
if (toDisable == 0)
|
||
return;
|
||
|
||
RobustRandom.Shuffle(stationApcs);
|
||
|
||
for (var i = 0; i < toDisable; i++)
|
||
{
|
||
_apcSystem.ApcToggleBreaker(stationApcs[i], stationApcs[i]);
|
||
}
|
||
}
|
||
}
|