2 using System.Collections.Generic;
8 public enum VoteState {
None = 0, Started = 1, Running = 2, Passed = 3, Failed = 4 };
10 private static IReadOnlyDictionary<T, int> GetVoteCounts<T>(VoteType voteType, IEnumerable<Client> voters)
12 Dictionary<T, int> voteList =
new Dictionary<T, int>();
14 foreach (
Client voter
in voters)
16 T vote = voter.GetVote<T>(voteType);
17 if (vote ==
null)
continue;
19 if (!voteList.ContainsKey(vote))
21 voteList.Add(vote, 1);
36 public static T
HighestVoted<T>(VoteType voteType, IEnumerable<Client> voters, out
int voteCount)
39 if (voteType == VoteType.Sub && !
GameMain.
NetworkMember.ServerSettings.AllowSubVoting) {
return default; }
40 if (voteType == VoteType.Mode && !
GameMain.
NetworkMember.ServerSettings.AllowModeVoting) {
return default; }
42 IReadOnlyDictionary<T, int> voteList = GetVoteCounts<T>(voteType, voters);
46 foreach (KeyValuePair<T, int> votable
in voteList)
48 if (voteType == VoteType.Sub
55 if (selected ==
null || votable.Value > highestVotes)
57 highestVotes = votable.Value;
58 selected = votable.Key;
61 voteCount = highestVotes;
static NetworkMember NetworkMember
static T HighestVoted< T >(VoteType voteType, IEnumerable< Client > voters)