private void LaunchGameInstance() { roomState = GameRoomState.InSession; _gameInstance = new GameInstance(ComponentClients, ID); _gameInstance.OnGameCompleted += OnGameCompleted; }
public GameRoom(int maxConnections, string name) { _maxConnections = maxConnections; RoomName = name; _clientReadyStatus = new Dictionary <ServerConnection, bool>(); roomState = GameRoomState.Waiting; ID = Guid.NewGuid().ToString(); ComponentClients = new List <ServerConnection>(); ServerLeaderboard.OnClientLeaveGameRoom += ServerLeaderboard_OnClientLeaveGameRoom; ServerLeaderboard.OnStartRematch += ServerLeaderboard_OnStartRematch; }
private void OnGameCompleted(BasePacket packet) { _gameInstance.OnGameCompleted -= OnGameCompleted; roomState = GameRoomState.Leaderboards; OnRoomStateChanged(); for (int i = 0; i < ComponentClients.Count; i++) { ComponentClients[i].RemoveServerComponent(_gameInstance); } _gameLeaderboard = new ServerLeaderboard(ComponentClients, ID); }
private void OnRoomStateChangeHandler(GameRoomState state, bool isFirstState) { if (isFirstState) { // First setup of your client state if (!_initialStateReceived) { _initialStateReceived = true; onInitialState?.Invoke(state); } } else { // Further updates on your client state } }
public ConnectionStateMachine(MixedManager game) { _game = game; var startState = new GameStartState(this, _game); var connectingState = new GameConnectingState(this, _game); var connectedState = new GameConnectedState(this, _game); var disconnectedState = new GameDisconnectedState(this, _game); var roomState = new GameRoomState(this, _game); var stateList = new Dictionary <ConnectionFSMStateEnum.StateEnum, IFsmState> { { ConnectionFSMStateEnum.StateEnum.START, startState }, { ConnectionFSMStateEnum.StateEnum.CONNECTING, connectingState }, { ConnectionFSMStateEnum.StateEnum.CONNECTED, connectedState }, { ConnectionFSMStateEnum.StateEnum.DISCONNECTED, disconnectedState }, { ConnectionFSMStateEnum.StateEnum.ROOM, roomState }, }; SetStates(stateList); var allowedTransitions = new Dictionary <ConnectionFSMStateEnum.StateEnum, IList <ConnectionFSMStateEnum.StateEnum> >(); allowedTransitions.Add(ConnectionFSMStateEnum.StateEnum.START, new List <ConnectionFSMStateEnum.StateEnum> { ConnectionFSMStateEnum.StateEnum.CONNECTING, }); allowedTransitions.Add(ConnectionFSMStateEnum.StateEnum.CONNECTING, new List <ConnectionFSMStateEnum.StateEnum> { ConnectionFSMStateEnum.StateEnum.CONNECTED, }); allowedTransitions.Add(ConnectionFSMStateEnum.StateEnum.CONNECTED, new List <ConnectionFSMStateEnum.StateEnum> { ConnectionFSMStateEnum.StateEnum.ROOM, }); allowedTransitions.Add(ConnectionFSMStateEnum.StateEnum.DISCONNECTED, new List <ConnectionFSMStateEnum.StateEnum> { ConnectionFSMStateEnum.StateEnum.START, }); allowedTransitions.Add(ConnectionFSMStateEnum.StateEnum.ROOM, new List <ConnectionFSMStateEnum.StateEnum> { ConnectionFSMStateEnum.StateEnum.START, }); SetTransitions(allowedTransitions); }
public void CreateGameRoom(IApiClient client, SetupController setupController) { GameRoomState = new GameRoomState(); client.GameRoomCreated(); }
public void CreateGameRoom(IApiClient client, SetupController setupController) { GameRoomState = new GameRoomState(); client.GameRoomCreated(); }
public ConnectionStateMachine(ClientManager game) { _game = game; var startState = new GameStartState(this, _game); var playFabLoginState = new GamePlayFabLoginState(this, _game); var playFabRegisterState = new GamePlayFabRegisterState(this, _game); var connectingState = new GameConnectingState(this, _game); var connectedState = new GameConnectedState(this, _game); var disconnectedState = new GameDisconnectedState(this, _game); var resultState = new GameResultState(this, _game); var lobbyState = new GameLobbyState(this, _game); var roomState = new GameRoomState(this, _game); var connectingRoomState = new GameConnectingRoomState(this, _game); var connectedRoomState = new GameConnectedRoomState(this, _game); var stateList = new Dictionary <ConnectionFSMStateEnum.StateEnum, IFsmState> { { ConnectionFSMStateEnum.StateEnum.START, startState }, { ConnectionFSMStateEnum.StateEnum.PLAYFAB_LOGIN, playFabLoginState }, { ConnectionFSMStateEnum.StateEnum.PLAYFAB_REGISTER, playFabRegisterState }, { ConnectionFSMStateEnum.StateEnum.CONNECTING, connectingState }, { ConnectionFSMStateEnum.StateEnum.CONNECTED, connectedState }, { ConnectionFSMStateEnum.StateEnum.DISCONNECTED, disconnectedState }, { ConnectionFSMStateEnum.StateEnum.RESULT, resultState }, { ConnectionFSMStateEnum.StateEnum.LOBBY, lobbyState }, { ConnectionFSMStateEnum.StateEnum.ROOM, roomState }, { ConnectionFSMStateEnum.StateEnum.CONNECTING_ROOM, connectingRoomState }, { ConnectionFSMStateEnum.StateEnum.CONNECTED_ROOM, connectedRoomState }, }; SetStates(stateList); var allowedTransitions = new Dictionary <ConnectionFSMStateEnum.StateEnum, IList <ConnectionFSMStateEnum.StateEnum> >(); allowedTransitions.Add(ConnectionFSMStateEnum.StateEnum.START, new List <ConnectionFSMStateEnum.StateEnum> { ConnectionFSMStateEnum.StateEnum.PLAYFAB_LOGIN, ConnectionFSMStateEnum.StateEnum.PLAYFAB_REGISTER, }); allowedTransitions.Add(ConnectionFSMStateEnum.StateEnum.PLAYFAB_LOGIN, new List <ConnectionFSMStateEnum.StateEnum> { ConnectionFSMStateEnum.StateEnum.START, ConnectionFSMStateEnum.StateEnum.CONNECTING, }); allowedTransitions.Add(ConnectionFSMStateEnum.StateEnum.PLAYFAB_REGISTER, new List <ConnectionFSMStateEnum.StateEnum> { ConnectionFSMStateEnum.StateEnum.START, ConnectionFSMStateEnum.StateEnum.CONNECTING, }); allowedTransitions.Add(ConnectionFSMStateEnum.StateEnum.CONNECTING, new List <ConnectionFSMStateEnum.StateEnum> { ConnectionFSMStateEnum.StateEnum.CONNECTED, ConnectionFSMStateEnum.StateEnum.DISCONNECTED, }); allowedTransitions.Add(ConnectionFSMStateEnum.StateEnum.CONNECTED, new List <ConnectionFSMStateEnum.StateEnum> { ConnectionFSMStateEnum.StateEnum.LOBBY, }); allowedTransitions.Add(ConnectionFSMStateEnum.StateEnum.DISCONNECTED, new List <ConnectionFSMStateEnum.StateEnum> { ConnectionFSMStateEnum.StateEnum.START, }); allowedTransitions.Add(ConnectionFSMStateEnum.StateEnum.RESULT, new List <ConnectionFSMStateEnum.StateEnum> { ConnectionFSMStateEnum.StateEnum.LOBBY, }); allowedTransitions.Add(ConnectionFSMStateEnum.StateEnum.LOBBY, new List <ConnectionFSMStateEnum.StateEnum> { ConnectionFSMStateEnum.StateEnum.START, ConnectionFSMStateEnum.StateEnum.CONNECTING_ROOM, ConnectionFSMStateEnum.StateEnum.DISCONNECTED, }); allowedTransitions.Add(ConnectionFSMStateEnum.StateEnum.CONNECTING_ROOM, new List <ConnectionFSMStateEnum.StateEnum> { ConnectionFSMStateEnum.StateEnum.LOBBY, ConnectionFSMStateEnum.StateEnum.CONNECTED_ROOM, }); allowedTransitions.Add(ConnectionFSMStateEnum.StateEnum.CONNECTED_ROOM, new List <ConnectionFSMStateEnum.StateEnum> { ConnectionFSMStateEnum.StateEnum.ROOM, }); allowedTransitions.Add(ConnectionFSMStateEnum.StateEnum.ROOM, new List <ConnectionFSMStateEnum.StateEnum> { ConnectionFSMStateEnum.StateEnum.LOBBY, ConnectionFSMStateEnum.StateEnum.RESULT, ConnectionFSMStateEnum.StateEnum.DISCONNECTED, }); SetTransitions(allowedTransitions); }
public RoomInformation MakeRoomInformationPacket(string roomName, string roomID, List <ServerConnection> connections, int readyCount, GameRoomState roomState) { RoomInformation packet = new RoomInformation { SendDate = DateTime.UtcNow, RoomName = roomName, RoomID = roomID, ReadyCount = readyCount, ConnectionCount = connections.Count, RoomState = (int)roomState }; packet.ConnectionIDs = new string[packet.ConnectionCount]; packet.ConnectionNames = new string[packet.ConnectionCount]; for (int i = 0; i < packet.ConnectionCount; i++) { packet.ConnectionIDs[i] = connections[i].ID; packet.ConnectionNames[i] = connections[i].Name; } return(packet); }