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 2873131 commit ea0b0e1
Showing 1 changed file with 56 additions and 4 deletions.
60 changes: 56 additions & 4 deletions Modules/Managers/Game.cs
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,32 @@ 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.");
foreach (var player in newTerrorists)
{
Expand All @@ -101,19 +127,45 @@ public void CounterTerroristRoundWin()
{
_consecutiveRoundsWon = 0;

var numTerrorists = Queue.GetTargetNumTerrorists();
var targetNumTerrorists = Queue.GetTargetNumTerrorists();

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

var newTerrorists = sortedCounterTerroristPlayers.Where(player => player.Score > 0).Take(numTerrorists).ToList();
var newTerrorists = sortedCounterTerroristPlayers.Where(player => player.Score > 0).Take(targetNumTerrorists).ToList();

if (newTerrorists.Count < numTerrorists)
if (newTerrorists.Count < targetNumTerrorists)
{
var playersLeft = Helpers.Shuffle(sortedCounterTerroristPlayers.Except(newTerrorists).ToList());
newTerrorists.AddRange(playersLeft.Take(targetNumTerrorists - newTerrorists.Count));
}

if (newTerrorists.Count < targetNumTerrorists)
{
Console.WriteLine($"{RetakesPlugin.MessagePrefix}Still not enough terrorists needed.");
var playersLeft = Helpers.Shuffle(sortedCounterTerroristPlayers.Except(newTerrorists).ToList());
newTerrorists.AddRange(playersLeft.Take(targetNumTerrorists - 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(targetNumTerrorists - 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 < targetNumTerrorists)
{
Console.WriteLine($"{RetakesPlugin.MessagePrefix}Still not enough terrorists needed.");
var playersLeft = Helpers.Shuffle(sortedCounterTerroristPlayers.Except(newTerrorists).ToList());
newTerrorists.AddRange(playersLeft.Take(numTerrorists - newTerrorists.Count));
newTerrorists.AddRange(playersLeft.Take(targetNumTerrorists - newTerrorists.Count));
}

foreach (var player in Utilities.GetPlayers().Where(Helpers.IsValidPlayer))
Expand Down

0 comments on commit ea0b0e1

Please sign in to comment.