Skip to content

Commit

Permalink
Merge pull request #27 from B3none/147-updates
Browse files Browse the repository at this point in the history
Update to CounterStrikeSharp 147
  • Loading branch information
B3none authored Jan 15, 2024
2 parents 6e48ee0 + cad295f commit 758fda0
Show file tree
Hide file tree
Showing 10 changed files with 28 additions and 31 deletions.
2 changes: 1 addition & 1 deletion Modules/Allocators/EquipmentAllocator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ public static void Allocate(CCSPlayerController player)
player.GiveNamedItem(CsItem.KevlarHelmet);

if (
(CsTeam)player.TeamNum == CsTeam.CounterTerrorist
player.Team == CsTeam.CounterTerrorist
&& player.PlayerPawn.IsValid
&& player.PlayerPawn.Value != null
&& player.PlayerPawn.Value.IsValid
Expand Down
2 changes: 1 addition & 1 deletion Modules/Allocators/GrenadeAllocator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public static void Allocate(CCSPlayerController player)
player.GiveNamedItem(CsItem.HEGrenade);
break;
case 3:
player.GiveNamedItem((CsTeam)player.TeamNum == CsTeam.Terrorist ? CsItem.Molotov : CsItem.Incendiary);
player.GiveNamedItem(player.Team == CsTeam.Terrorist ? CsItem.Molotov : CsItem.Incendiary);
break;
}
}
Expand Down
4 changes: 2 additions & 2 deletions Modules/Allocators/WeaponsAllocator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@ public abstract class WeaponsAllocator
{
public static void Allocate(CCSPlayerController player)
{
if ((CsTeam)player.TeamNum == CsTeam.Terrorist)
if (player.Team == CsTeam.Terrorist)
{
player.GiveNamedItem(CsItem.AK47);
// player.GiveNamedItem(CsItem.Glock);
player.GiveNamedItem(CsItem.Deagle);
}

if ((CsTeam)player.TeamNum == CsTeam.CounterTerrorist)
if (player.Team == CsTeam.CounterTerrorist)
{
// player.GiveNamedItem(CsItem.M4A4);
player.GiveNamedItem(CsItem.M4A1S);
Expand Down
2 changes: 1 addition & 1 deletion Modules/Helpers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ public static int GetCurrentNumPlayers(CsTeam csTeam)

foreach (var player in Utilities.GetPlayers().Where(player => IsValidPlayer(player) && IsPlayerConnected(player)))
{
if ((CsTeam)player.TeamNum == csTeam)
if (player.Team == csTeam)
{
players++;
}
Expand Down
10 changes: 5 additions & 5 deletions Modules/Managers/GameManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ public void BalanceTeams()
var terroristsWithZeroScore = QueueManager.ActivePlayers
.Where(player =>
Helpers.IsValidPlayer(player)
&& (CsTeam)player.TeamNum == CsTeam.Terrorist
&& player.Team == CsTeam.Terrorist
&& _playerRoundScores.GetValueOrDefault((int)player.UserId!, 0) == 0
)
.Except(newTerrorists)
Expand All @@ -164,7 +164,7 @@ public void BalanceTeams()
QueueManager.ActivePlayers
.Except(newCounterTerrorists)
.Except(newTerrorists)
.Where(player => Helpers.IsValidPlayer(player) && (CsTeam)player.TeamNum == CsTeam.Terrorist)
.Where(player => Helpers.IsValidPlayer(player) && player.Team == CsTeam.Terrorist)
.OrderBy(player => _playerRoundScores.GetValueOrDefault((int)player.UserId!, 0))
.Take(numTerroristsNeeded - newCounterTerrorists.Count)
.ToList()
Expand All @@ -179,7 +179,7 @@ private List<CCSPlayerController> GetSortedActivePlayers(CsTeam? team = null)
{
return QueueManager.ActivePlayers
.Where(Helpers.IsValidPlayer)
.Where(player => team == null || (CsTeam)player.TeamNum == team)
.Where(player => team == null || player.Team == team)
.OrderByDescending(player => _playerRoundScores.GetValueOrDefault((int)player.UserId!, 0))
.ToList();
}
Expand All @@ -193,14 +193,14 @@ private void SetTeams(List<CCSPlayerController>? terrorists, List<CCSPlayerContr
{
if (terrorists.Contains(player))
{
if ((CsTeam)player.TeamNum != CsTeam.Terrorist)
if (player.Team != CsTeam.Terrorist)
{
player.SwitchTeam(CsTeam.Terrorist);
}
}
else if (counterTerrorists.Contains(player))
{
if ((CsTeam)player.TeamNum != CsTeam.CounterTerrorist)
if (player.Team != CsTeam.CounterTerrorist)
{
player.SwitchTeam(CsTeam.CounterTerrorist);
}
Expand Down
6 changes: 3 additions & 3 deletions Modules/Managers/QueueManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ public void Update()
{
ActivePlayers.Add(player);

if ((CsTeam)player.TeamNum != CsTeam.CounterTerrorist)
if (player.Team != CsTeam.CounterTerrorist)
{
player.SwitchTeam(CsTeam.CounterTerrorist);
}
Expand Down Expand Up @@ -266,7 +266,7 @@ public void ClearRoundTeams()

public void SetRoundTeams()
{
_roundTerrorists = Utilities.GetPlayers().Where(player => Helpers.IsValidPlayer(player) && (CsTeam)player.TeamNum == CsTeam.Terrorist).ToList();
_roundCounterTerrorists = Utilities.GetPlayers().Where(player => Helpers.IsValidPlayer(player) && (CsTeam)player.TeamNum == CsTeam.CounterTerrorist).ToList();
_roundTerrorists = Utilities.GetPlayers().Where(player => Helpers.IsValidPlayer(player) && player.Team == CsTeam.Terrorist).ToList();
_roundCounterTerrorists = Utilities.GetPlayers().Where(player => Helpers.IsValidPlayer(player) && player.Team == CsTeam.CounterTerrorist).ToList();
}
}
23 changes: 10 additions & 13 deletions Modules/Managers/SpawnManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -61,29 +61,30 @@ public List<Spawn> GetSpawns(Bombsite bombsite, CsTeam? team = null)
Helpers.GetCurrentNumPlayers(CsTeam.Terrorist) > spawns[CsTeam.Terrorist].Count
)
{
// TODO: Potentially update the maxRetakesPlayers on the fly.
throw new Exception($"There are not enough spawns in the map config for Bombsite {bombsite.ToString()}!");
}

var planterSpawns = spawns[CsTeam.Terrorist].Where(spawn => spawn.CanBePlanter).ToList();
var randomPlanterSpawn = planterSpawns[Helpers.Random.Next(planterSpawns.Count)];

if (randomPlanterSpawn != null)

if (planterSpawns.Count == 0)
{
spawns[CsTeam.Terrorist].Remove(randomPlanterSpawn);
throw new Exception($"There are no planter spawns for Bombsite {bombsite.ToString()}!");
}


var randomPlanterSpawn = planterSpawns[Helpers.Random.Next(planterSpawns.Count)];
spawns[CsTeam.Terrorist].Remove(randomPlanterSpawn);

CCSPlayerController? planter = null;

int i = -1;
foreach (var player in Helpers.Shuffle(players))
{
i++;
if (!Helpers.DoesPlayerHavePawn(player))
{
continue;
}

var team = (CsTeam)player.TeamNum;
var team = player.Team;
if (planter == null && team == CsTeam.Terrorist)
{
planter = player;
Expand All @@ -95,11 +96,7 @@ public List<Spawn> GetSpawns(Bombsite bombsite, CsTeam? team = null)
continue;
}

var spawn = (player == planter) ? randomPlanterSpawn : spawns[team][Helpers.Random.Next(count)];
if (spawn == null)
{
continue;
}
var spawn = player == planter ? randomPlanterSpawn : spawns[team][Helpers.Random.Next(count)];

player.PlayerPawn.Value!.Teleport(spawn.Vector, spawn.QAngle, new Vector());
spawns[team].Remove(spawn);
Expand Down
2 changes: 1 addition & 1 deletion Modules/Translator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ private string Translate(string key, params object[] arguments)
.Replace("[LIGHT_BLUE]", ChatColors.LightBlue.ToString())
.Replace("[LIGHT_PURPLE]", ChatColors.LightPurple.ToString())
.Replace("[LIGHT_YELLOW]", ChatColors.LightYellow.ToString())
.Replace("[DARK_RED]", ChatColors.Darkred.ToString())
.Replace("[DARK_RED]", ChatColors.DarkRed.ToString())
.Replace("[DARK_BLUE]", ChatColors.DarkBlue.ToString())
.Replace("[BLUE_GREY]", ChatColors.BlueGrey.ToString())
.Replace("[OLIVE]", ChatColors.Olive.ToString())
Expand Down
6 changes: 3 additions & 3 deletions RetakesPlugin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@

namespace RetakesPlugin;

[MinimumApiVersion(131)]
[MinimumApiVersion(147)]
public class RetakesPlugin : BasePlugin
{
private const string Version = "1.3.3";
private const string Version = "1.3.4";

#region Plugin info
public override string ModuleName => "Retakes Plugin";
Expand Down Expand Up @@ -740,7 +740,7 @@ private void AnnounceBombsite(Bombsite bombsite, bool onlyCenter = false)
continue;
}

if ((CsTeam)player.TeamNum == CsTeam.CounterTerrorist)
if (player.Team == CsTeam.CounterTerrorist)
{
player.PrintToCenter(announcementMessage);
}
Expand Down
2 changes: 1 addition & 1 deletion RetakesPlugin.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="CounterStrikeSharp.API" Version="1.0.142" />
<PackageReference Include="CounterStrikeSharp.API" Version="1.0.147" />
<PackageReference Include="Microsoft.Extensions.Localization.Abstractions" Version="7.0.14" />
</ItemGroup>

Expand Down

0 comments on commit 758fda0

Please sign in to comment.