/// <summary> /// ゲームを開始する。 /// </summary> private void RequestedStartGame(NetworkConnection connection, StartGame.Request request) { var msg = new StartGame.Response(); var id = connection.connectionId; RoomData roomData; try { // プレイヤーが存在しているかどうかチェック if (!playerDataHolder.ExistPlayerData(id)) { Debug.LogWarningFormat("[RequestedStartGame] 存在しないプレイヤーが指定されました\nid : {0}", id); msg.Result = StartGame.Result.FailureNonExistPlayer; connection.Send(msg); return; } // 部屋が存在しているかどうかチェック if (!roomDataHolder.ExistRoomByHostPlayer(id)) { Debug.LogWarningFormat("[RequestedStartGame] 指定したプレイヤーがホストである部屋が存在しません\nid : {0}", id); msg.Result = StartGame.Result.FailureNonHost; connection.Send(msg); return; } // ゲームを開始しているかどうかチェック roomData = roomDataHolder.GetRoomDataByHostPlayer(id); if (roomData.IsPlaying) { Debug.LogWarningFormat("[RequestedStartGame] 既にゲームを開始しています\nid : {0}", id); msg.Result = StartGame.Result.FailurePlaying; connection.Send(msg); return; } roomData.StartGame(); msg.Result = StartGame.Result.Succeed; connection.Send(msg); } catch (Exception e) { Debug.LogErrorFormat("[RequestedStartGame] 予期せぬエラーが発生しました\nid : {0}", id); Debug.LogException(e); msg.Result = StartGame.Result.FailureUnknown; msg.Exception = e; connection.Send(msg); return; } SendRoomStartGame(roomData); }
private void ResponseStartGame(NetworkConnection connection, StartGame.Response response) { OnStartGameResponseEvent?.Invoke(response); }