-
Notifications
You must be signed in to change notification settings - Fork 294
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
make midround antag spawn code better (#919)
* kill shitcode * give each midround antag its own spawn rule * using * break test real * typographical error --------- Co-authored-by: deltanedas <@deltanedas:kde.org>
- Loading branch information
1 parent
8183085
commit 1d24249
Showing
3 changed files
with
63 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
51 changes: 34 additions & 17 deletions
51
Content.Server/Nyanotrasen/StationEvents/Events/MidRoundAntagRule.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters