AnomalySpawnRule.cs 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. using Content.Server.Anomaly;
  2. using Content.Server.Station.Components;
  3. using Content.Server.StationEvents.Components;
  4. using Content.Shared.GameTicking.Components;
  5. namespace Content.Server.StationEvents.Events;
  6. public sealed class AnomalySpawnRule : StationEventSystem<AnomalySpawnRuleComponent>
  7. {
  8. [Dependency] private readonly AnomalySystem _anomaly = default!;
  9. protected override void Added(EntityUid uid, AnomalySpawnRuleComponent component, GameRuleComponent gameRule, GameRuleAddedEvent args)
  10. {
  11. if (!TryComp<StationEventComponent>(uid, out var stationEvent))
  12. return;
  13. var str = Loc.GetString("anomaly-spawn-event-announcement",
  14. ("sighting", Loc.GetString($"anomaly-spawn-sighting-{RobustRandom.Next(1, 6)}")));
  15. stationEvent.StartAnnouncement = str;
  16. base.Added(uid, component, gameRule, args);
  17. }
  18. protected override void Started(EntityUid uid, AnomalySpawnRuleComponent component, GameRuleComponent gameRule, GameRuleStartedEvent args)
  19. {
  20. base.Started(uid, component, gameRule, args);
  21. if (!TryGetRandomStation(out var chosenStation))
  22. return;
  23. if (!TryComp<StationDataComponent>(chosenStation, out var stationData))
  24. return;
  25. var grid = StationSystem.GetLargestGrid(stationData);
  26. if (grid is null)
  27. return;
  28. var amountToSpawn = 1;
  29. for (var i = 0; i < amountToSpawn; i++)
  30. {
  31. _anomaly.SpawnOnRandomGridLocation(grid.Value, component.AnomalySpawnerPrototype);
  32. }
  33. }
  34. }