Skip to content

Commit

Permalink
Scattershot antag fixes (#27429)
Browse files Browse the repository at this point in the history
* scattershot antag fixes

* this too?

* dawg fuck this code

* ok so we kinda need this?
  • Loading branch information
EmoGarbage404 authored and NullWanderer committed May 15, 2024
1 parent c4bbb2a commit 76695a7
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 15 deletions.
4 changes: 2 additions & 2 deletions Content.Server/Access/Systems/PresetIdCardSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<StationJobsComponent>(station.Value).ExtendedAccess)
return;
if (station == null || !TryComp<StationJobsComponent>(station.Value, out var jobsComp) || !jobsComp.ExtendedAccess)
continue;

SetupIdAccess(uid, card, true);
SetupIdName(uid, card);
Expand Down
9 changes: 6 additions & 3 deletions Content.Server/Antag/AntagSelectionSystem.API.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -63,15 +64,17 @@ public int GetTargetAntagCount(Entity<AntagSelectionComponent> ent, AntagSelecti
/// </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);
}
Expand Down
17 changes: 8 additions & 9 deletions Content.Server/Antag/AntagSelectionSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -280,11 +280,13 @@ public void MakeAntag(Entity<AntagSelectionComponent> 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<GhostRoleAntagSpawnerComponent>(player, out var spawnerComp))
{
Log.Error("Antag spawner with GhostRoleAntagSpawnerComponent.");
Log.Error($"Antag spawner {player} does not have a GhostRoleAntagSpawnerComponent.");
return;
}

Expand All @@ -293,6 +295,7 @@ public void MakeAntag(Entity<AntagSelectionComponent> 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);

Expand All @@ -308,11 +311,7 @@ public void MakeAntag(Entity<AntagSelectionComponent> 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);
Expand All @@ -325,7 +324,7 @@ public void MakeAntag(Entity<AntagSelectionComponent> ent, ICommonSession? sessi
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)
Expand All @@ -344,15 +343,15 @@ public AntagSelectionPlayerPool GetPlayerPool(Entity<AntagSelectionComponent> en
}
else if (def.FallbackRoles.Count != 0 && pref.AntagPreferences.Any(p => def.FallbackRoles.Contains(p)))
{
secondBestList.Add(session);
fallbackList.Add(session);
}
else
{
unwantedList.Add(session);
}
}

return new AntagSelectionPlayerPool(new() { preferredList, secondBestList, unwantedList, invalidList });
return new AntagSelectionPlayerPool(new() { preferredList, fallbackList, unwantedList, invalidList });
}

/// <summary>
Expand Down
2 changes: 1 addition & 1 deletion Resources/Prototypes/GameRules/midround.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
playerRatio: 1
lateJoinAdditional: true
allowNonHumans: true
multiAntagSetting: All
multiAntagSetting: NotExclusive
startingGear: ThiefGear
components:
- type: Pacified
Expand Down

0 comments on commit 76695a7

Please sign in to comment.