mirror of
https://github.com/space-syndicate/space-station-14.git
synced 2026-10-09 10:21:18 +03:00
* Resolve StationEvent warnings * fix misuses of ent after rename, paracusia flip * oh god more rules * comments, whitespace, unnecessary precision * comments, NotNull->IsNull oops * more consistent ent vs. ent.Owner, whitespace * Greytide: "with accress from... access groups"
66 lines
2.5 KiB
C#
66 lines
2.5 KiB
C#
using Content.Server.Shuttles.Systems;
|
|
using Content.Server.Station.Components;
|
|
using Content.Server.Station.Events;
|
|
using Content.Shared.GameTicking.Components;
|
|
using Content.Shared.GameTicking.Rules;
|
|
using Content.Shared.GameTicking.Rules.Components;
|
|
using Content.Shared.Station.Components;
|
|
using Content.Shared.Storage;
|
|
using Robust.Shared.Random;
|
|
|
|
namespace Content.Server.GameTicking.Rules;
|
|
|
|
/// <inheritdoc cref="RoundstartStationVariationRuleComponent"/>
|
|
public sealed partial class RoundstartStationVariationRuleSystem : GameRuleSystem<RoundstartStationVariationRuleComponent>
|
|
{
|
|
[Dependency] private IRobustRandom _random = default!;
|
|
|
|
public override void Initialize()
|
|
{
|
|
base.Initialize();
|
|
|
|
SubscribeLocalEvent<StationPostInitEvent>(OnStationPostInit, after: new[] { typeof(ShuttleSystem) });
|
|
}
|
|
|
|
protected override void Added(Entity<RoundstartStationVariationRuleComponent, GameRuleComponent> ent, ref GameRuleAddedEvent args)
|
|
{
|
|
base.Added(ent, ref args);
|
|
|
|
var spawns = EntitySpawnCollection.GetSpawns(ent.Comp1.Rules, _random);
|
|
foreach (var rule in spawns)
|
|
{
|
|
GameTicker.AddGameRule(rule);
|
|
}
|
|
}
|
|
|
|
private void OnStationPostInit(ref StationPostInitEvent ev)
|
|
{
|
|
// as long as one is running
|
|
if (!GameTicker.IsGameRuleAdded<RoundstartStationVariationRuleComponent>())
|
|
return;
|
|
|
|
// this is unlikely, but could theoretically happen if it was saved and reloaded, so check anyway
|
|
if (HasComp<StationVariationHasRunComponent>(ev.Station))
|
|
return;
|
|
|
|
Log.Info($"Running variation rules for station {ToPrettyString(ev.Station)}");
|
|
|
|
// raise the event on any passes that have been added
|
|
var passEv = new StationVariationPassEvent(ev.Station);
|
|
var passQuery = EntityQueryEnumerator<StationVariationPassRuleComponent, GameRuleComponent>();
|
|
while (passQuery.MoveNext(out var uid, out _, out _))
|
|
{
|
|
RaiseLocalEvent(uid, ref passEv);
|
|
}
|
|
|
|
EnsureComp<StationVariationHasRunComponent>(ev.Station);
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Raised directed on game rule entities which are added and marked as <see cref="StationVariationPassRuleComponent"/>
|
|
/// when a new station is initialized that should be varied.
|
|
/// </summary>
|
|
/// <param name="Station">The new station that was added, and its config & grids.</param>
|
|
[ByRefEvent]
|
|
public readonly record struct StationVariationPassEvent(Entity<StationDataComponent> Station);
|