Exemplo n.º 1
0
 static void Self_ChatFromSimulator(object sender, ChatEventArgs e)
 {
     if (e.FromName != _Client.Self.Name && e.Type == ChatType.Normal && e.AudibleLevel == ChatAudibleLevel.Fully)
     {
         string str = "<" + e.FromName + "> " + e.Message;
         _IRC.SendMessage(_AutoJoinChannel, str);
         Console.WriteLine("[SL->IRC] " + str);
     }
 }
Exemplo n.º 2
0
        void _timer_Elapsed(object sender, ElapsedEventArgs e)
        {
            try
            {
                Helper.Log("Timer Elapsed");
                _timerElapsed = DateTime.Now;

                if (_paused || _client == null || !Helper.ModActive)
                {
                    return;
                }

                if (_eventsPossible == null)
                {
                    if (Current.Game.tickManager.Paused)
                    {
                        _paused = true;
                        return;
                    }

                    if (_extraWait > 0)
                    {
                        return;
                    }
                }

                Helper.Log("Checking Voting Stage");


                _extraWait = 0;

                if (_votingStage == 0)
                {
                    if (_eventsPossible.Count() <= 0)
                    {
                        return;
                    }
                    _voteActive = true;
                    _voteAnswers.Clear();

                    List <IncidentDef> eventTest = _eventsPossible.ToList();
                    Helper.Log("Playing event lottery, total events " + eventTest.Count());

                    int eventsTotal  = eventTest.Count();
                    int eventsNeeded = Settings.VoteOptions;
                    if (eventsTotal < eventsNeeded)
                    {
                        eventsNeeded = eventsTotal;
                    }
                    _eventsPossibleChosen = new IncidentDef[eventsNeeded];
                    System.Random rnd = new System.Random();
                    for (int i = 0; i < eventTest.Count(); i++)
                    {
                        if (eventsNeeded == 0)
                        {
                            break;
                        }

                        int    win  = rnd.Next(1, 101);
                        double perc = ((double)eventsNeeded / eventsTotal) * 100;
                        if (win <= perc)
                        {
                            _eventsPossibleChosen[eventsNeeded - 1] = eventTest[i];
                            eventsNeeded--;
                        }
                        eventsTotal--;
                    }
                    Helper.Log("Chose events to vote with " + _eventsPossibleChosen.Count());

                    if (!Find.WindowStack.TryRemove(typeof(VoteDuelWindow), true) && _eventsPossibleChosen.Count() == 200)
                    {
                        Find.WindowStack.Add(new VoteDuelWindow(_eventsPossibleChosen, this));
                    }
                    else if (!Find.WindowStack.TryRemove(typeof(VoteWindow), true))
                    {
                        Find.WindowStack.Add(new VoteWindow(_eventsPossibleChosen, this));
                    }

                    //_client.SendMessage("TwitchStoriesChatMessageNewVote".Translate() + ": " + "TwitchToolKitVoteInstructions".Translate());
                    //for (int i = 0; i < _eventsPossibleChosen.Count(); i++)
                    //{
                    //    Helper.Log("Event " + _eventsPossibleChosen.ToString());
                    //    string msg = "[" + (i + 1) + "] ";
                    //    msg += (_eventsPossibleChosen[i].LabelCap);
                    //    _client.SendMessage(msg);
                    //}

                    _votingStage = 1;
                }
                else if (_votingStage == 1)
                {
                    Helper.Log("Starting Votes Count");
                    if (_eventsPossibleChosen.Length <= 0)
                    {
                        return;
                    }
                    Helper.Log("Counting Votes");
                    int[] votekeys = new int[_eventsPossibleChosen.Count()];
                    foreach (KeyValuePair <string, int> vote in _voteAnswers)
                    {
                        if (_eventsPossibleChosen.Length < vote.Value)
                        {
                            continue;
                        }
                        Helper.Log($"Trying to register vote for {votekeys[vote.Value - 1]}");
                        votekeys[vote.Value - 1] += 1;
                        Helper.Log($"New Count {votekeys[vote.Value - 1]}");
                    }
                    int evt       = 0;
                    int voteCount = 0;
                    for (int i = 0; i < votekeys.Count(); i++)
                    {
                        Helper.Log($"{votekeys[i]}:{_eventsPossibleChosen[i]} vs {votekeys[evt]}:{_eventsPossibleChosen[evt]}");
                        if (votekeys[i] > votekeys[evt])
                        {
                            evt = i;
                        }
                        else if (votekeys[i] == votekeys[evt] && _rand.Next(0, 2) == 1)
                        {
                            Helper.Log("Tied, picking random winner");
                            evt = i;
                        }
                        voteCount += votekeys[i];
                    }

                    double wonPercentage = ((double)evt / (double)(voteCount == 0 ? 1 : voteCount));

                    string msg = "TwitchStoriesChatMessageVoteEnd".Translate() + " ";

                    msg += $"{_eventsPossibleChosen[evt].LabelCap}";


                    _client.SendMessage(msg);

                    FiringIncident chosen = new FiringIncident(_eventsPossibleChosen[evt], _currentVote.storytellerComp_CustomStoryTeller, _currentVote.parms);
                    Ticker.FiringIncidents.Enqueue(chosen);

                    Helper.Log("Vote: " + _eventsPossibleChosen[evt].LabelCap + " won");
                    Find.WindowStack.TryRemove(typeof(VoteDuelWindow), true);
                    Find.WindowStack.TryRemove(typeof(VoteWindow), true);

                    _voteActive           = false;
                    _voteEvents           = null;
                    _eventsPossibleChosen = null;
                    _eventsPossible       = null;
                    _votingStage          = 2;
                }
            }
            catch (Exception exception)
            {
                Helper.Log("Exception: " + exception.Message + " " + exception.StackTrace);
            }
            finally
            {
                Helper.Log("Starting Timer Back up");
                StartTimer();
            }
        }