using Content.Shared.Mind;
using JetBrains.Annotations;
using Robust.Shared.Audio;
+using Robust.Shared.Enums;
using Robust.Shared.Player;
namespace Content.Server.Antag;
/// </summary>
public int GetTargetAntagCount(Entity<AntagSelectionComponent> 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);
}
_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<GhostRoleAntagSpawnerComponent>(player, out var spawnerComp))
{
- Log.Error("Antag spawner with GhostRoleAntagSpawnerComponent.");
+ Log.Error($"Antag spawner {player} does not have a GhostRoleAntagSpawnerComponent.");
return;
}
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);
_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);
public AntagSelectionPlayerPool GetPlayerPool(Entity<AntagSelectionComponent> ent, List<ICommonSession> sessions, AntagSelectionDefinition def)
{
var preferredList = new List<ICommonSession>();
- var secondBestList = new List<ICommonSession>();
+ var fallbackList = new List<ICommonSession>();
var unwantedList = new List<ICommonSession>();
var invalidList = new List<ICommonSession>();
foreach (var session in sessions)
}
else if (def.FallbackRoles.Count != 0 && pref.AntagPreferences.Any(p => def.FallbackRoles.Contains(p)))
{
- secondBestList.Add(session);
+ fallbackList.Add(session);
}
else
{
}
}
- return new AntagSelectionPlayerPool(new() { preferredList, secondBestList, unwantedList, invalidList });
+ return new AntagSelectionPlayerPool(new() { preferredList, fallbackList, unwantedList, invalidList });
}
/// <summary>