Files
tbd-station-14/Content.Server/StationEvents/Events/AnomalySpawnRule.cs
Moony e92a8fedab Refactor stations to properly use entity prototypes. (stationsv3) (#16570)
* Update StationSpawningSystem.cs

Web-edit to allow feeding in an existing entity.

* Update StationSpawningSystem.cs

value type moment

* Update StationSpawningSystem.cs

* Oh goddamnit this is a refactor now.

* awawawa

* aaaaaaaaaaa

* ee

* forgot records.

* no records? no records.

* What's in a name?

* Sloth forcing me to do the refactor properly smh.

* e

* optional evac in test.

* tests pls work

* awa

---------

Co-authored-by: moonheart08 <moonheart08@users.noreply.github.com>
2023-05-19 15:45:09 -05:00

49 lines
1.7 KiB
C#

using System.Linq;
using Content.Server.Anomaly;
using Content.Server.GameTicking.Rules.Components;
using Content.Server.Station.Components;
using Content.Server.StationEvents.Components;
using Robust.Shared.Random;
namespace Content.Server.StationEvents.Events;
public sealed class AnomalySpawnRule : StationEventSystem<AnomalySpawnRuleComponent>
{
[Dependency] private readonly AnomalySystem _anomaly = default!;
protected override void Added(EntityUid uid, AnomalySpawnRuleComponent component, GameRuleComponent gameRule, GameRuleAddedEvent args)
{
base.Added(uid, component, gameRule, args);
var str = Loc.GetString("anomaly-spawn-event-announcement",
("sighting", Loc.GetString($"anomaly-spawn-sighting-{RobustRandom.Next(1, 6)}")));
ChatSystem.DispatchGlobalAnnouncement(str, colorOverride: Color.FromHex("#18abf5"));
}
protected override void Started(EntityUid uid, AnomalySpawnRuleComponent component, GameRuleComponent gameRule, GameRuleStartedEvent args)
{
base.Started(uid, component, gameRule, args);
if (!TryGetRandomStation(out var chosenStation))
return;
if (!TryComp<StationDataComponent>(chosenStation, out var stationData))
return;
EntityUid? grid = null;
foreach (var g in stationData.Grids.Where(HasComp<BecomesStationComponent>))
{
grid = g;
}
if (grid is not { })
return;
var amountToSpawn = Math.Max(1, (int) MathF.Round(GetSeverityModifier() / 2));
for (var i = 0; i < amountToSpawn; i++)
{
_anomaly.SpawnOnRandomGridLocation(grid.Value, component.AnomalySpawnerPrototype);
}
}
}