Skip to content

Commit

Permalink
Rename site to side
Browse files Browse the repository at this point in the history
  • Loading branch information
MD-V committed Feb 23, 2024
1 parent 9f63cf4 commit ab1acff
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 43 deletions.
58 changes: 28 additions & 30 deletions PugSharp.Match/Match.cs
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ private void InitializeStateMachine()
_MatchStateMachine.Configure(MatchState.TeamVote)
.Permit(MatchCommand.VoteTeam, MatchState.SwitchMap)
.OnEntry(SendTeamVoteToVotingTeam)
.OnExit(SetSelectedTeamSite);
.OnExit(SetSelectedTeamSide);

_MatchStateMachine.Configure(MatchState.SwitchMap)
.Permit(MatchCommand.SwitchMap, MatchState.WaitingForPlayersReady)
Expand Down Expand Up @@ -284,7 +284,7 @@ private void StartMatch()
string demoDirectory = Path.Combine(_CsServer.GameDirectory, "csgo", "PugSharp", "Demo");
MatchInfo.DemoFile = _CsServer.StartDemoRecording(demoDirectory, demoFileName);

_CsServer.PrintToChatAll(_TextHelper.GetText(nameof(Resources.PugSharp_Match_Info_StartMatch), MatchInfo.MatchTeam1.TeamConfig.Name, MatchInfo.MatchTeam1.CurrentTeamSite, MatchInfo.MatchTeam2.TeamConfig.Name, MatchInfo.MatchTeam2.CurrentTeamSite));
_CsServer.PrintToChatAll(_TextHelper.GetText(nameof(Resources.PugSharp_Match_Info_StartMatch), MatchInfo.MatchTeam1.TeamConfig.Name, MatchInfo.MatchTeam1.CurrentTeamSide, MatchInfo.MatchTeam2.TeamConfig.Name, MatchInfo.MatchTeam2.CurrentTeamSide));

_ = _ApiProvider.GoingLiveAsync(new GoingLiveParams(MatchInfo.Config.MatchId, MatchInfo.CurrentMap.MapName, MatchInfo.CurrentMap.MapNumber), CancellationToken.None);

Expand Down Expand Up @@ -317,18 +317,18 @@ public void SendRoundResults(IRoundResults roundResults)

UpdateStats(roundResults.PlayerResults);

var team1Results = MatchInfo.MatchTeam1.CurrentTeamSite == Team.Terrorist ? roundResults.TRoundResult : roundResults.CTRoundResult;
var team2Results = MatchInfo.MatchTeam2.CurrentTeamSite == Team.Terrorist ? roundResults.TRoundResult : roundResults.CTRoundResult;
var team1Results = MatchInfo.MatchTeam1.CurrentTeamSide == Team.Terrorist ? roundResults.TRoundResult : roundResults.CTRoundResult;
var team2Results = MatchInfo.MatchTeam2.CurrentTeamSide == Team.Terrorist ? roundResults.TRoundResult : roundResults.CTRoundResult;

MatchInfo.CurrentMap.Team1Points = team1Results.Score;
MatchInfo.CurrentMap.Team2Points = team2Results.Score;

_Logger.LogInformation("Team 1: {teamSite} : {teamScore}", MatchInfo.MatchTeam1.CurrentTeamSite, team1Results.Score);
_Logger.LogInformation("Team 2: {teamSite} : {teamScore}", MatchInfo.MatchTeam2.CurrentTeamSite, team2Results.Score);
_Logger.LogInformation("Team 1: {teamSide} : {teamScore}", MatchInfo.MatchTeam1.CurrentTeamSide, team1Results.Score);
_Logger.LogInformation("Team 2: {teamSide} : {teamScore}", MatchInfo.MatchTeam2.CurrentTeamSide, team2Results.Score);

var mapTeamInfo1 = new MapTeamInfo
{
StartingSide = MatchInfo.MatchTeam1.StartingTeamSite == Team.Terrorist ? TeamSide.T : TeamSide.CT,
StartingSide = MatchInfo.MatchTeam1.StartingTeamSide == Team.Terrorist ? TeamSide.T : TeamSide.CT,
Score = team1Results.Score,
ScoreT = team1Results.ScoreT,
ScoreCT = team1Results.ScoreCT,
Expand All @@ -339,7 +339,7 @@ public void SendRoundResults(IRoundResults roundResults)

var mapTeamInfo2 = new MapTeamInfo
{
StartingSide = MatchInfo.MatchTeam2.StartingTeamSite == Team.Terrorist ? TeamSide.T : TeamSide.CT,
StartingSide = MatchInfo.MatchTeam2.StartingTeamSide == Team.Terrorist ? TeamSide.T : TeamSide.CT,
Score = team2Results.Score,
ScoreT = team2Results.ScoreT,
ScoreCT = team2Results.ScoreCT,
Expand All @@ -356,7 +356,7 @@ public void SendRoundResults(IRoundResults roundResults)
return;
}

var map = new Map { WinnerTeamName = winnerTeam.TeamConfig.Name, WinnerTeamSide = (TeamSide)(int)winnerTeam.CurrentTeamSite, Name = MatchInfo.CurrentMap.MapName, Team1 = mapTeamInfo1, Team2 = mapTeamInfo2, DemoFileName = Path.GetFileName(MatchInfo.DemoFile) ?? string.Empty };
var map = new Map { WinnerTeamName = winnerTeam.TeamConfig.Name, WinnerTeamSide = (TeamSide)(int)winnerTeam.CurrentTeamSide, Name = MatchInfo.CurrentMap.MapName, Team1 = mapTeamInfo1, Team2 = mapTeamInfo2, DemoFileName = Path.GetFileName(MatchInfo.DemoFile) ?? string.Empty };
_ = _ApiProvider?.RoundStatsUpdateAsync(new RoundStatusUpdateParams(MatchInfo.Config.MatchId, MatchInfo.CurrentMap.MapNumber, teamInfo1, teamInfo2, map, roundResults.Reason, roundResults.RoundTime), CancellationToken.None);
}

Expand Down Expand Up @@ -775,23 +775,23 @@ private void SendTeamVoteToVotingTeam()
_VoteTimer.Start();
}

private void SetSelectedTeamSite()
private void SetSelectedTeamSide()
{
_VoteTimer.Stop();

var startTeam = _TeamVotes.MaxBy(m => m.Votes.Count)!.Name.Equals("T", StringComparison.OrdinalIgnoreCase) ? Team.Terrorist : Team.CounterTerrorist;
_Logger.LogInformation("Set selected teamsite to {startTeam}. Voted by {team}", startTeam, _CurrentMatchTeamToVote!.TeamConfig.Name);

if (_CurrentMatchTeamToVote!.CurrentTeamSite != startTeam)
if (_CurrentMatchTeamToVote!.CurrentTeamSide != startTeam)
{
_CurrentMatchTeamToVote.StartingTeamSite = startTeam;
_CurrentMatchTeamToVote.CurrentTeamSite = startTeam;
_CurrentMatchTeamToVote.StartingTeamSide = startTeam;
_CurrentMatchTeamToVote.CurrentTeamSide = startTeam;
var otherTeam = GetOtherTeam(_CurrentMatchTeamToVote);
otherTeam.StartingTeamSite = startTeam == Team.Terrorist ? Team.CounterTerrorist : Team.Terrorist;
otherTeam.CurrentTeamSite = otherTeam.StartingTeamSite;
otherTeam.StartingTeamSide = startTeam == Team.Terrorist ? Team.CounterTerrorist : Team.Terrorist;
otherTeam.CurrentTeamSide = otherTeam.StartingTeamSide;

_Logger.LogInformation("{team} starts as Team {startTeam}", _CurrentMatchTeamToVote.TeamConfig.Name, _CurrentMatchTeamToVote!.CurrentTeamSite.ToString());
_Logger.LogInformation("{team} starts as Team {startTeam}", otherTeam.TeamConfig.Name, otherTeam!.CurrentTeamSite.ToString());
_Logger.LogInformation("{team} starts as Team {startTeam}", _CurrentMatchTeamToVote.TeamConfig.Name, _CurrentMatchTeamToVote!.CurrentTeamSide.ToString());
_Logger.LogInformation("{team} starts as Team {startTeam}", otherTeam.TeamConfig.Name, otherTeam!.CurrentTeamSide.ToString());
}

_CsServer.PrintToChatAll(_TextHelper.GetText(nameof(Resources.PugSharp_Match_SelectedTeam), _CurrentMatchTeamToVote!.TeamConfig.Name, startTeam));
Expand Down Expand Up @@ -929,7 +929,7 @@ private async Task TryFireStateAsync(MatchCommand command)

private MatchTeam? GetMatchTeam(Team team)
{
return MatchInfo.MatchTeam1.CurrentTeamSite == team ? MatchInfo.MatchTeam1 : MatchInfo.MatchTeam2;
return MatchInfo.MatchTeam1.CurrentTeamSide == team ? MatchInfo.MatchTeam1 : MatchInfo.MatchTeam2;
}

private MatchPlayer GetMatchPlayer(ulong steamID)
Expand Down Expand Up @@ -972,19 +972,19 @@ public bool TryAddPlayer(IPlayer player)
}

var team = isTeam1 ? MatchInfo.MatchTeam1 : MatchInfo.MatchTeam2;
var startSite = team.CurrentTeamSite;
if (startSite == Team.None)
var startSide = team.CurrentTeamSide;
if (startSide == Team.None)
{
startSite = isTeam1 ? Team.Terrorist : Team.CounterTerrorist;
startSide = isTeam1 ? Team.Terrorist : Team.CounterTerrorist;
}

_Logger.LogInformation("Player {playerName} belongs to {teamName}", player.PlayerName, team.TeamConfig.Name);

if (player.Team != startSite)
if (player.Team != startSide)
{
_Logger.LogInformation("Player {playerName} should be on {startSite} but is {currentTeam}", player.PlayerName, startSite, player.Team);
_Logger.LogInformation("Player {playerName} should be on {startSide} but is {currentTeam}", player.PlayerName, startSide, player.Team);

player.SwitchTeam(startSite);
player.SwitchTeam(startSide);
}

team.Players.Add(new MatchPlayer(player));
Expand Down Expand Up @@ -1060,7 +1060,7 @@ public Team GetPlayerTeam(ulong steamID)

if (matchTeam != null)
{
return matchTeam.CurrentTeamSite;
return matchTeam.CurrentTeamSide;
}

_Logger.LogInformation("No matchTeam found. Fallback to Config Team!");
Expand Down Expand Up @@ -1208,14 +1208,12 @@ public void Unpause(IPlayer player)

public void SwitchTeam()
{
_Logger.LogInformation("Toggle TeamSites");
_Logger.LogInformation("Toggle TeamSides");

MatchInfo.MatchTeam1.ToggleTeamSite();
MatchInfo.MatchTeam2.ToggleTeamSite();
MatchInfo.MatchTeam1.ToggleTeamSide();
MatchInfo.MatchTeam2.ToggleTeamSide();
}



protected virtual void Dispose(bool disposing)
{
if (!_DisposedValue)
Expand Down
4 changes: 2 additions & 2 deletions PugSharp.Match/MatchInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ public MatchInfo(MatchConfig config)
CurrentMap = MatchMaps[0];
Config = config;

MatchTeam1 = new MatchTeam(Config.Team1) { CurrentTeamSite = Contract.Team.Terrorist };
MatchTeam2 = new MatchTeam(Config.Team2) { CurrentTeamSite = Contract.Team.CounterTerrorist };
MatchTeam1 = new MatchTeam(Config.Team1) { CurrentTeamSide = Contract.Team.Terrorist };
MatchTeam2 = new MatchTeam(Config.Team2) { CurrentTeamSide = Contract.Team.CounterTerrorist };
RandomPlayersAllowed = Config.Team1.Players.Count == 0 && Config.Team2.Players.Count == 0;
}

Expand Down
8 changes: 4 additions & 4 deletions PugSharp.Match/MatchTeam.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ public MatchTeam(Config.Team teamConfig)
[JsonIgnore]
public IList<MatchPlayer> Players { get; } = new List<MatchPlayer>();

public Team StartingTeamSite { get; set; }
public Team StartingTeamSide { get; set; }

public Team CurrentTeamSite { get; set; }
public Team CurrentTeamSide { get; set; }

public Config.Team TeamConfig { get; }

Expand All @@ -32,8 +32,8 @@ internal void PrintToChat(string message)
}
}

internal void ToggleTeamSite()
internal void ToggleTeamSide()
{
CurrentTeamSite = CurrentTeamSite == Team.Terrorist ? Team.CounterTerrorist : Team.Terrorist;
CurrentTeamSide = CurrentTeamSide == Team.Terrorist ? Team.CounterTerrorist : Team.Terrorist;
}
}
14 changes: 7 additions & 7 deletions PugSharp/Application.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1503,7 +1503,7 @@ public void OnCommandTeam1Side(CCSPlayerController? player, CommandInfo command)
return;
}
c.ReplyToCommand(_Match.MatchInfo.MatchTeam1.CurrentTeamSite.ToString());
c.ReplyToCommand(_Match.MatchInfo.MatchTeam1.CurrentTeamSide.ToString());
},
command,
player);
Expand All @@ -1522,7 +1522,7 @@ public void OnCommandTeam2Side(CCSPlayerController? player, CommandInfo command)
return;
}
c.ReplyToCommand(_Match.MatchInfo.MatchTeam2.CurrentTeamSite.ToString());
c.ReplyToCommand(_Match.MatchInfo.MatchTeam2.CurrentTeamSide.ToString());
},
command,
player);
Expand Down Expand Up @@ -1623,15 +1623,15 @@ public void OnCommandMapScoreJson(CCSPlayerController? player, CommandInfo comma
{
_Match.MatchInfo.Config.Team1.Name,
Score = _Match.MatchInfo.CurrentMap.Team1Points,
StartingSide = _Match.MatchInfo.MatchTeam1.StartingTeamSite,
CurrentSide = _Match.MatchInfo.MatchTeam1.CurrentTeamSite,
StartingSide = _Match.MatchInfo.MatchTeam1.StartingTeamSide,
CurrentSide = _Match.MatchInfo.MatchTeam1.CurrentTeamSide,
},
Team2 = new
{
_Match.MatchInfo.Config.Team2.Name,
Score = _Match.MatchInfo.CurrentMap.Team2Points,
StartingSide = _Match.MatchInfo.MatchTeam2.StartingTeamSite,
CurrentSide = _Match.MatchInfo.MatchTeam2.CurrentTeamSite,
StartingSide = _Match.MatchInfo.MatchTeam2.StartingTeamSide,
CurrentSide = _Match.MatchInfo.MatchTeam2.CurrentTeamSide,
},
};
Expand Down Expand Up @@ -1945,7 +1945,7 @@ private void SetMatchVariable()
_CsServer.UpdateConvar("mp_maxrounds", _Match.MatchInfo.Config.MaxRounds);

// Compare with not equals to support initial state with current teamsite none
var tTeam = _Match.MatchInfo.MatchTeam1.CurrentTeamSite != Match.Contract.Team.CounterTerrorist ? _Match.MatchInfo.MatchTeam1 : _Match.MatchInfo.MatchTeam2;
var tTeam = _Match.MatchInfo.MatchTeam1.CurrentTeamSide != Match.Contract.Team.CounterTerrorist ? _Match.MatchInfo.MatchTeam1 : _Match.MatchInfo.MatchTeam2;
var ctTeam = _Match.GetOtherTeam(tTeam);

// Set CT Site Names
Expand Down

0 comments on commit ab1acff

Please sign in to comment.