From 76695a70ddef02bbf7c6f6f352809ea6e93ec6b6 Mon Sep 17 00:00:00 2001 From: Nemanja <98561806+EmoGarbage404@users.noreply.github.com> Date: Sun, 5 May 2024 05:23:43 -0400 Subject: [PATCH] Scattershot antag fixes (#27429) * scattershot antag fixes * this too? * dawg fuck this code * ok so we kinda need this? --- .../Access/Systems/PresetIdCardSystem.cs | 4 ++-- .../Antag/AntagSelectionSystem.API.cs | 9 ++++++--- Content.Server/Antag/AntagSelectionSystem.cs | 17 ++++++++--------- Resources/Prototypes/GameRules/midround.yml | 2 +- 4 files changed, 17 insertions(+), 15 deletions(-) diff --git a/Content.Server/Access/Systems/PresetIdCardSystem.cs b/Content.Server/Access/Systems/PresetIdCardSystem.cs index 696b7a1dcfd..3e775b9c35d 100644 --- a/Content.Server/Access/Systems/PresetIdCardSystem.cs +++ b/Content.Server/Access/Systems/PresetIdCardSystem.cs @@ -33,8 +33,8 @@ private void PlayerJobsAssigned(RulePlayerJobsAssignedEvent ev) var station = _stationSystem.GetOwningStation(uid); // If we're not on an extended access station, the ID is already configured correctly from MapInit. - if (station == null || !Comp(station.Value).ExtendedAccess) - return; + if (station == null || !TryComp(station.Value, out var jobsComp) || !jobsComp.ExtendedAccess) + continue; SetupIdAccess(uid, card, true); SetupIdName(uid, card); diff --git a/Content.Server/Antag/AntagSelectionSystem.API.cs b/Content.Server/Antag/AntagSelectionSystem.API.cs index f8ec5bcafcd..6acd17a35b2 100644 --- a/Content.Server/Antag/AntagSelectionSystem.API.cs +++ b/Content.Server/Antag/AntagSelectionSystem.API.cs @@ -7,6 +7,7 @@ using Content.Shared.Mind; using JetBrains.Annotations; using Robust.Shared.Audio; +using Robust.Shared.Enums; using Robust.Shared.Player; namespace Content.Server.Antag; @@ -63,15 +64,17 @@ public int GetTargetAntagCount(Entity ent, AntagSelecti /// public int GetTargetAntagCount(Entity ent, AntagSelectionPlayerPool? pool, AntagSelectionDefinition def) { - var poolSize = pool?.Count ?? _playerManager.Sessions.Length; + var poolSize = pool?.Count ?? _playerManager.Sessions + .Count(s => s.State.Status is not SessionStatus.Disconnected and not SessionStatus.Zombie); + // factor in other definitions' affect on the count. var countOffset = 0; foreach (var otherDef in ent.Comp.Definitions) { - countOffset += Math.Clamp(poolSize / otherDef.PlayerRatio, otherDef.Min, otherDef.Max) * otherDef.PlayerRatio; + countOffset += Math.Clamp((poolSize - countOffset) / otherDef.PlayerRatio, otherDef.Min, otherDef.Max) * otherDef.PlayerRatio; } // make sure we don't double-count the current selection - countOffset -= Math.Clamp((poolSize + countOffset) / def.PlayerRatio, def.Min, def.Max) * def.PlayerRatio; + countOffset -= Math.Clamp(poolSize / def.PlayerRatio, def.Min, def.Max) * def.PlayerRatio; return Math.Clamp((poolSize - countOffset) / def.PlayerRatio, def.Min, def.Max); } diff --git a/Content.Server/Antag/AntagSelectionSystem.cs b/Content.Server/Antag/AntagSelectionSystem.cs index 6bfb7394f5b..57df82d6fd9 100644 --- a/Content.Server/Antag/AntagSelectionSystem.cs +++ b/Content.Server/Antag/AntagSelectionSystem.cs @@ -280,11 +280,13 @@ public void MakeAntag(Entity ent, ICommonSession? sessi _transform.SetMapCoordinates((player, playerXform), pos); } + // If we want to just do a ghost role spawner, set up data here and then return early. + // This could probably be an event in the future if we want to be more refined about it. if (isSpawner) { if (!TryComp(player, out var spawnerComp)) { - Log.Error("Antag spawner with GhostRoleAntagSpawnerComponent."); + Log.Error($"Antag spawner {player} does not have a GhostRoleAntagSpawnerComponent."); return; } @@ -293,6 +295,7 @@ public void MakeAntag(Entity ent, ICommonSession? sessi return; } + // The following is where we apply components, equipment, and other changes to our antagonist entity. EntityManager.AddComponents(player, def.Components); _stationSpawning.EquipStartingGear(player, def.StartingGear); @@ -308,11 +311,7 @@ public void MakeAntag(Entity ent, ICommonSession? sessi _mind.TransferTo(curMind.Value, antagEnt, ghostCheckOverride: true); _role.MindAddRoles(curMind.Value, def.MindComponents); ent.Comp.SelectedMinds.Add((curMind.Value, Name(player))); - } - - if (def.Briefing is { } briefing) - { - SendBriefing(session, briefing); + SendBriefing(session, def.Briefing); } var afterEv = new AfterAntagEntitySelectedEvent(session, player, ent, def); @@ -325,7 +324,7 @@ public void MakeAntag(Entity ent, ICommonSession? sessi public AntagSelectionPlayerPool GetPlayerPool(Entity ent, List sessions, AntagSelectionDefinition def) { var preferredList = new List(); - var secondBestList = new List(); + var fallbackList = new List(); var unwantedList = new List(); var invalidList = new List(); foreach (var session in sessions) @@ -344,7 +343,7 @@ public AntagSelectionPlayerPool GetPlayerPool(Entity en } else if (def.FallbackRoles.Count != 0 && pref.AntagPreferences.Any(p => def.FallbackRoles.Contains(p))) { - secondBestList.Add(session); + fallbackList.Add(session); } else { @@ -352,7 +351,7 @@ public AntagSelectionPlayerPool GetPlayerPool(Entity en } } - return new AntagSelectionPlayerPool(new() { preferredList, secondBestList, unwantedList, invalidList }); + return new AntagSelectionPlayerPool(new() { preferredList, fallbackList, unwantedList, invalidList }); } /// diff --git a/Resources/Prototypes/GameRules/midround.yml b/Resources/Prototypes/GameRules/midround.yml index 74b73d6a4b3..17c1a2b7dfc 100644 --- a/Resources/Prototypes/GameRules/midround.yml +++ b/Resources/Prototypes/GameRules/midround.yml @@ -43,7 +43,7 @@ playerRatio: 1 lateJoinAdditional: true allowNonHumans: true - multiAntagSetting: All + multiAntagSetting: NotExclusive startingGear: ThiefGear components: - type: Pacified