using Barotrauma.Networking; using System.Collections.Generic; namespace Barotrauma { partial class Voting { private bool allowSubVoting, allowModeVoting; public bool AllowVoteKick = true; public bool AllowEndVoting = true; private List> GetVoteList(VoteType voteType, List voters) { List> voteList = new List>(); foreach (Client voter in voters) { object vote = voter.GetVote(voteType); if (vote == null) continue; var existingVotable = voteList.Find(v => v.First == vote || v.First.Equals(vote)); if (existingVotable == null) { voteList.Add(new Pair(vote, 1)); } else { existingVotable.Second++; } } return voteList; } public T HighestVoted(VoteType voteType, List voters) { if (voteType == VoteType.Sub && !AllowSubVoting) return default(T); if (voteType == VoteType.Mode && !AllowModeVoting) return default(T); List> voteList = GetVoteList(voteType, voters); T selected = default(T); int highestVotes = 0; foreach (Pair votable in voteList) { if (selected == null || votable.Second > highestVotes) { highestVotes = votable.Second; selected = (T)votable.First; } } return selected; } public void ResetVotes(List connectedClients) { foreach (Client client in connectedClients) { client.ResetVotes(); } GameMain.NetworkMember.EndVoteCount = 0; GameMain.NetworkMember.EndVoteMax = 0; #if CLIENT UpdateVoteTexts(connectedClients, VoteType.Mode); UpdateVoteTexts(connectedClients, VoteType.Sub); #endif } } }