//摸牌 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 QiangGang(SocketModel socketModel) { //收到这个数据说明,能抢杠胡 List <int> list = socketModel.GetData(); RoomEvent.DoActionList(list); }
//重连 private void reJoinRoom() { List <int> infoList = GameInfo.Instance.skm.GetData(); GameInfo.Instance.roomId = infoList[0]; GameInfo.Instance.roomPassWord = infoList[1]; GameInfo.Instance.hostId = infoList[2]; GameInfo.Instance.positon = infoList[3]; GameInfo.Instance.maxRound = infoList[4]; GameInfo.Instance.maxPoint = infoList[5]; GameInfo.Instance.isZjDouble = infoList[6]; GameInfo.Instance.canQiangGang = infoList[7]; GameInfo.Instance.isDaiGen = infoList[8]; GameInfo.Instance.isZiMoHu = infoList[9]; GameInfo.Instance.round = infoList[10]; GameInfo.Instance.zhuangjia = infoList[11]; GameInfo.Instance.mjLeft = infoList[12]; GameInfo.Instance.actionFlag = infoList[13]; int moMj = infoList[14]; //自己摸的牌,0就是没摸 int chuPaiPos = infoList[15]; //出牌的位置 int chuPaiMj = infoList[16]; //出的什么牌 int stat = infoList[17]; //有没人操作 int roomStat = infoList[18]; //游戏的当前阶段 1.准备。2,游戏中 if (roomStat == 2) { if (stat > 0) { GameEvent.DoChuPai(chuPaiPos, chuPaiMj, true); } //GameInfo.Instance List <PlayerData> playerDataList = GameInfo.Instance.skm.GetPdata(); for (int i = 0; i < playerDataList.Count; i++) { PlayerData pd = playerDataList[i]; if (pd.getUserId() == GameInfo.Instance.positon)//自己的数据 { GameInfo.Instance.myGold = pd.getWinGold(); GameInfo.Instance.myHandMj = pd.gethandlist(); GameInfo.Instance.myHandMj.Reverse(); if (pd.getactionlist() != null) { GameInfo.Instance.myAcionList = pd.getactionlist(); } mjView.GetComponent <CardView>().ReJoinSetHandlist("bot", moMj, stat); //还原手牌 mjView.GetComponent <CardView>().ReJoinSetCpglist("bot", pd.getactionlist()); //还原碰,杠 mjView.GetComponent <CardView>().reJoinSetOutlist("bot", pd.getoutlist()); //还原出牌 if (pd.GetPghList() != null && pd.GetPghList().Count > 0) { RoomEvent.DoActionList(pd.GetPghList()); } else { Debug.Log("为什么我不能杠?="); } if (pd.GetGangList() != null && pd.GetGangList().Count > 0) { GameInfo.Instance.gangList = pd.GetGangList();//杠的数据保存在INFO, 选择牌型后清空 } } else { GameInfo.Instance.addNewPlayer(pd.getUserId(), pd.getPlayerName(), pd.getPlayerIcon().ToString(), pd.getWinGold(), pd.getactionlist()); string pos = GameInfo.Instance.TryGetLocPos(GameInfo.Instance.positon, pd.getUserId()); mjView.GetComponent <CardView>().ReJoinSetHandlist(pos, pd.getHupai()); //还原手牌 mjView.GetComponent <CardView>().ReJoinSetCpglist(pos, pd.getactionlist()); //还原碰,杠 mjView.GetComponent <CardView>().reJoinSetOutlist(pos, pd.getoutlist()); //还原出牌 } } // setReadyView(false); backView.GetComponent <BackView>().resetView(); startView.GetComponent <RoomView>().initPlayerInfo(); startView.GetComponent <RoomView>().setCurrentPos(GameInfo.Instance.actionFlag); startView.GetComponent <RoomView>().updateMjNum(GameInfo.Instance.mjLeft); actionView.GetComponent <RoomAction>().reset(); } else//游戏阶段在准备 { GameInfo.Instance.isGameStart = 1; reset(); } }
//出牌 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("有人操作,吃,碰等操作,要等待"); } } }