Unstable 0.15.15.0 (and the one before it I forgor)

This commit is contained in:
Markus Isberg
2021-11-18 21:34:30 +09:00
parent 10e5fd5f3e
commit 80f39cd2a3
257 changed files with 4916 additions and 2582 deletions
@@ -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;
}
}