-
-
Notifications
You must be signed in to change notification settings - Fork 73
/
ReadySystem.cs
124 lines (102 loc) · 4.04 KB
/
ReadySystem.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
using CounterStrikeSharp.API.Core;
using CounterStrikeSharp.API.Core.Attributes.Registration;
using CounterStrikeSharp.API.Modules.Commands;
using CounterStrikeSharp.API.Modules.Utils;
namespace MatchZy;
public partial class MatchZy
{
public Dictionary<CsTeam, bool> teamReadyOverride = new() {
{CsTeam.Terrorist, false},
{CsTeam.CounterTerrorist, false},
{CsTeam.Spectator, false}
};
public bool allowForceReady = true;
public bool IsTeamsReady()
{
return IsTeamReady((int)CsTeam.CounterTerrorist) && IsTeamReady((int)CsTeam.Terrorist);
}
public bool IsSpectatorsReady()
{
return IsTeamReady((int)CsTeam.Spectator);
}
public bool IsTeamReady(int team)
{
// if (matchStarted) return true;
int minPlayers = GetPlayersPerTeam(team);
int minReady = GetTeamMinReady(team);
(int playerCount, int readyCount) = GetTeamPlayerCount(team, false);
Log($"[IsTeamReady] team: {team} minPlayers:{minPlayers} minReady:{minReady} playerCount:{playerCount} readyCount:{readyCount}");
if (team == (int)CsTeam.Spectator && minReady == 0)
{
return true;
}
if (readyAvailable && playerCount == 0)
{
// We cannot ready for veto with no players, regardless of force status or min_players_to_ready.
return false;
}
if (playerCount == readyCount && playerCount >= minPlayers)
{
return true;
}
if (IsTeamForcedReady((CsTeam)team) && readyCount >= minReady)
{
return true;
}
return false;
}
public int GetPlayersPerTeam(int team)
{
if (team == (int)CsTeam.CounterTerrorist || team == (int)CsTeam.Terrorist) return matchConfig.PlayersPerTeam;
if (team == (int)CsTeam.Spectator) return matchConfig.MinSpectatorsToReady;
return 0;
}
public int GetTeamMinReady(int team)
{
if (team == (int)CsTeam.CounterTerrorist || team == (int)CsTeam.Terrorist) return matchConfig.MinPlayersToReady;
if (team == (int)CsTeam.Spectator) return matchConfig.MinSpectatorsToReady;
return 0;
}
public (int, int) GetTeamPlayerCount(int team, bool includeCoaches = false)
{
int playerCount = 0;
int readyCount = 0;
foreach (var key in playerData.Keys)
{
if (!playerData[key].IsValid) continue;
if (playerData[key].TeamNum == team) {
playerCount++;
if (playerReadyStatus[key] == true) readyCount++;
}
}
return (playerCount, readyCount);
}
public bool IsTeamForcedReady(CsTeam team) {
return teamReadyOverride[team];
}
[ConsoleCommand("css_forceready", "Force-readies the team")]
public void OnForceReadyCommandCommand(CCSPlayerController? player, CommandInfo? command)
{
Log($"{readyAvailable} {isMatchSetup} {allowForceReady} {IsPlayerValid(player)}");
if (!readyAvailable || !isMatchSetup || !allowForceReady || !IsPlayerValid(player)) return;
int minReady = GetTeamMinReady(player!.TeamNum);
(int playerCount, int readyCount) = GetTeamPlayerCount(player!.TeamNum, false);
if (playerCount < minReady)
{
// ReplyToUserCommand(player, $"You must have at least {minReady} player(s) on the server to ready up.");
ReplyToUserCommand(player, Localizer["matchzy.rs.minreadyplayers", minReady]);
return;
}
foreach (var key in playerData.Keys)
{
if (!playerData[key].IsValid) continue;
if (playerData[key].TeamNum == player.TeamNum) {
playerReadyStatus[key] = true;
// ReplyToUserCommand(playerData[key], $"Your team was force-readied by {player.PlayerName}");
ReplyToUserCommand(playerData[key], Localizer["matchzy.rs.forcereadiedby", player.PlayerName]);
}
}
teamReadyOverride[(CsTeam)player.TeamNum] = true;
CheckLiveRequired();
}
}