Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 12 additions & 5 deletions Content.Shared/_ES/Voting/ESSharedVoteSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -137,11 +137,18 @@ public void EndVote(Entity<ESVoteComponent> ent)
result = _random.Pick(winningOptions);
break;
case ResultStrategy.WeightedPick:
// Convert each option into a weight based on counts
var weights = ent.Comp.Votes
.Select(p => (p.Key, (float) (1 + p.Value.Count))) // + 1 so every option can be chosen
.ToDictionary();
result = _random.Pick(weights);
if (ent.Comp.Votes.Values.Sum(p => p.Count) == 0)
{
result = _random.Pick(ent.Comp.VoteOptions);
}
else
{
// Convert each option into a weight based on counts
var weights = ent.Comp.Votes
.Select(p => (p.Key, (float) p.Value.Count))
.ToDictionary();
result = _random.Pick(weights);
}
break;
default:
throw new ArgumentOutOfRangeException();
Expand Down
Loading