コード例 #1
0
ファイル: Plugin.cs プロジェクト: PatPeter/callvote
        public IEnumerator <float> StartVoteCoroutine(Vote newVote, CallvoteFunction callback)
        {
            int timerCounter = 0;

            CurrentVote          = newVote;
            CurrentVote.Callback = callback;
            string firstBroadcast = CurrentVote.Question + " Press ~ and type ";
            int    counter        = 0;

            foreach (KeyValuePair <int, string> kv in CurrentVote.Options)
            {
                if (counter == CurrentVote.Options.Count - 1)
                {
                    firstBroadcast += "or ." + kv.Key + " for " + kv.Value + " ";
                }
                else
                {
                    firstBroadcast += "." + kv.Key + " for " + kv.Value + ", ";
                }
                counter++;
            }
            int textsize = firstBroadcast.Length / 10;

            Map.Broadcast(5, "<size=" + (48 - textsize).ToString() + ">" + firstBroadcast + "</size>");
            yield return(Timing.WaitForSeconds(5f));

            for (; ;)
            {
                if (timerCounter >= Plugin.Instance.Config.VoteDuration + 1)
                {
                    if (CurrentVote.Callback == null)
                    {
                        string timerBroadcast = "Final results:\n";
                        foreach (KeyValuePair <int, string> kv in CurrentVote.Options)
                        {
                            timerBroadcast += CurrentVote.Options[kv.Key] + " (" + CurrentVote.Counter[kv.Key] + ") ";
                            textsize        = timerBroadcast.Length / 10;
                        }
                        Map.Broadcast(5, "<size=" + (48 - textsize).ToString() + ">" + timerBroadcast + "</size>");
                    }
                    else
                    {
                        CurrentVote.Callback.Invoke(CurrentVote);
                    }
                    CurrentVote = null;
                    yield break;
                }
                else
                {
                    string timerBroadcast = firstBroadcast + "\n";
                    foreach (KeyValuePair <int, string> kv in CurrentVote.Options)
                    {
                        timerBroadcast += CurrentVote.Options[kv.Key] + " (" + CurrentVote.Counter[kv.Key] + ") ";
                        textsize        = timerBroadcast.Length / 10;
                    }
                    Map.Broadcast(1, "<size=" + (48 - textsize).ToString() + ">" + timerBroadcast + "</size>");
                }
                timerCounter++;
                yield return(Timing.WaitForSeconds(1f));
            }
        }
コード例 #2
0
ファイル: Plugin.cs プロジェクト: PatPeter/callvote
        public void OnStartVote(string question, Dictionary <int, string> options, HashSet <string> votes, Dictionary <int, int> counter)
        {
            Vote newVote = new Vote(question, options, votes, counter);

            voteCoroutine = Timing.RunCoroutine(StartVoteCoroutine(newVote, null));
        }