Files
wwdpublic/Content.Server/StationEvents/Events/AnomalySpawnRule.cs
2024-11-21 17:49:04 +07:00

52 lines
1.7 KiB
C#
Raw Blame History

This file contains invisible Unicode characters
This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
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);
}
}
}