mirror of
https://github.com/space-syndicate/space-station-14.git
synced 2026-10-09 18:31:17 +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"
49 lines
1.6 KiB
C#
49 lines
1.6 KiB
C#
using Content.Server.Anomaly;
|
|
using Content.Server.StationEvents.Components;
|
|
using Content.Shared.GameTicking.Components;
|
|
using Content.Shared.Station.Components;
|
|
|
|
namespace Content.Server.StationEvents.Events;
|
|
|
|
/// <summary>
|
|
/// Handler for events spawning an anomaly on station.
|
|
/// </summary>
|
|
/// <seealso cref="AnomalySpawnRuleComponent"/>
|
|
public sealed partial class AnomalySpawnRule : StationEventSystem<AnomalySpawnRuleComponent>
|
|
{
|
|
[Dependency] private AnomalySystem _anomaly = default!;
|
|
|
|
protected override void Added(Entity<AnomalySpawnRuleComponent, GameRuleComponent> ent, ref GameRuleAddedEvent args)
|
|
{
|
|
if (!TryComp<StationEventComponent>(ent, out var stationEvent))
|
|
return;
|
|
|
|
var str = Loc.GetString("anomaly-spawn-event-announcement",
|
|
("sighting", Loc.GetString($"anomaly-spawn-sighting-{RobustRandom.Next(1, 6)}")));
|
|
stationEvent.StartAnnouncement = str;
|
|
|
|
base.Added(ent, ref args);
|
|
}
|
|
|
|
protected override void Started(Entity<AnomalySpawnRuleComponent, GameRuleComponent> ent, ref GameRuleStartedEvent args)
|
|
{
|
|
base.Started(ent, ref args);
|
|
|
|
if (!Station.TryGetRandomStation<StationEventEligibleComponent>(out var chosenStation))
|
|
return;
|
|
|
|
if (!TryComp<StationDataComponent>(chosenStation, out var stationData))
|
|
return;
|
|
|
|
var grid = Station.GetLargestGrid((chosenStation.Value, stationData));
|
|
|
|
if (grid is null)
|
|
return;
|
|
|
|
var amountToSpawn = 1;
|
|
for (var i = 0; i < amountToSpawn; i++)
|
|
{
|
|
_anomaly.SpawnOnRandomGridLocation(grid.Value, ent.Comp1.AnomalySpawnerPrototype);
|
|
}
|
|
}
|
|
}
|