private void MapVoteEnded(object sender, PollOutcome e) { if (Users.Values.Count(x => !x.IsSpectator) >= MinimumAutostartPlayers) { StartVote(new CmdStart(), null, "", MapVoteTime); } }
private async Task <bool> CheckEnd(bool timeout, bool forceEnd) { List <int> votes = Options.Select((o, i) => userVotes.Count(x => x.Value == i)).ToList(); List <int> potentialWinnerIndexes = new List <int>(); for (int i = 0; i < votes.Count; i++) { if (votes[i] == votes.Max()) { potentialWinnerIndexes.Add(i); } } Random rng = new Random(); var winnerId = potentialWinnerIndexes[rng.Next(potentialWinnerIndexes.Count)]; if (votes[winnerId] >= winCount || timeout && !absoluteMajorityVote) { Ended = true; if (yesNoVote) { if (winnerId == 0) { battle.SayGame($"Poll: {Topic} [END:SUCCESS]"); //Option Yes } else { battle.SayGame($"Poll: {Topic} [END:FAILED]"); //Option No } } else { battle.SayGame($"Poll: Choose {Options[winnerId].Name}? [END:SUCCESS]"); } Outcome = new PollOutcome() { ChosenOption = Options[winnerId] }; await Options[winnerId].Action(); return(true); } else if (timeout || forceEnd) { Ended = true; if (yesNoVote) { battle.SayGame($"Poll: {Topic} [END:FAILED]"); } else { battle.SayGame($"Option Poll: {Topic} [END:FAILED]"); } Outcome = new PollOutcome() { ChosenOption = null }; return(true); } return(false); }
private async Task <bool> CheckEnd(bool timeout) { List <int> votes = Options.Select((o, i) => userVotes.Count(x => x.Value == i)).ToList(); var winnerId = votes.IndexOf(votes.Max()); if (votes[winnerId] >= winCount || timeout && !absoluteMajorityVote) { Ended = true; if (yesNoVote) { if (winnerId == 0) { battle.SayGame($"Poll: {Topic} [END:SUCCESS]"); //Option Yes } else { battle.SayGame($"Poll: {Topic} [END:FAILED]"); //Option No } } else { battle.SayGame($"Poll: Choose {Options[winnerId].Name}? [END:SUCCESS]"); } Outcome = new PollOutcome() { ChosenOption = Options[winnerId] }; await Options[winnerId].Action(); return(true); } else if (timeout) { Ended = true; if (yesNoVote) { battle.SayGame($"Poll: {Topic} [END:FAILED]"); } else { battle.SayGame($"Option Poll: {Topic} [END:FAILED]"); } Outcome = new PollOutcome() { ChosenOption = null }; return(true); } return(false); }
private async Task <bool> CheckEnd(bool timeout) { var yes = userVotes.Count(x => x.Value == true); var no = userVotes.Count(x => x.Value == false); if (yes >= winCount || timeout && !AbsoluteMajorityVote && yes > no) { Ended = true; await battle.SayBattle($"Poll: {question} [END:SUCCESS]"); if (command.Access == BattleCommand.AccessType.NotIngame && battle.spring.IsRunning) { return(true); } if (command.Access == BattleCommand.AccessType.Ingame && !battle.spring.IsRunning) { return(true); } await command.ExecuteArmed(battle, Creator); Outcome = new PollOutcome() { Success = true }; return(true); } else if (no >= winCount || timeout) { Ended = true; await battle.SayBattle($"Poll: {question} [END:FAILED]"); Outcome = new PollOutcome() { Success = false }; return(true); } return(false); }
private void MapVoteEnded(object sender, PollOutcome e) { StartVote(new CmdStart(), null, "", MapVoteTime); }