Skip to content
This repository has been archived by the owner on Oct 22, 2024. It is now read-only.

Commit

Permalink
refactor: Optimise EventRoundEnd
Browse files Browse the repository at this point in the history
  • Loading branch information
K4ryuu committed Nov 20, 2023
1 parent a75ecdd commit 1c92f7c
Showing 1 changed file with 25 additions and 34 deletions.
59 changes: 25 additions & 34 deletions src/Events.cs
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,7 @@ private void SetupGameEvents()
CsTeam winnerTeam = (CsTeam)@event.Winner;
List<CCSPlayerController> players = Utilities.GetPlayers();
foreach (CCSPlayerController player in players)
{
if (player.IsBot || player.IsHLTV)
Expand All @@ -282,53 +283,43 @@ private void SetupGameEvents()
if (!PlayerSummaries[player].SpawnedThisRound)
continue;
string prefix = Config.GeneralSettings.Prefix;
string playerName = player.PlayerName;
int pointsChanged = PlayerSummaries[player].PointsChanged;
if (Config.RankSettings.RoundEndPoints)
{
if (PlayerSummaries[player].PointsChanged > 0)
{
player.PrintToChat($" {Config.GeneralSettings.Prefix} {ChatColors.White}Points: {ChatColors.Green}+{PlayerSummaries[player].PointsChanged} Round Summary");
}
else if (PlayerSummaries[player].PointsChanged < 0)
{
int absPointsChanged = Math.Abs(PlayerSummaries[player].PointsChanged);
player.PrintToChat($" {Config.GeneralSettings.Prefix} {ChatColors.White}Points: {ChatColors.Red}-{PlayerSummaries[player].PointsChanged} Round Summary");
}
string message = $"{prefix} {ChatColors.White}Points: ";
if (pointsChanged > 0)
player.PrintToChat($"{message}{ChatColors.Green}+{pointsChanged} Round Summary");
else if (pointsChanged < 0)
player.PrintToChat($"{message}{ChatColors.Red}-{Math.Abs(pointsChanged)} Round Summary");
else
player.PrintToChat($" {Config.GeneralSettings.Prefix} {ChatColors.White}Points: No changes in this round");
player.PrintToChat($"{message}No changes in this round");
PlayerSummaries[player].PointsChanged = 0;
}
CsTeam playerTeam = (CsTeam)player.TeamNum;
if (playerTeam != CsTeam.None && playerTeam != CsTeam.Spectator)
{
if (winnerTeam == playerTeam)
{
if (IsStatsAllowed())
{
PlayerSummaries[player].StatFields["round_win"]++;
Log($"EventRoundEnd: Recorded round win for player: {player.PlayerName}", LogLevel.Debug);
}
bool isWinner = winnerTeam == playerTeam;
if (IsPointsAllowed())
{
ModifyClientPoints(player, CHANGE_MODE.GIVE, Config.PointSettings.RoundWin, "Round Win");
Log($"EventRoundEnd: Modified points (round win) for player: {player.PlayerName}", LogLevel.Debug);
}
}
else
if (IsStatsAllowed())
{
if (IsStatsAllowed())
{
PlayerSummaries[player].StatFields["round_lose"]++;
Log($"EventRoundEnd: Recorded round lose for player: {player.PlayerName}", LogLevel.Debug);
}
string statType = isWinner ? "round_win" : "round_lose";
PlayerSummaries[player].StatFields[statType]++;
Log($"EventRoundEnd: Recorded {statType} for player: {playerName}", LogLevel.Debug);
}
if (IsPointsAllowed())
{
ModifyClientPoints(player, CHANGE_MODE.REMOVE, Config.PointSettings.RoundLose, "Round Lose");
Log($"EventRoundEnd: Modified points (round lose) for player: {player.PlayerName}", LogLevel.Debug);
}
if (IsPointsAllowed())
{
CHANGE_MODE changeMode = isWinner ? CHANGE_MODE.GIVE : CHANGE_MODE.REMOVE;
int pointsChange = isWinner ? Config.PointSettings.RoundWin : Config.PointSettings.RoundLose;
ModifyClientPoints(player, changeMode, pointsChange, isWinner ? "Round Win" : "Round Lose");
Log($"EventRoundEnd: Modified points ({(isWinner ? "round win" : "round lose")}) for player: {playerName}", LogLevel.Debug);
}
}
Expand Down

0 comments on commit 1c92f7c

Please sign in to comment.