NukeOps game rule tweaks (#10005)
Co-authored-by: metalgearsloth <31366439+metalgearsloth@users.noreply.github.com>
This commit is contained in:
@@ -1,27 +1,28 @@
|
||||
using System.Linq;
|
||||
using Content.Server.CharacterAppearance.Components;
|
||||
using Content.Server.Chat.Managers;
|
||||
using Content.Server.GameTicking.Rules.Components;
|
||||
using Content.Server.GameTicking.Rules.Configurations;
|
||||
using Content.Server.Ghost.Roles.Components;
|
||||
using Content.Server.Ghost.Roles.Events;
|
||||
using Content.Server.Mind.Components;
|
||||
using Content.Server.Nuke;
|
||||
using Content.Server.Players;
|
||||
using Content.Server.RoundEnd;
|
||||
using Content.Server.Shuttles.Components;
|
||||
using Content.Server.Shuttles.Systems;
|
||||
using Content.Server.Spawners.Components;
|
||||
using Content.Server.Station.Systems;
|
||||
using Content.Shared.CCVar;
|
||||
using Content.Shared.MobState;
|
||||
using Content.Shared.Dataset;
|
||||
using Content.Shared.Roles;
|
||||
using Robust.Server.Maps;
|
||||
using Robust.Server.Player;
|
||||
using Robust.Shared.Configuration;
|
||||
using Robust.Shared.Map;
|
||||
using Robust.Shared.Prototypes;
|
||||
using Robust.Shared.Random;
|
||||
using Robust.Shared.Utility;
|
||||
using Content.Server.Traitor;
|
||||
using System.Data;
|
||||
using Content.Server.Traitor.Uplink;
|
||||
using Content.Shared.MobState.Components;
|
||||
using Robust.Shared.Audio;
|
||||
using Robust.Shared.Player;
|
||||
|
||||
@@ -31,23 +32,44 @@ public sealed class NukeopsRuleSystem : GameRuleSystem
|
||||
{
|
||||
[Dependency] private readonly IPrototypeManager _prototypeManager = default!;
|
||||
[Dependency] private readonly IRobustRandom _random = default!;
|
||||
[Dependency] private readonly IConfigurationManager _cfg = default!;
|
||||
[Dependency] private readonly IChatManager _chatManager = default!;
|
||||
[Dependency] private readonly IMapLoader _mapLoader = default!;
|
||||
[Dependency] private readonly IMapManager _mapManager = default!;
|
||||
[Dependency] private readonly StationSpawningSystem _stationSpawningSystem = default!;
|
||||
[Dependency] private readonly RoundEndSystem _roundEndSystem = default!;
|
||||
[Dependency] private readonly UplinkSystem _uplink = default!;
|
||||
[Dependency] private readonly IPlayerManager _playerSystem = default!;
|
||||
[Dependency] private readonly SharedAudioSystem _audioSystem = default!;
|
||||
|
||||
private Dictionary<Mind.Mind, bool> _aliveNukeops = new();
|
||||
private bool _opsWon;
|
||||
|
||||
private MapId? _nukiePlanet;
|
||||
private EntityUid? _nukieOutpost;
|
||||
private EntityUid? _nukieShuttle;
|
||||
|
||||
public override string Prototype => "Nukeops";
|
||||
|
||||
private readonly SoundSpecifier _greetSound = new SoundPathSpecifier("/Audio/Misc/nukeops.ogg");
|
||||
private NukeopsRuleConfiguration _nukeopsRuleConfig = new();
|
||||
|
||||
/// <summary>
|
||||
/// Cached starting gear prototypes.
|
||||
/// </summary>
|
||||
private readonly Dictionary<string, StartingGearPrototype> _startingGearPrototypes = new ();
|
||||
|
||||
/// <summary>
|
||||
/// Cached operator name prototypes.
|
||||
/// </summary>
|
||||
private readonly Dictionary<string, List<string>> _operativeNames = new();
|
||||
|
||||
/// <summary>
|
||||
/// Data to be used in <see cref="OnMindAdded"/> for an operative once the Mind has been added.
|
||||
/// </summary>
|
||||
private readonly Dictionary<EntityUid, string> _operativeMindPendingData = new();
|
||||
|
||||
/// <summary>
|
||||
/// Players who played as an operative at some point in the round.
|
||||
/// </summary>
|
||||
private readonly HashSet<IPlayerSession> _operativePlayers = new();
|
||||
|
||||
private const string NukeopsPrototypeId = "Nukeops";
|
||||
private const string NukeopsCommanderPrototypeId = "NukeopsCommander";
|
||||
|
||||
public override void Initialize()
|
||||
{
|
||||
@@ -55,9 +77,29 @@ public sealed class NukeopsRuleSystem : GameRuleSystem
|
||||
|
||||
SubscribeLocalEvent<RoundStartAttemptEvent>(OnStartAttempt);
|
||||
SubscribeLocalEvent<RulePlayerSpawningEvent>(OnPlayersSpawning);
|
||||
SubscribeLocalEvent<MobStateChangedEvent>(OnMobStateChanged);
|
||||
SubscribeLocalEvent<NukeOperativeComponent, MobStateChangedEvent>(OnMobStateChanged);
|
||||
SubscribeLocalEvent<RoundEndTextAppendEvent>(OnRoundEndText);
|
||||
SubscribeLocalEvent<NukeExplodedEvent>(OnNukeExploded);
|
||||
SubscribeLocalEvent<NukeOperativeComponent, GhostRoleSpawnerUsedEvent>(OnPlayersGhostSpawning);
|
||||
SubscribeLocalEvent<NukeOperativeComponent, MindAddedMessage>(OnMindAdded);
|
||||
SubscribeLocalEvent<NukeOperativeComponent, ComponentInit>(OnComponentInit);
|
||||
SubscribeLocalEvent<NukeOperativeComponent, ComponentRemove>(OnComponentRemove);
|
||||
}
|
||||
|
||||
private void OnComponentInit(EntityUid uid, NukeOperativeComponent component, ComponentInit args)
|
||||
{
|
||||
// If entity has a prior mind attached, add them to the players list.
|
||||
if (!TryComp<MindComponent>(uid, out var mindComponent) || !RuleAdded)
|
||||
return;
|
||||
|
||||
var session = mindComponent.Mind?.Session;
|
||||
if (session != null)
|
||||
_operativePlayers.Add(session);
|
||||
}
|
||||
|
||||
private void OnComponentRemove(EntityUid uid, NukeOperativeComponent component, ComponentRemove args)
|
||||
{
|
||||
CheckRoundShouldEnd();
|
||||
}
|
||||
|
||||
private void OnNukeExploded(NukeExplodedEvent ev)
|
||||
@@ -76,25 +118,44 @@ public sealed class NukeopsRuleSystem : GameRuleSystem
|
||||
|
||||
ev.AddLine(_opsWon ? Loc.GetString("nukeops-ops-won") : Loc.GetString("nukeops-crew-won"));
|
||||
ev.AddLine(Loc.GetString("nukeops-list-start"));
|
||||
foreach (var nukeop in _aliveNukeops)
|
||||
foreach (var nukeop in _operativePlayers)
|
||||
{
|
||||
ev.AddLine($"- {nukeop.Key.Session?.Name}");
|
||||
ev.AddLine($"- {nukeop.Name}");
|
||||
}
|
||||
}
|
||||
|
||||
private void OnMobStateChanged(MobStateChangedEvent ev)
|
||||
private void CheckRoundShouldEnd()
|
||||
{
|
||||
if (!RuleAdded)
|
||||
return;
|
||||
|
||||
if (!_aliveNukeops.TryFirstOrNull(x => x.Key.OwnedEntity == ev.Entity, out var op)) return;
|
||||
MapId? shuttleMapId = EntityManager.EntityExists(_nukieShuttle)
|
||||
? Transform(_nukieShuttle!.Value).MapID
|
||||
: null;
|
||||
|
||||
_aliveNukeops[op.Value.Key] = op.Value.Key.CharacterDeadIC;
|
||||
// Check if there are nuke operatives still alive on the same map as the shuttle.
|
||||
// If there are, the round can continue.
|
||||
var operatives = EntityQuery<NukeOperativeComponent, MobStateComponent, TransformComponent>(true);
|
||||
var operativesAlive = operatives
|
||||
.Where(ent => ent.Item3.MapID == shuttleMapId)
|
||||
.Any(ent => ent.Item2.CurrentState == DamageState.Alive && ent.Item1.Running);
|
||||
|
||||
if (_aliveNukeops.Values.All(x => !x))
|
||||
{
|
||||
_roundEndSystem.EndRound();
|
||||
}
|
||||
if (operativesAlive)
|
||||
return; // There are living operatives than can access the shuttle.
|
||||
|
||||
// Check that there are spawns available and that they can access the shuttle.
|
||||
var spawnsAvailable = EntityQuery<NukeOperativeSpawnerComponent>(true).Any();
|
||||
if (spawnsAvailable && shuttleMapId == _nukiePlanet)
|
||||
return; // Ghost spawns can still access the shuttle. Continue the round.
|
||||
|
||||
// The shuttle is inaccessible to both living nuke operatives and yet to spawn nuke operatives.
|
||||
_roundEndSystem.EndRound();
|
||||
}
|
||||
|
||||
private void OnMobStateChanged(EntityUid uid, NukeOperativeComponent component, MobStateChangedEvent ev)
|
||||
{
|
||||
if(ev.CurrentMobState == DamageState.Dead)
|
||||
CheckRoundShouldEnd();
|
||||
}
|
||||
|
||||
private void OnPlayersSpawning(RulePlayerSpawningEvent ev)
|
||||
@@ -102,11 +163,9 @@ public sealed class NukeopsRuleSystem : GameRuleSystem
|
||||
if (!RuleAdded)
|
||||
return;
|
||||
|
||||
_aliveNukeops.Clear();
|
||||
|
||||
// Basically copied verbatim from traitor code
|
||||
var playersPerOperative = _cfg.GetCVar(CCVars.NukeopsPlayersPerOp);
|
||||
var maxOperatives = _cfg.GetCVar(CCVars.NukeopsMaxOps);
|
||||
var playersPerOperative = _nukeopsRuleConfig.PlayersPerOperative;
|
||||
var maxOperatives = _nukeopsRuleConfig.MaxOperatives;
|
||||
|
||||
var everyone = new List<IPlayerSession>(ev.PlayerPool);
|
||||
var prefList = new List<IPlayerSession>();
|
||||
@@ -122,11 +181,11 @@ public sealed class NukeopsRuleSystem : GameRuleSystem
|
||||
continue;
|
||||
}
|
||||
var profile = ev.Profiles[player.UserId];
|
||||
if (profile.AntagPreferences.Contains(NukeopsPrototypeId))
|
||||
if (profile.AntagPreferences.Contains(_nukeopsRuleConfig.OperativeRoleProto))
|
||||
{
|
||||
prefList.Add(player);
|
||||
}
|
||||
if (profile.AntagPreferences.Contains(NukeopsCommanderPrototypeId))
|
||||
if (profile.AntagPreferences.Contains(_nukeopsRuleConfig.CommanderRolePrototype))
|
||||
{
|
||||
cmdrPrefList.Add(player);
|
||||
}
|
||||
@@ -189,118 +248,226 @@ public sealed class NukeopsRuleSystem : GameRuleSystem
|
||||
operatives.Add(nukeOp);
|
||||
}
|
||||
|
||||
// TODO: Make this a prototype
|
||||
// so true PAUL!
|
||||
var path = "/Maps/nukieplanet.yml";
|
||||
var shuttlePath = "/Maps/infiltrator.yml";
|
||||
var mapId = _mapManager.CreateMap();
|
||||
SpawnOperatives(numNukies, operatives, false);
|
||||
|
||||
var (_, outpost) = _mapLoader.LoadGrid(mapId, "/Maps/nukieplanet.yml");
|
||||
|
||||
if (outpost == null)
|
||||
foreach(var session in operatives)
|
||||
{
|
||||
Logger.ErrorS("nukies", $"Error loading map {path} for nukies!");
|
||||
return;
|
||||
ev.PlayerPool.Remove(session);
|
||||
GameTicker.PlayerJoinGame(session);
|
||||
_operativePlayers.Add(session);
|
||||
}
|
||||
|
||||
if (_nukeopsRuleConfig.GreetSound == null)
|
||||
return;
|
||||
|
||||
_audioSystem.PlayGlobal(_nukeopsRuleConfig.GreetSound, Filter.Empty().AddPlayers(operatives), AudioParams.Default);
|
||||
}
|
||||
|
||||
private void OnPlayersGhostSpawning(EntityUid uid, NukeOperativeComponent component, GhostRoleSpawnerUsedEvent args)
|
||||
{
|
||||
var spawner = args.Spawner;
|
||||
|
||||
if (!TryComp<NukeOperativeSpawnerComponent>(spawner, out var nukeOpSpawner))
|
||||
return;
|
||||
|
||||
SetupOperativeEntity(uid, nukeOpSpawner.OperativeName, nukeOpSpawner.OperativeStartingGear);
|
||||
|
||||
_operativeMindPendingData.Add(uid, nukeOpSpawner.OperativeRolePrototype);
|
||||
}
|
||||
|
||||
private void OnMindAdded(EntityUid uid, NukeOperativeComponent component, MindAddedMessage args)
|
||||
{
|
||||
if (!TryComp<MindComponent>(uid, out var mindComponent) || mindComponent.Mind == null)
|
||||
return;
|
||||
|
||||
var mind = mindComponent.Mind;
|
||||
|
||||
if (_operativeMindPendingData.TryGetValue(uid, out var role))
|
||||
{
|
||||
mind.AddRole(new TraitorRole(mind, _prototypeManager.Index<AntagPrototype>(role)));
|
||||
_operativeMindPendingData.Remove(uid);
|
||||
}
|
||||
|
||||
if (!mind.TryGetSession(out var playerSession))
|
||||
return;
|
||||
|
||||
_operativePlayers.Add(playerSession);
|
||||
|
||||
if (_nukeopsRuleConfig.GreetSound != null)
|
||||
_audioSystem.PlayGlobal(_nukeopsRuleConfig.GreetSound, Filter.Empty().AddPlayer(playerSession), AudioParams.Default);
|
||||
}
|
||||
|
||||
private bool SpawnMap()
|
||||
{
|
||||
if (_nukiePlanet != null)
|
||||
return true; // Map is already loaded.
|
||||
|
||||
var path = _nukeopsRuleConfig.NukieOutpostMap;
|
||||
var shuttlePath = _nukeopsRuleConfig.NukieShuttleMap;
|
||||
if (path == null)
|
||||
{
|
||||
Logger.ErrorS("nukies", "No station map specified for nukeops!");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (shuttlePath == null)
|
||||
{
|
||||
Logger.ErrorS("nukies", "No shuttle map specified for nukeops!");
|
||||
return false;
|
||||
}
|
||||
|
||||
var mapId = _mapManager.CreateMap();
|
||||
|
||||
var (_, outpostGrids) = _mapLoader.LoadMap(mapId, path.ToString());
|
||||
if (outpostGrids.Count == 0)
|
||||
{
|
||||
Logger.ErrorS("nukies", $"Error loading map {path} for nukies!");
|
||||
return false;
|
||||
}
|
||||
|
||||
// Assume the first grid is the outpost grid.
|
||||
_nukieOutpost = outpostGrids[0];
|
||||
|
||||
// Listen I just don't want it to overlap.
|
||||
var (_, shuttleId) = _mapLoader.LoadGrid(mapId, shuttlePath, new MapLoadOptions()
|
||||
var (_, shuttleId) = _mapLoader.LoadGrid(mapId, shuttlePath.ToString(), new MapLoadOptions()
|
||||
{
|
||||
Offset = Vector2.One * 1000f,
|
||||
});
|
||||
|
||||
// Naughty, someone saved the shuttle as a map.
|
||||
if (Deleted(outpost))
|
||||
if (Deleted(shuttleId))
|
||||
{
|
||||
Logger.ErrorS("nukeops", $"Tried to load nukeops shuttle as a map, aborting.");
|
||||
_mapManager.DeleteMap(mapId);
|
||||
return;
|
||||
return false;
|
||||
}
|
||||
|
||||
if (TryComp<ShuttleComponent>(shuttleId, out var shuttle))
|
||||
{
|
||||
IoCManager.Resolve<IEntitySystemManager>().GetEntitySystem<ShuttleSystem>().TryFTLDock(shuttle, outpost.Value);
|
||||
IoCManager.Resolve<IEntitySystemManager>().GetEntitySystem<ShuttleSystem>().TryFTLDock(shuttle, _nukieOutpost.Value);
|
||||
}
|
||||
|
||||
// TODO: Loot table or something
|
||||
var commanderGear = _prototypeManager.Index<StartingGearPrototype>("SyndicateCommanderGearFull");
|
||||
var starterGear = _prototypeManager.Index<StartingGearPrototype>("SyndicateOperativeGearFull");
|
||||
var medicGear = _prototypeManager.Index<StartingGearPrototype>("SyndicateOperativeMedicFull");
|
||||
var syndicateNamesElite = new List<string>(_prototypeManager.Index<DatasetPrototype>("SyndicateNamesElite").Values);
|
||||
var syndicateNamesNormal = new List<string>(_prototypeManager.Index<DatasetPrototype>("SyndicateNamesNormal").Values);
|
||||
_nukiePlanet = mapId;
|
||||
_nukieShuttle = shuttleId;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
private (string Name, string Role, string Gear) GetOperativeSpawnDetails(int spawnNumber)
|
||||
{
|
||||
string name;
|
||||
string role;
|
||||
string gear;
|
||||
|
||||
// Spawn the Commander then Agent first.
|
||||
switch (spawnNumber)
|
||||
{
|
||||
case 0:
|
||||
name = $"Commander " + _random.PickAndTake(_operativeNames[_nukeopsRuleConfig.EliteNames]);
|
||||
role = _nukeopsRuleConfig.CommanderRolePrototype;
|
||||
gear = _nukeopsRuleConfig.CommanderStartGearPrototype;
|
||||
break;
|
||||
case 1:
|
||||
name = $"Agent " + _random.PickAndTake(_operativeNames[_nukeopsRuleConfig.NormalNames]);
|
||||
role = _nukeopsRuleConfig.OperativeRoleProto;
|
||||
gear = _nukeopsRuleConfig.MedicStartGearPrototype;
|
||||
break;
|
||||
default:
|
||||
name = $"Operator " + _random.PickAndTake(_operativeNames[_nukeopsRuleConfig.NormalNames]);
|
||||
role = _nukeopsRuleConfig.OperativeRoleProto;
|
||||
gear = _nukeopsRuleConfig.OperativeStartGearPrototype;
|
||||
break;
|
||||
}
|
||||
|
||||
return (name, role, gear);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Adds missing nuke operative components, equips starting gear and renames the entity.
|
||||
/// </summary>
|
||||
private void SetupOperativeEntity(EntityUid mob, string name, string gear)
|
||||
{
|
||||
EntityManager.GetComponent<MetaDataComponent>(mob).EntityName = name;
|
||||
EntityManager.EnsureComponent<RandomHumanoidAppearanceComponent>(mob);
|
||||
EntityManager.EnsureComponent<NukeOperativeComponent>(mob);
|
||||
|
||||
if(_startingGearPrototypes.TryGetValue(gear, out var gearPrototype))
|
||||
_stationSpawningSystem.EquipStartingGear(mob, gearPrototype, null);
|
||||
}
|
||||
|
||||
private void SpawnOperatives(int spawnCount, List<IPlayerSession> sessions, bool addSpawnPoints)
|
||||
{
|
||||
if (_nukieOutpost == null)
|
||||
return;
|
||||
|
||||
var outpostUid = _nukieOutpost.Value;
|
||||
var spawns = new List<EntityCoordinates>();
|
||||
|
||||
// Forgive me for hardcoding prototypes
|
||||
foreach (var (_, meta, xform) in EntityManager.EntityQuery<SpawnPointComponent, MetaDataComponent, TransformComponent>(true))
|
||||
{
|
||||
if (meta.EntityPrototype?.ID != "SpawnPointNukies") continue;
|
||||
if (meta.EntityPrototype?.ID != _nukeopsRuleConfig.SpawnPointPrototype)
|
||||
continue;
|
||||
|
||||
if (xform.ParentUid == outpost)
|
||||
{
|
||||
spawns.Add(xform.Coordinates);
|
||||
break;
|
||||
}
|
||||
if (xform.ParentUid != _nukieOutpost)
|
||||
continue;
|
||||
|
||||
spawns.Add(xform.Coordinates);
|
||||
break;
|
||||
}
|
||||
|
||||
if (spawns.Count == 0)
|
||||
{
|
||||
spawns.Add(EntityManager.GetComponent<TransformComponent>(outpost.Value).Coordinates);
|
||||
spawns.Add(EntityManager.GetComponent<TransformComponent>(outpostUid).Coordinates);
|
||||
Logger.WarningS("nukies", $"Fell back to default spawn for nukies!");
|
||||
}
|
||||
|
||||
// TODO: This should spawn the nukies in regardless and transfer if possible; rest should go to shot roles.
|
||||
for (var i = 0; i < operatives.Count; i++)
|
||||
for(var i = 0; i < spawnCount; i++)
|
||||
{
|
||||
string name;
|
||||
string role;
|
||||
StartingGearPrototype gear;
|
||||
var spawnDetails = GetOperativeSpawnDetails(i);
|
||||
var nukeOpsAntag = _prototypeManager.Index<AntagPrototype>(spawnDetails.Role);
|
||||
|
||||
switch (i)
|
||||
if (sessions.TryGetValue(i, out var session))
|
||||
{
|
||||
case 0:
|
||||
name = $"Commander " + _random.PickAndTake<string>(syndicateNamesElite);
|
||||
role = NukeopsCommanderPrototypeId;
|
||||
gear = commanderGear;
|
||||
break;
|
||||
case 1:
|
||||
name = $"Agent " + _random.PickAndTake<string>(syndicateNamesNormal);
|
||||
role = NukeopsPrototypeId;
|
||||
gear = medicGear;
|
||||
break;
|
||||
default:
|
||||
name = $"Operator " + _random.PickAndTake<string>(syndicateNamesNormal);
|
||||
role = NukeopsPrototypeId;
|
||||
gear = starterGear;
|
||||
break;
|
||||
var mob = EntityManager.SpawnEntity(_nukeopsRuleConfig.SpawnEntityPrototype, _random.Pick(spawns));
|
||||
SetupOperativeEntity(mob, spawnDetails.Name, spawnDetails.Gear);
|
||||
|
||||
var newMind = new Mind.Mind(session.UserId)
|
||||
{
|
||||
CharacterName = spawnDetails.Name
|
||||
};
|
||||
newMind.ChangeOwningPlayer(session.UserId);
|
||||
newMind.AddRole(new TraitorRole(newMind, nukeOpsAntag));
|
||||
|
||||
newMind.TransferTo(mob);
|
||||
}
|
||||
|
||||
var session = operatives[i];
|
||||
var newMind = new Mind.Mind(session.UserId)
|
||||
else if (addSpawnPoints)
|
||||
{
|
||||
CharacterName = name
|
||||
};
|
||||
newMind.ChangeOwningPlayer(session.UserId);
|
||||
newMind.AddRole(new TraitorRole(newMind, _prototypeManager.Index<AntagPrototype>(role)));
|
||||
var spawnPoint = EntityManager.SpawnEntity(_nukeopsRuleConfig.GhostSpawnPointProto, _random.Pick(spawns));
|
||||
var spawner = EnsureComp<GhostRoleMobSpawnerComponent>(spawnPoint);
|
||||
spawner.RoleName = nukeOpsAntag.Name;
|
||||
spawner.RoleDescription = nukeOpsAntag.Objective;
|
||||
|
||||
var mob = EntityManager.SpawnEntity("MobHuman", _random.Pick(spawns));
|
||||
EntityManager.GetComponent<MetaDataComponent>(mob).EntityName = name;
|
||||
EntityManager.AddComponent<RandomHumanoidAppearanceComponent>(mob);
|
||||
|
||||
newMind.TransferTo(mob);
|
||||
_stationSpawningSystem.EquipStartingGear(mob, gear, null);
|
||||
|
||||
ev.PlayerPool.Remove(session);
|
||||
_aliveNukeops.Add(newMind, true);
|
||||
|
||||
GameTicker.PlayerJoinGame(session);
|
||||
var nukeOpSpawner = EnsureComp<NukeOperativeSpawnerComponent>(spawnPoint);
|
||||
nukeOpSpawner.OperativeName = spawnDetails.Name;
|
||||
nukeOpSpawner.OperativeRolePrototype = spawnDetails.Role;
|
||||
nukeOpSpawner.OperativeStartingGear = spawnDetails.Gear;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
SoundSystem.Play(_greetSound.GetSound(), Filter.Empty().AddWhere(s =>
|
||||
{
|
||||
var mind = ((IPlayerSession) s).Data.ContentData()?.Mind;
|
||||
return mind != null && _aliveNukeops.ContainsKey(mind);
|
||||
}), AudioParams.Default);
|
||||
private void SpawnOperativesForGhostRoles()
|
||||
{
|
||||
// Basically copied verbatim from traitor code
|
||||
var playersPerOperative = _nukeopsRuleConfig.PlayersPerOperative;
|
||||
var maxOperatives = _nukeopsRuleConfig.MaxOperatives;
|
||||
|
||||
var playerPool = _playerSystem.ServerSessions.ToList();
|
||||
var numNukies = MathHelper.Clamp(playerPool.Count / playersPerOperative, 1, maxOperatives);
|
||||
|
||||
var operatives = new List<IPlayerSession>();
|
||||
SpawnOperatives(numNukies, operatives, true);
|
||||
}
|
||||
|
||||
//For admins forcing someone to nukeOps.
|
||||
@@ -309,7 +476,7 @@ public sealed class NukeopsRuleSystem : GameRuleSystem
|
||||
if (!mind.OwnedEntity.HasValue)
|
||||
return;
|
||||
|
||||
mind.AddRole(new TraitorRole(mind, _prototypeManager.Index<AntagPrototype>(NukeopsPrototypeId)));
|
||||
mind.AddRole(new TraitorRole(mind, _prototypeManager.Index<AntagPrototype>(_nukeopsRuleConfig.OperativeRoleProto)));
|
||||
_stationSpawningSystem.EquipStartingGear(mind.OwnedEntity.Value, _prototypeManager.Index<StartingGearPrototype>("SyndicateOperativeGearFull"), null);
|
||||
}
|
||||
|
||||
@@ -318,7 +485,7 @@ public sealed class NukeopsRuleSystem : GameRuleSystem
|
||||
if (!RuleAdded)
|
||||
return;
|
||||
|
||||
var minPlayers = _cfg.GetCVar(CCVars.NukeopsMinPlayers);
|
||||
var minPlayers = _nukeopsRuleConfig.MinPlayers;
|
||||
if (!ev.Forced && ev.Players.Length < minPlayers)
|
||||
{
|
||||
_chatManager.DispatchServerAnnouncement(Loc.GetString("nukeops-not-enough-ready-players", ("readyPlayersCount", ev.Players.Length), ("minimumPlayers", minPlayers)));
|
||||
@@ -326,17 +493,60 @@ public sealed class NukeopsRuleSystem : GameRuleSystem
|
||||
return;
|
||||
}
|
||||
|
||||
if (ev.Players.Length == 0)
|
||||
{
|
||||
_chatManager.DispatchServerAnnouncement(Loc.GetString("nukeops-no-one-ready"));
|
||||
ev.Cancel();
|
||||
if (ev.Players.Length != 0)
|
||||
return;
|
||||
}
|
||||
|
||||
_chatManager.DispatchServerAnnouncement(Loc.GetString("nukeops-no-one-ready"));
|
||||
ev.Cancel();
|
||||
}
|
||||
|
||||
public override void Started()
|
||||
{
|
||||
_opsWon = false;
|
||||
_nukieOutpost = null;
|
||||
_nukiePlanet = null;
|
||||
|
||||
_startingGearPrototypes.Clear();
|
||||
_operativeNames.Clear();
|
||||
_operativeMindPendingData.Clear();
|
||||
_operativePlayers.Clear();
|
||||
|
||||
if (Configuration is not NukeopsRuleConfiguration)
|
||||
return;
|
||||
|
||||
// TODO: Loot table or something
|
||||
foreach (var proto in new[]
|
||||
{
|
||||
_nukeopsRuleConfig.CommanderStartGearPrototype,
|
||||
_nukeopsRuleConfig.MedicStartGearPrototype,
|
||||
_nukeopsRuleConfig.OperativeStartGearPrototype
|
||||
})
|
||||
{
|
||||
_startingGearPrototypes.Add(proto, _prototypeManager.Index<StartingGearPrototype>(proto));
|
||||
}
|
||||
|
||||
foreach (var proto in new[] { _nukeopsRuleConfig.EliteNames, _nukeopsRuleConfig.NormalNames })
|
||||
{
|
||||
_operativeNames.Add(proto, new List<string>(_prototypeManager.Index<DatasetPrototype>(proto).Values));
|
||||
}
|
||||
|
||||
|
||||
if (!SpawnMap())
|
||||
{
|
||||
Logger.InfoS("nukies", "Failed to load map for nukeops");
|
||||
return;
|
||||
}
|
||||
|
||||
// Add pre-existing nuke operatives to the credit list.
|
||||
var query = EntityQuery<NukeOperativeComponent, MindComponent>(true);
|
||||
foreach (var (_, mindComp) in query)
|
||||
{
|
||||
if (mindComp.Mind?.TryGetSession(out var session) == true)
|
||||
_operativePlayers.Add(session);
|
||||
}
|
||||
|
||||
if (GameTicker.RunLevel == GameRunLevel.InRound)
|
||||
SpawnOperativesForGhostRoles();
|
||||
}
|
||||
|
||||
public override void Ended() { }
|
||||
|
||||
Reference in New Issue
Block a user