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 #2
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 #3
0
    private void Start()
    {
        _gameInfo = GetComponent <KMGameInfo>();
        _gameInfo.OnStateChange += OnStateChange;

        _modSettings = GetComponent <KMModSettings>();

        ModSettingsJSON settings = JsonConvert.DeserializeObject <ModSettingsJSON>(_modSettings.Settings);

        if (settings == null)
        {
            DebugHelper.LogError("Failed to read connection settings from mod settings.");
            return;
        }

        DebugMode = (settings.debug == true);

        _ircConnection = new IRCConnection(settings.authToken, settings.userName, settings.channelName, settings.serverName, settings.serverPort);
        _ircConnection.Connect();

        _coroutineCanceller = new CoroutineCanceller();

        _coroutineQueue = GetComponent <CoroutineQueue>();
        _coroutineQueue.coroutineCanceller = _coroutineCanceller;

        logUploader = GetComponent <LogUploader>();
        logUploader.ircConnection = _ircConnection;

        urlHelper = GetComponent <UrlHelper>();
        urlHelper.ChangeMode(settings.shortUrls == true);

        _leaderboard = new Leaderboard();
        _leaderboard.LoadDataFromFile();

        ModuleData.LoadDataFromFile();
        ModuleData.WriteDataToFile();

        TwitchPlaySettings.LoadDataFromFile();

        UserAccess.AddUser(settings.userName, AccessLevel.Streamer | AccessLevel.SuperUser | AccessLevel.Admin | AccessLevel.Mod);
        UserAccess.AddUser(settings.channelName.Replace("#", ""), AccessLevel.Streamer | AccessLevel.SuperUser | AccessLevel.Admin | AccessLevel.Mod);
        UserAccess.WriteAccessList();

        SetupResponder(bombMessageResponder);
        SetupResponder(postGameMessageResponder);
        SetupResponder(missionMessageResponder);
        SetupResponder(miscellaneousMessageResponder);

        bombMessageResponder.leaderboard          = _leaderboard;
        postGameMessageResponder.leaderboard      = _leaderboard;
        miscellaneousMessageResponder.leaderboard = _leaderboard;

        bombMessageResponder.parentService = this;
    }
Beispiel #4
0
    private void Start()
    {
        Instance = this;

        transform.Find("Prefabs").gameObject.SetActive(false);
        twitchGame = GetComponentInChildren <TwitchGame>(true);

        twitchGame.twitchBombPrefab    = GetComponentInChildren <TwitchBomb>(true);
        twitchGame.twitchModulePrefab  = GetComponentInChildren <TwitchModule>(true);
        twitchGame.moduleCamerasPrefab = GetComponentInChildren <ModuleCameras>(true);

        TwitchGame.Instance = twitchGame;

        GameRoom.InitializeSecondaryCamera();
        _gameInfo = GetComponent <KMGameInfo>();
        _gameInfo.OnStateChange += OnStateChange;

        CoroutineQueue = GetComponent <CoroutineQueue>();

        Leaderboard.Instance.LoadDataFromFile();
        LeaderboardController.Install();

        ModuleData.LoadDataFromFile();
        ModuleData.WriteDataToFile();

        AuditLog.SetupLog();
        MainThreadQueue.Initialize();

        TwitchPlaySettings.LoadDataFromFile();

        MusicPlayer.LoadMusic();

        IRCConnection.Instance.OnMessageReceived.AddListener(OnMessageReceived);

        twitchGame.ParentService = this;

        GameObject infoObject = new GameObject("TwitchPlays_Info");

        infoObject.transform.parent          = gameObject.transform;
        _publicProperties                    = infoObject.AddComponent <TwitchPlaysProperties>();
        _publicProperties.TwitchPlaysService = this;         // TODO: Useless variable?
        if (TwitchPlaySettings.data.SkipModManagerInstructionScreen || IRCConnection.Instance.State == IRCConnectionState.Connected)
        {
            ModManagerManualInstructionScreen.HasShownOnce = true;
        }

        UpdateUiHue();
        SetupChatSimulator();
    }
Beispiel #5
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;
        }
    }
    private void Start()
    {
        transform.Find("Prefabs").gameObject.SetActive(false);
        bombMessageResponder          = GetComponentInChildren <BombMessageResponder>(true);
        postGameMessageResponder      = GetComponentInChildren <PostGameMessageResponder>(true);
        missionMessageResponder       = GetComponentInChildren <MissionMessageResponder>(true);
        miscellaneousMessageResponder = GetComponentInChildren <MiscellaneousMessageResponder>(true);

        bombMessageResponder.twitchBombHandlePrefab      = GetComponentInChildren <TwitchBombHandle>(true);
        bombMessageResponder.twitchComponentHandlePrefab = GetComponentInChildren <TwitchComponentHandle>(true);
        bombMessageResponder.moduleCamerasPrefab         = GetComponentInChildren <ModuleCameras>(true);

        BombMessageResponder.Instance = bombMessageResponder;

        GameRoom.InitializeSecondaryCamera();
        _gameInfo = GetComponent <KMGameInfo>();
        _gameInfo.OnStateChange += OnStateChange;

        _coroutineQueue = GetComponent <CoroutineQueue>();

        Leaderboard.Instance.LoadDataFromFile();

        ModuleData.LoadDataFromFile();
        ModuleData.WriteDataToFile();

        TwitchPlaySettings.LoadDataFromFile();

        SetupResponder(bombMessageResponder);
        SetupResponder(postGameMessageResponder);
        SetupResponder(missionMessageResponder);
        SetupResponder(miscellaneousMessageResponder);

        bombMessageResponder.parentService = this;

        GameObject infoObject = new GameObject("TwitchPlays_Info");

        infoObject.transform.parent          = gameObject.transform;
        _publicProperties                    = infoObject.AddComponent <TwitchPlaysProperties>();
        _publicProperties.TwitchPlaysService = this;
        if (TwitchPlaySettings.data.SkipModManagerInstructionScreen || IRCConnection.Instance.State == IRCConnectionState.Connected)
        {
            ModManagerManualInstructionScreen.HasShownOnce = true;
        }
    }
Beispiel #7
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);
        }
    }
    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;
        }
    }
    private void Start()
    {
        Instance = this;

        transform.Find("Prefabs").gameObject.SetActive(false);
        twitchGame = GetComponentInChildren <TwitchGame>(true);

        twitchGame.twitchBombPrefab    = GetComponentInChildren <TwitchBomb>(true);
        twitchGame.twitchModulePrefab  = GetComponentInChildren <TwitchModule>(true);
        twitchGame.moduleCamerasPrefab = GetComponentInChildren <ModuleCameras>(true);

        TwitchGame.Instance = twitchGame;

        GameRoom.InitializeSecondaryCamera();
        _gameInfo = GetComponent <KMGameInfo>();
        _gameInfo.OnStateChange += OnStateChange;

        CoroutineQueue = GetComponent <CoroutineQueue>();

        Leaderboard.Instance.LoadDataFromFile();
        LeaderboardController.Install();

        ModuleData.LoadDataFromFile();
        ModuleData.WriteDataToFile();

        AuditLog.SetupLog();
        MainThreadQueue.Initialize();

        TwitchPlaySettings.LoadDataFromFile();

        MusicPlayer.LoadMusic();

        IRCConnection.Instance.OnMessageReceived.AddListener(OnMessageReceived);

        twitchGame.ParentService = this;

        TwitchPlaysAPI.Setup();

        GameObject infoObject = new GameObject("TwitchPlays_Info");

        infoObject.transform.parent          = gameObject.transform;
        _publicProperties                    = infoObject.AddComponent <TwitchPlaysProperties>();
        _publicProperties.TwitchPlaysService = this;         // TODO: Useless variable?
        if (TwitchPlaySettings.data.SkipModManagerInstructionScreen || IRCConnection.Instance.State == IRCConnectionState.Connected)
        {
            ModManagerManualInstructionScreen.HasShownOnce = true;
        }

        UpdateUiHue();

        if (TwitchPlaySettings.data.DarkMode)
        {
            HeaderBackground.color   = new Color32(0x0E, 0x0E, 0x10, 0xFF);
            HeaderText.color         = new Color32(0xEF, 0xEF, 0xEC, 0xFF);
            MessagesBackground.color = new Color32(0x3A, 0x3A, 0x3D, 0xFF);
        }
        else
        {
            HeaderBackground.color   = new Color32(0xEE, 0xEE, 0xEE, 0xFF);
            HeaderText.color         = new Color32(0x4F, 0x4F, 0x4F, 0xFF);
            MessagesBackground.color = new Color32(0xD8, 0xD8, 0xD8, 0xFF);
        }

        SetupChatSimulator();

        // Delete the steam_appid.txt since it was created for a one-time steam boot.
        // Steam will have initialized before this.
        if (File.Exists("steam_appid.txt"))
        {
            File.Delete("steam_appid.txt");
        }
    }