Example #1
0
        private void TickTwitchHost()
        {
            if (!Config.Instance.Enabled)
            {
                return;
            }

            if (Config.Instance.IsTwitchVoting)
            {
                if (progressBarTwitch.Maximum != Config.Instance.TwitchVotingTime)
                {
                    progressBarTwitch.Maximum = Config.Instance.TwitchVotingTime;
                }

                // Hack to fix Windows' broken-ass progress bar handling
                int value = Math.Max(1, (int)Stopwatch.ElapsedMilliseconds);
                progressBarTwitch.Value = Math.Max(progressBarTwitch.Maximum - value, 0);
                progressBarTwitch.Value = Math.Max(progressBarTwitch.Maximum - value - 1, 0);

                if (Stopwatch.ElapsedMilliseconds - elapsedCount > 100)
                {
                    long remaining  = Math.Max(0, Config.Instance.TwitchVotingTime - Stopwatch.ElapsedMilliseconds);
                    int  iRemaining = (int)((float)remaining / Config.Instance.TwitchVotingTime * 1000f);

                    ProcessHooker.SendEffectToGame("time", iRemaining.ToString());

                    elapsedCount = (int)Stopwatch.ElapsedMilliseconds;
                }

                if (Stopwatch.ElapsedMilliseconds >= Config.Instance.TwitchVotingTime)
                {
                    ProcessHooker.SendEffectToGame("time", "0");
                    elapsedCount = 0;

                    progressBarTwitch.Value   = 0;
                    progressBarTwitch.Maximum = Config.Instance.TwitchVotingCooldown;

                    Stopwatch.Restart();
                    Config.Instance.IsTwitchVoting = false;

                    labelTwitchCurrentMode.Text = "Current Mode: Cooldown";

                    VotingCooldownComboBoxItem item = (VotingCooldownComboBoxItem)comboBoxVotingCooldown.SelectedItem;

                    AbstractEffect effect = Twitch.GetRandomVotedEffect(out string username);

                    Twitch.SetVoting(false, item.VotingCooldown, item.Text, effect, username);
                    if (!Config.Instance.TwitchDontActivateEffects)
                    {
                        CallEffect(effect);
                    }
                }
            }
            else
            {
                if (progressBarTwitch.Maximum != Config.Instance.TwitchVotingCooldown)
                {
                    progressBarTwitch.Maximum = Config.Instance.TwitchVotingCooldown;
                }

                // Hack to fix Windows' broken-ass progress bar handling
                int value = Math.Max(1, (int)Stopwatch.ElapsedMilliseconds);
                progressBarTwitch.Value = Math.Min(value, progressBarTwitch.Maximum);
                progressBarTwitch.Value = Math.Min(value, progressBarTwitch.Maximum);

                if (!Config.Instance.TwitchAllowVoting && Stopwatch.ElapsedMilliseconds - elapsedCount > 100)
                {
                    long remaining  = Math.Max(0, Config.Instance.TwitchVotingTime - Stopwatch.ElapsedMilliseconds);
                    int  iRemaining = (int)((float)remaining / Config.Instance.TwitchVotingTime * 1000f);

                    ProcessHooker.SendEffectToGame("time", iRemaining.ToString());

                    elapsedCount = (int)Stopwatch.ElapsedMilliseconds;
                }

                if (Stopwatch.ElapsedMilliseconds >= Config.Instance.TwitchVotingCooldown)
                {
                    if (Config.Instance.TwitchAllowVoting)
                    {
                        progressBarTwitch.Value = progressBarTwitch.Maximum = Config.Instance.TwitchVotingTime;

                        Config.Instance.IsTwitchVoting = true;

                        labelTwitchCurrentMode.Text = "Current Mode: Voting";

                        VotingTimeComboBoxItem item = (VotingTimeComboBoxItem)comboBoxVotingTime.SelectedItem;

                        Twitch.SetVoting(true, item.VotingTime, item.Text);
                    }
                    else
                    {
                        ProcessHooker.SendEffectToGame("time", "0");
                        elapsedCount = 0;

                        progressBarTwitch.Value   = 0;
                        progressBarTwitch.Maximum = Config.Instance.TwitchVotingCooldown;

                        labelTwitchCurrentMode.Text = "Current Mode: Cooldown";

                        VotingCooldownComboBoxItem item = (VotingCooldownComboBoxItem)comboBoxVotingCooldown.SelectedItem;

                        AbstractEffect effect = Twitch.GetRandomVotedEffect(out string username);

                        Twitch.SetVoting(false, item.VotingCooldown, item.Text, effect, username);
                        if (!Config.Instance.TwitchDontActivateEffects)
                        {
                            CallEffect(effect);
                        }
                    }
                    Stopwatch.Restart();
                }
            }
        }
Example #2
0
        private void TickTwitch()
        {
            if (!Config.Instance().Enabled)
            {
                return;
            }

            if (Config.Instance().TwitchVotingMode == 1)
            {
                if (progressBarTwitch.Maximum != Config.Instance().TwitchVotingTime)
                {
                    progressBarTwitch.Maximum = Config.Instance().TwitchVotingTime;
                }

                // Hack to fix Windows' broken-ass progress bar handling
                int value = Math.Max(1, (int)stopwatch.ElapsedMilliseconds);
                progressBarTwitch.Value = Math.Max(progressBarTwitch.Maximum - value, 0);
                progressBarTwitch.Value = Math.Max(progressBarTwitch.Maximum - value - 1, 0);

                if (stopwatch.ElapsedMilliseconds - elapsedCount > 100)
                {
                    long remaining = Math.Max(0, Config.Instance().TwitchVotingTime - stopwatch.ElapsedMilliseconds);

                    ProcessHooker.SendEffectToGame("time", $"{remaining},{Config.Instance().TwitchVotingTime}");

                    twitch?.SendEffectVotingToGame();

                    elapsedCount = (int)stopwatch.ElapsedMilliseconds;
                }

                if (stopwatch.ElapsedMilliseconds >= Config.Instance().TwitchVotingTime)
                {
                    ProcessHooker.SendEffectToGame("time", "0");
                    elapsedCount = 0;

                    progressBarTwitch.Value   = 0;
                    progressBarTwitch.Maximum = Config.Instance().TwitchVotingCooldown;

                    stopwatch.Restart();
                    Config.Instance().TwitchVotingMode = 0;

                    labelTwitchCurrentMode.Text = "Current Mode: Cooldown";

                    if (twitch != null)
                    {
                        TwitchConnection.VotingElement element = twitch.GetRandomVotedEffect(out string username);

                        twitch.SetVoting(0, timesUntilRapidFire, element, username);
                        CallEffect(element.Effect);
                    }
                }
            }
            else if (Config.Instance().TwitchVotingMode == 2)
            {
                if (progressBarTwitch.Maximum != 1000 * 10)
                {
                    progressBarTwitch.Maximum = 1000 * 10;
                }

                // Hack to fix Windows' broken-ass progress bar handling
                int value = Math.Max(1, (int)stopwatch.ElapsedMilliseconds);
                progressBarTwitch.Value = Math.Max(progressBarTwitch.Maximum - value, 0);
                progressBarTwitch.Value = Math.Max(progressBarTwitch.Maximum - value - 1, 0);

                if (stopwatch.ElapsedMilliseconds - elapsedCount > 100)
                {
                    long remaining = Math.Max(0, (1000 * 10) - stopwatch.ElapsedMilliseconds);

                    ProcessHooker.SendEffectToGame("time", $"{remaining},10000");

                    elapsedCount = (int)stopwatch.ElapsedMilliseconds;
                }

                if (stopwatch.ElapsedMilliseconds >= 1000 * 10) // Set 10 seconds
                {
                    ProcessHooker.SendEffectToGame("time", "0");
                    elapsedCount = 0;

                    progressBarTwitch.Value   = 0;
                    progressBarTwitch.Maximum = Config.Instance().TwitchVotingCooldown;

                    stopwatch.Restart();
                    Config.Instance().TwitchVotingMode = 0;

                    labelTwitchCurrentMode.Text = "Current Mode: Cooldown";

                    twitch?.SetVoting(0, timesUntilRapidFire);
                }
            }
            else if (Config.Instance().TwitchVotingMode == 0)
            {
                if (progressBarTwitch.Maximum != Config.Instance().TwitchVotingCooldown)
                {
                    progressBarTwitch.Maximum = Config.Instance().TwitchVotingCooldown;
                }

                // Hack to fix Windows' broken-ass progress bar handling
                int value = Math.Max(1, (int)stopwatch.ElapsedMilliseconds);
                progressBarTwitch.Value = Math.Min(value + 1, progressBarTwitch.Maximum);
                progressBarTwitch.Value = Math.Min(value, progressBarTwitch.Maximum);

                if (stopwatch.ElapsedMilliseconds - elapsedCount > 100)
                {
                    long remaining = Math.Max(0, Config.Instance().TwitchVotingCooldown - stopwatch.ElapsedMilliseconds);

                    ProcessHooker.SendEffectToGame("time", $"{remaining},{Config.Instance().TwitchVotingCooldown}");

                    elapsedCount = (int)stopwatch.ElapsedMilliseconds;
                }

                if (stopwatch.ElapsedMilliseconds >= Config.Instance().TwitchVotingCooldown)
                {
                    elapsedCount = 0;

                    if (--timesUntilRapidFire == 0)
                    {
                        progressBarTwitch.Value = progressBarTwitch.Maximum = 1000 * 10;

                        timesUntilRapidFire = new Random().Next(10, 15);

                        Config.Instance().TwitchVotingMode = 2;
                        labelTwitchCurrentMode.Text = "Current Mode: Rapid-Fire";

                        twitch?.SetVoting(2, timesUntilRapidFire);
                    }
                    else
                    {
                        progressBarTwitch.Value = progressBarTwitch.Maximum = Config.Instance().TwitchVotingTime;

                        Config.Instance().TwitchVotingMode = 1;
                        labelTwitchCurrentMode.Text = "Current Mode: Voting";

                        twitch?.SetVoting(1, timesUntilRapidFire);
                    }
                    stopwatch.Restart();
                }
            }
        }