//分享钻石 public void FenXiangRqs(SocketModel socketModel) { if (socketModel.GetCommand() == 18) { List <int> list = socketModel.GetData(); int fk = list[0]; GameInfo.Instance.setUserFk(fk); GameEvent.DoMsgTipEvent("分享钻石成功!"); List <string> mList = socketModel.GetMessage(); MailData md = new MailData(); md.setDataTime(mList[0]); md.setFk(int.Parse(mList[1])); md.setGid(int.Parse(mList[2])); md.setStype(int.Parse(mList[3])); GameInfo.Instance.mailList.Insert(0, md); } else if (socketModel.GetCommand() == 17) { GameEvent.DoMsgTipEvent("用户不存在!"); } else { GameEvent.DoMsgTipEvent("未知错误!"); } }
//开局 public void RoomGameStart(SocketModel socketModel) { // GameInfo.Instance.isGameStart = 1; int value = socketModel.GetCommand(); if (value > 0) { //手牌 List <int> list = socketModel.GetData(); list.Reverse(); GameInfo.Instance.myHandMj = list; //房间信息 List <string> msg = socketModel.GetMessage(); GameInfo.Instance.zhuangjia = int.Parse(msg[0]); GameInfo.Instance.round = int.Parse(msg[1]); GameInfo.Instance.mjLeft = int.Parse(msg[2]); //开始后,设置所有人状态为未准备 GameInfo.Instance.isMyReady = 0; GameInfo.Instance.isRightReady = 0; GameInfo.Instance.isTopReady = 0; GameInfo.Instance.isLeftReady = 0; //通知UI游戏开始了 GameEvent.DoGameStartEvent(1); Debug.Log("人满开局发牌 " + list); } int mjNum = socketModel.GetCommand(); RoomEvent.DoActionLeftMj(mjNum); }
//返回开房结果 public void CreatRoomRqs(SocketModel socketModel) { if (socketModel.GetCommand() == 11) { List <int> list = socketModel.GetData(); GameInfo.Instance.roomId = list[0]; GameInfo.Instance.positon = list[1]; GameInfo.Instance.myGold = list[2]; GameInfo.Instance.maxRound = list[3]; GameInfo.Instance.maxPoint = list[4]; GameInfo.Instance.isZjDouble = list[5]; GameInfo.Instance.canQiangGang = list[6]; GameInfo.Instance.isDaiGen = list[7]; GameInfo.Instance.isZiMoHu = list[8]; GameInfo.Instance.roomPassWord = list[9]; int fk = list[10]; //更新钻石 int fk2 = GameInfo.Instance.UserFK - fk; GameInfo.Instance.setUserFk(fk2); GameEvent.DoSenceEvent("game"); Debug.Log("开房成功,房间ID=" + GameInfo.Instance.roomId); Debug.Log("开房成功,我的位置=" + GameInfo.Instance.positon); Debug.Log("开房成功,我的金币=" + GameInfo.Instance.myGold); Debug.Log("开房成功,最大圈数=" + GameInfo.Instance.maxRound); Debug.Log("开房成功,最大番数=" + GameInfo.Instance.maxPoint); } else { Debug.Log("开房失败 socketModel.GetComman=" + socketModel.GetCommand()); GameEvent.DoMsgEvent("开房失败!"); } }
//摸牌 public void MoPai(SocketModel socketModel) { //GameEvent.DoMsgTipEvent(" 收到摸牌数据"); List <string> msgList = socketModel.GetMessage(); //如果是自己摸牌 Debug.Log("摸牌的位置=" + int.Parse(msgList[0])); if (int.Parse(msgList[0]) == GameInfo.Instance.positon) { Debug.Log("是自己摸牌 摸的牌= " + int.Parse(msgList[1])); //GameEvent.DoMsgTipEvent("是自己摸牌 摸的牌= " + int.Parse(msgList[1])); //摸起的牌放到手牌队列里 int mj = int.Parse(msgList[1]); GameInfo.Instance.putMjtoHandList(mj); //广播给UI显示 GameEvent.DoMoPai(mj); Debug.Log("摸牌==" + mj); //是否能,杠,糊 List <int> list = socketModel.GetData(); RoomEvent.DoActionList(list); //如果Action有数据,可以杠 if (socketModel.GetAdata() != null && socketModel.GetAdata().Count > 0) { Debug.Log("可以杠牌=" + socketModel.GetAdata().Count); GameInfo.Instance.gangList = socketModel.GetAdata();//杠的数据保存在INFO, 选择牌型后清空 } } //不管是谁摸,更新牌的数量 Debug.Log("剩余牌的数量=" + socketModel.GetCommand()); int mjNum = socketModel.GetCommand(); RoomEvent.DoActionLeftMj(mjNum); }
//加入开房结果 public void JoinRoomRqs(SocketModel socketModel) { Debug.Log("收到加入房间返回结果" + socketModel.GetCommand()); if (socketModel.GetCommand() == Helper_ErrCode.ErrCommand_Hall_JoinSucceed_加入房间成功) { GameInfo.Instance.roomId = socketModel.GetData()[0]; GameInfo.Instance.positon = socketModel.GetData()[1]; GameInfo.Instance.myGold = socketModel.GetData()[2]; GameInfo.Instance.maxRound = socketModel.GetData()[3]; GameInfo.Instance.maxPoint = socketModel.GetData()[4]; GameInfo.Instance.isZjDouble = socketModel.GetData()[5]; GameInfo.Instance.canQiangGang = socketModel.GetData()[6]; GameInfo.Instance.isDaiGen = socketModel.GetData()[7]; GameInfo.Instance.isZiMoHu = socketModel.GetData()[8]; GameInfo.Instance.roomPassWord = socketModel.GetData()[9]; List <String> list = socketModel.GetMessage(); for (int i = 0; i < list.Count; i++) { if ((i + 1) % 4 == 0) { GameInfo.Instance.addNewPlayer(int.Parse(list[i - 3]), list[i - 2], list[i - 1], int.Parse(list[i])); Debug.Log("有玩家=" + i); } } Debug.Log("加入房间成功"); GameEvent.DoSenceEvent("game"); } else { switch (socketModel.GetCommand()) { case Helper_ErrCode.ErrCommand_Hall_WrongPW_密码不正确: GameEvent.DoMsgEvent("密码不正确!"); break; case Helper_ErrCode.ErrCommand_Hall_RooMInvalid_房间不存在: GameEvent.DoMsgEvent("房间不存在!"); break; case Helper_ErrCode.ErrCommand_Hall_RoomFull_房间人满: GameEvent.DoMsgEvent("房间人满!"); break; case Helper_ErrCode.ErrCommand_Hall_UserExit_玩家已在房间: GameEvent.DoMsgEvent("玩家已存在!"); break; } } }
//返回登录结果 public void loginRqs(SocketModel socketModel) { GameEvent.DoNetSocket(2); if (socketModel.GetCommand() == 10) { List <String> list = socketModel.GetMessage(); GameInfo.Instance.ToKen = list[0]; GameInfo.Instance.UserID = int.Parse(list[1]); GameInfo.Instance.UserName = list[2]; GameInfo.Instance.UserIcon = int.Parse(list[3]); GameInfo.Instance.UserFK = int.Parse(list[4]); GameInfo.Instance.roomId = int.Parse(list[5]);//根据ROOMID判断,是否在房间中,如果roomID不为0,说明上次下线是在房间,请求加入房间 //邮件 //GameInfo.Instance.mailList = socketModel.GetMailList(); //战绩 //GameInfo.Instance.battleList = socketModel.GetBattleList(); if (GameInfo.Instance.UserIcon > 4) { GameInfo.Instance.sex = "boy"; } else { GameInfo.Instance.sex = "girl"; } Debug.Log("登录成功," + "用户房卡=" + GameInfo.Instance.UserFK); //重连 if (GameInfo.Instance.roomId > 0) { GameEvent.DoNetSocket(1); SocketModel HeartBeatRequset = new SocketModel(); HeartBeatRequset.SetMainCmd(ProtocolMC.Main_Cmd_ROOM); HeartBeatRequset.SetSubCmd(ProtocolSC.Sub_Cmd_GAME_REJOINROOM_房间重连); HeartBeatRequset.SetCommand(GameInfo.Instance.roomId); NettySocket.Instance.SendMsg(HeartBeatRequset); } else { LoginView.str = "hall"; } } else if (socketModel.GetCommand() == 30) { GameEvent.DoMsgEvent("数据异常,登录失败!"); } else { Debug.Log("登录失败!"); } }
void Update() { //处理事务 while (MainClient.Instance.messages.Count > 0) { SocketModel model = MainClient.Instance.messages.Dequeue(); BaseHandler handler; MainClient.Instance.handlers.TryGetValue(model.GetType(), out handler); handler.Dispatch(model.GetCommand(), model.GetMessage()); int type = model.GetType(); int area = model.GetArea(); int command = model.GetCommand(); string str = "num : " + ++num + " -> " + type + " " + area + " " + command + " "; foreach (string strr in model.GetMessage()) { str += strr + " "; } Debug.Log(str); } }
//重连房间 public void ReJoinRoomRqs(SocketModel socketModel) { GameEvent.DoNetSocket(2); if (socketModel.GetCommand() == 25) { LoginView.str = "hall"; Debug.Log("房间已解散"); } else { GameInfo.Instance.skm = socketModel; LoginView.str = "game"; } }
//PaSS牌 public void GuoPai(SocketModel socketModel) { int value = socketModel.GetCommand(); // Debug.Log("都PASS了 通知清理MJ 添加MJ到出牌区"); RoomEvent.DoPlayerDiction(value, 1); // if (value == GameInfo.Instance.positon) { Debug.Log("本轮操作权是自己,告诉服务器摸牌"); //告诉服务器摸牌 RoomEvent.DoActionMoPai(); } }
//出牌 public void ChuPai(SocketModel socketModel) { //1.先把出的牌显示出来 List <string> list = socketModel.GetMessage(); //2.其他玩家有没有操作 int stats = socketModel.GetCommand(); if (stats == 0) { GameEvent.DoChuPai(int.Parse(list[0]), int.Parse(list[1]), false); } else { GameEvent.DoChuPai(int.Parse(list[0]), int.Parse(list[1]), true); } Debug.Log("位置=" + list[0] + "出牌 = " + list[1]); //3如果没人操作,设置指示方向 if (stats == 0) { Debug.Log("设置指示方向"); RoomEvent.DoPlayerDiction(int.Parse(list[2])); } //如果是玩家自己出的牌就不继续判断读取数据了 if (int.Parse(list[0]) == GameInfo.Instance.positon) { Debug.Log("如果是玩家自己出的牌就不继续判断读取数据了"); return; } //4.看看自己是否可以可以吃,碰 等操作; List <int> mylist = socketModel.GetData(); Debug.Log("mylist=" + mylist); if (mylist != null) { //如果有操作,通知UI显示相关按键 Debug.Log("自己有操作=" + mylist[0]); //如果Action有数据,可以杠 List <Action> actionlist = socketModel.GetAdata(); if (actionlist != null) { Debug.Log("可以杠牌=" + actionlist.Count); GameInfo.Instance.gangList = actionlist;//杠的数据保存在INFO, 选择牌型后清空 } RoomEvent.DoActionList(mylist); } else { //3.如果自己没有操作,再看其他玩家可以,吃,碰等操作.如果有,就等待. if (stats == 0) { Debug.Log("没有人可以吃,碰操作"); //4.如果其他玩家也没操作,那看看本轮出牌权是否是自己,如果是自己那就向服务器摸牌 if (int.Parse(list[2]) == GameInfo.Instance.positon) { RoomEvent.DoActionMoPai(); } } else { Debug.Log("有人操作,吃,碰等操作,要等待"); } } }
//断线了 public void PlayerOffLine(SocketModel socketModel) { int pos = socketModel.GetCommand(); RoomEvent.DoPlayerOffLine(pos); }
//玩家准备了 public void PlayerReady(SocketModel socketModel) { int pos = socketModel.GetCommand(); GameInfo.Instance.PlayerGetReady(pos); }
//投票解散结果 public void VoteDismiss(SocketModel socketModel) { int comd = socketModel.GetCommand(); RoomEvent.DoVoteDisResults(comd); }