public IEnumerator HoldBomb(bool frontFace = true)
    {
        FloatingHoldable.HoldStateEnum holdState = FloatingHoldable.HoldState;
        bool doForceRotate = false;

        if (holdState != FloatingHoldable.HoldStateEnum.Held)
        {
            SelectObject(Selectable);
            doForceRotate = true;
            BombMessageResponder.moduleCameras?.ChangeBomb(this);
        }
        else if (frontFace != _heldFrontFace)
        {
            doForceRotate = true;
        }

        if (doForceRotate)
        {
            float       holdTime = FloatingHoldable.PickupTime;
            IEnumerator forceRotationCoroutine = ForceHeldRotation(frontFace, holdTime);
            while (forceRotationCoroutine.MoveNext())
            {
                yield return(forceRotationCoroutine.Current);
            }
        }
    }
    public IEnumerator Hold(bool frontFace = true)
    {
        FloatingHoldable holdable = FloatingHoldable.GetComponent <FloatingHoldable>();

        FloatingHoldable.HoldStateEnum holdState = holdable.HoldState;
        bool doForceRotate = false;

        if (holdState != global::FloatingHoldable.HoldStateEnum.Held)
        {
            SelectObject(Selectable.GetComponent <Selectable>());
            doForceRotate = true;
        }
        else if (frontFace != _heldFrontFace)
        {
            doForceRotate = true;
        }

        if (!doForceRotate)
        {
            yield break;
        }

        float       holdTime = holdable.PickupTime;
        IEnumerator forceRotationCoroutine = ForceHeldRotation(frontFace, holdTime);

        while (forceRotationCoroutine.MoveNext())
        {
            yield return(forceRotationCoroutine.Current);
        }
    }
Example #3
0
 public void LetGoFreeplayDevice()
 {
     FloatingHoldable.HoldStateEnum holdState = FloatingHoldable.HoldState;
     if (holdState == FloatingHoldable.HoldStateEnum.Held)
     {
         DeselectObject(Selectable);
     }
 }
Example #4
0
 public void LetGoBombBinder()
 {
     FloatingHoldable.HoldStateEnum holdState = FloatingHoldable.HoldState;
     if (holdState == FloatingHoldable.HoldStateEnum.Held)
     {
         DeselectObject(Selectable);
     }
 }
Example #5
0
 public IEnumerator LetGoBombBinder()
 {
     FloatingHoldable.HoldStateEnum holdState = FloatingHoldable.HoldState;
     if (holdState != FloatingHoldable.HoldStateEnum.Held)
     {
         yield break;
     }
     while (FloatingHoldable.HoldState == FloatingHoldable.HoldStateEnum.Held)
     {
         DeselectObject(Selectable);
         yield return(new WaitForSeconds(0.1f));
     }
 }
Example #6
0
    public IEnumerator HoldFreeplayDevice()
    {
        FloatingHoldable.HoldStateEnum holdState = FloatingHoldable.HoldState;

        if (holdState != FloatingHoldable.HoldStateEnum.Held)
        {
            SelectObject(Selectable);

            float       holdTime = FloatingHoldable.PickupTime;
            IEnumerator forceRotationCoroutine = ForceHeldRotation(holdTime);
            while (forceRotationCoroutine.MoveNext())
            {
                yield return(forceRotationCoroutine.Current);
            }
        }
    }
    public IEnumerator HoldBomb(bool frontFace = true)
    {
        IEnumerator gameRoomHoldBomb   = GameRoom.Instance?.BombCommanderHoldBomb(Bomb, frontFace);
        bool        continueInvocation = true;

        if (gameRoomHoldBomb != null && gameRoomHoldBomb.MoveNext() && gameRoomHoldBomb.Current is bool continueInvoke)
        {
            continueInvocation = continueInvoke;
            do
            {
                yield return(gameRoomHoldBomb.Current);
            } while (gameRoomHoldBomb.MoveNext());
        }

        if (!continueInvocation || FloatingHoldable == null)
        {
            yield break;
        }
        FloatingHoldable.HoldStateEnum holdState = FloatingHoldable.HoldState;
        bool doForceRotate = false;

        if (holdState != FloatingHoldable.HoldStateEnum.Held)
        {
            SelectObject(Selectable);
            doForceRotate = true;
            BombMessageResponder.moduleCameras?.ChangeBomb(this);
        }
        else if (frontFace != _heldFrontFace)
        {
            doForceRotate = true;
        }

        if (doForceRotate)
        {
            float       holdTime = FloatingHoldable.PickupTime;
            IEnumerator forceRotationCoroutine = ForceHeldRotation(frontFace, holdTime);
            while (forceRotationCoroutine.MoveNext())
            {
                yield return(forceRotationCoroutine.Current);
            }
        }
    }
Example #8
0
    public IEnumerator HoldBombBinder()
    {
        FloatingHoldable.HoldStateEnum holdState = FloatingHoldable.HoldState;

        if (holdState != FloatingHoldable.HoldStateEnum.Held)
        {
            SelectObject(Selectable);

            float       holdTime = FloatingHoldable.PickupTime;
            IEnumerator forceRotationCoroutine = ForceHeldRotation(holdTime);
            while (forceRotationCoroutine.MoveNext())
            {
                yield return(forceRotationCoroutine.Current);
            }

            yield return(null);

            InitialisePage();
        }
    }
Example #9
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));
                    }
                }
            }
        }
    }
    public IEnumerator RespondToCommand(string userNickName, string message)
    {
        DisableOnStrike      = false;
        Strike               = false;
        StrikeCount          = 0;
        _currentUserNickName = userNickName;

        FloatingHoldable.HoldStateEnum holdState = Holdable.HoldState;

        if (holdState == FloatingHoldable.HoldStateEnum.Held)
        {
        }
        else
        {
            IEnumerator holdCoroutine = HoldableCommander.Hold();
            while (holdCoroutine.MoveNext() && !Strike)
            {
                yield return(holdCoroutine.Current);
            }
        }

        IEnumerator processCommand = RespondToCommandCommon(message);

        if (processCommand == null || !processCommand.MoveNext())
        {
            DebugHelper.Log("Running RespondToCommandInternal()");
            processCommand = RespondToCommandInternal(message);
            bool cancelled  = false;
            bool parseError = false;
            bool cancelling = false;

            if (processCommand == null || !processCommand.MoveNext())
            {
                if (!Strike)
                {
                    SendToChat(null, userNickName, ref parseError);
                }
            }
            else
            {
                processIEnumerators.Push(processCommand);
                processIEnumerators.Push(FirstItem(processCommand.Current));
            }

            do
            {
                try
                {
                    bool result = false;
                    while (!result && !Strike)
                    {
                        if (processIEnumerators.Count > 0)
                        {
                            processCommand = processIEnumerators.Pop();
                            result         = processCommand.MoveNext();
                            if (result)
                            {
                                processIEnumerators.Push(processCommand);
                            }
                        }
                        else
                        {
                            break;
                        }
                    }
                    if (Strike)
                    {
                        DebugHelper.Log("A strike was caused by the command. Invocation will not continue.");
                    }
                    if (!result || Strike)
                    {
                        break;
                    }
                }
                catch (Exception ex)
                {
                    DebugHelper.LogException(ex, "Error Processing command due to an exception. Invocation will not continue.:");
                    break;
                }

                switch (processCommand.Current)
                {
                case IEnumerator iEnumerator:
                    if (iEnumerator != null)
                    {
                        processIEnumerators.Push(iEnumerator);
                    }
                    continue;

                case KMSelectable kmSelectable when kmSelectable != null:
                    if (heldSelectables.Contains(kmSelectable))
                    {
                        DoInteractionEnd(kmSelectable);
                        heldSelectables.Remove(kmSelectable);
                    }
                    else
                    {
                        DoInteractionStart(kmSelectable);
                        heldSelectables.Add(kmSelectable);
                    }
                    break;

                case KMSelectable[] kmSelectables:
                    foreach (KMSelectable selectable in kmSelectables)
                    {
                        if (selectable != null)
                        {
                            yield return(DoInteractionClick(selectable));

                            if (Strike)
                            {
                                break;
                            }
                        }
                        else
                        {
                            yield return(new WaitForSeconds(0.1f));
                        }
                    }
                    break;

                case Quaternion quaternion:
                    HoldableCommander.RotateByLocalQuaternion(quaternion);
                    break;

                case string currentString when !string.IsNullOrEmpty(currentString):
                    if (currentString.Equals("trycancel", StringComparison.InvariantCultureIgnoreCase) &&
                        CoroutineCanceller.ShouldCancel)
                    {
                        CoroutineCanceller.ResetCancel();
                        cancelled = true;
                    }
                    else if (currentString.ToLowerInvariant().EqualsAny("elevator music", "hold music", "waiting music"))
                    {
                        if (_musicPlayer == null)
                        {
                            _musicPlayer = MusicPlayer.StartRandomMusic();
                        }
                    }
                    else if (currentString.ToLowerInvariant().Equals("cancelled") && cancelling)
                    {
                        CancelBool?.SetValue(CommandComponent, false);
                        CoroutineCanceller.ResetCancel();
                        cancelled = true;
                    }
                    else if (currentString.StartsWith("strikemessage ", StringComparison.InvariantCultureIgnoreCase) &&
                             currentString.Substring(14).Trim() != string.Empty)
                    {
                        StrikeMessage = currentString.Substring(14);
                    }
                    else if (currentString.Equals("strike", StringComparison.InvariantCultureIgnoreCase))
                    {
                        _delegatedStrikeUserNickName = _currentUserNickName;
                    }
                    else if (currentString.Equals("multiple strikes", StringComparison.InvariantCultureIgnoreCase))
                    {
                        DisableOnStrike = true;
                    }
                    else if (currentString.ToLowerInvariant().EqualsAny("detonate", "explode") && BombMessageResponder.BombActive)
                    {
                        BombCommander BombCommander = BombMessageResponder.Instance.BombCommanders[0];
                        AwardStrikes(_currentUserNickName, BombCommander.StrikeLimit - BombCommander.StrikeCount);
                        BombCommander.twitchBombHandle.CauseExplosionByModuleCommand(string.Empty, HoldableCommander.ID);
                        Strike = true;
                    }
                    else if (currentString.ToLowerInvariant().Equals("show front"))
                    {
                        processIEnumerators.Push(HoldableCommander.Hold(true));
                    }
                    else if (currentString.ToLowerInvariant().Equals("show back"))
                    {
                        processIEnumerators.Push(HoldableCommander.Hold(false));
                    }
                    else
                    {
                        SendToChat(currentString, userNickName, ref parseError);
                    }
                    break;

                case string[] currentStrings:
                    if (currentStrings.Length >= 1)
                    {
                        if (currentStrings[0].ToLowerInvariant().EqualsAny("detonate", "explode") && BombMessageResponder.BombActive)
                        {
                            BombCommander BombCommander = BombMessageResponder.Instance.BombCommanders[0];
                            AwardStrikes(_currentUserNickName, BombCommander.StrikeLimit - BombCommander.StrikeCount);
                            switch (currentStrings.Length)
                            {
                            case 2:
                                BombCommander.twitchBombHandle.CauseExplosionByModuleCommand(currentStrings[1], HoldableCommander.ID);
                                break;

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

                            default:
                                BombCommander.twitchBombHandle.CauseExplosionByModuleCommand(string.Empty, HoldableCommander.ID);
                                break;
                            }
                            break;
                        }
                    }
                    break;

                case Dictionary <string, bool> permissions:
                    foreach (KeyValuePair <string, bool> pair in permissions)
                    {
                        if (TwitchPlaySettings.data.ModPermissions.ContainsKey(pair.Key))
                        {
                            continue;
                        }
                        TwitchPlaySettings.data.ModPermissions.Add(pair.Key, pair.Value);
                        TwitchPlaySettings.WriteDataToFile();
                    }
                    break;

                case KMMission mission:
                    MiscellaneousMessageResponder.Instance.RunMission(mission);
                    break;

                case object[] objects:
                    if (objects == null)
                    {
                        break;
                    }
                    switch (objects.Length)
                    {
                    case 3 when objects[0] is string objstr:
                        if (IsAskingPermission(objstr, userNickName, out bool permissionGranted))
                        {
                            if (permissionGranted)
                            {
                                switch (objects[1])
                                {
                                case Action actionTrue:
                                    actionTrue.Invoke();
                                    break;

                                case IEnumerator iEnumerator when iEnumerator != null:
                                    processIEnumerators.Push(iEnumerator);
                                    yield return(null);

                                    continue;
                                }
                            }
                            else
                            {
                                switch (objects[2])
                                {
                                case Action actionFalse:
                                    actionFalse.Invoke();
                                    break;

                                case string objStr2 when !string.IsNullOrEmpty(objStr2):
                                    SendToChat(objStr2, userNickName, ref parseError);
                                    break;

                                case IEnumerator iEnumerator when iEnumerator != null:
                                    processIEnumerators.Push(iEnumerator);
                                    yield return(null);

                                    continue;
                                }
                            }
                        }
                        break;
                    }
                    break;
Example #11
0
    public IEnumerator FreeplayRespondToCommand(string userNickName, string message, ICommandResponseNotifier responseNotifier, IRCConnection connection)
    {
        message = message.ToLowerInvariant();
        FloatingHoldable.HoldStateEnum holdState = FloatingHoldable.HoldState;

        if (holdState == FloatingHoldable.HoldStateEnum.Held)
        {
            if (message.EqualsAny("drop", "let go", "put down"))
            {
                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.EqualsAny("needy on", "needy off"))
        {
            if (TwitchPlaySettings.data.EnableFreeplayNeedy || UserAccess.HasAccess(userNickName, AccessLevel.Admin, true))
            {
                SetNeedy(message.Equals("needy on"));
            }
            else
            {
                connection.SendMessage(TwitchPlaySettings.data.FreePlayNeedyDisabled, userNickName);
            }
        }
        else if (message.EqualsAny("hardcore on", "hardcore off"))
        {
            if (TwitchPlaySettings.data.EnableFreeplayHardcore || UserAccess.HasAccess(userNickName, AccessLevel.Admin, true))
            {
                SetHardcore(message.Equals("hardcore on"));
            }
            else
            {
                connection.SendMessage(TwitchPlaySettings.data.FreePlayHardcoreDisabled, userNickName);
            }
        }
        else if (message.EqualsAny("mods only on", "mods only off"))
        {
            if (TwitchPlaySettings.data.EnableFreeplayModsOnly || UserAccess.HasAccess(userNickName, AccessLevel.Admin, true))
            {
                SetModsOnly(message.Equals("mods only on"));
            }
            else
            {
                connection.SendMessage(TwitchPlaySettings.data.FreePlayModsOnlyDisabled, userNickName);
            }
        }
        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))
            {
                SetHardcore(message.Contains("hardcore"));
            }
            else if (message.Contains("hardcore") != IsHardcore)
            {
                connection.SendMessage(TwitchPlaySettings.data.FreePlayHardcoreDisabled, userNickName);
                startBomb = false;
            }

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

            if (TwitchPlaySettings.data.EnableFreeplayModsOnly || UserAccess.HasAccess(userNickName, AccessLevel.Admin, true))
            {
                if (message.Contains("vanilla"))
                {
                    SetModsOnly(false);
                }
                else if (message.Contains("mods"))
                {
                    SetModsOnly();
                }
            }
            else if (message.Contains("vanilla") || message.Contains("mods"))
            {
                connection.SendMessage(TwitchPlaySettings.data.FreePlayModsOnlyDisabled, userNickName);
                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();
        }
    }