public IEnumerator RespondToCommand(string userNickName, string message, ICommandResponseNotifier responseNotifier)
    {
        MonoBehaviour button = null;

        if (message.Equals("!continue", StringComparison.InvariantCultureIgnoreCase) ||
            message.Equals("!back", StringComparison.InvariantCultureIgnoreCase))
        {
            button = ContinueButton;
        }
        else if (message.Equals("!retry", StringComparison.InvariantCultureIgnoreCase))
        {
            button = RetryButton;
        }

        if (button == null)
        {
            yield break;
        }

        // Press the button twice, in case the first is too early and skips the message instead
        for (int i = 0; i < 2; i++)
        {
            DoInteractionStart(button);
            yield return(new WaitForSeconds(0.1f));

            DoInteractionEnd(button);
        }
    }
    public IEnumerator RespondToCommand(string userNickName, string message, ICommandResponseNotifier responseNotifier)
    {
        Selectable button = null;

        message = message.ToLowerInvariant();

        if (message.EqualsAny("!continue", "!back"))
        {
            button = ContinueButton;
        }
        else if (message.Equals("!retry"))
        {
            if (!TwitchPlaySettings.data.EnableRetryButton)
            {
                IRCConnection.Instance.SendMessage(TwitchPlaySettings.data.RetryInactive);
            }
            button = TwitchPlaySettings.data.EnableRetryButton ? RetryButton : ContinueButton;
        }

        if (button == null)
        {
            yield break;
        }

        // Press the button twice, in case the first is too early and skips the message instead
        for (int i = 0; i < 2; i++)
        {
            DoInteractionStart(button);
            yield return(new WaitForSeconds(0.1f));

            DoInteractionEnd(button);
        }
    }
    private IEnumerator DelayBombExplosionCoroutine(ICommandResponseNotifier notifier)
    {
        notifier.ProcessResponse(CommandResponse.Start);
        yield return(DelayBombExplosionCoroutine(TwitchPlaySettings.data.BombDetonateCommand, "Detonate Command", 1.0f));

        notifier.ProcessResponse(CommandResponse.EndNotComplete);
    }
    public IEnumerator RespondToCommand(string userNickName, string message, ICommandResponseNotifier responseNotifier, IRCConnection connection)
    {
        message = message.ToLowerInvariant();

        if (message.EqualsAny("hold", "pick up"))
        {
            responseNotifier.ProcessResponse(CommandResponse.Start);

            IEnumerator holdCoroutine = HoldBomb(_heldFrontFace);
            while (holdCoroutine.MoveNext())
            {
                yield return(holdCoroutine.Current);
            }

            responseNotifier.ProcessResponse(CommandResponse.EndNotComplete);
        }
        else if (message.EqualsAny("turn", "turn round", "turn around", "rotate", "flip", "spin"))
        {
            responseNotifier.ProcessResponse(CommandResponse.Start);

            IEnumerator holdCoroutine = HoldBomb(!_heldFrontFace);
            while (holdCoroutine.MoveNext())
            {
                yield return(holdCoroutine.Current);
            }

            responseNotifier.ProcessResponse(CommandResponse.EndNotComplete);
        }
        else if (message.EqualsAny("drop", "let go", "put down"))
        {
            responseNotifier.ProcessResponse(CommandResponse.Start);

            IEnumerator letGoCoroutine = LetGoBomb();
            while (letGoCoroutine.MoveNext())
            {
                yield return(letGoCoroutine.Current);
            }

            responseNotifier.ProcessResponse(CommandResponse.EndNotComplete);
        }
        else if (Regex.IsMatch(message, "^(edgework( 45|-45)?)$") ||
                 Regex.IsMatch(message, "^(edgework( 45|-45)? )?(top|top right|right top|right|right bottom|bottom right|bottom|bottom left|left bottom|left|left top|top left|)$"))
        {
            responseNotifier.ProcessResponse(CommandResponse.Start);
            bool        _45Degrees        = Regex.IsMatch(message, "^(edgework(-45| 45)).*$");
            IEnumerator edgeworkCoroutine = ShowEdgework(message.Replace("edgework", "").Replace(" 45", "").Replace("-45", "").Trim(), _45Degrees);
            while (edgeworkCoroutine.MoveNext())
            {
                yield return(edgeworkCoroutine.Current);
            }

            responseNotifier.ProcessResponse(CommandResponse.EndNotComplete);
        }
        else
        {
            responseNotifier.ProcessResponse(CommandResponse.NoResponse);
        }
    }
Exemple #5
0
    public IEnumerator RespondToCommand(string userNickName, string message, ICommandResponseNotifier responseNotifier, bool isWhisper = false)
    {
        IEnumerator respond = FreeplayRespondToCommand(userNickName, message, responseNotifier, isWhisper);
        bool        result;

        do
        {
            try
            {
                result = respond.MoveNext();
            }
            catch (Exception ex)
            {
                DebugHelper.LogException(ex);
                result = false;
            }
            if (result)
            {
                yield return(respond.Current);
            }
        } while (result);
    }
Exemple #6
0
    private void AwardSolve(string userNickName, ICommandResponseNotifier responseNotifier, int ComponentValue)
    {
        string headerText = UnsupportedModule ? modInfo.moduleDisplayName : BombComponent.GetModuleDisplayName();

        IRCConnection.SendMessage(TwitchPlaySettings.data.AwardSolve, Code, userNickName, ComponentValue, headerText);
        string RecordMessageTone = $"Module ID: {Code} | Player: {userNickName} | Module Name: {headerText} | Value: {ComponentValue}";

        responseNotifier.ProcessResponse(CommandResponse.EndComplete, ComponentValue);
        TwitchPlaySettings.AppendToSolveStrikeLog(RecordMessageTone);
        TwitchPlaySettings.AppendToPlayerLog(userNickName);
        if (OtherModes.timedModeOn)
        {
            float multiplier = OtherModes.getMultiplier();
            float time       = multiplier * ComponentValue;
            BombCommander.timerComponent.TimeRemaining = BombCommander.CurrentTimer + time;
            IRCConnection.SendMessage("Bomb time increased by {0} seconds!", Math.Round(time, 1));
            if (multiplier < 10)
            {
                multiplier = multiplier + 0.1f;
                OtherModes.setMultiplier(multiplier);
            }
        }
    }
    public IEnumerator RespondToCommand(string userNickName, string message, ICommandResponseNotifier responseNotifier)
    {
        message = message.ToLowerInvariant();

        if (message.EqualsAny("hold", "pick up"))
        {
            responseNotifier.ProcessResponse(CommandResponse.Start);

            IEnumerator holdCoroutine = HoldBomb(_heldFrontFace);
            while (holdCoroutine.MoveNext())
            {
                yield return(holdCoroutine.Current);
            }

            responseNotifier.ProcessResponse(CommandResponse.EndNotComplete);
        }
        else if (message.EqualsAny("turn", "turn round", "turn around", "rotate", "flip", "spin"))
        {
            responseNotifier.ProcessResponse(CommandResponse.Start);

            IEnumerator turnCoroutine = TurnBomb();
            while (turnCoroutine.MoveNext())
            {
                yield return(turnCoroutine.Current);
            }

            responseNotifier.ProcessResponse(CommandResponse.EndNotComplete);
        }
        else if (message.EqualsAny("drop", "let go", "put down"))
        {
            responseNotifier.ProcessResponse(CommandResponse.Start);

            IEnumerator letGoCoroutine = LetGoBomb();
            while (letGoCoroutine.MoveNext())
            {
                yield return(letGoCoroutine.Current);
            }

            responseNotifier.ProcessResponse(CommandResponse.EndNotComplete);
        }
        else if (message.RegexMatch(out Match edgeworkMatch, GameRoom.Instance.ValidEdgeworkRegex))
        {
            responseNotifier.ProcessResponse(CommandResponse.Start);
            if (!TwitchPlaySettings.data.EnableEdgeworkCommand)
            {
                IRCConnection.Instance.SendMessage(TwitchPlaySettings.data.BombEdgework, twitchBombHandle.edgeworkText.text);
            }
            else
            {
                IEnumerator edgeworkCoroutine = ShowEdgework(edgeworkMatch);
                while (edgeworkCoroutine.MoveNext())
                {
                    yield return(edgeworkCoroutine.Current);
                }
            }
            responseNotifier.ProcessResponse(CommandResponse.EndNotComplete);
        }
        else
        {
            responseNotifier.ProcessResponse(CommandResponse.NoResponse);
        }
    }
Exemple #8
0
    public IEnumerator RespondToCommand(string userNickName, string message, ICommandResponseNotifier responseNotifier)
    {
        message = message.ToLowerInvariant();
        int holdState = (int)_holdStateProperty.GetValue(FloatingHoldable, null);

        if (holdState == 0)
        {
            if (message.Equals("drop", StringComparison.InvariantCultureIgnoreCase) ||
                message.Equals("let go", StringComparison.InvariantCultureIgnoreCase) ||
                message.Equals("put down", StringComparison.InvariantCultureIgnoreCase))
            {
                LetGoFreeplayDevice();
                yield break;
            }
        }
        else
        {
            IEnumerator holdCoroutine = HoldFreeplayDevice();
            while (holdCoroutine.MoveNext())
            {
                yield return(holdCoroutine.Current);
            }
        }

        string changeHoursTo   = String.Empty;
        string changeMinutesTo = String.Empty;
        string changeSecondsTo = String.Empty;
        string changeBombsTo   = String.Empty;
        string changeModulesTo = String.Empty;
        bool   startBomb       = false;

        if (message.Equals("needy on", StringComparison.InvariantCultureIgnoreCase))
        {
            SetNeedy();
        }
        else if (message.Equals("needy off", StringComparison.InvariantCultureIgnoreCase))
        {
            SetNeedy(false);
        }
        else if (message.Equals("hardcore on", StringComparison.InvariantCultureIgnoreCase))
        {
            SetHardcore();
        }
        else if (message.Equals("hardcore off", StringComparison.InvariantCultureIgnoreCase))
        {
            SetHardcore(false);
        }
        else if (message.Equals("mods only on", StringComparison.InvariantCultureIgnoreCase))
        {
            SetModsOnly();
        }
        else if (message.Equals("mods only off", StringComparison.InvariantCultureIgnoreCase))
        {
            SetModsOnly(false);
        }
        else if (message.Equals("start", StringComparison.InvariantCultureIgnoreCase))
        {
            StartBomb();
        }
        else if (message.StartsWith("profile"))
        {
            string profile = message.Remove(0, 8).Trim();

            switch (profile)
            {
            case "single":
            case "solo":
                changeBombsTo   = "1";
                changeHoursTo   = "0";
                changeMinutesTo = "20";
                changeModulesTo = "11";
                break;

            case "double":
                changeBombsTo   = "1";
                changeHoursTo   = "0";
                changeMinutesTo = "40";
                changeModulesTo = "23";
                break;

            case "quadruple":
            case "quad":
                changeBombsTo   = "1";
                changeHoursTo   = "1";
                changeMinutesTo = "20";
                changeModulesTo = "47";
                break;

            case "dual single":
            case "dual solo":
                changeBombsTo   = "2";
                changeHoursTo   = "0";
                changeMinutesTo = "40";
                changeModulesTo = "11";
                break;

            case "dual double":
                changeBombsTo   = "2";
                changeHoursTo   = "1";
                changeMinutesTo = "20";
                changeModulesTo = "23";
                break;

            case "dual quadruple":
            case "dual quad":
                changeBombsTo   = "2";
                changeHoursTo   = "2";
                changeMinutesTo = "40";
                changeModulesTo = "47";
                break;
            }
        }
        else if (message.StartsWith("start"))
        {
            Match timerMatch = Regex.Match(message, "([0-9]):([0-9]{2}):([0-9]{2})");
            if (timerMatch.Success)
            {
                changeHoursTo   = timerMatch.Groups[1].Value;
                changeMinutesTo = timerMatch.Groups[2].Value;
                changeSecondsTo = timerMatch.Groups[3].Value;
                message         = message.Remove(timerMatch.Index, timerMatch.Length);
            }
            else
            {
                timerMatch = Regex.Match(message, "([0-9]+):([0-9]{2})");
                if (timerMatch.Success)
                {
                    changeMinutesTo = timerMatch.Groups[1].Value;
                    changeSecondsTo = timerMatch.Groups[2].Value;
                    message         = message.Remove(timerMatch.Index, timerMatch.Length);
                }
            }


            Match modulesMatch = Regex.Match(message, "[0-9]+");

            while (modulesMatch.Success)
            {
                int count = 0;

                if (int.TryParse(modulesMatch.Value, out count))
                {
                    if (count <= 2)
                    {
                        changeBombsTo = modulesMatch.Value;
                    }
                    else
                    {
                        changeModulesTo = modulesMatch.Value;
                    }

                    Debug.Log(string.Format("[FreeplayCommander] Setting {1} to {0}", modulesMatch.Value,
                                            count <= 2 ? "bombs" : "modules"));
                }
                message      = message.Remove(modulesMatch.Index, modulesMatch.Length);
                modulesMatch = Regex.Match(message, "[0-9]+");
            }

            string messageLower = message.ToLowerInvariant();

            SetHardcore(messageLower.Contains("hardcore"));
            SetNeedy(messageLower.Contains("needy"));

            if (messageLower.Contains("vanilla"))
            {
                SetModsOnly(false);
            }
            else if (messageLower.Contains("mods"))
            {
                SetModsOnly();
            }

            startBomb = true;
        }
        else
        {
            Match timerMatch = Regex.Match(message, "^timer? ([0-9]+)(?::([0-9]{2}))(?::([0-9]{2}))$", RegexOptions.IgnoreCase);
            if (timerMatch.Success)
            {
                changeHoursTo   = timerMatch.Groups[1].Value;
                changeMinutesTo = timerMatch.Groups[2].Value;
                changeSecondsTo = timerMatch.Groups[3].Value;
            }

            timerMatch = Regex.Match(message, "^timer? ([0-9]+)(?::([0-9]{2}))?$", RegexOptions.IgnoreCase);
            if (timerMatch.Success)
            {
                changeMinutesTo = timerMatch.Groups[1].Value;
                changeSecondsTo = timerMatch.Groups[2].Value;
            }

            Match bombsMatch = Regex.Match(message, "^bombs ([0-9]+)$", RegexOptions.IgnoreCase);
            if (bombsMatch.Success)
            {
                changeBombsTo = bombsMatch.Groups[1].Value;
            }

            Match modulesMatch = Regex.Match(message, "^modules ([0-9]+)$", RegexOptions.IgnoreCase);
            if (modulesMatch.Success)
            {
                changeModulesTo = modulesMatch.Groups[1].Value;
            }
        }

        if (changeMinutesTo != String.Empty)
        {
            IEnumerator setTimerCoroutine = SetBombTimer(changeHoursTo, changeMinutesTo, changeSecondsTo);
            while (setTimerCoroutine.MoveNext())
            {
                yield return(setTimerCoroutine.Current);
            }
        }
        if (changeBombsTo != String.Empty)
        {
            IEnumerator setBombsCoroutine = SetBombCount(changeBombsTo);
            while (setBombsCoroutine.MoveNext())
            {
                yield return(setBombsCoroutine.Current);
            }
        }
        if (changeModulesTo != String.Empty)
        {
            IEnumerator setModulesCoroutine = SetBombModules(changeModulesTo);
            while (setModulesCoroutine.MoveNext())
            {
                yield return(setModulesCoroutine.Current);
            }
        }
        if (startBomb)
        {
            StartBomb();
        }
    }
    public IEnumerator RespondToCommand(string userNickName, string message, ICommandResponseNotifier responseNotifier)
    {
        if (message.Equals("hold", StringComparison.InvariantCultureIgnoreCase) ||
            message.Equals("pick up", StringComparison.InvariantCultureIgnoreCase))
        {
            responseNotifier.ProcessResponse(CommandResponse.Start);

            IEnumerator holdCoroutine = HoldBomb(_heldFrontFace);
            while (holdCoroutine.MoveNext())
            {
                yield return(holdCoroutine.Current);
            }

            responseNotifier.ProcessResponse(CommandResponse.EndNotComplete);
        }
        else if (message.Equals("turn", StringComparison.InvariantCultureIgnoreCase) ||
                 message.Equals("turn round", StringComparison.InvariantCultureIgnoreCase) ||
                 message.Equals("turn around", StringComparison.InvariantCultureIgnoreCase) ||
                 message.Equals("rotate", StringComparison.InvariantCultureIgnoreCase) ||
                 message.Equals("flip", StringComparison.InvariantCultureIgnoreCase) ||
                 message.Equals("spin", StringComparison.InvariantCultureIgnoreCase))
        {
            responseNotifier.ProcessResponse(CommandResponse.Start);

            IEnumerator holdCoroutine = HoldBomb(!_heldFrontFace);
            while (holdCoroutine.MoveNext())
            {
                yield return(holdCoroutine.Current);
            }

            responseNotifier.ProcessResponse(CommandResponse.EndNotComplete);
        }
        else if (message.Equals("drop", StringComparison.InvariantCultureIgnoreCase) ||
                 message.Equals("let go", StringComparison.InvariantCultureIgnoreCase) ||
                 message.Equals("put down", StringComparison.InvariantCultureIgnoreCase))
        {
            responseNotifier.ProcessResponse(CommandResponse.Start);

            IEnumerator letGoCoroutine = LetGoBomb();
            while (letGoCoroutine.MoveNext())
            {
                yield return(letGoCoroutine.Current);
            }

            responseNotifier.ProcessResponse(CommandResponse.EndNotComplete);
        }
        else if (Regex.IsMatch(message, "^(edgework( 45|-45)?)$", RegexOptions.IgnoreCase | RegexOptions.CultureInvariant) ||
                 Regex.IsMatch(message, "^(edgework( 45|-45)? )?(top|top right|right top|right|right bottom|bottom right|bottom|bottom left|left bottom|left|left top|top left|)$", RegexOptions.IgnoreCase | RegexOptions.CultureInvariant))
        {
            responseNotifier.ProcessResponse(CommandResponse.Start);
            bool        _45Degrees        = Regex.IsMatch(message, "^(edgework(-45| 45)).*$", RegexOptions.IgnoreCase | RegexOptions.CultureInvariant);
            IEnumerator edgeworkCoroutine = ShowEdgework(message.Replace("edgework", "").Replace(" 45", "").Replace("-45", "").Trim().ToLowerInvariant(), _45Degrees);
            while (edgeworkCoroutine.MoveNext())
            {
                yield return(edgeworkCoroutine.Current);
            }

            responseNotifier.ProcessResponse(CommandResponse.EndNotComplete);
        }
        else if (message.Equals("unview", StringComparison.InvariantCultureIgnoreCase))
        {
            BombMessageResponder.moduleCameras.DetachFromModule(_timerComponent);
        }
        else if (message.StartsWith("view", StringComparison.InvariantCultureIgnoreCase))
        {
            int priority = (message.Equals("view pin", StringComparison.InvariantCultureIgnoreCase)) ? ModuleCameras.CameraPinned : ModuleCameras.CameraPrioritised;
            BombMessageResponder.moduleCameras.AttachToModule(_timerComponent, null, priority);
        }
        else
        {
            responseNotifier.ProcessResponse(CommandResponse.NoResponse);
        }
    }
Exemple #10
0
    private IEnumerator RespondToCommandCoroutine(string userNickName, string internalCommand, ICommandResponseNotifier message, float fadeDuration = 0.1f)
    {
        float time = Time.time;

        while (Time.time - time < fadeDuration)
        {
            float lerp = (Time.time - time) / fadeDuration;
            highlightGroup.alpha = Mathf.Lerp(0.0f, 1.0f, lerp);
            yield return(null);
        }
        highlightGroup.alpha = 1.0f;

        if (_solver != null)
        {
            IEnumerator commandResponseCoroutine = _solver.RespondToCommand(userNickName, internalCommand, message);
            while (commandResponseCoroutine.MoveNext())
            {
                yield return(commandResponseCoroutine.Current);
            }
        }

        time = Time.time;
        while (Time.time - time < fadeDuration)
        {
            float lerp = (Time.time - time) / fadeDuration;
            highlightGroup.alpha = Mathf.Lerp(1.0f, 0.0f, lerp);
            yield return(null);
        }
        highlightGroup.alpha = 0.0f;
    }
Exemple #11
0
    public IEnumerator RespondToCommand(string userNickName, string message, ICommandResponseNotifier responseNotifier, IRCConnection connection)
    {
        _responded = false;
        _processingTwitchCommand = true;
        if (Solved)
        {
            responseNotifier.ProcessResponse(CommandResponse.NoResponse);
            _processingTwitchCommand = false;
            yield break;
        }

        _currentResponseNotifier = responseNotifier;
        _currentUserNickName     = userNickName;

        int beforeStrikeCount = StrikeCount;

        IEnumerator subcoroutine = null;

        if (message.StartsWith("send to module ", StringComparison.InvariantCultureIgnoreCase))
        {
            message = message.Substring(15);
        }
        else
        {
            subcoroutine = RespondToCommandCommon(message, userNickName);
        }

        if (subcoroutine == null || !subcoroutine.MoveNext())
        {
            if (_responded)
            {
                yield break;
            }

            try
            {
                subcoroutine = RespondToCommandInternal(message);
            }
            catch (Exception e)
            {
                HandleModuleException(e);
                yield break;
            }

            bool moved = false;
            if (subcoroutine != null)
            {
                try
                {
                    moved = subcoroutine.MoveNext();

                    if (moved && modInfo.DoesTheRightThing)
                    {
                        _responded = true;
                    }
                }
                catch (Exception e)
                {
                    HandleModuleException(e);
                    yield break;
                }
            }

            if (subcoroutine == null || !moved || Solved || beforeStrikeCount != StrikeCount)
            {
                if (Solved || beforeStrikeCount != StrikeCount)
                {
                    IEnumerator focusDefocus = BombCommander.Focus(Selectable, FocusDistance, FrontFace);
                    while (focusDefocus.MoveNext())
                    {
                        yield return(focusDefocus.Current);
                    }
                    yield return(new WaitForSeconds(0.5f));

                    responseNotifier.ProcessResponse(Solved ? CommandResponse.EndComplete : CommandResponse.EndError);

                    focusDefocus = BombCommander.Defocus(Selectable, FrontFace);
                    while (focusDefocus.MoveNext())
                    {
                        yield return(focusDefocus.Current);
                    }
                    yield return(new WaitForSeconds(0.5f));
                }
                else
                {
                    ComponentHandle.CommandInvalid(userNickName);
                    responseNotifier.ProcessResponse(CommandResponse.NoResponse);
                }

                _currentResponseNotifier = null;
                _currentUserNickName     = null;
                _processingTwitchCommand = false;
                yield break;
            }
        }

        responseNotifier.ProcessResponse(CommandResponse.Start);

        IEnumerator focusCoroutine = BombCommander.Focus(Selectable, FocusDistance, FrontFace);

        while (focusCoroutine.MoveNext())
        {
            yield return(focusCoroutine.Current);
        }

        yield return(new WaitForSeconds(0.5f));

        int  previousStrikeCount = StrikeCount;
        bool parseError          = false;
        bool needQuaternionReset = false;
        bool hideCamera          = false;
        bool exceptionThrown     = false;

        while (previousStrikeCount == StrikeCount && !Solved)
        {
            try
            {
                if (!subcoroutine.MoveNext())
                {
                    break;
                }
                else
                {
                    _responded = true;
                }
            }
            catch (Exception e)
            {
                exceptionThrown = true;
                HandleModuleException(e);
                break;
            }

            object currentValue = subcoroutine.Current;
            if (currentValue is string currentString)
            {
                if (currentString.Equals("strike", StringComparison.InvariantCultureIgnoreCase))
                {
                    _delegatedStrikeUserNickName     = userNickName;
                    _delegatedStrikeResponseNotifier = responseNotifier;
                }
                else if (currentString.Equals("solve", StringComparison.InvariantCultureIgnoreCase))
                {
                    _delegatedSolveUserNickName     = userNickName;
                    _delegatedSolveResponseNotifier = responseNotifier;
                }
                else if (currentString.Equals("unsubmittablepenalty", StringComparison.InvariantCultureIgnoreCase))
                {
                    if (TwitchPlaySettings.data.UnsubmittablePenaltyPercent <= 0)
                    {
                        continue;
                    }

                    int penalty = Math.Max((int)(modInfo.moduleScore * TwitchPlaySettings.data.UnsubmittablePenaltyPercent), 1);
                    ComponentHandle.leaderboard.AddScore(_currentUserNickName, -penalty);
                    IRCConnection.SendMessage(TwitchPlaySettings.data.UnsubmittableAnswerPenalty, _currentUserNickName, ComponentHandle.idText.text, modInfo.moduleDisplayName, penalty, penalty > 1 ? "s" : "");
                }
                else if (currentString.StartsWith("strikemessage ", StringComparison.InvariantCultureIgnoreCase) &&
                         currentString.Substring(14).Trim() != string.Empty)
                {
                    StrikeMessage = currentString.Substring(14);
                }
                else if (currentString.Equals("parseerror", StringComparison.InvariantCultureIgnoreCase))
                {
                    parseError = true;
                    break;
                }
                else if (currentString.Equals("trycancel", StringComparison.InvariantCultureIgnoreCase) &&
                         Canceller.ShouldCancel)
                {
                    Canceller.ResetCancel();
                    break;
                }
                else if (currentString.StartsWith("sendtochat ", StringComparison.InvariantCultureIgnoreCase) &&
                         currentString.Substring(11).Trim() != string.Empty)
                {
                    IRCConnection.SendMessage(currentString.Substring(11));
                }
                else if (currentString.StartsWith("sendtochaterror ", StringComparison.InvariantCultureIgnoreCase) &&
                         currentString.Substring(16).Trim() != string.Empty)
                {
                    ComponentHandle.CommandError(userNickName, currentString.Substring(16));
                }
                else if (currentString.StartsWith("add strike", StringComparison.InvariantCultureIgnoreCase))
                {
                    OnStrike(null);
                }
                else if (currentString.Equals("multiple strikes", StringComparison.InvariantCultureIgnoreCase))
                {
                    DisableOnStrike = true;
                }
                else if (currentString.StartsWith("award strikes ", StringComparison.CurrentCultureIgnoreCase))
                {
                    if (int.TryParse(currentString.Substring(14), out int awardStrikeCount))
                    {
                        StrikeCount += awardStrikeCount;
                        AwardStrikes(_currentUserNickName, _currentResponseNotifier, awardStrikeCount);
                        DisableOnStrike = false;
                    }
                }
                else if (currentString.StartsWith("autosolve", StringComparison.InvariantCultureIgnoreCase))
                {
                    HandleModuleException(new Exception(currentString));
                    break;
                }
                else if (currentString.ToLowerInvariant().EqualsAny("detonate", "explode"))
                {
                    AwardStrikes(_currentUserNickName, _currentResponseNotifier, BombCommander.StrikeLimit - BombCommander.StrikeCount);
                    BombCommander.twitchBombHandle.CauseExplosionByModuleCommand(string.Empty, modInfo.moduleDisplayName);
                    break;
                }
                else if (currentString.ToLowerInvariant().EqualsAny("elevator music", "hold music", "waiting music"))
                {
                    if (_musicPlayer == null)
                    {
                        _musicPlayer = MusicPlayer.StartRandomMusic();
                    }
                }
                else if (currentString.ToLowerInvariant().Equals("hide camera"))
                {
                    if (!hideCamera)
                    {
                        BombMessageResponder.moduleCameras?.Hide();
                        BombMessageResponder.moduleCameras?.HideHUD();
                        IEnumerator hideUI = BombCommander.twitchBombHandle.HideMainUIWindow();
                        while (hideUI.MoveNext())
                        {
                            yield return(hideUI.Current);
                        }
                    }
                    hideCamera = true;
                }
            }
            else if (currentValue is Quaternion localQuaternion)
            {
                BombCommander.RotateByLocalQuaternion(localQuaternion);
                needQuaternionReset = true;
            }
            else if (currentValue is string[] currentStrings)
            {
                if (currentStrings.Length >= 1)
                {
                    if (currentStrings[0].ToLowerInvariant().EqualsAny("detonate", "explode"))
                    {
                        AwardStrikes(_currentUserNickName, _currentResponseNotifier, BombCommander.StrikeLimit - BombCommander.StrikeCount);
                        switch (currentStrings.Length)
                        {
                        case 2:
                            BombCommander.twitchBombHandle.CauseExplosionByModuleCommand(currentStrings[1], modInfo.moduleDisplayName);
                            break;

                        case 3:
                            BombCommander.twitchBombHandle.CauseExplosionByModuleCommand(currentStrings[1], currentStrings[2]);
                            break;

                        default:
                            BombCommander.twitchBombHandle.CauseExplosionByModuleCommand(string.Empty, modInfo.moduleDisplayName);
                            break;
                        }
                        break;
                    }
                }
            }
            yield return(currentValue);
        }

        if (!_responded && !exceptionThrown)
        {
            ComponentHandle.CommandInvalid(userNickName);
        }

        if (needQuaternionReset)
        {
            BombCommander.RotateByLocalQuaternion(Quaternion.identity);
        }

        if (hideCamera)
        {
            BombMessageResponder.moduleCameras?.Show();
            BombMessageResponder.moduleCameras?.ShowHUD();
            IEnumerator showUI = BombCommander.twitchBombHandle.ShowMainUIWindow();
            while (showUI.MoveNext())
            {
                yield return(showUI.Current);
            }
        }

        if (_musicPlayer != null)
        {
            _musicPlayer.StopMusic();
            _musicPlayer = null;
        }

        if (parseError)
        {
            responseNotifier.ProcessResponse(CommandResponse.NoResponse);
        }
        else
        {
            if (!Solved && (previousStrikeCount == StrikeCount))
            {
                responseNotifier.ProcessResponse(CommandResponse.EndNotComplete);
            }

            yield return(new WaitForSeconds(0.5f));
        }

        IEnumerator defocusCoroutine = BombCommander.Defocus(Selectable, FrontFace);

        while (defocusCoroutine.MoveNext())
        {
            yield return(defocusCoroutine.Current);
        }

        yield return(new WaitForSeconds(0.5f));

        _currentResponseNotifier = null;
        _currentUserNickName     = null;
        _processingTwitchCommand = false;
    }
Exemple #12
0
    private void AwardStrikes(string userNickName, ICommandResponseNotifier responseNotifier, int strikeCount)
    {
        string headerText    = BombComponent.GetModuleDisplayName();
        int    strikePenalty = modInfo.strikePenalty * (TwitchPlaySettings.data.EnableRewardMultipleStrikes ? strikeCount : 1);

        IRCConnection.SendMessage(TwitchPlaySettings.data.AwardStrike, Code, strikeCount == 1 ? "a" : strikeCount.ToString(), strikeCount == 1 ? "" : "s", 0, userNickName, string.IsNullOrEmpty(StrikeMessage) ? "" : " caused by " + StrikeMessage, headerText, strikePenalty);
        if (strikeCount <= 0)
        {
            return;
        }

        string RecordMessageTone = $"Module ID: {Code} | Player: {userNickName} | Module Name: {headerText} | Strike";

        TwitchPlaySettings.AppendToSolveStrikeLog(RecordMessageTone, TwitchPlaySettings.data.EnableRewardMultipleStrikes ? strikeCount : 1);

        int currentReward = TwitchPlaySettings.GetRewardBonus();

        currentReward = Convert.ToInt32(currentReward * .80);
        TwitchPlaySettings.SetRewardBonus(currentReward);
        IRCConnection.SendMessage("Reward reduced to " + currentReward + " points.");
        if (OtherModes.timedModeOn)
        {
            bool   multiDropped = OtherModes.dropMultiplier();
            float  multiplier   = OtherModes.getMultiplier();
            string tempMessage;
            if (multiDropped)
            {
                tempMessage = "Multiplier reduced to " + Math.Round(multiplier, 1) + " and time";
            }
            else
            {
                tempMessage = "Mutliplier set at 1, cannot be further reduced.  Time";
            }
            if (BombCommander.CurrentTimer < 60)
            {
                BombCommander.timerComponent.TimeRemaining = BombCommander.CurrentTimer - 15;
                tempMessage = tempMessage + " reduced by 15 seconds.";
            }
            else
            {
                float  timeReducer = BombCommander.CurrentTimer * .25f;
                double easyText    = Math.Round(timeReducer, 1);
                BombCommander.timerComponent.TimeRemaining = BombCommander.CurrentTimer - timeReducer;
                tempMessage = tempMessage + " reduced by 25%. (" + easyText + " seconds)";
            }
            IRCConnection.SendMessage(tempMessage);
        }
        if (responseNotifier != null)
        {
            responseNotifier.ProcessResponse(CommandResponse.EndErrorSubtractScore, strikePenalty);
            responseNotifier.ProcessResponse(CommandResponse.EndError, strikeCount);
        }
        else
        {
            ComponentHandle.leaderboard.AddScore(userNickName, strikePenalty);
            ComponentHandle.leaderboard.AddStrike(userNickName, strikeCount);
        }
        if (OtherModes.timedModeOn)
        {
            BombCommander.StrikeCount = 0;
            BombMessageResponder.moduleCameras.UpdateStrikes();
        }
        StrikeMessage = string.Empty;
    }
    private IEnumerator RespondToCommandCoroutine(string userNickName, string internalCommand, ICommandResponseNotifier message, float fadeDuration = 0.1f)
    {
        float time = Time.time;

        while (Time.time - time < fadeDuration)
        {
            float lerp = (Time.time - time) / fadeDuration;
            highlightGroup.alpha = Mathf.Lerp(0.0f, 1.0f, lerp);
            yield return(null);
        }
        highlightGroup.alpha = 1.0f;

        IEnumerator commandResponseCoroutine = bombCommander.RespondToCommand(userNickName, internalCommand, message);

        while (commandResponseCoroutine.MoveNext())
        {
            if (commandResponseCoroutine.Current is string chatmessage)
            {
                if (chatmessage.StartsWith("sendtochat "))
                {
                    IRCConnection.Instance.SendMessage(chatmessage.Substring(11));
                }
            }

            yield return(commandResponseCoroutine.Current);
        }

        time = Time.time;
        while (Time.time - time < fadeDuration)
        {
            float lerp = (Time.time - time) / fadeDuration;
            highlightGroup.alpha = Mathf.Lerp(1.0f, 0.0f, lerp);
            yield return(null);
        }
        highlightGroup.alpha = 0.0f;
    }
Exemple #14
0
    public IEnumerator RespondToCommand(string userNickName, string message, ICommandResponseNotifier responseNotifier)
    {
        message = message.ToLowerInvariant();
        if (message.EqualsAny("hold", "pick up"))
        {
            IEnumerator holdCoroutine = HoldBombBinder();
            while (holdCoroutine.MoveNext())
            {
                yield return(holdCoroutine.Current);
            }
        }
        else
        {
            FloatingHoldable.HoldStateEnum holdState = FloatingHoldable.HoldState;
            if (holdState != FloatingHoldable.HoldStateEnum.Held)
            {
                yield break;
            }

            if (message.EqualsAny("drop", "let go", "put down"))
            {
                IEnumerator drop = LetGoBombBinder();
                while (drop.MoveNext())
                {
                    yield return(drop.Current);
                }
            }
            else if (message.Equals("select"))
            {
                IEnumerator selectCoroutine = SelectOnPage();
                while (selectCoroutine.MoveNext())
                {
                    yield return(selectCoroutine.Current);
                }
            }
            else if (message.StartsWith("select"))
            {
                string[]    commandParts    = message.Split(' ');
                IEnumerator selectCoroutine = null;
                if ((commandParts.Length == 2) &&
                    (int.TryParse(commandParts[1], out int index)))
                {
                    selectCoroutine = SelectOnPage(index);
                }
                else
                {
                    selectCoroutine = SelectOnPage(0, commandParts.Skip(1).ToArray());
                }
                while (selectCoroutine.MoveNext())
                {
                    yield return(selectCoroutine.Current);
                }
            }
            else
            {
                string[] sequence = message.Split(new[] { ',', ' ' }, StringSplitOptions.RemoveEmptyEntries);
                foreach (string subCommand in sequence)
                {
                    if (subCommand.EqualsAny("down", "d"))
                    {
                        MoveDownOnPage();
                        yield return(new WaitForSeconds(0.2f));
                    }
                    else if (subCommand.EqualsAny("up", "u"))
                    {
                        MoveUpOnPage();
                        yield return(new WaitForSeconds(0.2f));
                    }
                }
            }
        }
    }
Exemple #15
0
 private void AwardStrikes(string userNickName, ICommandResponseNotifier responseNotifier, int strikeCount)
 {
     IRCConnection.SendMessage(string.Format("VoteNay Module {0} got {1} strike{2}! +{3} strike{2} to {4}{5}", Code, strikeCount == 1 ? "a" : strikeCount.ToString(), strikeCount == 1 ? "" : "s", strikeCount, userNickName, string.IsNullOrEmpty(StrikeMessage) ? "" : " caused by " + StrikeMessage));
     responseNotifier.ProcessResponse(CommandResponse.EndError, strikeCount);
     StrikeMessage = string.Empty;
 }
Exemple #16
0
 private void AwardSolve(string userNickName, ICommandResponseNotifier responseNotifier)
 {
     IRCConnection.SendMessage(string.Format("VoteYea Module {0} is solved! +1 solve to {1}", Code, userNickName));
     responseNotifier.ProcessResponse(CommandResponse.EndComplete);
 }
Exemple #17
0
    public IEnumerator RespondToCommand(string userNickName, string message, ICommandResponseNotifier responseNotifier)
    {
        _responded = false;
        _processingTwitchCommand = true;
        if (Solved)
        {
            responseNotifier.ProcessResponse(CommandResponse.NoResponse);
            _processingTwitchCommand = false;
            yield break;
        }

        _currentResponseNotifier = responseNotifier;
        _currentUserNickName     = userNickName;

        int beforeStrikeCount = StrikeCount;

        IEnumerator subcoroutine = null;

        if (message.StartsWith("send to module ", StringComparison.InvariantCultureIgnoreCase))
        {
            message = message.Substring(15);
        }
        else
        {
            subcoroutine = RespondToCommandCommon(message);
        }

        if (subcoroutine == null || !subcoroutine.MoveNext())
        {
            try
            {
                subcoroutine = RespondToCommandInternal(message);
            }
            catch (Exception e)
            {
                HandleModuleException(e);
                yield break;
            }

            bool moved = false;
            if (subcoroutine != null)
            {
                try
                {
                    moved = subcoroutine.MoveNext();
                }
                catch (Exception e)
                {
                    HandleModuleException(e);
                    yield break;
                }
            }

            if (subcoroutine == null || !moved || Solved || beforeStrikeCount != StrikeCount)
            {
                if (Solved || beforeStrikeCount != StrikeCount)
                {
                    IEnumerator focusDefocus = BombCommander.Focus(Selectable, FocusDistance, FrontFace);
                    while (focusDefocus.MoveNext())
                    {
                        yield return(focusDefocus.Current);
                    }
                    yield return(new WaitForSeconds(0.5f));

                    responseNotifier.ProcessResponse(Solved ? CommandResponse.EndComplete : CommandResponse.EndError);

                    focusDefocus = BombCommander.Defocus(Selectable, FrontFace);
                    while (focusDefocus.MoveNext())
                    {
                        yield return(focusDefocus.Current);
                    }
                    yield return(new WaitForSeconds(0.5f));
                }
                else
                {
                    IRCConnection.SendMessage(string.Format("Sorry @{0}, that command is invalid.", userNickName));

                    responseNotifier.ProcessResponse(CommandResponse.NoResponse);
                }

                _currentResponseNotifier = null;
                _currentUserNickName     = null;
                _processingTwitchCommand = false;
                yield break;
            }
        }

        responseNotifier.ProcessResponse(CommandResponse.Start);

        IEnumerator focusCoroutine = BombCommander.Focus(Selectable, FocusDistance, FrontFace);

        while (focusCoroutine.MoveNext())
        {
            yield return(focusCoroutine.Current);
        }

        yield return(new WaitForSeconds(0.5f));

        int  previousStrikeCount = StrikeCount;
        bool parseError          = false;
        bool needQuaternionReset = false;
        bool exceptionThrown     = false;

        while (previousStrikeCount == StrikeCount && !Solved)
        {
            try
            {
                if (!subcoroutine.MoveNext())
                {
                    break;
                }
                else
                {
                    _responded = true;
                }
            }
            catch (Exception e)
            {
                exceptionThrown = true;
                HandleModuleException(e);
                break;
            }

            object currentValue = subcoroutine.Current;
            if (currentValue is string)
            {
                string currentString = (string)currentValue;
                if (currentString.Equals("strike", StringComparison.InvariantCultureIgnoreCase))
                {
                    _delegatedStrikeUserNickName     = userNickName;
                    _delegatedStrikeResponseNotifier = responseNotifier;
                }
                else if (currentString.Equals("solve", StringComparison.InvariantCultureIgnoreCase))
                {
                    _delegatedSolveUserNickName     = userNickName;
                    _delegatedSolveResponseNotifier = responseNotifier;
                }
                else if (currentString.StartsWith("strikemessage ", StringComparison.InvariantCultureIgnoreCase) &&
                         currentString.Substring(14).Trim() != string.Empty)
                {
                    StrikeMessage = currentString.Substring(14);
                }
                else if (currentString.Equals("parseerror", StringComparison.InvariantCultureIgnoreCase))
                {
                    parseError = true;
                    break;
                }
                else if (currentString.Equals("trycancel", StringComparison.InvariantCultureIgnoreCase) &&
                         Canceller.ShouldCancel)
                {
                    Canceller.ResetCancel();
                    break;
                }
                else if (currentString.StartsWith("sendtochat ", StringComparison.InvariantCultureIgnoreCase) &&
                         currentString.Substring(11).Trim() != string.Empty)
                {
                    IRCConnection.SendMessage(currentString.Substring(11));
                }
                else if (currentString.StartsWith("add strike", StringComparison.InvariantCultureIgnoreCase))
                {
                    OnStrike(null);
                }
                else if (currentString.Equals("multiple strikes", StringComparison.InvariantCultureIgnoreCase))
                {
                    DisableOnStrike = true;
                }
                else if (currentString.StartsWith("award strikes ", StringComparison.CurrentCultureIgnoreCase))
                {
                    int awardStrikeCount;
                    if (int.TryParse(currentString.Substring(14), out awardStrikeCount))
                    {
                        _strikeCount += awardStrikeCount;
                        AwardStrikes(_currentUserNickName, _currentResponseNotifier, awardStrikeCount);
                        DisableOnStrike = false;
                    }
                }
            }
            else if (currentValue is Quaternion)
            {
                if (!needQuaternionReset)
                {
                    BombMessageResponder.moduleCameras.Hide();
                }

                Quaternion localQuaternion = (Quaternion)currentValue;
                BombCommander.RotateByLocalQuaternion(localQuaternion);
                needQuaternionReset = true;
            }
            yield return(currentValue);
        }

        if (!_responded && !exceptionThrown)
        {
            IRCConnection.SendMessage(string.Format("Sorry @{0}, that command is invalid.", userNickName));
        }

        if (needQuaternionReset)
        {
            BombCommander.RotateByLocalQuaternion(Quaternion.identity);
            BombMessageResponder.moduleCameras.Show();
        }

        if (parseError)
        {
            responseNotifier.ProcessResponse(CommandResponse.NoResponse);
        }
        else
        {
            if (!Solved && (previousStrikeCount == StrikeCount))
            {
                responseNotifier.ProcessResponse(CommandResponse.EndNotComplete);
            }

            yield return(new WaitForSeconds(0.5f));
        }

        IEnumerator defocusCoroutine = BombCommander.Defocus(Selectable, FrontFace);

        while (defocusCoroutine.MoveNext())
        {
            yield return(defocusCoroutine.Current);
        }

        yield return(new WaitForSeconds(0.5f));

        _currentResponseNotifier = null;
        _currentUserNickName     = null;
        _processingTwitchCommand = false;
    }
Exemple #18
0
    public IEnumerator FreeplayRespondToCommand(string userNickName, string message, ICommandResponseNotifier responseNotifier, bool isWhisper)
    {
        message = message.ToLowerInvariant().Trim();

        if (message.EqualsAny("drop", "let go", "put down"))
        {
            IEnumerator drop = LetGoFreeplayDevice();
            while (drop.MoveNext())
            {
                yield return(drop.Current);
            }
            yield break;
        }
        else
        {
            IEnumerator holdCoroutine = HoldFreeplayDevice();
            while (holdCoroutine.MoveNext())
            {
                yield return(holdCoroutine.Current);
            }
        }

        string changeHoursTo   = string.Empty;
        string changeMinutesTo = string.Empty;
        string changeSecondsTo = string.Empty;
        string changeBombsTo   = string.Empty;
        string changeModulesTo = string.Empty;
        bool   startBomb       = false;

        if (message.EqualsAny("needy on", "needy off"))
        {
            if (TwitchPlaySettings.data.EnableFreeplayNeedy || UserAccess.HasAccess(userNickName, AccessLevel.Admin, true) || TwitchPlaySettings.data.AnarchyMode)
            {
                SetNeedy(message.Equals("needy on"));
            }
            else
            {
                IRCConnection.Instance.SendMessage(string.Format(TwitchPlaySettings.data.FreePlayNeedyDisabled, userNickName), userNickName, !isWhisper);
            }
        }
        else if (message.EqualsAny("hardcore on", "hardcore off"))
        {
            if (TwitchPlaySettings.data.EnableFreeplayHardcore || UserAccess.HasAccess(userNickName, AccessLevel.Admin, true) || TwitchPlaySettings.data.AnarchyMode)
            {
                SetHardcore(message.Equals("hardcore on"));
            }
            else
            {
                IRCConnection.Instance.SendMessage(string.Format(TwitchPlaySettings.data.FreePlayHardcoreDisabled, userNickName), !isWhisper);
            }
        }
        else if (message.EqualsAny("mods only on", "mods only off"))
        {
            if (TwitchPlaySettings.data.EnableFreeplayModsOnly || UserAccess.HasAccess(userNickName, AccessLevel.Admin, true) || TwitchPlaySettings.data.AnarchyMode)
            {
                SetModsOnly(message.Equals("mods only on"));
            }
            else
            {
                IRCConnection.Instance.SendMessage(string.Format(TwitchPlaySettings.data.FreePlayModsOnlyDisabled, userNickName), userNickName, !isWhisper);
            }
        }
        else if (message.Equals("start"))
        {
            StartBomb();
        }
        else if (message.StartsWith("profile"))
        {
            string profile = message.Remove(0, 8).Trim();

            switch (profile)
            {
            case "single":
            case "solo":
                changeBombsTo   = "1";
                changeHoursTo   = "0";
                changeMinutesTo = "20";
                changeModulesTo = "11";
                break;

            case "double":
                changeBombsTo   = "1";
                changeHoursTo   = "0";
                changeMinutesTo = "40";
                changeModulesTo = "23";
                break;

            case "quadruple":
            case "quad":
                changeBombsTo   = "1";
                changeHoursTo   = "1";
                changeMinutesTo = "20";
                changeModulesTo = "47";
                break;

            case "dual single":
            case "dual solo":
                changeBombsTo   = "2";
                changeHoursTo   = "0";
                changeMinutesTo = "40";
                changeModulesTo = "11";
                break;

            case "dual double":
                changeBombsTo   = "2";
                changeHoursTo   = "1";
                changeMinutesTo = "20";
                changeModulesTo = "23";
                break;

            case "dual quadruple":
            case "dual quad":
                changeBombsTo   = "2";
                changeHoursTo   = "2";
                changeMinutesTo = "40";
                changeModulesTo = "47";
                break;
            }
        }
        else if (message.StartsWith("start"))
        {
            Match timerMatch = Regex.Match(message, "([0-9]):([0-9]{2}):([0-9]{2})");
            if (timerMatch.Success)
            {
                changeHoursTo   = timerMatch.Groups[1].Value;
                changeMinutesTo = timerMatch.Groups[2].Value;
                changeSecondsTo = timerMatch.Groups[3].Value;
                message         = message.Remove(timerMatch.Index, timerMatch.Length);
            }
            else
            {
                timerMatch = Regex.Match(message, "([0-9]+):([0-9]{2})");
                if (timerMatch.Success)
                {
                    changeMinutesTo = timerMatch.Groups[1].Value;
                    changeSecondsTo = timerMatch.Groups[2].Value;
                    message         = message.Remove(timerMatch.Index, timerMatch.Length);
                }
            }

            Match modulesMatch = Regex.Match(message, "[0-9]+");

            while (modulesMatch.Success)
            {
                if (int.TryParse(modulesMatch.Value, out int count))
                {
                    if (count <= 2)
                    {
                        changeBombsTo = modulesMatch.Value;
                    }
                    else
                    {
                        changeModulesTo = modulesMatch.Value;
                    }

                    DebugHelper.Log("[FreeplayCommander] Setting {1} to {0}", modulesMatch.Value,
                                    count <= 2 ? "bombs" : "modules");
                }
                message      = message.Remove(modulesMatch.Index, modulesMatch.Length);
                modulesMatch = Regex.Match(message, "[0-9]+");
            }

            startBomb = true;

            if (TwitchPlaySettings.data.EnableFreeplayHardcore || UserAccess.HasAccess(userNickName, AccessLevel.Admin, true) || TwitchPlaySettings.data.AnarchyMode)
            {
                SetHardcore(message.Contains("hardcore"));
            }
            else if (message.Contains("hardcore") != IsHardcore)
            {
                IRCConnection.Instance.SendMessage(string.Format(TwitchPlaySettings.data.FreePlayHardcoreDisabled, userNickName), userNickName, !isWhisper);
                startBomb = false;
            }

            if (TwitchPlaySettings.data.EnableFreeplayNeedy || UserAccess.HasAccess(userNickName, AccessLevel.Admin, true) || TwitchPlaySettings.data.AnarchyMode)
            {
                SetNeedy(message.Contains("needy"));
            }
            else if (message.Contains("needy") != HasNeedy)
            {
                IRCConnection.Instance.SendMessage(string.Format(TwitchPlaySettings.data.FreePlayNeedyDisabled, userNickName), userNickName, !isWhisper);
                startBomb = false;
            }

            if (TwitchPlaySettings.data.EnableFreeplayModsOnly || UserAccess.HasAccess(userNickName, AccessLevel.Admin, true) || TwitchPlaySettings.data.AnarchyMode)
            {
                if (message.Contains("vanilla"))
                {
                    SetModsOnly(false);
                }
                else if (message.Contains("mods"))
                {
                    SetModsOnly();
                }
            }
            else if (message.Contains("vanilla") || message.Contains("mods"))
            {
                IRCConnection.Instance.SendMessage(string.Format(TwitchPlaySettings.data.FreePlayModsOnlyDisabled, userNickName), userNickName, !isWhisper);
                startBomb = false;
            }
        }
        else
        {
            Match timerMatch = Regex.Match(message, "^timer? ([0-9]+)(?::([0-9]{2}))(?::([0-9]{2}))$", RegexOptions.IgnoreCase);
            if (timerMatch.Success)
            {
                changeHoursTo   = timerMatch.Groups[1].Value;
                changeMinutesTo = timerMatch.Groups[2].Value;
                changeSecondsTo = timerMatch.Groups[3].Value;
            }

            timerMatch = Regex.Match(message, "^timer? ([0-9]+)(?::([0-9]{2}))?$", RegexOptions.IgnoreCase);
            if (timerMatch.Success)
            {
                changeMinutesTo = timerMatch.Groups[1].Value;
                changeSecondsTo = timerMatch.Groups[2].Value;
            }

            Match bombsMatch = Regex.Match(message, "^bombs ([0-9]+)$", RegexOptions.IgnoreCase);
            if (bombsMatch.Success)
            {
                changeBombsTo = bombsMatch.Groups[1].Value;
            }

            Match modulesMatch = Regex.Match(message, "^modules ([0-9]+)$", RegexOptions.IgnoreCase);
            if (modulesMatch.Success)
            {
                changeModulesTo = modulesMatch.Groups[1].Value;
            }
        }

        if (changeMinutesTo != string.Empty)
        {
            IEnumerator setTimerCoroutine = SetBombTimer(changeHoursTo, changeMinutesTo, changeSecondsTo);
            while (setTimerCoroutine.MoveNext())
            {
                yield return(setTimerCoroutine.Current);
            }
        }
        if (changeBombsTo != string.Empty)
        {
            IEnumerator setBombsCoroutine = SetBombCount(changeBombsTo);
            while (setBombsCoroutine.MoveNext())
            {
                yield return(setBombsCoroutine.Current);
            }
        }
        if (changeModulesTo != string.Empty)
        {
            IEnumerator setModulesCoroutine = SetBombModules(changeModulesTo);
            while (setModulesCoroutine.MoveNext())
            {
                yield return(setModulesCoroutine.Current);
            }
        }
        if (startBomb)
        {
            StartBomb();
        }
    }
Exemple #19
0
    public IEnumerator OnMessageReceived(string userNickName, string userColor, string text)
    {
        Match match = Regex.Match(text, string.Format("^!{0} (.+)", _code), RegexOptions.IgnoreCase);

        if (!match.Success)
        {
            return(null);
        }

        string internalCommand = match.Groups[1].Value;

        TwitchMessage message = (TwitchMessage)Instantiate(messagePrefab, messageScrollContents.transform, false);

        if (string.IsNullOrEmpty(userColor))
        {
            message.SetMessage(string.Format("<b>{0}</b>: {1}", userNickName, internalCommand));
        }
        else
        {
            message.SetMessage(string.Format("<b><color={2}>{0}</color></b>: {1}", userNickName, internalCommand, userColor));
        }

        //Respond instantly to these commands without dropping "The Bomb", should the command be for "The Other Bomb" and vice versa.
        ICommandResponseNotifier icrn = message;

        if (internalCommand.Equals("timestamp", StringComparison.InvariantCultureIgnoreCase) ||
            internalCommand.Equals("date", StringComparison.InvariantCultureIgnoreCase))
        {
            //Some modules depend on the date/time the bomb, and therefore that Module instance has spawned, in the bomb defusers timezone.

            icrn.ProcessResponse(CommandResponse.Start);

            StringBuilder sb = new StringBuilder();
            sb.Append("The Date/Time this bomb started is ");
            sb.Append(string.Format("{0:F}", bombCommander.BombTimeStamp));
            ircConnection.SendMessage(sb.ToString());

            icrn.ProcessResponse(CommandResponse.EndNotComplete);
        }
        else if (internalCommand.Equals("help", StringComparison.InvariantCultureIgnoreCase))
        {
            icrn.ProcessResponse(CommandResponse.Start);

            ircConnection.SendMessage("The Bomb: !bomb hold [pick up] | !bomb drop | !bomb turn [turn to the other side] | !bomb edgework [show the widgets on the sides] | !bomb top [show one side; sides are Top/Bottom/Left/Right | !bomb time [time remaining] | !bomb timestamp [bomb start time]");

            icrn.ProcessResponse(CommandResponse.EndNotComplete);
        }

        else if (internalCommand.Equals("time", StringComparison.InvariantCultureIgnoreCase) ||
                 internalCommand.Equals("timer", StringComparison.InvariantCultureIgnoreCase) ||
                 internalCommand.Equals("clock", StringComparison.InvariantCultureIgnoreCase))
        {
            icrn.ProcessResponse(CommandResponse.Start);

            ircConnection.SendMessage(string.Format("panicBasket [{0}]",
                                                    bombCommander.GetFullFormattedTime));

            icrn.ProcessResponse(CommandResponse.EndNotComplete);
        }
        else
        {
            return(RespondToCommandCoroutine(userNickName, internalCommand, message));
        }

        return(null);
    }
    public IEnumerator OnMessageReceived(string userNickName, string userColor, string text)
    {
        string internalCommand;
        Match  match = Regex.Match(text, string.Format("^{0} (.+)", _code), RegexOptions.IgnoreCase);

        if (!match.Success)
        {
            match = Regex.Match(text, string.Format("^{0}(?> (.+))?", _edgeworkCode), RegexOptions.IgnoreCase);
            if (match.Success)
            {
                internalCommand = match.Groups[1].Value;
                if (!string.IsNullOrEmpty(internalCommand))
                {
                    if (!IsAuthorizedDefuser(userNickName))
                    {
                        return(null);
                    }
                    edgeworkText.text = internalCommand;
                }
                IRCConnection.Instance.SendMessage(TwitchPlaySettings.data.BombEdgework, edgeworkText.text);
            }
            return(null);
        }

        internalCommand = match.Groups[1].Value;

        TwitchMessage message = Instantiate <TwitchMessage>(messagePrefab, messageScrollContents.transform, false);

        message.SetMessage(string.IsNullOrEmpty(userColor)
                        ? string.Format("<b>{0}</b>: {1}", userNickName, internalCommand)
                        : string.Format("<b><color={2}>{0}</color></b>: {1}", userNickName, internalCommand, userColor));

        string internalCommandLower = internalCommand.ToLowerInvariant();

        string[] split = internalCommandLower.Split(new[] { " " }, StringSplitOptions.RemoveEmptyEntries);

        //Respond instantly to these commands without dropping "The Bomb", should the command be for "The Other Bomb" and vice versa.
        ICommandResponseNotifier notifier = message;

        if (internalCommandLower.EqualsAny("timestamp", "date"))
        {
            //Some modules depend on the date/time the bomb, and therefore that Module instance has spawned, in the bomb defusers timezone.

            notifier.ProcessResponse(CommandResponse.Start);
            IRCConnection.Instance.SendMessage(TwitchPlaySettings.data.BombTimeStamp, bombCommander.BombTimeStamp);
            notifier.ProcessResponse(CommandResponse.EndNotComplete);
        }
        else if (internalCommandLower.Equals("help"))
        {
            notifier.ProcessResponse(CommandResponse.Start);

            IRCConnection.Instance.SendMessage(TwitchPlaySettings.data.BombHelp);

            notifier.ProcessResponse(CommandResponse.EndNotComplete);
        }
        else if (internalCommandLower.EqualsAny("time", "timer", "clock"))
        {
            notifier.ProcessResponse(CommandResponse.Start);
            IRCConnection.Instance.SendMessage(TwitchPlaySettings.data.BombTimeRemaining, bombCommander.GetFullFormattedTime, bombCommander.GetFullStartingTime);
            notifier.ProcessResponse(CommandResponse.EndNotComplete);
        }
        else if (internalCommandLower.EqualsAny("explode", "detonate", "endzenmode"))
        {
            if (UserAccess.HasAccess(userNickName, AccessLevel.Mod, true) || (OtherModes.ZenModeOn && internalCommandLower.Equals("endzenmode")))
            {
                return(DelayBombExplosionCoroutine(notifier));
            }

            return(null);
        }
        else if (internalCommandLower.Equals("status") || internalCommandLower.Equals("info"))
        {
            int currentReward = TwitchPlaySettings.GetRewardBonus();
            if (OtherModes.TimeModeOn)
            {
                IRCConnection.Instance.SendMessage(TwitchPlaySettings.data.BombStatusTimeMode, bombCommander.GetFullFormattedTime, bombCommander.GetFullStartingTime,
                                                   OtherModes.GetAdjustedMultiplier(), bombCommander.bombSolvedModules, bombCommander.bombSolvableModules, currentReward);
            }
            else if (OtherModes.VSModeOn)
            {
                IRCConnection.Instance.SendMessage(TwitchPlaySettings.data.BombStatusVsMode, bombCommander.GetFullFormattedTime,
                                                   bombCommander.GetFullStartingTime, OtherModes.teamHealth, OtherModes.bossHealth, currentReward);
            }
            else
            {
                IRCConnection.Instance.SendMessage(TwitchPlaySettings.data.BombStatus, bombCommander.GetFullFormattedTime, bombCommander.GetFullStartingTime,
                                                   bombCommander.StrikeCount, bombCommander.StrikeLimit, bombCommander.bombSolvedModules, bombCommander.bombSolvableModules, currentReward);
            }
        }
        else if (split[0].EqualsAny("add", "increase", "change", "subtract", "decrease", "remove", "set"))
        {
            if (UserAccess.HasAccess(userNickName, AccessLevel.Admin, true))
            {
                bool negitive = split[0].EqualsAny("subtract", "decrease", "remove");
                bool direct   = split[0].EqualsAny("set");
                switch (split[1])
                {
                case "time":
                case "t":
                    float time = 0;
                    Dictionary <string, float> timeLengths = new Dictionary <string, float>()
                    {
                        { "ms", 0.001f },
                        { "s", 1 },
                        { "m", 60 },
                        { "h", 3600 },
                        { "d", 86400 },
                        { "w", 604800 },
                        { "y", 31536000 },
                    };

                    foreach (string part in split.Skip(2))
                    {
                        bool valid = false;
                        foreach (string unit in timeLengths.Keys)
                        {
                            if (!part.EndsWith(unit) || !float.TryParse(part.Substring(0, part.Length - unit.Length), out float length))
                            {
                                continue;
                            }
                            time += length * timeLengths[unit];
                            valid = true;
                            break;
                        }

                        if (!valid)
                        {
                            return(null);
                        }
                    }

                    time = (float)Math.Round((decimal)time, 2, MidpointRounding.AwayFromZero);
                    if (!direct && Math.Abs(time) == 0)
                    {
                        break;
                    }
                    if (negitive)
                    {
                        time = -time;
                    }

                    if (direct)
                    {
                        bombCommander.timerComponent.TimeRemaining = time;
                    }
                    else
                    {
                        bombCommander.timerComponent.TimeRemaining = bombCommander.CurrentTimer + time;
                    }

                    if (direct)
                    {
                        IRCConnection.Instance.SendMessage("Set the bomb's timer to {0}.", Math.Abs(time < 0 ? 0 : time).FormatTime());
                    }
                    else
                    {
                        IRCConnection.Instance.SendMessage("{0} {1} {2} the timer.", time > 0 ? "Added" : "Subtracted", Math.Abs(time).FormatTime(), time > 0 ? "to" : "from");
                    }
                    break;

                case "strikes":
                case "strike":
                case "s":
                    if (int.TryParse(split[2], out int strikes) && (strikes != 0 || direct))
                    {
                        if (negitive)
                        {
                            strikes = -strikes;
                        }

                        if (direct && strikes < 0)
                        {
                            strikes = 0;
                        }
                        else if (!direct && (bombCommander.StrikeCount + strikes) < 0)
                        {
                            strikes = -bombCommander.StrikeCount;                                       //Minimum of zero strikes. (Simon says is unsolvable with negative strikes.)
                        }

                        if (direct)
                        {
                            bombCommander.StrikeCount = strikes;
                        }
                        else
                        {
                            bombCommander.StrikeCount += strikes;
                        }

                        if (direct)
                        {
                            IRCConnection.Instance.SendMessage("Set the bomb's strike count to {0} {1}.", Math.Abs(strikes), Math.Abs(strikes) != 1 ? "strikes" : "strike");
                        }
                        else
                        {
                            IRCConnection.Instance.SendMessage("{0} {1} {2} {3} the bomb.", strikes > 0 ? "Added" : "Subtracted", Math.Abs(strikes), Math.Abs(strikes) != 1 ? "strikes" : "strike", strikes > 0 ? "to" : "from");
                        }
                        BombMessageResponder.moduleCameras.UpdateStrikes();
                    }
                    break;

                case "strikelimit":
                case "sl":
                case "maxstrikes":
                case "ms":
                    if (int.TryParse(split[2], out int maxStrikes) && (maxStrikes != 0 || direct))
                    {
                        if (negitive)
                        {
                            maxStrikes = -maxStrikes;
                        }

                        if (direct && maxStrikes < 0)
                        {
                            maxStrikes = 0;
                        }
                        else if (!direct && (bombCommander.StrikeLimit + maxStrikes) < 0)
                        {
                            maxStrikes = -bombCommander.StrikeLimit;
                        }

                        if (direct)
                        {
                            bombCommander.StrikeLimit = maxStrikes;
                        }
                        else
                        {
                            bombCommander.StrikeLimit += maxStrikes;
                        }

                        if (direct)
                        {
                            IRCConnection.Instance.SendMessage("Set the bomb's strike limit to {0} {1}.", Math.Abs(maxStrikes), Math.Abs(maxStrikes) != 1 ? "strikes" : "strike");
                        }
                        else
                        {
                            IRCConnection.Instance.SendMessage("{0} {1} {2} {3} the strike limit.", maxStrikes > 0 ? "Added" : "Subtracted", Math.Abs(maxStrikes), Math.Abs(maxStrikes) > 1 ? "strikes" : "strike", maxStrikes > 0 ? "to" : "from");
                        }
                        BombMessageResponder.moduleCameras.UpdateStrikes();
                        BombMessageResponder.moduleCameras.UpdateStrikeLimit();
                    }
                    break;
                }
            }

            return(null);
        }
        else if (!IsAuthorizedDefuser(userNickName))
        {
            return(null);
        }
        else
        {
            return(RespondToCommandCoroutine(userNickName, internalCommand, message));
        }

        return(null);
    }
    public IEnumerator RespondToCommand(string userNickName, string message, ICommandResponseNotifier responseNotifier)
    {
        if (message.Equals("hold", StringComparison.InvariantCultureIgnoreCase) ||
            message.Equals("pick up", StringComparison.InvariantCultureIgnoreCase))
        {
            IEnumerator holdCoroutine = HoldBombBinder();
            while (holdCoroutine.MoveNext())
            {
                yield return(holdCoroutine.Current);
            }
        }
        else
        {
            int holdState = (int)_holdStateProperty.GetValue(FloatingHoldable, null);
            if (holdState != 0)
            {
                yield break;
            }

            if (message.Equals("drop", StringComparison.InvariantCultureIgnoreCase) ||
                message.Equals("let go", StringComparison.InvariantCultureIgnoreCase) ||
                message.Equals("put down", StringComparison.InvariantCultureIgnoreCase))
            {
                LetGoBombBinder();
            }
            else if (message.Equals("select", StringComparison.InvariantCultureIgnoreCase))
            {
                IEnumerator selectCoroutine = SelectOnPage();
                while (selectCoroutine.MoveNext())
                {
                    yield return(selectCoroutine.Current);
                }
            }
            else if (message.StartsWith("select", StringComparison.InvariantCultureIgnoreCase))
            {
                string[]    commandParts    = message.Split(' ');
                int         index           = 0;
                IEnumerator selectCoroutine = null;
                if ((commandParts.Length == 2) &&
                    (int.TryParse(commandParts[1], out index)))
                {
                    selectCoroutine = SelectOnPage(index);
                }
                else
                {
                    selectCoroutine = SelectOnPage(0, commandParts.Skip(1).ToArray());
                }
                while (selectCoroutine.MoveNext())
                {
                    yield return(selectCoroutine.Current);
                }
            }
            else
            {
                string[] sequence = message.Split(new[] { ',', ' ' }, StringSplitOptions.RemoveEmptyEntries);
                foreach (string subCommand in sequence)
                {
                    if (subCommand.Equals("down", StringComparison.InvariantCultureIgnoreCase) ||
                        subCommand.Equals("d", StringComparison.InvariantCultureIgnoreCase))
                    {
                        MoveDownOnPage();
                        yield return(new WaitForSeconds(0.2f));
                    }
                    else if (subCommand.Equals("up", StringComparison.InvariantCultureIgnoreCase) ||
                             subCommand.Equals("u", StringComparison.InvariantCultureIgnoreCase))
                    {
                        MoveUpOnPage();
                        yield return(new WaitForSeconds(0.2f));
                    }
                }
            }
        }
    }