/// <summary> /// Starts a vote if one is not already in progress. /// </summary> /// <param name="builder">The <see cref="VoteBuilder"/> object with the vote information.</param> /// <returns><c>true</c> if the vote started; <c>false</c> if another vote is already started.</returns> internal static bool StartVote(VoteBuilder builder) { if (VoteInProgress) { return(false); } VoteInProgress = true; CurrentVote = new Vote(builder); CurrentVote.Ended += VoteEnded; CurrentVote.Cancelled += VoteEnded; return(true); }
/// <summary> /// Initializes a new instance of the <see cref="Vote"/> class. /// </summary> /// <param name="builder">The <see cref="VoteBuilder"/> object with the vote information.</param> internal Vote(VoteBuilder builder) { if (builder.Options == null || builder.Options.Count == 0) { this.voteOptions = new string[] { "Yes", "No" }; this.boolVote = true; } else { this.voteOptions = builder.Options.ToArray(); this.boolVote = false; } this.data = builder.Data; ChatHook.ChatMessage += this.OnChatMessage; this.timer = new Timer(20000); this.timer.Elapsed += this.OnTimerElapsed; this.timer.Enabled = true; foreach (var client in ConnectionManager.Instance.Clients.List) { this.votingPool.Add(client.playerId, -1); ChatHelper.SendTo(client, "Vote question", Language.GetString(builder.Message, client, builder.MessageArgs)); if (this.boolVote) { ChatHelper.SendTo(client, "Vote Yes Or No"); } else { ChatHelper.SendTo(client, "Vote Number"); for (var i = 0; i < this.voteOptions.Length; i++) { ChatHelper.SendTo(client, "Vote option", i + 1, this.voteOptions[i]); } } } }