Beispiel #1
0
    public IEnumerator SetBombCount(string bombs)
    {
        if (!int.TryParse(bombs, out int bombCount))
        {
            yield break;
        }

        if (!MultipleBombs.Installed())
        {
            yield break;
        }

        int        currentBombCount = MultipleBombs.GetFreePlayBombCount();
        Selectable buttonSelectable = bombCount > currentBombCount ? SelectableChildren[3] : SelectableChildren[2];

        for (int hitCount = 0; hitCount < Mathf.Abs(bombCount - currentBombCount); ++hitCount)
        {
            int lastBombCount = MultipleBombs.GetFreePlayBombCount();
            SelectObject(buttonSelectable);
            yield return(new WaitForSeconds(0.01f));

            if (lastBombCount == MultipleBombs.GetFreePlayBombCount())
            {
                yield break;
            }
        }
    }
    public FreeplayCommander(FreeplayDevice freeplayDevice)
    {
        FreeplayDevice     = freeplayDevice;
        Selectable         = FreeplayDevice.GetComponent <Selectable>();
        FloatingHoldable   = FreeplayDevice.GetComponent <FloatingHoldable>();
        _selectableManager = KTInputManager.Instance.SelectableManager;


        _originalTimeIncrementHandler   = FreeplayDevice.TimeIncrement.OnPush;
        _originalTimeDecrementHandler   = FreeplayDevice.TimeDecrement.OnPush;
        _originalModuleIncrementHandler = FreeplayDevice.ModuleCountIncrement.OnPush;
        _originalModuleDecrementHandler = FreeplayDevice.ModuleCountDecrement.OnPush;

        FreeplayDevice.TimeIncrement.OnPush        = () => { FreeplayDevice.StartCoroutine(IncrementBombTimer()); };
        FreeplayDevice.TimeDecrement.OnPush        = () => { FreeplayDevice.StartCoroutine(DecrementBombTimer()); };
        FreeplayDevice.ModuleCountIncrement.OnPush = () => { FreeplayDevice.StartCoroutine(IncrementModuleCount()); };
        FreeplayDevice.ModuleCountDecrement.OnPush = () => { FreeplayDevice.StartCoroutine(DecrementModuleCount()); };

        if (!MultipleBombs.Installed())
        {
            return;
        }

        _bombsIncrementButton = Selectable.Children[3].GetComponent <KeypadButton>();
        _bombsDecrementButton = Selectable.Children[2].GetComponent <KeypadButton>();

        _originalBombIncrementHandler = _bombsIncrementButton.OnPush;
        _originalBombDecrementHandler = _bombsDecrementButton.OnPush;

        _bombsIncrementButton.OnPush = () => { FreeplayDevice.StartCoroutine(IncrementBombCount()); };
        _bombsDecrementButton.OnPush = () => { FreeplayDevice.StartCoroutine(DecrementBombCount()); };
    }
    private MessageResponder GetActiveResponder(KMGameInfo.State state)
    {
        switch (state)
        {
        case KMGameInfo.State.Gameplay:
            DefaultCamera();
            return(bombMessageResponder);

        case KMGameInfo.State.Setup:
            DefaultCamera();
            _coroutinesToStart.Enqueue(VanillaRuleModifier.Refresh());
            _coroutinesToStart.Enqueue(MultipleBombs.Refresh());
            _coroutinesToStart.Enqueue(FactoryRoomAPI.Refresh());
            _coroutinesToStart.Enqueue(CreateSolversForAllBombComponents());

            return(missionMessageResponder);

        case KMGameInfo.State.PostGame:
            DefaultCamera();
            return(postGameMessageResponder);

        case KMGameInfo.State.Transitioning:
            ModuleData.LoadDataFromFile();
            TwitchPlaySettings.LoadDataFromFile();
            return(null);

        default:
            return(null);
        }
    }
Beispiel #4
0
    private IEnumerator CheckForFreeplayDevice()
    {
        yield return(null);

        DebugLog("Attempting to find Freeplay device");
        while (true)
        {
            UnityEngine.Object[] freeplayDevices = FindObjectsOfType(CommonReflectedTypeInfo.FreeplayDeviceType);
            if (freeplayDevices != null && freeplayDevices.Length > 0)
            {
                DebugLog("Freeplay Device found - Hooking into it.");

                IEnumerator multipleBombs = MultipleBombs.Refresh();
                while (multipleBombs.MoveNext())
                {
                    yield return(multipleBombs.Current);
                }
                if (MultipleBombs.Installed())
                {
                    DebugLog("Multiple Bombs is also installed");
                }

                _freeplayCommander = new FreeplayCommander((MonoBehaviour)freeplayDevices[0]);
                break;
            }

            yield return(null);
        }
    }
Beispiel #5
0
    public IEnumerator SetBombTimer(string hours, string mins, string secs)
    {
        DebugHelper.Log("Time parsing section");
        int hoursInt = 0;

        if (!string.IsNullOrEmpty(hours) && !int.TryParse(hours, out hoursInt))
        {
            yield break;
        }

        if (!int.TryParse(mins, out int minutes))
        {
            yield break;
        }

        int seconds = 0;

        if (!string.IsNullOrEmpty(secs) &&
            (!int.TryParse(secs, out seconds) || seconds >= 60))
        {
            yield break;
        }

        int timeIndex = (hoursInt * 120) + (minutes * 2) + (seconds / 30);

        DebugHelper.Log("Freeplay time doubling section");
        //Double the available free play time. (The doubling stacks with the Multiple bombs module installed)
        float originalMaxTime = FreeplayDevice.MAX_SECONDS_TO_SOLVE;
        int   maxModules      = (int)_maxModuleField.GetValue(FreeplayDevice);
        int   multiplier      = MultipleBombs.Installed() ? (MultipleBombs.GetMaximumBombCount() * 2) - 1 : 1;
        float newMaxTime      = 600f + ((maxModules - 1) * multiplier * 60);

        FreeplayDevice.MAX_SECONDS_TO_SOLVE = newMaxTime;


        DebugHelper.Log("Freeplay settings reading section");
        FreeplaySettings currentSettings = FreeplayDevice.CurrentSettings;
        float            currentTime     = currentSettings.Time;
        int          currentTimeIndex    = Mathf.FloorToInt(currentTime) / 30;
        KeypadButton button           = timeIndex > currentTimeIndex ? FreeplayDevice.TimeIncrement : FreeplayDevice.TimeDecrement;
        Selectable   buttonSelectable = button.GetComponent <Selectable>();

        DebugHelper.Log("Freeplay time setting section");
        for (int hitCount = 0; hitCount < Mathf.Abs(timeIndex - currentTimeIndex); ++hitCount)
        {
            currentTime = currentSettings.Time;
            SelectObject(buttonSelectable);
            yield return(new WaitForSeconds(0.01f));

            if (Mathf.FloorToInt(currentTime) == Mathf.FloorToInt(currentSettings.Time))
            {
                break;
            }
        }

        //Restore original max time, just in case Multiple bombs module was NOT installed, to avoid false detection.
        FreeplayDevice.MAX_SECONDS_TO_SOLVE = originalMaxTime;
    }
Beispiel #6
0
    private void OnStateChange(KMGameInfo.State state)
    {
        CurrentState = state;
        if (!transform.gameObject.activeInHierarchy)
        {
            return;
        }

        StartCoroutine(StopEveryCoroutine());

        if (state != KMGameInfo.State.PostGame && _leaderboardDisplay != null)
        {
            DestroyObject(_leaderboardDisplay);
            _leaderboardDisplay = null;
        }

        twitchGame?.gameObject.SetActive(state == KMGameInfo.State.Gameplay);

        OtherModes.RefreshModes(state);

        // Automatically check for updates after a round is finished or when entering the setup state but never more than once per hour.
        bool hourPassed = DateTime.Now.Subtract(Updater.LastCheck).TotalHours >= 1;

        if ((state == KMGameInfo.State.PostGame || state == KMGameInfo.State.Setup) && hourPassed && !Updater.UpdateAvailable)
        {
            _coroutinesToStart.Enqueue(AutomaticUpdateCheck());
        }

        switch (state)
        {
        case KMGameInfo.State.Gameplay:
            DefaultCamera();
            break;

        case KMGameInfo.State.Setup:
            DefaultCamera();
            _coroutinesToStart.Enqueue(VanillaRuleModifier.Refresh());
            _coroutinesToStart.Enqueue(MultipleBombs.Refresh());
            _coroutinesToStart.Enqueue(FactoryRoomAPI.Refresh());
            _coroutinesToStart.Enqueue(FindSupportedModules());
            break;

        case KMGameInfo.State.PostGame:
            DefaultCamera();
            if (_leaderboardDisplay == null)
            {
                _leaderboardDisplay = Instantiate(TwitchLeaderboardPrefab);
            }
            Leaderboard.Instance.SaveDataToFile();
            break;

        case KMGameInfo.State.Transitioning:
            ModuleData.LoadDataFromFile();
            TwitchPlaySettings.LoadDataFromFile();
            break;
        }
    }
Beispiel #7
0
    public static IEnumerator StartAdvanced(FloatingHoldable holdable, [Group(1)] string command, [Group(2)] string parameters, string user, bool isWhisper)
    {
        if (parameters.RegexMatch(out Match m, @"(\d):(\d{1,3}):(\d{2})"))
        {
            var e = SetBombTimer(holdable, int.Parse(m.Groups[1].Value), int.Parse(m.Groups[2].Value), int.Parse(m.Groups[3].Value));
            while (e.MoveNext())
            {
                yield return(e.Current);
            }
        }
        else if (parameters.RegexMatch(out m, @"(\d{1,3}):(\d{2})"))
        {
            var e = SetBombTimer(holdable, 0, int.Parse(m.Groups[1].Value), int.Parse(m.Groups[2].Value));
            while (e.MoveNext())
            {
                yield return(e.Current);
            }
        }

        if (MultipleBombs.Installed() && parameters.RegexMatch(out m, @"(\d+) +bombs"))
        {
            var e = ChangeBombCount(holdable, int.Parse(m.Groups[1].Value));
            while (e.MoveNext())
            {
                yield return(e.Current);
            }
        }
        if (parameters.RegexMatch(out m, @"(\d+) +modules"))
        {
            var e = ChangeModuleCount(holdable, int.Parse(m.Groups[1].Value));
            while (e.MoveNext())
            {
                yield return(e.Current);
            }
        }

        yield return(null);

        SetSetting(holdable, parameters.Contains("hardcore"), user, isWhisper, s => s.IsHardCore, s => s.HardcoreToggle, TwitchPlaySettings.data.EnableFreeplayHardcore, TwitchPlaySettings.data.FreePlayHardcoreDisabled);
        yield return(null);

        SetSetting(holdable, parameters.Contains("modsonly"), user, isWhisper, s => s.OnlyMods, s => s.ModsOnly, TwitchPlaySettings.data.EnableFreeplayModsOnly, TwitchPlaySettings.data.FreePlayModsOnlyDisabled);
        yield return(null);

        SetSetting(holdable, parameters.Contains("needy") || parameters.Contains("needies"), user, isWhisper, s => s.HasNeedy, s => s.NeedyToggle, TwitchPlaySettings.data.EnableFreeplayNeedy, TwitchPlaySettings.data.FreePlayNeedyDisabled);
        yield return(null);

        if (command.EqualsIgnoreCase("start"))
        {
            holdable.GetComponent <FreeplayDevice>().StartButton.GetComponent <Selectable>().Trigger();
        }
    }
Beispiel #8
0
    private void OnStateChange(KMGameInfo.State state)
    {
        CurrentState = state;
        if (!transform.gameObject.activeInHierarchy)
        {
            return;
        }

        StartCoroutine(StopEveryCoroutine());

        if (state != KMGameInfo.State.PostGame && _leaderboardDisplay != null)
        {
            DestroyObject(_leaderboardDisplay);
            _leaderboardDisplay = null;
        }

        twitchGame?.gameObject.SetActive(state == KMGameInfo.State.Gameplay);

        OtherModes.RefreshModes(state);

        switch (state)
        {
        case KMGameInfo.State.Gameplay:
            DefaultCamera();
            break;

        case KMGameInfo.State.Setup:
            DefaultCamera();
            _coroutinesToStart.Enqueue(VanillaRuleModifier.Refresh());
            _coroutinesToStart.Enqueue(MultipleBombs.Refresh());
            _coroutinesToStart.Enqueue(FactoryRoomAPI.Refresh());
            _coroutinesToStart.Enqueue(FindSupportedModules());
            break;

        case KMGameInfo.State.PostGame:
            DefaultCamera();
            if (_leaderboardDisplay == null)
            {
                _leaderboardDisplay = Instantiate(TwitchLeaderboardPrefab);
            }
            Leaderboard.Instance.SaveDataToFile();
            break;

        case KMGameInfo.State.Transitioning:
            ModuleData.LoadDataFromFile();
            TwitchPlaySettings.LoadDataFromFile();
            break;
        }
    }
    public IEnumerator DecrementBombCount()
    {
        if (!MultipleBombs.Installed())
        {
            yield break;
        }
        float delay = startDelay;

        while (Input.GetKey(KeyCode.LeftArrow))
        {
            SelectObject(SelectableChildren[2]);
            yield return(new WaitForSeconds(Mathf.Max(delay, minDelay)));

            delay -= Acceleration;
        }
    }
    string resolveMissionID(string targetID, out string failureMessage)
    {
        failureMessage = null;
        ModManager     modManager = ModManager.Instance;
        List <Mission> missions   = modManager.ModMissions;

        Mission mission = missions.FirstOrDefault(x => Regex.IsMatch(x.name, "mod_.+_" + Regex.Escape(targetID), RegexOptions.CultureInvariant | RegexOptions.IgnoreCase));

        if (mission == null)
        {
            failureMessage = $"Unable to find a mission with an ID of \"{targetID}\".";
            return(null);
        }

        List <string> availableMods = GameInfo.GetAvailableModuleInfo().Where(x => x.IsMod).Select(y => y.ModuleId).ToList();

        if (MultipleBombs.Installed())
        {
            availableMods.Add("Multiple Bombs");
        }
        HashSet <string>         missingMods = new HashSet <string>();
        List <ModuleInformation> modules     = ComponentSolverFactory.GetModuleInformation().ToList();

        GeneratorSetting     generatorSetting = mission.GeneratorSetting;
        List <ComponentPool> componentPools   = generatorSetting.ComponentPools;

        foreach (ComponentPool componentPool in componentPools)
        {
            List <string> modTypes = componentPool.ModTypes;
            if (modTypes == null || modTypes.Count == 0)
            {
                continue;
            }
            foreach (string mod in modTypes.Where(x => !availableMods.Contains(x)))
            {
                missingMods.Add(modules.FirstOrDefault(x => x.moduleID == mod)?.moduleDisplayName ?? mod);
            }
        }
        if (missingMods.Count > 0)
        {
            failureMessage = $"Mission \"{targetID}\" was found, however, the following mods are not installed / loaded: {string.Join(", ", missingMods.OrderBy(x => x).ToArray())}";
            return(null);
        }

        return(mission.name);
    }
Beispiel #11
0
    private static IEnumerator SetBombTimer(FloatingHoldable holdable, int hours, int minutes, int seconds)
    {
        if (seconds >= 60)
        {
            yield break;
        }

        var device    = holdable.GetComponent <FreeplayDevice>();
        int timeIndex = (hours * 120) + (minutes * 2) + (seconds / 30);

        DebugHelper.Log("Freeplay time doubling section");
        //Double the available free play time. (The doubling stacks with the Multiple bombs module installed)
        float originalMaxTime = FreeplayDevice.MAX_SECONDS_TO_SOLVE;
        int   maxModules      = (int)_maxModuleField.GetValue(device);
        int   multiplier      = MultipleBombs.Installed() ? (MultipleBombs.GetMaximumBombCount() * 2) - 1 : 1;
        float newMaxTime      = 600f + (maxModules - 1) * multiplier * 60;

        FreeplayDevice.MAX_SECONDS_TO_SOLVE = newMaxTime;

        DebugHelper.Log("Freeplay settings reading section");
        float        currentTime      = device.CurrentSettings.Time;
        int          currentTimeIndex = Mathf.FloorToInt(currentTime) / 30;
        KeypadButton button           = timeIndex > currentTimeIndex ? device.TimeIncrement : device.TimeDecrement;
        Selectable   buttonSelectable = button.GetComponent <Selectable>();

        DebugHelper.Log("Freeplay time setting section");
        for (int hitCount = 0; hitCount < Mathf.Abs(timeIndex - currentTimeIndex); ++hitCount)
        {
            currentTime = device.CurrentSettings.Time;
            buttonSelectable.Trigger();
            yield return(new WaitForSeconds(0.01f));

            if (Mathf.FloorToInt(currentTime) == Mathf.FloorToInt(device.CurrentSettings.Time))
            {
                break;
            }
        }

        //Restore original max time, just in case Multiple bombs module was NOT installed, to avoid false detection.
        FreeplayDevice.MAX_SECONDS_TO_SOLVE = originalMaxTime;
    }
Beispiel #12
0
    public static IEnumerator ChangeBombCount(FloatingHoldable holdable, [Group(1)] int bombCount)
    {
        if (!MultipleBombs.Installed())
        {
            yield break;
        }

        int currentBombCount = MultipleBombs.GetFreePlayBombCount();
        var buttonSelectable = holdable.GetComponent <Selectable>().Children[bombCount > currentBombCount ? 3 : 2];

        for (int hitCount = 0; hitCount < Mathf.Abs(bombCount - currentBombCount); ++hitCount)
        {
            int lastBombCount = MultipleBombs.GetFreePlayBombCount();
            buttonSelectable.Trigger();
            yield return(new WaitForSeconds(0.01f));

            // Stop here if we hit a maximum or minimum
            if (lastBombCount == MultipleBombs.GetFreePlayBombCount())
            {
                yield break;
            }
        }
    }
Beispiel #13
0
    private IEnumerator CheckForFreeplayDevice()
    {
        yield return(null);

        yield return(null);

        DebugLog("Attempting to find Freeplay device");

        var multipleBombs = MultipleBombs.Refresh();

        while (multipleBombs.MoveNext())
        {
            yield return(multipleBombs.Current);
        }
        if (MultipleBombs.Installed())
        {
            DebugLog("Multiple Bombs is also installed");
        }

        var setupRoom = (SetupRoom)SceneManager.Instance.CurrentRoom;

        _freeplayCommander = new FreeplayCommander(setupRoom.FreeplayDevice);
    }
Beispiel #14
0
    private MessageResponder GetActiveResponder(KMGameInfo.State state)
    {
        switch (state)
        {
        case KMGameInfo.State.Gameplay:
            return(bombMessageResponder);

        case KMGameInfo.State.Setup:
            StartCoroutine(VanillaRuleModifier.Refresh());
            StartCoroutine(MultipleBombs.Refresh());
            return(missionMessageResponder);

        case KMGameInfo.State.PostGame:
            return(postGameMessageResponder);

        case KMGameInfo.State.Transitioning:
            ModuleData.LoadDataFromFile();
            TwitchPlaySettings.LoadDataFromFile();
            return(null);

        default:
            return(null);
        }
    }
    public void ToggleIndex()
    {
        var currentSettings    = FreeplayDevice.CurrentSettings;
        var currentModuleCount = currentSettings.ModuleCount;
        var currentBombsCount  = MultipleBombs.GetBombCount();
        var currentTime        = currentSettings.Time;
        var onlyMods           = currentSettings.OnlyMods;

        switch (_index)
        {
        case FreeplaySelection.Timer:
            try
            {
                SelectObject(FreeplayDevice.TimeIncrement);
                if (Mathf.FloorToInt(currentTime) == Mathf.FloorToInt(currentSettings.Time))
                {
                    break;
                }
                SelectObject(FreeplayDevice.TimeDecrement);
            }
            catch (Exception ex)
            {
                DebugLog("Failed to Select the Timer buttons due to Exception: {0}, Stack Trace: {1}", ex.Message, ex.StackTrace);
            }
            break;

        case FreeplaySelection.Bombs:
            try
            {
                if (!MultipleBombs.Installed())
                {
                    break;
                }
                SelectObject(_bombsIncrementButton);
                if (currentBombsCount == MultipleBombs.GetBombCount())
                {
                    break;
                }
                SelectObject(_bombsDecrementButton);
            }
            catch (Exception ex)
            {
                DebugLog("Failed to Select the Bomb count buttons due to Exception: {0}, Stack Trace: {1}", ex.Message, ex.StackTrace);
            }
            break;

        case FreeplaySelection.Modules:
            try
            {
                SelectObject(FreeplayDevice.ModuleCountIncrement);
                if (currentModuleCount == currentSettings.ModuleCount)
                {
                    break;
                }
                SelectObject(FreeplayDevice.ModuleCountDecrement);
            }
            catch (Exception ex)
            {
                DebugLog("Failed to Select the Module count buttons due to Exception: {0}, Stack Trace: {1}", ex.Message, ex.StackTrace);
            }
            break;

        case FreeplaySelection.Needy:
            try
            {
                SelectObject(FreeplayDevice.NeedyToggle);
                SelectObject(FreeplayDevice.NeedyToggle);
            }
            catch (Exception ex)
            {
                DebugLog("Failed to Select the Needy toggle due to Exception: {0}, Stack Trace: {1}", ex.Message, ex.StackTrace);
            }
            break;

        case FreeplaySelection.Hardcore:
            try
            {
                SelectObject(FreeplayDevice.HardcoreToggle);
                SelectObject(FreeplayDevice.HardcoreToggle);
            }
            catch (Exception ex)
            {
                DebugLog("Failed to Select the Hardcore toggle due to Exception: {0}, Stack Trace: {1}", ex.Message, ex.StackTrace);
            }
            break;

        case FreeplaySelection.ModsOnly:
            try
            {
                SelectObject(FreeplayDevice.ModsOnly);
                var onlyModsCurrent = currentSettings.OnlyMods;
                SelectObject(FreeplayDevice.ModsOnly);
                if (onlyMods == onlyModsCurrent)
                {
                    if (Input.GetKey(KeyCode.DownArrow))
                    {
                        _index = FreeplaySelection.Timer;
                        goto case FreeplaySelection.Timer;
                    }
                    else
                    {
                        _index = FreeplaySelection.Hardcore;
                        goto case FreeplaySelection.Hardcore;
                    }
                }
            }
            catch (Exception ex)
            {
                DebugLog("Failed to Select the Mods only toggle due to Exception: {0}, Stack Trace: {1}", ex.Message, ex.StackTrace);
            }
            break;

        default:
            throw new ArgumentOutOfRangeException();
        }
    }
    private void OnStateChange(KMGameInfo.State state)
    {
        CurrentState = state;

        if (!transform.gameObject.activeInHierarchy)
        {
            return;
        }

        StartCoroutine(StopEveryCoroutine());
        CheckSupport.Cleanup();
        Votes.Clear();

        if (state != KMGameInfo.State.PostGame && _leaderboardDisplay != null)
        {
            DestroyObject(_leaderboardDisplay);
            _leaderboardDisplay = null;
        }

        twitchGame?.gameObject.SetActive(state == KMGameInfo.State.Gameplay);

        OtherModes.RefreshModes(state);

        // Automatically check for updates after a round is finished or when entering the setup state but never more than once per hour.
        bool hourPassed = DateTime.Now.Subtract(Updater.LastCheck).TotalHours >= 1;

        if ((state == KMGameInfo.State.PostGame || state == KMGameInfo.State.Setup) && hourPassed && !Updater.UpdateAvailable)
        {
            _coroutinesToStart.Enqueue(AutomaticUpdateCheck());
        }

        switch (state)
        {
        case KMGameInfo.State.Gameplay:
            DefaultCamera();
            break;

        case KMGameInfo.State.Setup:
            DefaultCamera();
            _coroutinesToStart.Enqueue(VanillaRuleModifier.Refresh());
            _coroutinesToStart.Enqueue(MultipleBombs.Refresh());
            _coroutinesToStart.Enqueue(FactoryRoomAPI.Refresh());

            if (!initialLoad)
            {
                initialLoad = true;
                _coroutinesToStart.Enqueue(ComponentSolverFactory.LoadDefaultInformation(true));
                if (!TwitchPlaySettings.data.TwitchPlaysDebugEnabled)
                {
                    _coroutinesToStart.Enqueue(CheckSupport.FindSupportedModules());
                }
            }

            // Clear out the retry reward if we return to the setup room since the retry button doesn't return to setup.
            // A post game run command would set the retry bonus and then return to the setup room to start the mission, so we don't want to clear that.
            if (TwitchPlaySettings.GetRewardBonus() == 0)
            {
                TwitchPlaySettings.ClearRetryReward();
            }
            break;

        case KMGameInfo.State.PostGame:
            DefaultCamera();
            if (_leaderboardDisplay == null)
            {
                _leaderboardDisplay = Instantiate(TwitchLeaderboardPrefab);
            }
            Leaderboard.Instance.SaveDataToFile();
            break;

        case KMGameInfo.State.Transitioning:
            ModuleData.LoadDataFromFile();
            TwitchPlaySettings.LoadDataFromFile();

            var pageManager = SceneManager.Instance?.SetupState?.Room.GetComponent <SetupRoom>().BombBinder.MissionTableOfContentsPageManager;
            if (pageManager != null)
            {
                var tableOfContentsList = pageManager.GetValue <List <Assets.Scripts.BombBinder.MissionTableOfContents> >("tableOfContentsList");
                if (tableOfContentsList[SetupState.LastBombBinderTOCIndex].ToCID == "toc_tp_search")
                {
                    SetupState.LastBombBinderTOCIndex = 0;
                    SetupState.LastBombBinderTOCPage  = 0;
                }
            }

            break;
        }
    }
Beispiel #17
0
    public void ToggleIndex()
    {
        object currentSettings    = _currentSettingsField.GetValue(FreeplayDevice, null);
        int    currentModuleCount = (int)_moduleCountField.GetValue(currentSettings);
        int    currentBombsCount  = MultipleBombs.GetBombCount();
        float  currentTime        = (float)_timeField.GetValue(currentSettings);
        bool   onlyMods           = (bool)_onlyModsField.GetValue(currentSettings);

        switch (_index)
        {
        case freeplaySelection.Timer:
            try
            {
                MonoBehaviour timerUp   = (MonoBehaviour)_timeIncrementField.GetValue(FreeplayDevice);
                MonoBehaviour timerDown = (MonoBehaviour)_timeDecrementField.GetValue(FreeplayDevice);
                SelectObject((MonoBehaviour)timerUp.GetComponent(_selectableType));
                if (Mathf.FloorToInt(currentTime) == Mathf.FloorToInt((float)_timeField.GetValue(currentSettings)))
                {
                    break;
                }
                SelectObject((MonoBehaviour)timerDown.GetComponent(_selectableType));
            }
            catch (Exception ex)
            {
                DebugLog("Failed to Select the Timer buttons due to Exception: {0}, Stack Trace: {1}", ex.Message, ex.StackTrace);
            }
            break;

        case freeplaySelection.Bombs:
            try
            {
                if (!MultipleBombs.Installed())
                {
                    break;
                }
                MonoBehaviour bombsUp   = SelectableChildren[3];
                MonoBehaviour bombsDown = SelectableChildren[2];
                SelectObject(bombsUp);
                if (currentBombsCount == MultipleBombs.GetBombCount())
                {
                    break;
                }
                SelectObject(bombsDown);
            }
            catch (Exception ex)
            {
                DebugLog("Failed to Select the Bomb count buttons due to Exception: {0}, Stack Trace: {1}", ex.Message, ex.StackTrace);
            }
            break;

        case freeplaySelection.Modules:
            try
            {
                MonoBehaviour moduleUp   = (MonoBehaviour)_moduleCountIncrementField.GetValue(FreeplayDevice);
                MonoBehaviour moduleDown = (MonoBehaviour)_moduleCountDecrementField.GetValue(FreeplayDevice);
                SelectObject((MonoBehaviour)moduleUp.GetComponent(_selectableType));
                if (currentModuleCount == (int)_moduleCountField.GetValue(currentSettings))
                {
                    break;
                }
                SelectObject((MonoBehaviour)moduleDown.GetComponent(_selectableType));
            }
            catch (Exception ex)
            {
                DebugLog("Failed to Select the Module count buttons due to Exception: {0}, Stack Trace: {1}", ex.Message, ex.StackTrace);
            }
            break;

        case freeplaySelection.Needy:
            try
            {
                MonoBehaviour needyToggle = (MonoBehaviour)_needyToggleField.GetValue(FreeplayDevice);
                SelectObject((MonoBehaviour)needyToggle.GetComponent(_selectableType));
                SelectObject((MonoBehaviour)needyToggle.GetComponent(_selectableType));
            }
            catch (Exception ex)
            {
                DebugLog("Failed to Select the Needy toggle due to Exception: {0}, Stack Trace: {1}", ex.Message, ex.StackTrace);
            }
            break;

        case freeplaySelection.Hardcore:
            try
            {
                MonoBehaviour hardcoreToggle = (MonoBehaviour)_hardcoreToggleField.GetValue(FreeplayDevice);
                SelectObject((MonoBehaviour)hardcoreToggle.GetComponent(_selectableType));
                SelectObject((MonoBehaviour)hardcoreToggle.GetComponent(_selectableType));
            }
            catch (Exception ex)
            {
                DebugLog("Failed to Select the Hardcore toggle due to Exception: {0}, Stack Trace: {1}", ex.Message, ex.StackTrace);
            }
            break;

        case freeplaySelection.ModsOnly:
            try
            {
                MonoBehaviour modsToggle = (MonoBehaviour)_modsOnlyToggleField.GetValue(FreeplayDevice);
                SelectObject((MonoBehaviour)modsToggle.GetComponent(_selectableType));
                bool onlyModsCurrent = (bool)_onlyModsField.GetValue(currentSettings);
                SelectObject((MonoBehaviour)modsToggle.GetComponent(_selectableType));
                if (onlyMods == onlyModsCurrent)
                {
                    if (Input.GetKey(KeyCode.DownArrow))
                    {
                        _index = freeplaySelection.Timer;
                        goto case freeplaySelection.Timer;
                    }
                    else
                    {
                        _index = freeplaySelection.Hardcore;
                        goto case freeplaySelection.Hardcore;
                    }
                }
            }
            catch (Exception ex)
            {
                DebugLog("Failed to Select the Mods only toggle due to Exception: {0}, Stack Trace: {1}", ex.Message, ex.StackTrace);
            }
            break;
        }
    }
    public IEnumerator HandleInput()
    {
        Selectable = FreeplayDevice.GetComponent <Selectable>();

        if (!Input.GetKeyDown(KeyCode.LeftArrow) && !Input.GetKeyDown(KeyCode.RightArrow) &&
            !Input.GetKeyDown(KeyCode.UpArrow) && !Input.GetKeyDown(KeyCode.DownArrow) &&
            !Input.GetKeyDown(KeyCode.Return) && !Input.GetKeyDown(KeyCode.KeypadEnter))
        {
            yield break;
        }

        if (Input.GetKeyDown(KeyCode.KeypadEnter) || Input.GetKeyDown(KeyCode.Return))
        {
            StartBomb();
            yield break;
        }

        if (Input.GetKeyDown(KeyCode.UpArrow))
        {
            _index--;
            if (_index == FreeplaySelection.Bombs && !MultipleBombs.Installed())
            {
                _index = FreeplaySelection.Timer;
            }
            if (_index < FreeplaySelection.Timer)
            {
                _index = FreeplaySelection.ModsOnly;
            }
            ToggleIndex();
            yield break;
        }
        if (Input.GetKeyDown(KeyCode.DownArrow))
        {
            _index++;
            if (_index == FreeplaySelection.Bombs && !MultipleBombs.Installed())
            {
                _index = FreeplaySelection.Modules;
            }
            if (_index > FreeplaySelection.ModsOnly)
            {
                _index = FreeplaySelection.Timer;
            }
            ToggleIndex();
            yield break;
        }

        if (!Input.GetKeyDown(KeyCode.LeftArrow) && !Input.GetKeyDown(KeyCode.RightArrow))
        {
            yield break;
        }

        IEnumerator handler = null;

        switch (_index)
        {
        case FreeplaySelection.Timer:
            SelectObject(Input.GetKeyDown(KeyCode.LeftArrow) ? FreeplayDevice.TimeDecrement : FreeplayDevice.TimeIncrement);
            break;

        case FreeplaySelection.Bombs:
            SelectObject(Input.GetKeyDown(KeyCode.LeftArrow) ? _bombsDecrementButton : _bombsIncrementButton);
            break;

        case FreeplaySelection.Modules:
            SelectObject(Input.GetKeyDown(KeyCode.LeftArrow) ? FreeplayDevice.ModuleCountDecrement : FreeplayDevice.ModuleCountIncrement);
            break;

        case FreeplaySelection.Needy:
            handler = SetNeedy();
            break;

        case FreeplaySelection.Hardcore:
            handler = SetHardcore();
            break;

        case FreeplaySelection.ModsOnly:
            handler = SetModsOnly();
            break;

        default:
            throw new ArgumentOutOfRangeException();
        }
        if (handler == null)
        {
            yield break;
        }
        while (handler.MoveNext())
        {
            yield return(handler.Current);
        }
    }
Beispiel #19
0
    public IEnumerator HandleInput()
    {
        Selectable         = (MonoBehaviour)FreeplayDevice.GetComponent(_selectableType);
        SelectableChildren = (MonoBehaviour[])_childrenField.GetValue(Selectable);

        if (!Input.GetKeyDown(KeyCode.LeftArrow) && !Input.GetKeyDown(KeyCode.RightArrow) &&
            !Input.GetKeyDown(KeyCode.UpArrow) && !Input.GetKeyDown(KeyCode.DownArrow) &&
            !Input.GetKeyDown(KeyCode.Return) && !Input.GetKeyDown(KeyCode.KeypadEnter))
        {
            yield break;
        }
        int holdState = (int)_holdStateProperty.GetValue(FloatingHoldable, null);

        if (holdState != 0)
        {
            _index = 0;
            IEnumerator hold = HoldFreeplayDevice();
            while (hold.MoveNext())
            {
                yield return(hold.Current);
            }
            ToggleIndex();
            yield break;
        }
        if (Input.GetKeyDown(KeyCode.KeypadEnter) || Input.GetKeyDown(KeyCode.Return))
        {
            StartBomb();
            yield break;
        }
        if (Input.GetKeyDown(KeyCode.UpArrow))
        {
            _index--;
            if (_index == freeplaySelection.Bombs && !MultipleBombs.Installed())
            {
                _index = freeplaySelection.Timer;
            }
            if (_index < freeplaySelection.Timer)
            {
                _index = freeplaySelection.ModsOnly;
            }
            ToggleIndex();
            yield break;
        }
        if (Input.GetKeyDown(KeyCode.DownArrow))
        {
            _index++;
            if (_index == freeplaySelection.Bombs && !MultipleBombs.Installed())
            {
                _index = freeplaySelection.Modules;
            }
            if (_index > freeplaySelection.ModsOnly)
            {
                _index = freeplaySelection.Timer;
            }
            ToggleIndex();
            yield break;
        }
        if (Input.GetKeyDown(KeyCode.LeftArrow) || Input.GetKeyDown(KeyCode.RightArrow))
        {
            IEnumerator handler = null;
            switch (_index)
            {
            case freeplaySelection.Timer:
                handler = Input.GetKeyDown(KeyCode.LeftArrow) ? DecrementBombTimer() : IncrementBombTimer();
                break;

            case freeplaySelection.Bombs:
                handler = Input.GetKeyDown(KeyCode.LeftArrow) ? DecrementBombCount() : IncrementBombCount();
                break;

            case freeplaySelection.Modules:
                handler = Input.GetKeyDown(KeyCode.LeftArrow) ? DecrementModuleCount() : IncrementModuleCount();
                break;

            case freeplaySelection.Needy:
                handler = SetNeedy();
                break;

            case freeplaySelection.Hardcore:
                handler = SetHardcore();
                break;

            case freeplaySelection.ModsOnly:
                handler = SetModsOnly();
                break;
            }
            if (handler == null)
            {
                yield break;
            }
            while (handler.MoveNext())
            {
                yield return(handler.Current);
            }
        }
    }