private InitializingState CreateInitializingState(ITAlertPhotonClient photonClient)
        {
            var input = new InitializingStateInput();
            var state = new InitializingState(_director, input, photonClient);

            var onPlayingStateSyncTransition = new OnMessageTransition(photonClient, ITAlertChannel.GameState, typeof(PlayingMessage), PlayingState.StateName);

            state.AddTransitions(onPlayingStateSyncTransition);

            return(state);
        }
Beispiel #2
0
        private ITAlertRoomStateController CreateStateController()
        {
            // TODO: handle the lifecyclemanager changestate event in the case of error -> kick players back to lobby.
            var lifecycleStoppedErrorTransition = new LifecycleStoppedTransition(ErrorState.StateName,
                                                                                 ExitCode.Error, ExitCode.Undefined, ExitCode.Abort);

            var lifecycleManager = InitializeSimulationRoot();

            lifecycleManager.Exception += _exceptionHandler.OnException;
            lifecycleManager.Stopped   += lifecycleStoppedErrorTransition.OnLifecycleStopped;

            var initializingState     = new InitializingState(lifecycleManager, PhotonPlugin, Messenger, PlayerManager, RoomSettings, Analytics);
            var initializedTransition = new CombinedPlayersStateTransition(ClientState.Initialized, PlayingState.StateName);

            initializingState.PlayersInitialized += initializedTransition.OnPlayersStateChange;
            initializingState.AddTransitions(initializedTransition, lifecycleStoppedErrorTransition);

            var playingState = new PlayingState(lifecycleManager, PhotonPlugin, Messenger, PlayerManager, RoomSettings, Analytics);
            var lifecycleCompleteTransition = new LifecycleStoppedTransition(FeedbackState.StateName, ExitCode.Complete);

            lifecycleManager.Stopped += lifecycleCompleteTransition.OnLifecycleStopped;
            playingState.AddTransitions(lifecycleCompleteTransition, lifecycleStoppedErrorTransition);

            var feedbackState           = new FeedbackState(lifecycleManager, PhotonPlugin, Messenger, PlayerManager, RoomSettings, Analytics);
            var feedbackStateTransition = new CombinedPlayersStateTransition(ClientState.FeedbackSent, ExitState.StateName);

            feedbackState.PlayerFeedbackSentEvent += feedbackStateTransition.OnPlayersStateChange;
            feedbackState.AddTransitions(feedbackStateTransition);

            var exitState = new ExitState(lifecycleManager, PhotonPlugin, Messenger, PlayerManager, RoomSettings, Analytics);

            var controller = new ITAlertRoomStateController(initializingState, playingState, feedbackState, exitState);

            controller.SetParent(ParentStateController);

            return(controller);
        }