2023-07-22 23:57:13 -04:00
|
|
|
|
using Content.Server.Anomaly;
|
2023-01-20 19:42:38 -05:00
|
|
|
|
using Content.Server.Station.Components;
|
2023-04-25 20:23:14 -04:00
|
|
|
|
using Content.Server.StationEvents.Components;
|
2024-06-04 11:53:24 +00:00
|
|
|
|
using Content.Shared.GameTicking.Components;
|
2023-01-20 19:42:38 -05:00
|
|
|
|
|
|
|
|
|
|
namespace Content.Server.StationEvents.Events;
|
|
|
|
|
|
|
2023-04-25 20:23:14 -04:00
|
|
|
|
public sealed class AnomalySpawnRule : StationEventSystem<AnomalySpawnRuleComponent>
|
2023-01-20 19:42:38 -05:00
|
|
|
|
{
|
|
|
|
|
|
[Dependency] private readonly AnomalySystem _anomaly = default!;
|
|
|
|
|
|
|
2023-04-25 20:23:14 -04:00
|
|
|
|
protected override void Added(EntityUid uid, AnomalySpawnRuleComponent component, GameRuleComponent gameRule, GameRuleAddedEvent args)
|
2023-01-20 19:42:38 -05:00
|
|
|
|
{
|
2024-06-01 23:34:58 +03:00
|
|
|
|
if (!TryComp<StationEventComponent>(uid, out var stationEvent))
|
|
|
|
|
|
return;
|
2023-01-20 19:42:38 -05:00
|
|
|
|
|
|
|
|
|
|
var str = Loc.GetString("anomaly-spawn-event-announcement",
|
2023-04-25 20:23:14 -04:00
|
|
|
|
("sighting", Loc.GetString($"anomaly-spawn-sighting-{RobustRandom.Next(1, 6)}")));
|
2024-06-01 23:34:58 +03:00
|
|
|
|
stationEvent.StartAnnouncement = str;
|
|
|
|
|
|
|
|
|
|
|
|
base.Added(uid, component, gameRule, args);
|
2023-01-20 19:42:38 -05:00
|
|
|
|
}
|
|
|
|
|
|
|
2023-04-25 20:23:14 -04:00
|
|
|
|
protected override void Started(EntityUid uid, AnomalySpawnRuleComponent component, GameRuleComponent gameRule, GameRuleStartedEvent args)
|
2023-01-20 19:42:38 -05:00
|
|
|
|
{
|
2023-04-25 20:23:14 -04:00
|
|
|
|
base.Started(uid, component, gameRule, args);
|
2023-01-20 19:42:38 -05:00
|
|
|
|
|
2023-05-19 15:45:09 -05:00
|
|
|
|
if (!TryGetRandomStation(out var chosenStation))
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
2023-01-20 19:42:38 -05:00
|
|
|
|
if (!TryComp<StationDataComponent>(chosenStation, out var stationData))
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
2023-07-22 23:57:13 -04:00
|
|
|
|
var grid = StationSystem.GetLargestGrid(stationData);
|
2023-01-20 19:42:38 -05:00
|
|
|
|
|
2023-07-22 23:57:13 -04:00
|
|
|
|
if (grid is null)
|
2023-01-20 19:42:38 -05:00
|
|
|
|
return;
|
|
|
|
|
|
|
2024-02-25 15:04:51 -07:00
|
|
|
|
var amountToSpawn = 1;
|
2023-01-20 19:42:38 -05:00
|
|
|
|
for (var i = 0; i < amountToSpawn; i++)
|
|
|
|
|
|
{
|
2023-04-25 20:23:14 -04:00
|
|
|
|
_anomaly.SpawnOnRandomGridLocation(grid.Value, component.AnomalySpawnerPrototype);
|
2023-01-20 19:42:38 -05:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|