SS-28662 Add cvars to support forcing people to departures and making those at departures invincible (#28765)

* SS-28662 Add cvar to force spawn everyone at departures

This cvar means everyone must spawn at departures. This
could be handy for an admin event? But mostly it's so the
tutorial departures terminal can be seen by all newbies on
gateway servers.

* Small fix to ArrivalsSystem flow

* Remove incorrect todo

* Add godmode arrivals cvar
This commit is contained in:
Hannah Giovanna Dawson
2024-06-14 12:15:42 +01:00
committed by GitHub
parent e70131e5b4
commit 3b3163c4f4
3 changed files with 71 additions and 28 deletions

View File

@@ -15,6 +15,7 @@ using Content.Server.Station.Events;
using Content.Server.Station.Systems;
using Content.Shared.Administration;
using Content.Shared.CCVar;
using Content.Shared.Damage.Components;
using Content.Shared.DeviceNetwork;
using Content.Shared.Mobs.Components;
using Content.Shared.Movement.Components;
@@ -63,6 +64,16 @@ public sealed class ArrivalsSystem : EntitySystem
/// </summary>
public bool Enabled { get; private set; }
/// <summary>
/// Flags if all players must arrive via the Arrivals system, or if they can spawn in other ways.
/// </summary>
public bool Forced { get; private set; }
/// <summary>
/// Flags if all players spawning at the departure terminal have godmode until they leave the terminal.
/// </summary>
public bool ArrivalsGodmode { get; private set; }
/// <summary>
/// The first arrival is a little early, to save everyone 10s
/// </summary>
@@ -94,7 +105,12 @@ public sealed class ArrivalsSystem : EntitySystem
// Don't invoke immediately as it will get set in the natural course of things.
Enabled = _cfgManager.GetCVar(CCVars.ArrivalsShuttles);
Subs.CVar(_cfgManager, CCVars.ArrivalsShuttles, SetArrivals);
Forced = _cfgManager.GetCVar(CCVars.ForceArrivals);
ArrivalsGodmode = _cfgManager.GetCVar(CCVars.GodmodeArrivals);
_cfgManager.OnValueChanged(CCVars.ArrivalsShuttles, SetArrivals);
_cfgManager.OnValueChanged(CCVars.ForceArrivals, b => Forced = b);
_cfgManager.OnValueChanged(CCVars.GodmodeArrivals, b => ArrivalsGodmode = b);
// Command so admins can set these for funsies
_console.RegisterCommand("arrivals", ArrivalsCommand, ArrivalsCompletion);
@@ -250,6 +266,9 @@ public sealed class ArrivalsSystem : EntitySystem
// The player has successfully left arrivals and is also not on the shuttle. Remove their warp coupon.
RemCompDeferred<PendingClockInComponent>(pUid);
RemCompDeferred<AutoOrientComponent>(pUid);
if (ArrivalsGodmode)
RemCompDeferred<GodmodeComponent>(pUid);
}
}
@@ -309,7 +328,7 @@ public sealed class ArrivalsSystem : EntitySystem
return;
// Only works on latejoin even if enabled.
if (!Enabled || _ticker.RunLevel != GameRunLevel.InRound)
if (!Enabled || !Forced && _ticker.RunLevel != GameRunLevel.InRound)
return;
if (!HasComp<StationArrivalsComponent>(ev.Station))
@@ -317,33 +336,37 @@ public sealed class ArrivalsSystem : EntitySystem
TryGetArrivals(out var arrivals);
if (TryComp(arrivals, out TransformComponent? arrivalsXform))
if (!TryComp(arrivals, out TransformComponent? arrivalsXform))
return;
var mapId = arrivalsXform.MapID;
var points = EntityQueryEnumerator<SpawnPointComponent, TransformComponent>();
var possiblePositions = new List<EntityCoordinates>();
while (points.MoveNext(out var uid, out var spawnPoint, out var xform))
{
var mapId = arrivalsXform.MapID;
if (spawnPoint.SpawnType != SpawnPointType.LateJoin || xform.MapID != mapId)
continue;
var points = EntityQueryEnumerator<SpawnPointComponent, TransformComponent>();
var possiblePositions = new List<EntityCoordinates>();
while (points.MoveNext(out var uid, out var spawnPoint, out var xform))
{
if (spawnPoint.SpawnType != SpawnPointType.LateJoin || xform.MapID != mapId)
continue;
possiblePositions.Add(xform.Coordinates);
}
if (possiblePositions.Count > 0)
{
var spawnLoc = _random.Pick(possiblePositions);
ev.SpawnResult = _stationSpawning.SpawnPlayerMob(
spawnLoc,
ev.Job,
ev.HumanoidCharacterProfile,
ev.Station);
EnsureComp<PendingClockInComponent>(ev.SpawnResult.Value);
EnsureComp<AutoOrientComponent>(ev.SpawnResult.Value);
}
possiblePositions.Add(xform.Coordinates);
}
if (possiblePositions.Count <= 0)
return;
var spawnLoc = _random.Pick(possiblePositions);
ev.SpawnResult = _stationSpawning.SpawnPlayerMob(
spawnLoc,
ev.Job,
ev.HumanoidCharacterProfile,
ev.Station);
EnsureComp<PendingClockInComponent>(ev.SpawnResult.Value);
EnsureComp<AutoOrientComponent>(ev.SpawnResult.Value);
// If you're forced to spawn, you're invincible until you leave wherever you were forced to spawn.
if (ArrivalsGodmode)
EnsureComp<GodmodeComponent>(ev.SpawnResult.Value);
}
private bool TryTeleportToMapSpawn(EntityUid player, EntityUid stationId, TransformComponent? transform = null)

View File

@@ -65,7 +65,15 @@ public sealed class StationSpawningSystem : SharedStationSpawningSystem
_spawnerCallbacks = new Dictionary<SpawnPriorityPreference, Action<PlayerSpawningEvent>>()
{
{ SpawnPriorityPreference.Arrivals, _arrivalsSystem.HandlePlayerSpawning },
{ SpawnPriorityPreference.Cryosleep, _containerSpawnPointSystem.HandlePlayerSpawning }
{
SpawnPriorityPreference.Cryosleep, ev =>
{
if (_arrivalsSystem.Forced)
_arrivalsSystem.HandlePlayerSpawning(ev);
else
_containerSpawnPointSystem.HandlePlayerSpawning(ev);
}
}
};
}
@@ -308,4 +316,4 @@ public sealed class PlayerSpawningEvent : EntityEventArgs
HumanoidCharacterProfile = humanoidCharacterProfile;
Station = station;
}
}
}

View File

@@ -1425,6 +1425,18 @@ namespace Content.Shared.CCVar
public static readonly CVarDef<bool> ArrivalsReturns =
CVarDef.Create("shuttle.arrivals_returns", false, CVar.SERVERONLY);
/// <summary>
/// Should all players be forced to spawn at departures, even on roundstart, even if their loadout says they spawn in cryo?
/// </summary>
public static readonly CVarDef<bool> ForceArrivals =
CVarDef.Create("shuttle.force_arrivals", false, CVar.SERVERONLY);
/// <summary>
/// Should all players who spawn at arrivals have godmode until they leave the map?
/// </summary>
public static readonly CVarDef<bool> GodmodeArrivals =
CVarDef.Create("shuttle.godmode_arrivals", false, CVar.SERVERONLY);
/// <summary>
/// Whether to automatically spawn escape shuttles.
/// </summary>