Unstable 0.15.15.0 (and the one before it I forgor)
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
using Barotrauma.Networking;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
|
||||
namespace Barotrauma
|
||||
{
|
||||
@@ -15,23 +16,22 @@ namespace Barotrauma
|
||||
|
||||
public enum VoteState { None = 0, Started = 1, Running = 2, Passed = 3, Failed = 4 };
|
||||
|
||||
private List<Pair<object, int>> GetVoteList(VoteType voteType, List<Client> voters)
|
||||
private IReadOnlyDictionary<T, int> GetVoteCounts<T>(VoteType voteType, List<Client> voters)
|
||||
{
|
||||
List<Pair<object, int>> voteList = new List<Pair<object, int>>();
|
||||
Dictionary<T, int> voteList = new Dictionary<T, int>();
|
||||
|
||||
foreach (Client voter in voters)
|
||||
{
|
||||
object vote = voter.GetVote<object>(voteType);
|
||||
T vote = voter.GetVote<T>(voteType);
|
||||
if (vote == null) continue;
|
||||
|
||||
var existingVotable = voteList.Find(v => v.First == vote || v.First.Equals(vote));
|
||||
if (existingVotable == null)
|
||||
if (!voteList.ContainsKey(vote))
|
||||
{
|
||||
voteList.Add(new Pair<object, int>(vote, 1));
|
||||
voteList.Add(vote, 1);
|
||||
}
|
||||
else
|
||||
{
|
||||
existingVotable.Second++;
|
||||
voteList[vote]++;
|
||||
}
|
||||
}
|
||||
return voteList;
|
||||
@@ -42,16 +42,23 @@ namespace Barotrauma
|
||||
if (voteType == VoteType.Sub && !AllowSubVoting) return default(T);
|
||||
if (voteType == VoteType.Mode && !AllowModeVoting) return default(T);
|
||||
|
||||
List<Pair<object, int>> voteList = GetVoteList(voteType, voters);
|
||||
IReadOnlyDictionary<T, int> voteList = GetVoteCounts<T>(voteType, voters);
|
||||
|
||||
T selected = default(T);
|
||||
int highestVotes = 0;
|
||||
foreach (Pair<object, int> votable in voteList)
|
||||
foreach (KeyValuePair<T, int> votable in voteList)
|
||||
{
|
||||
if (selected == null || votable.Second > highestVotes)
|
||||
if (voteType == VoteType.Sub
|
||||
&& votable.Key is SubmarineInfo subInfo
|
||||
&& GameMain.NetworkMember.ServerSettings.HiddenSubs.Contains(subInfo.Name))
|
||||
{
|
||||
highestVotes = votable.Second;
|
||||
selected = (T)votable.First;
|
||||
//This sub is hidden so it can't be voted for, skip
|
||||
continue;
|
||||
}
|
||||
if (selected == null || votable.Value > highestVotes)
|
||||
{
|
||||
highestVotes = votable.Value;
|
||||
selected = votable.Key;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user