private void PlayerJoinRoom(IHanabiPlayer player, RequestJoinRoom request) { RoomInfo roomInfo = new RoomInfo(); JoinRoomResult result = JoinRoomResult.Fail; if (player.RoomStatus == PlayerRoomStatus.Idle) { RoomIndexType roomIndex = new RoomIndexType(request.RoomIndex); if (Rooms.ContainsKey(roomIndex)) { Room room = Rooms[roomIndex]; if (room.Players.Count < room.Setting.MaxPlayers) { room.Players.Add(player); roomInfo = room.Info; player.OnJoinRoom(room); result = JoinRoomResult.Success; } } } ResponseJoinRoom response = new ResponseJoinRoom(); response.Result = result; response.Room = roomInfo; SendCommand(player, ActionType.JoinRoom, response); }
private void PlayerJoinRoom(Game game, IHanabiPlayer player, RoomIndexType roomIndex) { RequestJoinRoom request = new RequestJoinRoom(); request.RoomIndex = roomIndex.Index; Command command = new Command(); command.action = ActionType.JoinRoom.ToString(); command.payload = JsonConvert.SerializeObject(request); game.DispatchRequest(player, JsonConvert.SerializeObject(command)); }
public void DispatchRequest(IPlayer player, string message) { IHanabiPlayer hanabiPlayer = player as IHanabiPlayer; if (hanabiPlayer == null) { return; } Command command = JsonConvert.DeserializeObject <Command>(message); ActionType action = ( ActionType )Enum.Parse(typeof(ActionType), command.Action, false); switch (action) { case ActionType.EnterGame: { RequestEnterGame request = JsonConvert.DeserializeObject <RequestEnterGame>(command.Payload); PlayerEnterGame(hanabiPlayer, request); break; } case ActionType.ExitGame: { RequestExitGame request = JsonConvert.DeserializeObject <RequestExitGame>(command.Payload); PlayerExitGame(hanabiPlayer, request); break; } case ActionType.GetRoomList: { PlayerGetRoomList(hanabiPlayer); break; } case ActionType.JoinRoom: { RequestJoinRoom request = JsonConvert.DeserializeObject <RequestJoinRoom>(command.Payload); PlayerJoinRoom(hanabiPlayer, request); break; } case ActionType.QuitRoom: { RequestQuitRoom request = JsonConvert.DeserializeObject <RequestQuitRoom>(command.Payload); PlayerQuitRoom(hanabiPlayer, request); break; } case ActionType.Message: { // TODO: break; } case ActionType.Ready: { PlayerReady(hanabiPlayer); break; } case ActionType.PromptCard: { RequestPromptCard request = JsonConvert.DeserializeObject <RequestPromptCard>(command.Payload); PlayerPrompt(hanabiPlayer, request); break; } case ActionType.PlayCard: { RequestPlayCard request = JsonConvert.DeserializeObject <RequestPlayCard>(command.Payload); PlayerPlayCard(hanabiPlayer, request); break; } case ActionType.DiscardCard: { RequestDiscardCard request = JsonConvert.DeserializeObject <RequestDiscardCard>(command.Payload); PlayerDiscardCard(hanabiPlayer, request); break; } default: break; } }