Mega Antag Refactor (#25786)

* Mega Antag Refactor

* last minute delta save

* more workshopping

* more shit

* ok tested this for once

* okkkkk sure

* generic delays for starting rules

* well darn

* nukies partially

* ouagh

* ballin' faded and smonkin wed

* obliterated the diff

* Spread my arms and soak up congratulations

* I've got plenty of love, but nothing to show for it

* but there’s too much sunlight
Shining on my laptop monitor, so I
Can’t see anything with any amount of clarity

* ok this junk

* OOK!

* fubar

* most of sloth's review

* oh boy

* eek

* hell yea!

* ASDFJASDJFvsakcvjkzjnhhhyh
This commit is contained in:
Nemanja
2024-04-24 21:31:45 -04:00
committed by GitHub
parent 771661f478
commit 161fd6c83c
99 changed files with 1931 additions and 2310 deletions

View File

@@ -1,31 +1,20 @@
using Content.Server.Administration.Commands;
using Content.Server.Administration.Managers;
using Content.Server.Antag;
using Content.Server.Communications;
using Content.Server.GameTicking.Rules.Components;
using Content.Server.Ghost.Roles.Components;
using Content.Server.Ghost.Roles.Events;
using Content.Server.Humanoid;
using Content.Server.Mind;
using Content.Server.Nuke;
using Content.Server.NukeOps;
using Content.Server.Popups;
using Content.Server.Preferences.Managers;
using Content.Server.RandomMetadata;
using Content.Server.Roles;
using Content.Server.RoundEnd;
using Content.Server.Shuttles.Events;
using Content.Server.Shuttles.Systems;
using Content.Server.Spawners.Components;
using Content.Server.Station.Components;
using Content.Server.Station.Systems;
using Content.Server.Store.Components;
using Content.Server.Store.Systems;
using Content.Shared.CCVar;
using Content.Shared.Dataset;
using Content.Shared.Humanoid;
using Content.Shared.Humanoid.Prototypes;
using Content.Shared.Mind.Components;
using Content.Shared.Mobs;
using Content.Shared.Mobs.Components;
using Content.Shared.NPC.Components;
@@ -33,45 +22,30 @@ using Content.Shared.NPC.Systems;
using Content.Shared.Nuke;
using Content.Shared.NukeOps;
using Content.Shared.Preferences;
using Content.Shared.Roles;
using Content.Shared.Store;
using Content.Shared.Tag;
using Content.Shared.Zombies;
using Robust.Server.Player;
using Robust.Shared.Configuration;
using Robust.Shared.Map;
using Robust.Shared.Player;
using Robust.Shared.Prototypes;
using Robust.Shared.Random;
using Robust.Shared.Utility;
using System.Linq;
using Content.Server.GameTicking.Components;
namespace Content.Server.GameTicking.Rules;
public sealed class NukeopsRuleSystem : GameRuleSystem<NukeopsRuleComponent>
{
[Dependency] private readonly IMapManager _mapManager = default!;
[Dependency] private readonly IPlayerManager _playerManager = default!;
[Dependency] private readonly IPrototypeManager _prototypeManager = default!;
[Dependency] private readonly IServerPreferencesManager _prefs = default!;
[Dependency] private readonly IAdminManager _adminManager = default!;
[Dependency] private readonly IConfigurationManager _cfg = default!;
[Dependency] private readonly ILogManager _logManager = default!;
[Dependency] private readonly EmergencyShuttleSystem _emergency = default!;
[Dependency] private readonly HumanoidAppearanceSystem _humanoid = default!;
[Dependency] private readonly MetaDataSystem _metaData = default!;
[Dependency] private readonly RandomMetadataSystem _randomMetadata = default!;
[Dependency] private readonly MindSystem _mind = default!;
[Dependency] private readonly NpcFactionSystem _npcFaction = default!;
[Dependency] private readonly AntagSelectionSystem _antag = default!;
[Dependency] private readonly PopupSystem _popupSystem = default!;
[Dependency] private readonly RoundEndSystem _roundEndSystem = default!;
[Dependency] private readonly SharedRoleSystem _roles = default!;
[Dependency] private readonly StationSpawningSystem _stationSpawning = default!;
[Dependency] private readonly StoreSystem _store = default!;
[Dependency] private readonly TagSystem _tag = default!;
[Dependency] private readonly AntagSelectionSystem _antagSelection = default!;
private ISawmill _sawmill = default!;
[ValidatePrototypeId<CurrencyPrototype>]
private const string TelecrystalCurrencyPrototype = "Telecrystal";
@@ -79,141 +53,67 @@ public sealed class NukeopsRuleSystem : GameRuleSystem<NukeopsRuleComponent>
[ValidatePrototypeId<TagPrototype>]
private const string NukeOpsUplinkTagPrototype = "NukeOpsUplink";
[ValidatePrototypeId<AntagPrototype>]
public const string NukeopsId = "Nukeops";
[ValidatePrototypeId<DatasetPrototype>]
private const string OperationPrefixDataset = "operationPrefix";
[ValidatePrototypeId<DatasetPrototype>]
private const string OperationSuffixDataset = "operationSuffix";
public override void Initialize()
{
base.Initialize();
_sawmill = _logManager.GetSawmill("NukeOps");
SubscribeLocalEvent<RoundStartAttemptEvent>(OnStartAttempt);
SubscribeLocalEvent<RulePlayerSpawningEvent>(OnPlayersSpawning);
SubscribeLocalEvent<RoundEndTextAppendEvent>(OnRoundEndText);
SubscribeLocalEvent<NukeExplodedEvent>(OnNukeExploded);
SubscribeLocalEvent<GameRunLevelChangedEvent>(OnRunLevelChanged);
SubscribeLocalEvent<NukeDisarmSuccessEvent>(OnNukeDisarm);
SubscribeLocalEvent<NukeOperativeComponent, ComponentRemove>(OnComponentRemove);
SubscribeLocalEvent<NukeOperativeComponent, MobStateChangedEvent>(OnMobStateChanged);
SubscribeLocalEvent<NukeOperativeComponent, GhostRoleSpawnerUsedEvent>(OnPlayersGhostSpawning);
SubscribeLocalEvent<NukeOperativeComponent, MindAddedMessage>(OnMindAdded);
SubscribeLocalEvent<NukeOperativeComponent, EntityZombifiedEvent>(OnOperativeZombified);
SubscribeLocalEvent<NukeOpsShuttleComponent, MapInitEvent>(OnMapInit);
SubscribeLocalEvent<ConsoleFTLAttemptEvent>(OnShuttleFTLAttempt);
SubscribeLocalEvent<WarDeclaredEvent>(OnWarDeclared);
SubscribeLocalEvent<CommunicationConsoleCallShuttleAttemptEvent>(OnShuttleCallAttempt);
SubscribeLocalEvent<NukeopsRuleComponent, AntagSelectEntityEvent>(OnAntagSelectEntity);
SubscribeLocalEvent<NukeopsRuleComponent, AfterAntagEntitySelectedEvent>(OnAfterAntagEntSelected);
}
protected override void Started(EntityUid uid, NukeopsRuleComponent component, GameRuleComponent gameRule,
GameRuleStartedEvent args)
{
base.Started(uid, component, gameRule, args);
var eligible = new List<Entity<StationEventEligibleComponent, NpcFactionMemberComponent>>();
var eligibleQuery = EntityQueryEnumerator<StationEventEligibleComponent, NpcFactionMemberComponent>();
while (eligibleQuery.MoveNext(out var eligibleUid, out var eligibleComp, out var member))
{
if (!_npcFaction.IsFactionHostile(component.Faction, (eligibleUid, member)))
continue;
if (GameTicker.RunLevel == GameRunLevel.InRound)
SpawnOperativesForGhostRoles(uid, component);
eligible.Add((eligibleUid, eligibleComp, member));
}
if (eligible.Count == 0)
return;
component.TargetStation = RobustRandom.Pick(eligible);
}
#region Event Handlers
private void OnStartAttempt(RoundStartAttemptEvent ev)
protected override void AppendRoundEndText(EntityUid uid, NukeopsRuleComponent component, GameRuleComponent gameRule,
ref RoundEndTextAppendEvent args)
{
TryRoundStartAttempt(ev, Loc.GetString("nukeops-title"));
}
var winText = Loc.GetString($"nukeops-{component.WinType.ToString().ToLower()}");
args.AddLine(winText);
private void OnPlayersSpawning(RulePlayerSpawningEvent ev)
{
var query = QueryActiveRules();
while (query.MoveNext(out var uid, out _, out var nukeops, out _))
foreach (var cond in component.WinConditions)
{
if (!SpawnMap((uid, nukeops)))
{
_sawmill.Info("Failed to load map for nukeops");
continue;
}
//Handle there being nobody readied up
if (ev.PlayerPool.Count == 0)
continue;
var commanderEligible = _antagSelection.GetEligibleSessions(ev.PlayerPool, nukeops.CommanderSpawnDetails.AntagRoleProto);
var agentEligible = _antagSelection.GetEligibleSessions(ev.PlayerPool, nukeops.AgentSpawnDetails.AntagRoleProto);
var operativeEligible = _antagSelection.GetEligibleSessions(ev.PlayerPool, nukeops.OperativeSpawnDetails.AntagRoleProto);
//Calculate how large the nukeops team needs to be
var nukiesToSelect = _antagSelection.CalculateAntagCount(_playerManager.PlayerCount, nukeops.PlayersPerOperative, nukeops.MaxOps);
//Select Nukies
//Select Commander, priority : commanderEligible, agentEligible, operativeEligible, all players
var selectedCommander = _antagSelection.ChooseAntags(1, commanderEligible, agentEligible, operativeEligible, ev.PlayerPool).FirstOrDefault();
//Select Agent, priority : agentEligible, operativeEligible, all players
var selectedAgent = _antagSelection.ChooseAntags(1, agentEligible, operativeEligible, ev.PlayerPool).FirstOrDefault();
//Select Operatives, priority : operativeEligible, all players
var selectedOperatives = _antagSelection.ChooseAntags(nukiesToSelect - 2, operativeEligible, ev.PlayerPool);
//Create the team!
//If the session is null, they will be spawned as ghost roles (provided the cvar is set)
var operatives = new List<NukieSpawn> { new NukieSpawn(selectedCommander, nukeops.CommanderSpawnDetails) };
if (nukiesToSelect > 1)
operatives.Add(new NukieSpawn(selectedAgent, nukeops.AgentSpawnDetails));
for (var i = 0; i < nukiesToSelect - 2; i++)
{
//Use up all available sessions first, then spawn the rest as ghost roles (if enabled)
if (selectedOperatives.Count > i)
{
operatives.Add(new NukieSpawn(selectedOperatives[i], nukeops.OperativeSpawnDetails));
}
else
{
operatives.Add(new NukieSpawn(null, nukeops.OperativeSpawnDetails));
}
}
SpawnOperatives(operatives, _cfg.GetCVar(CCVars.NukeopsSpawnGhostRoles), nukeops);
foreach (var nukieSpawn in operatives)
{
if (nukieSpawn.Session == null)
continue;
GameTicker.PlayerJoinGame(nukieSpawn.Session);
}
}
}
private void OnRoundEndText(RoundEndTextAppendEvent ev)
{
var ruleQuery = QueryActiveRules();
while (ruleQuery.MoveNext(out _, out _, out var nukeops, out _))
{
var winText = Loc.GetString($"nukeops-{nukeops.WinType.ToString().ToLower()}");
ev.AddLine(winText);
foreach (var cond in nukeops.WinConditions)
{
var text = Loc.GetString($"nukeops-cond-{cond.ToString().ToLower()}");
ev.AddLine(text);
}
var text = Loc.GetString($"nukeops-cond-{cond.ToString().ToLower()}");
args.AddLine(text);
}
ev.AddLine(Loc.GetString("nukeops-list-start"));
args.AddLine(Loc.GetString("nukeops-list-start"));
var nukiesQuery = EntityQueryEnumerator<NukeopsRoleComponent, MindContainerComponent>();
while (nukiesQuery.MoveNext(out var nukeopsUid, out _, out var mindContainer))
var antags =_antag.GetAntagIdentifiers(uid);
foreach (var (_, sessionData, name) in antags)
{
if (!_mind.TryGetMind(nukeopsUid, out _, out var mind, mindContainer))
continue;
ev.AddLine(mind.Session != null
? Loc.GetString("nukeops-list-name-user", ("name", Name(nukeopsUid)), ("user", mind.Session.Name))
: Loc.GetString("nukeops-list-name", ("name", Name(nukeopsUid))));
args.AddLine(Loc.GetString("nukeops-list-name-user", ("name", name), ("user", sessionData.UserName)));
}
}
@@ -224,10 +124,10 @@ public sealed class NukeopsRuleSystem : GameRuleSystem<NukeopsRuleComponent>
{
if (ev.OwningStation != null)
{
if (ev.OwningStation == nukeops.NukieOutpost)
if (ev.OwningStation == GetOutpost(uid))
{
nukeops.WinConditions.Add(WinCondition.NukeExplodedOnNukieOutpost);
SetWinType(uid, WinType.CrewMajor, nukeops);
SetWinType((uid, nukeops), WinType.CrewMajor);
continue;
}
@@ -242,7 +142,7 @@ public sealed class NukeopsRuleSystem : GameRuleSystem<NukeopsRuleComponent>
}
nukeops.WinConditions.Add(WinCondition.NukeExplodedOnCorrectStation);
SetWinType(uid, WinType.OpsMajor, nukeops);
SetWinType((uid, nukeops), WinType.OpsMajor);
correctStation = true;
}
@@ -263,19 +163,85 @@ public sealed class NukeopsRuleSystem : GameRuleSystem<NukeopsRuleComponent>
private void OnRunLevelChanged(GameRunLevelChangedEvent ev)
{
if (ev.New is not GameRunLevel.PostRound)
return;
var query = QueryActiveRules();
while (query.MoveNext(out var uid, out _, out var nukeops, out _))
{
switch (ev.New)
OnRoundEnd((uid, nukeops));
}
}
private void OnRoundEnd(Entity<NukeopsRuleComponent> ent)
{
// If the win condition was set to operative/crew major win, ignore.
if (ent.Comp.WinType == WinType.OpsMajor || ent.Comp.WinType == WinType.CrewMajor)
return;
var nukeQuery = AllEntityQuery<NukeComponent, TransformComponent>();
var centcomms = _emergency.GetCentcommMaps();
while (nukeQuery.MoveNext(out var nuke, out var nukeTransform))
{
if (nuke.Status != NukeStatus.ARMED)
continue;
// UH OH
if (nukeTransform.MapUid != null && centcomms.Contains(nukeTransform.MapUid.Value))
{
case GameRunLevel.InRound:
OnRoundStart(uid, nukeops);
break;
case GameRunLevel.PostRound:
OnRoundEnd(uid, nukeops);
break;
ent.Comp.WinConditions.Add(WinCondition.NukeActiveAtCentCom);
SetWinType((ent, ent), WinType.OpsMajor);
return;
}
if (nukeTransform.GridUid == null || ent.Comp.TargetStation == null)
continue;
if (!TryComp(ent.Comp.TargetStation.Value, out StationDataComponent? data))
continue;
foreach (var grid in data.Grids)
{
if (grid != nukeTransform.GridUid)
continue;
ent.Comp.WinConditions.Add(WinCondition.NukeActiveInStation);
SetWinType(ent, WinType.OpsMajor);
return;
}
}
if (_antag.AllAntagsAlive(ent.Owner))
{
SetWinType(ent, WinType.OpsMinor);
ent.Comp.WinConditions.Add(WinCondition.AllNukiesAlive);
return;
}
ent.Comp.WinConditions.Add(_antag.AnyAliveAntags(ent.Owner)
? WinCondition.SomeNukiesAlive
: WinCondition.AllNukiesDead);
var diskAtCentCom = false;
var diskQuery = AllEntityQuery<NukeDiskComponent, TransformComponent>();
while (diskQuery.MoveNext(out _, out var transform))
{
diskAtCentCom = transform.MapUid != null && centcomms.Contains(transform.MapUid.Value);
// TODO: The target station should be stored, and the nuke disk should store its original station.
// This is fine for now, because we can assume a single station in base SS14.
break;
}
// If the disk is currently at Central Command, the crew wins - just slightly.
// This also implies that some nuclear operatives have died.
SetWinType(ent, diskAtCentCom
? WinType.CrewMinor
: WinType.OpsMinor);
ent.Comp.WinConditions.Add(diskAtCentCom
? WinCondition.NukeDiskOnCentCom
: WinCondition.NukeDiskNotOnCentCom);
}
private void OnNukeDisarm(NukeDisarmSuccessEvent ev)
@@ -294,66 +260,31 @@ public sealed class NukeopsRuleSystem : GameRuleSystem<NukeopsRuleComponent>
CheckRoundShouldEnd();
}
private void OnPlayersGhostSpawning(EntityUid uid, NukeOperativeComponent component, GhostRoleSpawnerUsedEvent args)
{
var spawner = args.Spawner;
if (!TryComp<NukeOperativeSpawnerComponent>(spawner, out var nukeOpSpawner))
return;
HumanoidCharacterProfile? profile = null;
if (TryComp(args.Spawned, out ActorComponent? actor))
profile = _prefs.GetPreferences(actor.PlayerSession.UserId).SelectedCharacter as HumanoidCharacterProfile;
// TODO: this is kinda awful for multi-nukies
foreach (var nukeops in EntityQuery<NukeopsRuleComponent>())
{
SetupOperativeEntity(uid, nukeOpSpawner.OperativeName, nukeOpSpawner.SpawnDetails, profile);
nukeops.OperativeMindPendingData.Add(uid, nukeOpSpawner.SpawnDetails.AntagRoleProto);
}
}
private void OnMindAdded(EntityUid uid, NukeOperativeComponent component, MindAddedMessage args)
{
if (!_mind.TryGetMind(uid, out var mindId, out var mind))
return;
var query = QueryActiveRules();
while (query.MoveNext(out _, out _, out var nukeops, out _))
{
if (nukeops.OperativeMindPendingData.TryGetValue(uid, out var role) || !nukeops.SpawnOutpost ||
nukeops.RoundEndBehavior == RoundEndBehavior.Nothing)
{
role ??= nukeops.OperativeSpawnDetails.AntagRoleProto;
_roles.MindAddRole(mindId, new NukeopsRoleComponent { PrototypeId = role });
nukeops.OperativeMindPendingData.Remove(uid);
}
if (mind.Session is not { } playerSession)
return;
if (GameTicker.RunLevel != GameRunLevel.InRound)
return;
if (nukeops.TargetStation != null && !string.IsNullOrEmpty(Name(nukeops.TargetStation.Value)))
{
NotifyNukie(playerSession, component, nukeops);
}
}
}
private void OnOperativeZombified(EntityUid uid, NukeOperativeComponent component, ref EntityZombifiedEvent args)
{
RemCompDeferred(uid, component);
}
private void OnMapInit(Entity<NukeOpsShuttleComponent> ent, ref MapInitEvent args)
{
var map = Transform(ent).MapID;
var rules = EntityQueryEnumerator<NukeopsRuleComponent, LoadMapRuleComponent>();
while (rules.MoveNext(out var uid, out _, out var mapRule))
{
if (map != mapRule.Map)
continue;
ent.Comp.AssociatedRule = uid;
break;
}
}
private void OnShuttleFTLAttempt(ref ConsoleFTLAttemptEvent ev)
{
var query = QueryActiveRules();
while (query.MoveNext(out _, out _, out var nukeops, out _))
while (query.MoveNext(out var uid, out _, out var nukeops, out _))
{
if (ev.Uid != nukeops.NukieShuttle)
if (ev.Uid != GetShuttle((uid, nukeops)))
continue;
if (nukeops.WarDeclaredTime != null)
@@ -397,12 +328,12 @@ public sealed class NukeopsRuleSystem : GameRuleSystem<NukeopsRuleComponent>
{
// TODO: this is VERY awful for multi-nukies
var query = QueryActiveRules();
while (query.MoveNext(out _, out _, out var nukeops, out _))
while (query.MoveNext(out var uid, out _, out var nukeops, out _))
{
if (nukeops.WarDeclaredTime != null)
continue;
if (Transform(ev.DeclaratorEntity).MapID != nukeops.NukiePlanet)
if (TryComp<LoadMapRuleComponent>(uid, out var mapComp) && Transform(ev.DeclaratorEntity).MapID != mapComp.Map)
continue;
var newStatus = GetWarCondition(nukeops, ev.Status);
@@ -448,161 +379,22 @@ public sealed class NukeopsRuleSystem : GameRuleSystem<NukeopsRuleComponent>
if (!_tag.HasTag(uid, NukeOpsUplinkTagPrototype))
continue;
if (!nukieRule.NukieOutpost.HasValue)
if (GetOutpost(uid) is not {} outpost)
continue;
if (Transform(uid).MapID != Transform(nukieRule.NukieOutpost.Value).MapID) // Will receive bonus TC only on their start outpost
if (Transform(uid).MapID != Transform(outpost).MapID) // Will receive bonus TC only on their start outpost
continue;
_store.TryAddCurrency(new () { { TelecrystalCurrencyPrototype, nukieRule.WarTCAmountPerNukie } }, uid, component);
_store.TryAddCurrency(new () { { TelecrystalCurrencyPrototype, nukieRule.WarTcAmountPerNukie } }, uid, component);
var msg = Loc.GetString("store-currency-war-boost-given", ("target", uid));
_popupSystem.PopupEntity(msg, uid);
}
}
private void OnRoundStart(EntityUid uid, NukeopsRuleComponent? component = null)
private void SetWinType(Entity<NukeopsRuleComponent> ent, WinType type, bool endRound = true)
{
if (!Resolve(uid, ref component))
return;
// TODO: This needs to try and target a Nanotrasen station. At the very least,
// we can only currently guarantee that NT stations are the only station to
// exist in the base game.
var eligible = new List<Entity<StationEventEligibleComponent, NpcFactionMemberComponent>>();
var eligibleQuery = EntityQueryEnumerator<StationEventEligibleComponent, NpcFactionMemberComponent>();
while (eligibleQuery.MoveNext(out var eligibleUid, out var eligibleComp, out var member))
{
if (!_npcFaction.IsFactionHostile(component.Faction, (eligibleUid, member)))
continue;
eligible.Add((eligibleUid, eligibleComp, member));
}
if (eligible.Count == 0)
return;
component.TargetStation = RobustRandom.Pick(eligible);
component.OperationName = _randomMetadata.GetRandomFromSegments([OperationPrefixDataset, OperationSuffixDataset], " ");
var filter = Filter.Empty();
var query = EntityQueryEnumerator<NukeOperativeComponent, ActorComponent>();
while (query.MoveNext(out _, out var nukeops, out var actor))
{
NotifyNukie(actor.PlayerSession, nukeops, component);
filter.AddPlayer(actor.PlayerSession);
}
}
private void OnRoundEnd(EntityUid uid, NukeopsRuleComponent? component = null)
{
if (!Resolve(uid, ref component))
return;
// If the win condition was set to operative/crew major win, ignore.
if (component.WinType == WinType.OpsMajor || component.WinType == WinType.CrewMajor)
return;
var nukeQuery = AllEntityQuery<NukeComponent, TransformComponent>();
var centcomms = _emergency.GetCentcommMaps();
while (nukeQuery.MoveNext(out var nuke, out var nukeTransform))
{
if (nuke.Status != NukeStatus.ARMED)
continue;
// UH OH
if (nukeTransform.MapUid != null && centcomms.Contains(nukeTransform.MapUid.Value))
{
component.WinConditions.Add(WinCondition.NukeActiveAtCentCom);
SetWinType(uid, WinType.OpsMajor, component);
return;
}
if (nukeTransform.GridUid == null || component.TargetStation == null)
continue;
if (!TryComp(component.TargetStation.Value, out StationDataComponent? data))
continue;
foreach (var grid in data.Grids)
{
if (grid != nukeTransform.GridUid)
continue;
component.WinConditions.Add(WinCondition.NukeActiveInStation);
SetWinType(uid, WinType.OpsMajor, component);
return;
}
}
var allAlive = true;
var query = EntityQueryEnumerator<NukeopsRoleComponent, MindContainerComponent, MobStateComponent>();
while (query.MoveNext(out var nukeopsUid, out _, out var mindContainer, out var mobState))
{
// mind got deleted somehow so ignore it
if (!_mind.TryGetMind(nukeopsUid, out _, out var mind, mindContainer))
continue;
// check if player got gibbed or ghosted or something - count as dead
if (mind.OwnedEntity != null &&
// if the player somehow isn't a mob anymore that also counts as dead
// have to be alive, not crit or dead
mobState.CurrentState is MobState.Alive)
{
continue;
}
allAlive = false;
break;
}
// If all nuke ops were alive at the end of the round,
// the nuke ops win. This is to prevent people from
// running away the moment nuke ops appear.
if (allAlive)
{
SetWinType(uid, WinType.OpsMinor, component);
component.WinConditions.Add(WinCondition.AllNukiesAlive);
return;
}
component.WinConditions.Add(WinCondition.SomeNukiesAlive);
var diskAtCentCom = false;
var diskQuery = AllEntityQuery<NukeDiskComponent, TransformComponent>();
while (diskQuery.MoveNext(out _, out var transform))
{
diskAtCentCom = transform.MapUid != null && centcomms.Contains(transform.MapUid.Value);
// TODO: The target station should be stored, and the nuke disk should store its original station.
// This is fine for now, because we can assume a single station in base SS14.
break;
}
// If the disk is currently at Central Command, the crew wins - just slightly.
// This also implies that some nuclear operatives have died.
if (diskAtCentCom)
{
SetWinType(uid, WinType.CrewMinor, component);
component.WinConditions.Add(WinCondition.NukeDiskOnCentCom);
}
// Otherwise, the nuke ops win.
else
{
SetWinType(uid, WinType.OpsMinor, component);
component.WinConditions.Add(WinCondition.NukeDiskNotOnCentCom);
}
}
private void SetWinType(EntityUid uid, WinType type, NukeopsRuleComponent? component = null, bool endRound = true)
{
if (!Resolve(uid, ref component))
return;
component.WinType = type;
ent.Comp.WinType = type;
if (endRound && (type == WinType.CrewMajor || type == WinType.OpsMajor))
_roundEndSystem.EndRound();
@@ -613,243 +405,130 @@ public sealed class NukeopsRuleSystem : GameRuleSystem<NukeopsRuleComponent>
var query = QueryActiveRules();
while (query.MoveNext(out var uid, out _, out var nukeops, out _))
{
if (nukeops.RoundEndBehavior == RoundEndBehavior.Nothing || nukeops.WinType == WinType.CrewMajor || nukeops.WinType == WinType.OpsMajor)
continue;
CheckRoundShouldEnd((uid, nukeops));
}
}
// If there are any nuclear bombs that are active, immediately return. We're not over yet.
var armed = false;
foreach (var nuke in EntityQuery<NukeComponent>())
{
if (nuke.Status == NukeStatus.ARMED)
{
armed = true;
break;
}
}
if (armed)
continue;
private void CheckRoundShouldEnd(Entity<NukeopsRuleComponent> ent)
{
var nukeops = ent.Comp;
MapId? shuttleMapId = Exists(nukeops.NukieShuttle)
? Transform(nukeops.NukieShuttle.Value).MapID
if (nukeops.RoundEndBehavior == RoundEndBehavior.Nothing || nukeops.WinType == WinType.CrewMajor || nukeops.WinType == WinType.OpsMajor)
return;
// If there are any nuclear bombs that are active, immediately return. We're not over yet.
foreach (var nuke in EntityQuery<NukeComponent>())
{
if (nuke.Status == NukeStatus.ARMED)
return;
}
var shuttle = GetShuttle((ent, ent));
MapId? shuttleMapId = Exists(shuttle)
? Transform(shuttle.Value).MapID
: null;
MapId? targetStationMap = null;
if (nukeops.TargetStation != null && TryComp(nukeops.TargetStation, out StationDataComponent? data))
{
var grid = data.Grids.FirstOrNull();
targetStationMap = grid != null
? Transform(grid.Value).MapID
: null;
MapId? targetStationMap = null;
if (nukeops.TargetStation != null && TryComp(nukeops.TargetStation, out StationDataComponent? data))
{
var grid = data.Grids.FirstOrNull();
targetStationMap = grid != null
? Transform(grid.Value).MapID
: null;
}
// Check if there are nuke operatives still alive on the same map as the shuttle,
// or on the same map as the station.
// If there are, the round can continue.
var operatives = EntityQuery<NukeOperativeComponent, MobStateComponent, TransformComponent>(true);
var operativesAlive = operatives
.Where(ent =>
ent.Item3.MapID == shuttleMapId
|| ent.Item3.MapID == targetStationMap)
.Any(ent => ent.Item2.CurrentState == MobState.Alive && ent.Item1.Running);
if (operativesAlive)
continue; // There are living operatives than can access the shuttle, or are still on the station's map.
// Check that there are spawns available and that they can access the shuttle.
var spawnsAvailable = EntityQuery<NukeOperativeSpawnerComponent>(true).Any();
if (spawnsAvailable && shuttleMapId == nukeops.NukiePlanet)
continue; // 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,
// and there are no nuclear operatives on the target station's map.
nukeops.WinConditions.Add(spawnsAvailable
? WinCondition.NukiesAbandoned
: WinCondition.AllNukiesDead);
SetWinType(uid, WinType.CrewMajor, nukeops, false);
_roundEndSystem.DoRoundEndBehavior(
nukeops.RoundEndBehavior, nukeops.EvacShuttleTime, nukeops.RoundEndTextSender, nukeops.RoundEndTextShuttleCall, nukeops.RoundEndTextAnnouncement);
// prevent it called multiple times
nukeops.RoundEndBehavior = RoundEndBehavior.Nothing;
}
}
private bool SpawnMap(Entity<NukeopsRuleComponent> ent)
{
if (!ent.Comp.SpawnOutpost
|| ent.Comp.NukiePlanet != null)
return true;
ent.Comp.NukiePlanet = _mapManager.CreateMap();
var gameMap = _prototypeManager.Index(ent.Comp.OutpostMapPrototype);
ent.Comp.NukieOutpost = GameTicker.LoadGameMap(gameMap, ent.Comp.NukiePlanet.Value, null)[0];
var query = EntityQueryEnumerator<NukeOpsShuttleComponent, TransformComponent>();
while (query.MoveNext(out var grid, out _, out var shuttleTransform))
{
if (shuttleTransform.MapID != ent.Comp.NukiePlanet)
continue;
ent.Comp.NukieShuttle = grid;
break;
}
return true;
// Check if there are nuke operatives still alive on the same map as the shuttle,
// or on the same map as the station.
// If there are, the round can continue.
var operatives = EntityQuery<NukeOperativeComponent, MobStateComponent, TransformComponent>(true);
var operativesAlive = operatives
.Where(op =>
op.Item3.MapID == shuttleMapId
|| op.Item3.MapID == targetStationMap)
.Any(op => op.Item2.CurrentState == MobState.Alive && op.Item1.Running);
if (operativesAlive)
return; // There are living operatives than can access the shuttle, or are still on the station's map.
// Check that there are spawns available and that they can access the shuttle.
var spawnsAvailable = EntityQuery<NukeOperativeSpawnerComponent>(true).Any();
if (spawnsAvailable && CompOrNull<LoadMapRuleComponent>(ent)?.Map == shuttleMapId)
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,
// and there are no nuclear operatives on the target station's map.
nukeops.WinConditions.Add(spawnsAvailable
? WinCondition.NukiesAbandoned
: WinCondition.AllNukiesDead);
SetWinType(ent, WinType.CrewMajor, false);
_roundEndSystem.DoRoundEndBehavior(
nukeops.RoundEndBehavior, nukeops.EvacShuttleTime, nukeops.RoundEndTextSender, nukeops.RoundEndTextShuttleCall, nukeops.RoundEndTextAnnouncement);
// prevent it called multiple times
nukeops.RoundEndBehavior = RoundEndBehavior.Nothing;
}
/// <summary>
/// Adds missing nuke operative components, equips starting gear and renames the entity.
/// </summary>
private void SetupOperativeEntity(EntityUid mob, string name, NukeopSpawnPreset spawnDetails, HumanoidCharacterProfile? profile)
// this should really go anywhere else but im tired.
private void OnAntagSelectEntity(Entity<NukeopsRuleComponent> ent, ref AntagSelectEntityEvent args)
{
_metaData.SetEntityName(mob, name);
EnsureComp<NukeOperativeComponent>(mob);
if (profile != null)
_humanoid.LoadProfile(mob, profile);
var gear = _prototypeManager.Index(spawnDetails.GearProto);
_stationSpawning.EquipStartingGear(mob, gear);
_npcFaction.RemoveFaction(mob, "NanoTrasen", false);
_npcFaction.AddFaction(mob, "Syndicate");
}
private void SpawnOperatives(List<NukieSpawn> sessions, bool spawnGhostRoles, NukeopsRuleComponent component)
{
if (component.NukieOutpost is not { Valid: true } outpostUid)
if (args.Handled)
return;
var spawns = new List<EntityCoordinates>();
foreach (var (_, meta, xform) in EntityQuery<SpawnPointComponent, MetaDataComponent, TransformComponent>(true))
var profile = args.Session != null
? _prefs.GetPreferences(args.Session.UserId).SelectedCharacter as HumanoidCharacterProfile
: HumanoidCharacterProfile.RandomWithSpecies();
if (!_prototypeManager.TryIndex(profile?.Species ?? SharedHumanoidAppearanceSystem.DefaultSpecies, out SpeciesPrototype? species))
{
if (meta.EntityPrototype?.ID != component.SpawnPointProto.Id)
continue;
if (xform.ParentUid != component.NukieOutpost)
continue;
spawns.Add(xform.Coordinates);
break;
species = _prototypeManager.Index<SpeciesPrototype>(SharedHumanoidAppearanceSystem.DefaultSpecies);
}
//Fallback, spawn at the centre of the map
if (spawns.Count == 0)
{
spawns.Add(Transform(outpostUid).Coordinates);
_sawmill.Warning($"Fell back to default spawn for nukies!");
}
//Spawn the team
foreach (var nukieSession in sessions)
{
var name = $"{Loc.GetString(nukieSession.Type.NamePrefix)} {RobustRandom.PickAndTake(_prototypeManager.Index(nukieSession.Type.NameList).Values.ToList())}";
var nukeOpsAntag = _prototypeManager.Index(nukieSession.Type.AntagRoleProto);
//If a session is available, spawn mob and transfer mind into it
if (nukieSession.Session != null)
{
var profile = _prefs.GetPreferences(nukieSession.Session.UserId).SelectedCharacter as HumanoidCharacterProfile;
if (!_prototypeManager.TryIndex(profile?.Species ?? SharedHumanoidAppearanceSystem.DefaultSpecies, out SpeciesPrototype? species))
{
species = _prototypeManager.Index<SpeciesPrototype>(SharedHumanoidAppearanceSystem.DefaultSpecies);
}
var mob = Spawn(species.Prototype, RobustRandom.Pick(spawns));
SetupOperativeEntity(mob, name, nukieSession.Type, profile);
var newMind = _mind.CreateMind(nukieSession.Session.UserId, name);
_mind.SetUserId(newMind, nukieSession.Session.UserId);
_roles.MindAddRole(newMind, new NukeopsRoleComponent { PrototypeId = nukieSession.Type.AntagRoleProto });
_mind.TransferTo(newMind, mob);
}
//Otherwise, spawn as a ghost role
else if (spawnGhostRoles)
{
var spawnPoint = Spawn(component.GhostSpawnPointProto, RobustRandom.Pick(spawns));
var ghostRole = EnsureComp<GhostRoleComponent>(spawnPoint);
EnsureComp<GhostRoleMobSpawnerComponent>(spawnPoint);
ghostRole.RoleName = Loc.GetString(nukeOpsAntag.Name);
ghostRole.RoleDescription = Loc.GetString(nukeOpsAntag.Objective);
var nukeOpSpawner = EnsureComp<NukeOperativeSpawnerComponent>(spawnPoint);
nukeOpSpawner.OperativeName = name;
nukeOpSpawner.SpawnDetails = nukieSession.Type;
}
}
args.Entity = Spawn(species.Prototype);
_humanoid.LoadProfile(args.Entity.Value, profile);
}
/// <summary>
/// Display a greeting message and play a sound for a nukie
/// </summary>
private void NotifyNukie(ICommonSession session, NukeOperativeComponent nukeop, NukeopsRuleComponent nukeopsRule)
private void OnAfterAntagEntSelected(Entity<NukeopsRuleComponent> ent, ref AfterAntagEntitySelectedEvent args)
{
if (nukeopsRule.TargetStation is not { } station)
if (ent.Comp.TargetStation is not { } station)
return;
_antagSelection.SendBriefing(session, Loc.GetString("nukeops-welcome", ("station", station), ("name", nukeopsRule.OperationName)), Color.Red, nukeop.GreetSoundNotification);
_antag.SendBriefing(args.Session, Loc.GetString("nukeops-welcome",
("station", station),
("name", Name(ent))),
Color.Red,
ent.Comp.GreetSoundNotification);
}
/// <summary>
/// Spawn nukie ghost roles if this gamerule was started mid round
/// </summary>
private void SpawnOperativesForGhostRoles(EntityUid uid, NukeopsRuleComponent? component = null)
/// <remarks>
/// Is this method the shitty glue holding together the last of my sanity? yes.
/// Do i have a better solution? not presently.
/// </remarks>
private EntityUid? GetOutpost(Entity<LoadMapRuleComponent?> ent)
{
if (!Resolve(uid, ref component))
return;
if (!Resolve(ent, ref ent.Comp, false))
return null;
if (!SpawnMap((uid, component)))
{
_sawmill.Info("Failed to load map for nukeops");
return;
}
var numNukies = _antagSelection.CalculateAntagCount(_playerManager.PlayerCount, component.PlayersPerOperative, component.MaxOps);
//Dont continue if we have no nukies to spawn
if (numNukies == 0)
return;
//Fill the ranks, commander first, then agent, then operatives
//TODO: Possible alternative team compositions? Like multiple commanders or agents
var operatives = new List<NukieSpawn>();
if (numNukies >= 1)
operatives.Add(new NukieSpawn(null, component.CommanderSpawnDetails));
if (numNukies >= 2)
operatives.Add(new NukieSpawn(null, component.AgentSpawnDetails));
if (numNukies >= 3)
{
for (var i = 2; i < numNukies; i++)
{
operatives.Add(new NukieSpawn(null, component.OperativeSpawnDetails));
}
}
SpawnOperatives(operatives, true, component);
return ent.Comp.MapGrids.FirstOrNull();
}
//For admins forcing someone to nukeOps.
public void MakeLoneNukie(EntityUid entity)
/// <remarks>
/// Is this method the shitty glue holding together the last of my sanity? yes.
/// Do i have a better solution? not presently.
/// </remarks>
private EntityUid? GetShuttle(Entity<NukeopsRuleComponent?> ent)
{
if (!_mind.TryGetMind(entity, out var mindId, out var mindComponent))
return;
if (!Resolve(ent, ref ent.Comp, false))
return null;
//ok hardcoded value bad but so is everything else here
_roles.MindAddRole(mindId, new NukeopsRoleComponent { PrototypeId = NukeopsId }, mindComponent);
SetOutfitCommand.SetOutfit(entity, "SyndicateOperativeGearFull", EntityManager);
}
private sealed class NukieSpawn
{
public ICommonSession? Session { get; private set; }
public NukeopSpawnPreset Type { get; private set; }
public NukieSpawn(ICommonSession? session, NukeopSpawnPreset type)
var query = EntityQueryEnumerator<NukeOpsShuttleComponent>();
while (query.MoveNext(out var uid, out var comp))
{
Session = session;
Type = type;
if (comp.AssociatedRule == ent.Owner)
return uid;
}
return null;
}
}