57 lines
1.8 KiB
C#
57 lines
1.8 KiB
C#
using Content.Server._White.StationEvents.Components;
|
|
using Content.Server.Antag;
|
|
using Content.Server.StationEvents.Components;
|
|
using Content.Server.StationEvents.Events;
|
|
using Content.Shared.GameTicking.Components;
|
|
using Content.Shared.Station.Components;
|
|
using Robust.Shared.Map;
|
|
|
|
namespace Content.Server._White.StationEvents.Events;
|
|
|
|
public sealed class VentSpawnRule : StationEventSystem<VentSpawnRuleComponent>
|
|
{
|
|
[Dependency] private readonly SharedTransformSystem _transform = default!;
|
|
|
|
public override void Initialize()
|
|
{
|
|
base.Initialize();
|
|
|
|
SubscribeLocalEvent<VentSpawnRuleComponent, AntagSelectLocationEvent>(OnSelectLocation);
|
|
}
|
|
|
|
protected override void Added(EntityUid uid, VentSpawnRuleComponent component, GameRuleComponent gameRule, GameRuleAddedEvent args)
|
|
{
|
|
base.Added(uid, component, gameRule, args);
|
|
|
|
if (!TryGetRandomStation(out var station))
|
|
{
|
|
ForceEndSelf(uid, gameRule);
|
|
return;
|
|
}
|
|
|
|
var locations = EntityQueryEnumerator<VentCritterSpawnLocationComponent, TransformComponent>();
|
|
var validLocations = new List<MapCoordinates>();
|
|
while (locations.MoveNext(out _, out _, out var transform))
|
|
{
|
|
if (CompOrNull<StationMemberComponent>(transform.GridUid)?.Station != station)
|
|
continue;
|
|
|
|
validLocations.Add(_transform.GetMapCoordinates(transform));
|
|
}
|
|
|
|
if (validLocations.Count == 0)
|
|
{
|
|
ForceEndSelf(uid, gameRule);
|
|
return;
|
|
}
|
|
|
|
component.Coords = validLocations;
|
|
}
|
|
|
|
private void OnSelectLocation(Entity<VentSpawnRuleComponent> ent, ref AntagSelectLocationEvent args)
|
|
{
|
|
if (ent.Comp.Coords is {} coords)
|
|
args.Coordinates.AddRange(coords);
|
|
}
|
|
}
|