JustDerb / RoR2-VsTwitch

Risk of Rain 2 Mod - Fight Twitch Chat.
https://thunderstore.io/package/JustDerb/Vs_Twitch/
6 stars 4 forks source link

Tied votes should be picked randomly #24

Closed TheBolshe closed 3 years ago

TheBolshe commented 3 years ago

When a vote is tied, the system picks the first vote which is a bit less fun. Although this won't usually happen with larger streamers, it happens often with smaller creators. My understanding is that the vote resolution happens in RoR2-VsTwitch/ItemRoller/VoteStrategy/MaxVoteStrategy.cs in this bit :

winner = default; int highestVote = -1; foreach (var tally in totalVotes) { if (tally.Value > highestVote) { winner = tally.Key; highestVote = tally.Value; } } return winner;

Instead of this a list should be created to store all the tied votes then a random element of this list picked. I found a solution to this for the previous version of this mod

public int Apply(List options) { Debug.Log("start apply strategy"); var votedValue = 0; List voted = new List() { options.ElementAt(0) }; foreach (var item in voteCounter) { if (item.Value > votedValue) { votedValue = item.Value; voted.Clear(); } else { voted.Add(item.Key); } } //Debug.Log("votedKey: " + votedKey); var votedKey = voted.ElementAt(UnityEngine.Random.Range(0, voted.Count())); return options.IndexOf(votedKey); }

But this version seem a bit different, i don't know if it would work right away