Пример #1
0
    public string GetBombResult(bool lastBomb = true)
    {
        bool   hasDetonated           = false;
        bool   hasBeenSolved          = true;
        float  timeStarting           = float.MaxValue;
        float  timeRemaining          = float.MaxValue;
        string timeRemainingFormatted = "";

        foreach (TwitchBomb bomb in Bombs)
        {
            if (bomb == null)
            {
                continue;
            }

            hasDetonated  |= bomb.Bomb.HasDetonated;
            hasBeenSolved &= bomb.IsSolved;
            if (timeRemaining > bomb.CurrentTimer)
            {
                timeStarting  = bomb.BombStartingTimer;
                timeRemaining = bomb.CurrentTimer;
            }

            if (!string.IsNullOrEmpty(timeRemainingFormatted))
            {
                timeRemainingFormatted += ", " + bomb.GetFullFormattedTime;
            }
            else
            {
                timeRemainingFormatted = bomb.GetFullFormattedTime;
            }
        }

        string bombMessage = "";

        if (OtherModes.VSModeOn && (hasDetonated || hasBeenSolved))
        {
            OtherModes.Team winner = OtherModes.Team.Good;
            if (OtherModes.GetGoodHealth() == 0)
            {
                winner      = OtherModes.Team.Evil;
                bombMessage = TwitchPlaySettings.data.VersusEvilHeader;
            }
            else if (OtherModes.GetEvilHealth() == 0)
            {
                winner      = OtherModes.Team.Good;
                bombMessage = TwitchPlaySettings.data.VersusGoodHeader;
            }

            bombMessage += string.Format(TwitchPlaySettings.data.VersusEndMessage,
                                         winner == OtherModes.Team.Good ? "good" : "evil", timeRemainingFormatted);
            bombMessage += TwitchPlaySettings.GiveBonusPoints();

            if (winner == OtherModes.Team.Good)
            {
                bombMessage += TwitchPlaySettings.data.VersusGoodFooter;
            }
            else if (winner == OtherModes.Team.Evil)
            {
                bombMessage += TwitchPlaySettings.data.VersusEvilFooter;
            }

            if (lastBomb && hasBeenSolved)
            {
                Leaderboard.Instance.Success = true;
            }
        }
        else if (hasDetonated)
        {
            bombMessage = string.Format(TwitchPlaySettings.data.BombExplodedMessage, timeRemainingFormatted);
            Leaderboard.Instance.BombsExploded += Bombs.Count;
            if (!lastBomb)
            {
                return(bombMessage);
            }

            Leaderboard.Instance.Success = false;
            TwitchPlaySettings.ClearPlayerLog();
        }
        else if (hasBeenSolved)
        {
            bombMessage = string.Format(TwitchPlaySettings.data.BombDefusedMessage, timeRemainingFormatted);

            Leaderboard.Instance.BombsCleared += Bombs.Count;
            bombMessage += TwitchPlaySettings.GiveBonusPoints();

            if (lastBomb)
            {
                Leaderboard.Instance.Success = true;
            }

            if (Leaderboard.Instance.CurrentSolvers.Count != 1)
            {
                return(bombMessage);
            }

            float  elapsedTime = timeStarting - timeRemaining;
            string userName    = "";
            foreach (string uName in Leaderboard.Instance.CurrentSolvers.Keys)
            {
                userName = uName;
                break;
            }
            if (Leaderboard.Instance.CurrentSolvers[userName] == Leaderboard.RequiredSoloSolves * Bombs.Count && OtherModes.currentMode == TwitchPlaysMode.Normal)
            {
                Leaderboard.Instance.AddSoloClear(userName, elapsedTime, out float previousRecord);
                if (TwitchPlaySettings.data.EnableSoloPlayMode)
                {
                    //Still record solo information, should the defuser be the only one to actually defuse a 11 * bomb-count bomb, but display normal leaderboards instead if
                    //solo play is disabled.
                    TimeSpan elapsedTimeSpan = TimeSpan.FromSeconds(elapsedTime);
                    string   soloMessage     = string.Format(TwitchPlaySettings.data.BombSoloDefusalMessage, Leaderboard.Instance.SoloSolver.UserName, (int)elapsedTimeSpan.TotalMinutes, elapsedTimeSpan.Seconds);
                    if (elapsedTime < previousRecord)
                    {
                        TimeSpan previousTimeSpan = TimeSpan.FromSeconds(previousRecord);
                        soloMessage += string.Format(TwitchPlaySettings.data.BombSoloDefusalNewRecordMessage, (int)previousTimeSpan.TotalMinutes, previousTimeSpan.Seconds);
                    }
                    soloMessage += TwitchPlaySettings.data.BombSoloDefusalFooter;
                    ParentService.StartCoroutine(SendDelayedMessage(1.0f, soloMessage));
                }
                else
                {
                    Leaderboard.Instance.ClearSolo();
                }
            }
            else
            {
                Leaderboard.Instance.ClearSolo();
            }
        }
        else
        {
            bombMessage = string.Format(TwitchPlaySettings.data.BombAbortedMessage, timeRemainingFormatted);
            Leaderboard.Instance.Success = false;
            TwitchPlaySettings.ClearPlayerLog();
        }
        return(bombMessage);
    }
    private void OnDisable()
    {
        BombActive = false;
        EnableDisableInput();
        TwitchComponentHandle.ClaimedList.Clear();
        TwitchComponentHandle.ClearUnsupportedModules();
        StopAllCoroutines();
        leaderboard.BombsAttempted++;
        string bombMessage = null;

        bool HasDetonated           = false;
        bool HasBeenSolved          = true;
        var  timeStarting           = float.MaxValue;
        var  timeRemaining          = float.MaxValue;
        var  timeRemainingFormatted = "";

        TwitchPlaysService.logUploader.Post();

        foreach (var commander in _bombCommanders)
        {
            HasDetonated  |= commander.Bomb.HasDetonated;
            HasBeenSolved &= commander.IsSolved;
            if (timeRemaining > commander.CurrentTimer)
            {
                timeStarting  = commander.bombStartingTimer;
                timeRemaining = commander.CurrentTimer;
            }

            if (!string.IsNullOrEmpty(timeRemainingFormatted))
            {
                timeRemainingFormatted += ", " + commander.GetFullFormattedTime;
            }
            else
            {
                timeRemainingFormatted = commander.GetFullFormattedTime;
            }
        }

        if (HasDetonated)
        {
            bombMessage = string.Format(TwitchPlaySettings.data.BombExplodedMessage, timeRemainingFormatted);
            leaderboard.BombsExploded += _bombCommanders.Count;
            leaderboard.Success        = false;
            TwitchPlaySettings.ClearPlayerLog();
        }
        else if (HasBeenSolved)
        {
            bombMessage  = string.Format(TwitchPlaySettings.data.BombDefusedMessage, timeRemainingFormatted);
            bombMessage += TwitchPlaySettings.GiveBonusPoints(leaderboard);
            leaderboard.BombsCleared += _bombCommanders.Count;
            leaderboard.Success       = true;
            if (leaderboard.CurrentSolvers.Count == 1)
            {
                float  previousRecord = 0.0f;
                float  elapsedTime    = timeStarting - timeRemaining;
                string userName       = "";
                foreach (string uName in leaderboard.CurrentSolvers.Keys)
                {
                    userName = uName;
                    break;
                }
                if (leaderboard.CurrentSolvers[userName] == (Leaderboard.RequiredSoloSolves * _bombCommanders.Count))
                {
                    leaderboard.AddSoloClear(userName, elapsedTime, out previousRecord);
                    if (TwitchPlaySettings.data.EnableSoloPlayMode)
                    {
                        //Still record solo information, should the defuser be the only one to actually defuse a 11 * bomb-count bomb, but display normal leaderboards instead if
                        //solo play is disabled.
                        TimeSpan elapsedTimeSpan = TimeSpan.FromSeconds(elapsedTime);
                        string   soloMessage     = string.Format(TwitchPlaySettings.data.BombSoloDefusalMessage, leaderboard.SoloSolver.UserName, (int)elapsedTimeSpan.TotalMinutes, elapsedTimeSpan.Seconds);
                        if (elapsedTime < previousRecord)
                        {
                            TimeSpan previousTimeSpan = TimeSpan.FromSeconds(previousRecord);
                            soloMessage += string.Format(TwitchPlaySettings.data.BombSoloDefusalNewRecordMessage, (int)previousTimeSpan.TotalMinutes, previousTimeSpan.Seconds);
                        }
                        soloMessage += TwitchPlaySettings.data.BombSoloDefusalFooter;
                        parentService.StartCoroutine(SendDelayedMessage(1.0f, soloMessage));
                    }
                    else
                    {
                        leaderboard.ClearSolo();
                    }
                }
                else
                {
                    leaderboard.ClearSolo();
                }
            }
        }
        else
        {
            bombMessage         = string.Format(TwitchPlaySettings.data.BombAbortedMessage, timeRemainingFormatted);
            leaderboard.Success = false;
            TwitchPlaySettings.ClearPlayerLog();
        }
        parentService.StartCoroutine(SendDelayedMessage(1.0f, bombMessage, SendAnalysisLink));

        moduleCameras?.gameObject.SetActive(false);

        foreach (TwitchBombHandle handle in _bombHandles)
        {
            if (handle != null)
            {
                Destroy(handle.gameObject, 2.0f);
            }
        }
        _bombHandles.Clear();
        _bombCommanders.Clear();

        if (_componentHandles != null)
        {
            foreach (TwitchComponentHandle handle in _componentHandles)
            {
                Destroy(handle.gameObject, 2.0f);
            }
            _componentHandles.Clear();
        }

        MusicPlayer.StopAllMusic();
    }
Пример #3
0
    private void OnDisable()
    {
        StopAllCoroutines();
        leaderboard.BombsAttempted++;
        string bombMessage = null;

        bool HasDetonated           = false;
        var  timeStarting           = float.MaxValue;
        var  timeRemaining          = float.MaxValue;
        var  timeRemainingFormatted = "";

        TwitchPlaysService.logUploader.Post();

        foreach (var commander in _bombCommanders)
        {
            HasDetonated |= (bool)CommonReflectedTypeInfo.HasDetonatedProperty.GetValue(commander.Bomb, null);
            if (timeRemaining > commander.CurrentTimer)
            {
                timeStarting  = commander._bombStartingTimer;
                timeRemaining = commander.CurrentTimer;
            }

            if (!string.IsNullOrEmpty(timeRemainingFormatted))
            {
                timeRemainingFormatted += ", " + commander.GetFullFormattedTime;
            }
            else
            {
                timeRemainingFormatted = commander.GetFullFormattedTime;
            }
        }

        if (HasDetonated)
        {
            bombMessage = string.Format("KAPOW KAPOW The bomb has exploded, with {0} remaining! KAPOW KAPOW", timeRemainingFormatted);
            leaderboard.BombsExploded += _bombCommanders.Count;
            leaderboard.Success        = false;
        }
        else
        {
            bombMessage = string.Format("PraiseIt PraiseIt The bomb has been defused, with {0} remaining! PraiseIt PraiseIt", timeRemainingFormatted);
            leaderboard.BombsCleared += _bombCommanders.Count;
            leaderboard.Success       = true;
            if (leaderboard.CurrentSolvers.Count == 1)
            {
                float  previousRecord = 0.0f;
                float  elapsedTime    = timeStarting - timeRemaining;
                string userName       = "";
                foreach (string uName in leaderboard.CurrentSolvers.Keys)
                {
                    userName = uName;
                    break;
                }
                if (leaderboard.CurrentSolvers[userName] == (Leaderboard.RequiredSoloSolves * _bombCommanders.Count))
                {
                    leaderboard.AddSoloClear(userName, elapsedTime, out previousRecord);
                    TimeSpan elapsedTimeSpan = TimeSpan.FromSeconds(elapsedTime);
                    bombMessage = string.Format("PraiseIt PraiseIt {0} completed a solo defusal in {1}:{2:00}!", leaderboard.SoloSolver.UserName, (int)elapsedTimeSpan.TotalMinutes, elapsedTimeSpan.Seconds);
                    if (elapsedTime < previousRecord)
                    {
                        TimeSpan previousTimeSpan = TimeSpan.FromSeconds(previousRecord);
                        bombMessage += string.Format(" It's a new record! (Previous record: {0}:{1:00})", (int)previousTimeSpan.TotalMinutes, previousTimeSpan.Seconds);
                    }
                    bombMessage += " PraiseIt PraiseIt";
                }
                else
                {
                    leaderboard.ClearSolo();
                }
            }
        }

        parentService.StartCoroutine(SendDelayedMessage(1.0f, bombMessage, SendAnalysisLink));

        if (moduleCameras != null)
        {
            moduleCameras.gameObject.SetActive(false);
        }

        foreach (var handle in _bombHandles)
        {
            if (handle != null)
            {
                Destroy(handle.gameObject, 2.0f);
            }
        }
        _bombHandles.Clear();
        _bombCommanders.Clear();

        if (_componentHandles != null)
        {
            foreach (TwitchComponentHandle handle in _componentHandles)
            {
                Destroy(handle.gameObject, 2.0f);
            }
        }
        _componentHandles.Clear();

        MusicPlayer.StopAllMusic();
    }
    public string GetBombResult(bool lastBomb = true)
    {
        bool HasDetonated           = false;
        bool HasBeenSolved          = true;
        var  timeStarting           = float.MaxValue;
        var  timeRemaining          = float.MaxValue;
        var  timeRemainingFormatted = "";

        foreach (var commander in BombCommanders)
        {
            HasDetonated  |= commander.Bomb.HasDetonated;
            HasBeenSolved &= commander.IsSolved;
            if (timeRemaining > commander.CurrentTimer)
            {
                timeStarting  = commander.bombStartingTimer;
                timeRemaining = commander.CurrentTimer;
            }

            if (!string.IsNullOrEmpty(timeRemainingFormatted))
            {
                timeRemainingFormatted += ", " + commander.GetFullFormattedTime;
            }
            else
            {
                timeRemainingFormatted = commander.GetFullFormattedTime;
            }
        }

        string bombMessage;

        if (HasDetonated)
        {
            bombMessage = string.Format(TwitchPlaySettings.data.BombExplodedMessage, timeRemainingFormatted);
            Leaderboard.Instance.BombsExploded += BombCommanders.Count;
            if (lastBomb)
            {
                Leaderboard.Instance.Success = false;
                TwitchPlaySettings.ClearPlayerLog();
            }
        }
        else if (HasBeenSolved)
        {
            bombMessage = string.Format(TwitchPlaySettings.data.BombDefusedMessage, timeRemainingFormatted);
            Leaderboard.Instance.BombsCleared += BombCommanders.Count;
            bombMessage += TwitchPlaySettings.GiveBonusPoints();

            if (lastBomb)
            {
                Leaderboard.Instance.Success = true;
            }

            if (Leaderboard.Instance.CurrentSolvers.Count == 1)
            {
                float  previousRecord = 0.0f;
                float  elapsedTime    = timeStarting - timeRemaining;
                string userName       = "";
                foreach (string uName in Leaderboard.Instance.CurrentSolvers.Keys)
                {
                    userName = uName;
                    break;
                }
                if (Leaderboard.Instance.CurrentSolvers[userName] == (Leaderboard.RequiredSoloSolves * BombCommanders.Count))
                {
                    Leaderboard.Instance.AddSoloClear(userName, elapsedTime, out previousRecord);
                    if (TwitchPlaySettings.data.EnableSoloPlayMode)
                    {
                        //Still record solo information, should the defuser be the only one to actually defuse a 11 * bomb-count bomb, but display normal leaderboards instead if
                        //solo play is disabled.
                        TimeSpan elapsedTimeSpan = TimeSpan.FromSeconds(elapsedTime);
                        string   soloMessage     = string.Format(TwitchPlaySettings.data.BombSoloDefusalMessage, Leaderboard.Instance.SoloSolver.UserName, (int)elapsedTimeSpan.TotalMinutes, elapsedTimeSpan.Seconds);
                        if (elapsedTime < previousRecord)
                        {
                            TimeSpan previousTimeSpan = TimeSpan.FromSeconds(previousRecord);
                            soloMessage += string.Format(TwitchPlaySettings.data.BombSoloDefusalNewRecordMessage, (int)previousTimeSpan.TotalMinutes, previousTimeSpan.Seconds);
                        }
                        soloMessage += TwitchPlaySettings.data.BombSoloDefusalFooter;
                        parentService.StartCoroutine(SendDelayedMessage(1.0f, soloMessage));
                    }
                    else
                    {
                        Leaderboard.Instance.ClearSolo();
                    }
                }
                else
                {
                    Leaderboard.Instance.ClearSolo();
                }
            }
        }
        else
        {
            bombMessage = string.Format(TwitchPlaySettings.data.BombAbortedMessage, timeRemainingFormatted);
            Leaderboard.Instance.Success = false;
            TwitchPlaySettings.ClearPlayerLog();
        }
        return(bombMessage);
    }