Skip to content

Commit

Permalink
Continued updates to team swapping logic
Browse files Browse the repository at this point in the history
  • Loading branch information
B3none committed Dec 22, 2023
1 parent ea0b0e1 commit a0171fe
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 32 deletions.
28 changes: 1 addition & 27 deletions Modules/Managers/Game.cs
Original file line number Diff line number Diff line change
Expand Up @@ -89,33 +89,7 @@ public void TerroristRoundWin()
newTerrorists.AddRange(playersLeft.Take(numTerroristsNeeded - newTerrorists.Count));
}

if (newTerrorists.Count < numTerroristsNeeded)
{
Console.WriteLine($"{RetakesPlugin.MessagePrefix}Still not enough terrorists needed.");
var playersLeft = Helpers.Shuffle(sortedCounterTerroristPlayers.Except(newTerrorists).ToList());
newTerrorists.AddRange(playersLeft.Take(numTerroristsNeeded - newTerrorists.Count));
}

var sortedTerroristPlayers = Queue.ActivePlayers
.Where(player => Helpers.IsValidPlayer(player) && player.TeamNum == (int)CsTeam.Terrorist)
.OrderByDescending(player => _playerRoundScores.GetValueOrDefault((int)player.UserId!, 0))
.ToList();

Console.WriteLine($"{RetakesPlugin.MessagePrefix}Got {sortedTerroristPlayers.Count} sortedTerroristPlayers.");

newTerrorists.AddRange(sortedCounterTerroristPlayers.Where(player => player.Score > 0).Take(numTerroristsNeeded - newTerrorists.Count).ToList());

Console.WriteLine($"{RetakesPlugin.MessagePrefix}{sortedTerroristPlayers.Where(player => player.Score > 0).ToList().Count} sortedTerroristPlayers with more than 0 score found.");
Console.WriteLine($"{RetakesPlugin.MessagePrefix}There are currently {newTerrorists.Count} new terrorists.");

if (newTerrorists.Count < numTerroristsNeeded)
{
Console.WriteLine($"{RetakesPlugin.MessagePrefix}Still not enough terrorists needed.");
var playersLeft = Helpers.Shuffle(sortedCounterTerroristPlayers.Except(newTerrorists).ToList());
newTerrorists.AddRange(playersLeft.Take(numTerroristsNeeded - newTerrorists.Count));
}

Console.WriteLine($"{RetakesPlugin.MessagePrefix}Swapping players to terrorist.");
Console.WriteLine($"{RetakesPlugin.MessagePrefix}Swapping player(s) to terrorist...");
foreach (var player in newTerrorists)
{
Console.WriteLine($"{RetakesPlugin.MessagePrefix}Swapping player {player.PlayerName} to terrorist.");
Expand Down
10 changes: 5 additions & 5 deletions RetakesPlugin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -190,14 +190,14 @@ public HookResult OnRoundPreStart(EventRoundPrestart @event, GameEventInfo info)
_gameManager.Queue.DebugQueues(false);

// Handle team swaps at the start of the round
if (_didTerroristsWinLastRound)
{
_gameManager.TerroristRoundWin();
}
else
if (!_didTerroristsWinLastRound)
{
_gameManager.CounterTerroristRoundWin();

return HookResult.Continue;
}

_gameManager.TerroristRoundWin();

return HookResult.Continue;
}
Expand Down

0 comments on commit a0171fe

Please sign in to comment.