mirror of
https://github.com/WWhiteDreamProject/wwdpublic.git
synced 2026-04-20 06:58:55 +03:00
52 lines
1.7 KiB
C#
52 lines
1.7 KiB
C#
using Content.Server.Anomaly;
|
||
using Content.Server.Announcements.Systems;
|
||
using Content.Server.Station.Components;
|
||
using Content.Server.StationEvents.Components;
|
||
using Content.Shared.GameTicking.Components;
|
||
using Robust.Shared.Player;
|
||
|
||
namespace Content.Server.StationEvents.Events;
|
||
|
||
public sealed class AnomalySpawnRule : StationEventSystem<AnomalySpawnRuleComponent>
|
||
{
|
||
[Dependency] private readonly AnomalySystem _anomaly = default!;
|
||
[Dependency] private readonly AnnouncerSystem _announcer = default!;
|
||
|
||
protected override void Added(EntityUid uid, AnomalySpawnRuleComponent component, GameRuleComponent gameRule, GameRuleAddedEvent args)
|
||
{
|
||
base.Added(uid, component, gameRule, args);
|
||
|
||
_announcer.SendAnnouncement(
|
||
_announcer.GetAnnouncementId(args.RuleId),
|
||
Filter.Broadcast(),
|
||
"anomaly-spawn-event-announcement",
|
||
null,
|
||
Color.FromHex("#18abf5"),
|
||
null, null,
|
||
("sighting", Loc.GetString($"anomaly-spawn-sighting-{RobustRandom.Next(1, 6)}"))
|
||
);
|
||
}
|
||
|
||
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;
|
||
|
||
var grid = StationSystem.GetLargestGrid(stationData);
|
||
|
||
if (grid is null)
|
||
return;
|
||
|
||
var amountToSpawn = 1;
|
||
for (var i = 0; i < amountToSpawn; i++)
|
||
{
|
||
_anomaly.SpawnOnRandomGridLocation(grid.Value, component.AnomalySpawnerPrototype);
|
||
}
|
||
}
|
||
}
|