Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

make midround antag spawn code better #919

Merged
merged 5 commits into from
Mar 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,9 @@ namespace Content.Server.StationEvents.Components;
[RegisterComponent, Access(typeof(MidRoundAntagRule))]
public sealed partial class MidRoundAntagRuleComponent : Component
{
[DataField("antags")]
public List<EntProtoId> MidRoundAntags = new()
{
"SpawnPointGhostRatKing",
//"SpawnPointGhostVampSpider",
//"SpawnPointGhostFugitive",
"SpawnPointGhostParadoxAnomaly"
};
/// <summary>
/// Spawner to create at a random mid round antag marker.
/// </summary>
[DataField(required: true)]
public EntProtoId Spawner = string.Empty;
}
Original file line number Diff line number Diff line change
@@ -1,38 +1,55 @@
using Content.Server.GameTicking.Rules.Components;
using Content.Server.StationEvents.Components;
using Robust.Shared.Random;
using System.Linq;

namespace Content.Server.StationEvents.Events;

public sealed class MidRoundAntagRule : StationEventSystem<MidRoundAntagRuleComponent>
{
[Dependency] private readonly IRobustRandom _random = default!;

protected override void Started(EntityUid uid, MidRoundAntagRuleComponent component, GameRuleComponent gameRule, GameRuleStartedEvent args)
{
base.Started(uid, component, gameRule, args);

var spawnLocations = EntityQuery<MidRoundAntagSpawnLocationComponent, TransformComponent>().ToList();
var backupSpawnLocations = EntityQuery<VentCritterSpawnLocationComponent, TransformComponent>().ToList();

TransformComponent? spawn = new();
if (!TryGetRandomStation(out var station))
return;

if (spawnLocations.Count > 0)
{
var spawnLoc = _random.Pick(spawnLocations);
spawn = spawnLoc.Item2;
} else if (backupSpawnLocations.Count > 0)
var spawnLocations = FindSpawns(station.Value);
if (spawnLocations.Count == 0)
{
var spawnLoc = _random.Pick(backupSpawnLocations);
spawn = spawnLoc.Item2;
Log.Warning("Couldn't find any midround antag spawners or vent critter spawners, not spawning an antag.");
return;
}

if (spawn?.GridUid == null)
return;
var spawn = RobustRandom.Pick(spawnLocations);

var proto = _random.Pick(component.MidRoundAntags);
var proto = component.Spawner;
Log.Info($"Spawning midround antag {proto} at {spawn.Coordinates}");
Spawn(proto, spawn.Coordinates);
}

private List<TransformComponent> FindSpawns(EntityUid station)
{
var spawns = new List<TransformComponent>();
var query = EntityQueryEnumerator<MidRoundAntagSpawnLocationComponent, TransformComponent>();
while (query.MoveNext(out var uid, out _, out var xform))
{
if (StationSystem.GetOwningStation(uid, xform) == station && xform.GridUid != null)
spawns.Add(xform);
}

// if there are any midround antag spawns mapped, use them
if (spawns.Count > 0)
return spawns;

// otherwise, fall back to vent critter spawns
Log.Info($"Station {ToPrettyString(station):station} has no midround antag spawnpoints mapped, falling back. Please map them!");
var fallbackQuery = EntityQueryEnumerator<VentCritterSpawnLocationComponent, TransformComponent>();
while (fallbackQuery.MoveNext(out var uid, out _, out var xform))
{
if (StationSystem.GetOwningStation(uid, xform) == station && xform.GridUid != null)
spawns.Add(xform);
}

return spawns;
}
}
32 changes: 24 additions & 8 deletions Resources/Prototypes/Nyanotrasen/GameRules/events.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,34 @@
earliestStart: 15
- type: NoosphericStormRule

# Rat king and paradox anomaly.
# Mid round antag spawns
- type: entity
id: MidRoundAntag
abstract: true
parent: BaseGameRule
id: BaseMidRoundAntag
components:
- type: StationEvent
weight: 7
reoccurrenceDelay: 5
minimumPlayers: 15
earliestStart: 25
- type: MidRoundAntagRule

- type: entity
noSpawn: true
parent: BaseMidRoundAntag
id: RatKingSpawn
components:
- type: StationEvent
weight: 7
reoccurrenceDelay: 5
minimumPlayers: 15
earliestStart: 25
- type: MidRoundAntagRule
- type: MidRoundAntagRule
spawner: SpawnPointGhostRatKing

- type: entity
noSpawn: true
parent: BaseMidRoundAntag
id: ParadoxAnomalySpawn
components:
- type: MidRoundAntagRule
spawner: SpawnPointGhostParadoxAnomaly

# Base glimmer event
- type: entity
Expand Down
Loading