public void ExecuteCommand(GameSession session, ProtobufRequestInfo requestInfo) { if (!Gongyong.userlist.Any(w => w.session.SessionID.Equals(session.SessionID))) { session.Logger.Debug("AddRoom : 非法连接"); session.Close(); return; } ///定义返回状态码 string staut = "10000"; var nowsend = ReturnAddRoom.CreateBuilder(); List <Userinfo> listuser = new List <Userinfo>(); ///当前返回信息 var getdata = SendAddRoom.ParseFrom(requestInfo.Body); ///根据上传信息查找房间 Room rm = Gongyong.roomlist.Find(u => u.RoomID == getdata.RoomID); var roommsg = ReturnRoomMsg.CreateBuilder(); //储存IP List <UserInfo> ListUserIP = new List <UserInfo>(); if (rm != null) { List <mjuser> mulist = Gongyong.mulist.FindAll(u => u.RoomID == getdata.RoomID); mjuser mjuser = Gongyong.mulist.Find(u => u.RoomID == getdata.RoomID && u.Openid == getdata.Openid); if (mulist.Count == rm.room_peo) { staut = "10002"; } else { List <int> shuzhu = new List <int>() { 1, 2, 3, 4 }; ///移除以坐的方位,并添加以有玩家信息 var senddata = ReturnUserInfo.CreateBuilder(); //for(int i=0;i< mulist.Count();i++) foreach (mjuser item in mulist) { UserInfo gamer = Gongyong.userlist.Find(u => u.openid == item.Openid); Userinfo users = Userinfo.CreateBuilder().SetHeadimg(gamer.headimg).SetNickname(gamer.nickname).SetOpenid(gamer.openid).SetSex(int.Parse(gamer.sex)).SetUserFW(item.ZS_Fw).SetUserBean(0).SetUserGold(0).SetUserID(gamer.UserID).SetUserIP(gamer.UserIP).Build(); listuser.Add(users); shuzhu.Remove(item.ZS_Fw); senddata.AddUserinfo(users); nowsend.AddUserinfo(users); } if (mjuser != null) { return; } else { ///添加新加入玩家信息 mjuser mj = new mjuser() { Openid = getdata.Openid, ZS_Fw = shuzhu[0], RoomID = getdata.RoomID, ConfirmationStarts = true, SendData = new List <ArraySegment <byte> >(), IsGuoHu = false }; Gongyong.mulist.Add(mj); } ///将当前的用户信息添加到下发文件包 UserInfo gameuser = Gongyong.userlist.Find(u => u.openid == getdata.Openid); gameuser.Lat = getdata.Latitude; Userinfo newuser = Userinfo.CreateBuilder().SetHeadimg(gameuser.headimg).SetNickname(gameuser.nickname).SetOpenid(gameuser.openid).SetSex(int.Parse(gameuser.sex)).SetUserFW(shuzhu[0]).SetUserGold(0).SetUserBean(0).SetUserID(gameuser.UserID).SetUserIP(gameuser.UserIP).Build(); listuser.Add(newuser); senddata.AddUserinfo(newuser); nowsend.AddUserinfo(newuser); List <mjuser> mu = Gongyong.mulist.FindAll(u => u.RoomID == getdata.RoomID); var dis = ReturnDis.CreateBuilder(); var closeGPS = ReturnCloseGPS.CreateBuilder(); ///向已有玩家下发信息 foreach (mjuser items in mu) { UserInfo gamersend = Gongyong.userlist.Find(u => u.openid == items.Openid); if (gamersend.Lat.Equals("0,0") || string.IsNullOrEmpty(gamersend.Lat)) { //Console.WriteLine("AddRoom : " + gamersend.session.Config.Ip + " lat 为 0"); //Console.WriteLine(" : " + mjuser.) closeGPS.AddFW(items.ZS_Fw); //gamersend.session.Send(new ArraySegment<byte>(CreateHead.CreateMessage(GameInformationBase.BASEAGREEMENTNUMBER + 7091, dataGPS.Length, requestInfo.MessageNum, dataGPS))); } else if (gameuser.Lat.Equals("0,0") || string.IsNullOrEmpty(gameuser.Lat)) { if (items.Openid.Equals(gameuser.openid)) { //Console.WriteLine("AddRoom : " + gamersend.session.Config.Ip + " lat 为 0"); if (!closeGPS.FWList.Any(w => w == items.ZS_Fw)) { closeGPS.AddFW(items.ZS_Fw); } } } else { var userdis = ReturnDis.CreateBuilder(); //double jl = Erth.GetDistance(gamersend.Lat, gameuser.Lat); double jl = 1; // 测试修改 if (shuzhu[0] != items.ZS_Fw) { //if (jl < GameInformationBase.DISTANCE) if (jl < 0.001f) //任光粤测试修改 { Console.WriteLine("距离为 : " + jl + gamersend.nickname + ":" + gamersend.Lat + " , " + gameuser.nickname + " : " + gameuser.Lat); rm.Is_Jin = true; rm.Juser1 = shuzhu[0]; rm.Juser2 = items.ZS_Fw; } } dis.SetDis(jl.ToString()); dis.SetFW(items.ZS_Fw); userdis.SetFW(shuzhu[0]); userdis.SetDis(jl.ToString()); ListUserIP.Add(gamersend); byte[] dataMJ = userdis.Build().ToByteArray(); byte[] datauser = dis.Build().ToByteArray(); AppServer userserver = new AppServer(); gamersend.session.Send(new ArraySegment <byte>(CreateHead.CreateMessage(GameInformationBase.BASEAGREEMENTNUMBER + 7091, dataMJ.Length, requestInfo.MessageNum, dataMJ))); gameuser.session.Send(new ArraySegment <byte>(CreateHead.CreateMessage(GameInformationBase.BASEAGREEMENTNUMBER + 7091, datauser.Length, requestInfo.MessageNum, datauser))); } System.Threading.Thread.Sleep(100); byte[] data = senddata.Build().ToByteArray(); gamersend.session.Send(new ArraySegment <byte>(CreateHead.CreateMessage(GameInformationBase.BASEAGREEMENTNUMBER + 2005, data.Length, requestInfo.MessageNum, data))); ///如果人数满足,下发游戏开始信息 if (mu.Count == rm.room_peo) { //牌局回放保存用户信息 rm.gameOperationProcess.SetUserInfo(senddata); foreach (var item in Gongyong.mulist.FindAll(u => u.RoomID == rm.RoomID)) { if (!item.ConfirmationStarts) { rm.startgame = 2; } } rm.startgame = rm.startgame == 2 ? 0 : 1; //ReturnStart startgame = ReturnStart.CreateBuilder().SetStart(1).Build(); //byte[] bstart = startgame.ToByteArray(); //gamersend.session.TrySend(new ArraySegment<byte>(CreateHead.CreateMessage(GameInformationBase.BASEAGREEMENTNUMBER + 2008, bstart.Length, requestInfo.MessageNum, bstart))); } } if (closeGPS.FWCount > 0) { foreach (mjuser items in mu) { var dataGPS = closeGPS.Build().ToByteArray(); UserInfo gamersend = Gongyong.userlist.Find(u => u.openid == items.Openid); gamersend.session.Send(new ArraySegment <byte>(CreateHead.CreateMessage(GameInformationBase.BASEAGREEMENTNUMBER + 7097, dataGPS.Length, requestInfo.MessageNum, dataGPS))); } } } } else { staut = "10001"; } ///判断房间不为空 发生房间信息 if (rm != null) { roommsg.SetCount(rm.count) .SetIsBenji(rm.is_benji == true ? 1 : 0) .SetIsShangxiaji(rm.is_shangxiaji == true ? 1 : 0) .SetIsWgj(rm.is_wgj == true ? 1 : 0) .SetIsXinqiji(rm.is_xinqiji == true ? 1 : 0) .SetIsYikousan(rm.is_yikousan == true ? 1 : 0) .SetRoomPeo(rm.room_peo) .SetIsLianzhuang(rm.is_lianz == true ? 1 : 0) .SetIsYuanque(rm.IsYuanQue ? 1 : 0) .SetQuickCard(rm.QuickCard?1:0); byte[] roommsgb = roommsg.Build().ToByteArray(); session.TrySend(new ArraySegment <byte>(CreateHead.CreateMessage(GameInformationBase.BASEAGREEMENTNUMBER + 7003, roommsgb.Length, requestInfo.MessageNum, roommsgb))); } System.Threading.Thread.Sleep(100); nowsend.SetState(int.Parse(staut)); byte[] datanew = nowsend.Build().ToByteArray(); session.TrySend(new ArraySegment <byte>(CreateHead.CreateMessage(GameInformationBase.BASEAGREEMENTNUMBER + 2004, datanew.Length, requestInfo.MessageNum, datanew))); //如果有玩家距离过近,提醒牌桌所有用户,并接受确认 if (rm.Is_Jin) { byte[] jusers = ReturnIsJ.CreateBuilder().SetFWO(rm.Juser1).SetFWW(rm.Juser2).Build().ToByteArray(); rm.startgame = 0; SendRoomAllUser(new ArraySegment <byte>(CreateHead.CreateMessage(GameInformationBase.BASEAGREEMENTNUMBER + 7092, jusers.Length, requestInfo.MessageNum, jusers)), getdata.RoomID); } List <UserInfo> waringList = new List <UserInfo>(); //如果有玩家IP一样 foreach (var item in ListUserIP) { if (ListUserIP.Where(w => w.UserIP.Equals(item.UserIP)).Count() > 1) { waringList.Add(item); } } if (waringList.Count > 1) { var ipSame = ReturnIPSame.CreateBuilder(); foreach (var item in ListUserIP) { var userInfo = Gongyong.mulist.First(w => w.Openid.Equals(item.openid)); if (userInfo != null) { ipSame.AddFW(userInfo.ZS_Fw); } } var jusers = ipSame.Build().ToByteArray(); rm.startgame = 0; SendRoomAllUser(new ArraySegment <byte>(CreateHead.CreateMessage(GameInformationBase.BASEAGREEMENTNUMBER + 7093, jusers.Length, requestInfo.MessageNum, jusers)), getdata.RoomID); } rm.gameOperationProcess.SetMessage(roommsg);//牌局回放保存房间信息 session.Logger.Debug("用户请求加入房间:" + getdata.RoomID + ",openid:" + getdata.Openid + "----------" + DateTime.Now); if (rm.startgame == 1) { //将牌桌信息保存 RedisUtility.Set <RedisGameRoomInfo>(RedisUtility.GetKey(GameInformationBase.COMMUNITYROOMINFO, rm.RoomID.ToString(), ""), new RedisGameRoomInfo { room = rm, ServerName = GameInformationBase.serverName }); foreach (var item in Gongyong.mulist.FindAll(u => u.RoomID == rm.RoomID)) { if (!item.ConfirmationStarts) { return; } } session.Logger.Debug("发牌"); ///查找当前玩家集合 List <mjuser> mjList = Gongyong.mulist.FindAll(u => u.RoomID == rm.RoomID); CardsLogic logic = new CardsLogic(); int number = 0;//发牌次数,从0开始计数 //根据 ///获取房主信息 /// string homeownerOpenid = ""; foreach (var item in mjList) { if (item.IsHomeowner) { //如果是房主,记录该房主的openid homeownerOpenid = item.Openid; } } var roominfodal = new RoomInfoDAL(); var createuserid = roominfodal.GetCreateUserIdByRoomId(rm.RoomID); //var groupid = roominfodal.GetGroupInfoByGroupID(createuserid); var groupid = rm.GroupID; //不是圈子用户,直接进行扣费 if (groupid == 0) { RoomCardUtility.ReduceRoomCard(createuserid, (rm.count / 4) * 1); } else { GroupInfoDAL groupInfoDAL = new GroupInfoDAL(); var creategroupuderid = groupInfoDAL.GetUserIDByGuoupID(groupid); var reducecount = (rm.count / 8) * 1; RoomCardUtility.ReduceRoomCard(creategroupuderid, reducecount); ////向日志里面添加朋友圈耗卡信息 groupInfoDAL.AddCreateRoomRecord(creategroupuderid, groupid, rm.RoomID, reducecount); } var dcount = rm.Dcount; foreach (var item in mjList) { ReturnStartGame.Builder sendmj = ReturnStartGame.CreateBuilder(); ReturnGang.Builder ReturnGangMSG = ReturnGang.CreateBuilder(); List <model.ServerMaJiang> Ruturnjsmj = new List <model.ServerMaJiang>(); item.paixinfs = 5; Gongyong.mulist.Remove(item); if (rm.IsYuanQue) { item.QYM = 3; } logic.GetMyCards(requestInfo, sendmj, ReturnGangMSG, Ruturnjsmj, session, rm.RoomID, item, item.Openid, ref dcount); } } }
/// <summary> /// 出牌 /// </summary> /// <param name="session"></param> /// <param name="requestInfo"></param> public void ExecuteCommand(GameSession session, ProtobufRequestInfo requestInfo) { if (!Gongyong.userlist.Any(w => w.session.SessionID.Equals(session.SessionID))) { session.Logger.Debug("ChuPai : 非法连接"); session.Close(); return; } var returnmsg = ReturnMsg.CreateBuilder(); var PGH = ReturnAll.CreateBuilder(); var chu = SendCP.ParseFrom(requestInfo.Body); mjuser thisuser = Gongyong.mulist.Find(u => u.RoomID == chu.Roomid && u.Openid == chu.Openid); if (thisuser == null) { return; } if (thisuser.ByteData == requestInfo.Key) { return; } else { thisuser.ByteData = requestInfo.Key; } model.ServerMaJiang mj = new model.ServerMaJiang(); Room r = Gongyong.roomlist.Find(u => u.RoomID == chu.Roomid); if (r.room_peo != 4) { if (Gongyong.mulist.Any(w => w.RoomID == chu.Roomid && w.QYM == 0)) { thisuser.ByteData = string.Empty; session.Logger.Debug("牌桌玩家没有全部定缺"); return; } } if (r.DQcz != "3001") { session.Logger.Debug("当前操作不是出牌 当前操作为:" + r.DQcz); thisuser.ByteData = string.Empty; return; } mj = thisuser.majiangs.Find(u => u.PaiHs == chu.Mj.PaiHS && u.PaiId == chu.Mj.PaiID); //mj.PaiHs = chu.Mj.PaiHS; //mj.PaiId = chu.Mj.PaiID; if (r.DQHY != thisuser.ZS_Fw) { thisuser.ByteData = string.Empty; session.Logger.Debug("不是活跃用户"); return; } if (mj == null) { thisuser.ByteData = string.Empty; session.Logger.Debug("用户不存在"); return; } if (thisuser.Is_baotin || thisuser.Is_tiant)//报听天听用户必须摸牌打牌。不能换牌 { if (r.LastMoMJ != null && (chu.Mj.PaiHS != r.LastMoMJ.PaiHs || chu.Mj.PaiID != r.LastMoMJ.PaiId)) { session.Logger.Debug("出牌不是摸到的"); thisuser.ByteData = string.Empty; return; } } ThreadUtility.RemoveManagedThread(thisuser.Openid);//当用户操作时 取消用户的倒计时 r.LastChuMJ = mj; thisuser.SendData.Clear(); thisuser.majiangs.Remove(mj); List <model.ServerMaJiang> listmjs = new List <model.ServerMaJiang>(); listmjs.AddRange(thisuser.majiangs.ToArray()); //StringBuilder paidui = new StringBuilder(); //foreach (var item in r.RoomPai) //{ // paidui.Append(item.PaiHs + ","); //} //session.Logger.Error("出牌堆" + paidui); string is_paixin = new Ting().GetTing(listmjs); thisuser.majiangs.Sort((a, b) => - b.PaiHs.CompareTo(a.PaiHs)); r.DQcz = ""; int hStart = 0;//胡牌的数量? int hzs_fw = 0; GetPaiXin(is_paixin, thisuser); int index = 0; List <mjuser> mjuserss = Gongyong.mulist.FindAll(u => u.RoomID == chu.Roomid); session.Logger.Debug("判断放炮"); List <HuInfo> huList = new List <HuInfo>();//处理一炮多响新增一个胡牌类型对象 ///判断各种放炮 foreach (var item in mjuserss) { HuInfo huInfo = new HuInfo(); int Qcount = 0; if (r.room_peo < 4) { switch (item.QYM) { case 1: if (chu.Mj.PaiHS < 10) { Qcount++; } break; case 2: if (chu.Mj.PaiHS > 10 && chu.Mj.PaiHS < 20) { Qcount++; } break; case 3: if (chu.Mj.PaiHS > 20) { Qcount++; } break; default: break; } } if (Qcount == 0) { if (item.ZS_Fw != thisuser.ZS_Fw) { List <model.ServerMaJiang> listgett = new List <model.ServerMaJiang>(); List <model.ServerMaJiang> listnew = new List <model.ServerMaJiang>(); listgett.AddRange(item.majiangs.ToArray()); listnew.AddRange(item.majiangs.ToArray()); string hxx = new Ting().GetTing(listnew); model.ServerMaJiang mjh = new model.ServerMaJiang() { PaiHs = chu.Mj.PaiHS, PaiId = chu.Mj.PaiID }; listgett.Add(mjh); GetPaiXin(hxx, item); if (thisuser.Mtype == 1) { if (new Ting().GetTing(listgett) == "H") { hStart++; index++; hzs_fw = item.ZS_Fw; r.DQHY = item.ZS_Fw; session.Logger.Debug("热炮"); huInfo.HuIndex = item.ZS_Fw; huInfo.HuType = 4; huInfo.MJ = mjh; huInfo.OpenID = item.Openid; huInfo.PaoIndex = thisuser.ZS_Fw; huInfo.RoomID = r.RoomID; huList.Add(huInfo); r.DQHY = item.ZS_Fw; r.DQcz = "30080"; #region 旧热炮 //var sendh = SendHu.CreateBuilder(); //sendh.SetFWZ(item.ZS_Fw); //sendh.SetFWB(thisuser.ZS_Fw); //sendh.SetType(4); //sendh.SetMJ(chu.Mj); //sendh.SetOpenid(thisuser.Openid); //sendh.SetRoomid(r.RoomID); //byte[] rbyte = sendh.Build().ToByteArray(); // r.DQHY = item.ZS_Fw; // Gongyong.userlist.Find(u => u.openid == item.Openid).session.TrySend(new ArraySegment<byte>(CreateHead.CreateMessage(GameInformationBase.BASEAGREEMENTNUMBER + 5016, rbyte.Length, requestInfo.MessageNum, rbyte))); //int messageNum = (GameInformationBase.BASEAGREEMENTNUMBER + 5016); //热炮必胡,所以需要服务器自己返回胡牌的信息。 //new GetH().ExecuteCommand(Gongyong.userlist.Find(u => u.openid == item.Openid).session, // new ProtobufRequestInfo { Body = rbyte, Key = messageNum.ToString(), Messagelength = rbyte.Length, MessageNum = messageNum, MessageResNum = 0 }); // session.Logger.Debug("热炮"); //returnmsg.SetMj(chu.Mj); //returnmsg.SetFW(thisuser.ZS_Fw); //byte[] ball = returnmsg.Build().ToByteArray(); //foreach (var newitems in mjuserss) //{ // UserInfo user = Gongyong.userlist.Find(u => u.openid == newitems.Openid); // user.session.TrySend(new ArraySegment<byte>(CreateHead.CreateMessage(GameInformationBase.BASEAGREEMENTNUMBER + 3009, ball.Length, requestInfo.MessageNum, ball))); //} //return; #endregion } } else if ((item.Is_baotin || item.Is_tiant) && !item.IsGuoHu) { if (new Ting().GetTing(listgett) == "H") { hStart++; index++; hzs_fw = item.ZS_Fw; huInfo.HuIndex = item.ZS_Fw; huInfo.HuType = 2; huInfo.MJ = mjh; huInfo.OpenID = item.Openid; huInfo.PaoIndex = thisuser.ZS_Fw; huInfo.RoomID = r.RoomID; huList.Add(huInfo); //var sendh = ReturnHByType.CreateBuilder(); //sendh.SetFWZ(item.ZS_Fw); //sendh.SetFWB(thisuser.ZS_Fw); //sendh.SetType(2); //sendh.SetMJ(chu.Mj); //byte[] rbyte = sendh.Build().ToByteArray(); //r.DQHY = item.ZS_Fw; //Gongyong.userlist.Find(u => u.openid == item.Openid).session.TrySend(new ArraySegment<byte>(CreateHead.CreateMessage(GameInformationBase.BASEAGREEMENTNUMBER + 5015, rbyte.Length, requestInfo.MessageNum, rbyte))); r.DQHY = item.ZS_Fw; r.DQcz = "30080"; session.Logger.Debug("报听放炮"); } } #region 旧代码 //} //if (item.ZS_Fw != thisuser.ZS_Fw) //{ //if ((hxx == "QD" || hxx == "DD" || hxx == "DDDD" || hxx == "LQD")&& !item.IsGuoHu) //{ // if (item.ZS_Fw != thisuser.ZS_Fw) // { // if (new Ting().GetTing(listgett) == "H") // { // hStart++; // index++; // hzs_fw = item.ZS_Fw; // var sendh = ReturnHByType.CreateBuilder(); // //sendh.SetFWZ(item.ZS_Fw); // //sendh.SetFWB(thisuser.ZS_Fw); // //sendh.SetType(2); // //sendh.SetMJ(chu.Mj); // //r.DQHY = item.ZS_Fw; // //byte[] rbyte = sendh.Build().ToByteArray(); // //Gongyong.userlist.Find(u => u.openid == item.Openid).session.TrySend(new ArraySegment<byte>(CreateHead.CreateMessage(GameInformationBase.BASEAGREEMENTNUMBER + 5015, rbyte.Length, requestInfo.MessageNum, rbyte))); // huInfo.HuIndex = item.ZS_Fw; // huInfo.HuType =2; // huInfo.MJ = mjh; // huInfo.OpenID = item.Openid; // huInfo.PaoIndex = thisuser.ZS_Fw; // huInfo.RoomID = r.RoomID; // huList.Add(huInfo); // session.Logger.Debug("大牌"+ hxx+"牌"+ chu.Mj.PaiHS); // } // } //} //} //if (item.ZS_Fw #endregion != thisuser.ZS_Fw) //{ else if ((!string.IsNullOrEmpty(item.Gong)) && !item.IsGuoHu) { if (new Ting().GetTing(listgett) == "H") { hStart++; index++; hzs_fw = item.ZS_Fw; var sendh = ReturnHByType.CreateBuilder(); //sendh.SetFWZ(item.ZS_Fw); //sendh.SetFWB(thisuser.ZS_Fw); //sendh.SetType(2); //sendh.SetMJ(chu.Mj); //r.DQHY = item.ZS_Fw; //byte[] rbyte = sendh.Build().ToByteArray(); //Gongyong.userlist.Find(u => u.openid == item.Openid).session.TrySend(new ArraySegment<byte>(CreateHead.CreateMessage(GameInformationBase.BASEAGREEMENTNUMBER + 5015, rbyte.Length, requestInfo.MessageNum, rbyte))); huInfo.HuIndex = item.ZS_Fw; huInfo.HuType = 2; huInfo.MJ = mjh; huInfo.OpenID = item.Openid; huInfo.PaoIndex = thisuser.ZS_Fw; huInfo.RoomID = r.RoomID; huList.Add(huInfo); r.DQHY = item.ZS_Fw; r.DQcz = "30080"; session.Logger.Debug("有杠" + hxx + "牌" + chu.Mj.PaiHS); } } //} //if (item.ZS_Fw != thisuser.ZS_Fw) //{ else if ((item.paixinfs != 5 && item.paixinfs != 0) && !item.IsGuoHu) { var newlist = new List <model.ServerMaJiang>(); newlist.AddRange(listgett); Ting t = new Ting(); if (t.GetTing(listgett) == "H") { hxx = t.GetHPaiPaiXin(newlist, item.Peng.GroupBy(w => w.PaiHs).Count(), string.IsNullOrEmpty(item.Gong) ? 0 : item.Gong.Split(',').Length, chu.Mj.PaiHS); t.GetPaiXin(hxx, item); if (item.paixinfs != 5 && item.paixinfs != 0) { hStart++; index++; hzs_fw = item.ZS_Fw; huInfo.HuIndex = item.ZS_Fw; huInfo.HuType = 2; huInfo.MJ = mjh; huInfo.OpenID = item.Openid; huInfo.PaoIndex = thisuser.ZS_Fw; huInfo.RoomID = r.RoomID; huList.Add(huInfo); r.DQHY = item.ZS_Fw; r.DQcz = "30080"; session.Logger.Debug("胡牌" + hxx + "牌" + chu.Mj.PaiHS); } } } if (huList.Count == 0 || huList[0].HuType != 4)//热炮不能有碰 { //} //if (item.ZS_Fw != thisuser.ZS_Fw) //{ UserInfo userp = Gongyong.userlist.Find(u => u.openid == item.Openid); List <model.ServerMaJiang> UmjList = item.majiangs.FindAll(u => u.PaiHs == mj.PaiHs); if (item.Is_tiant || item.Is_baotin)//天听或者报听 不能有碰杠牌 { } else { if (UmjList.Count >= 2) { index++; PGH.SetPeng(1); PGH.SetFw(thisuser.ZS_Fw); PGH.SetMj(chu.Mj); byte[] xia = PGH.Build().ToByteArray(); if (huList.Count > 0 && hzs_fw != item.ZS_Fw) { RoomMsgWirte msgri = new RoomMsgWirte() { openid = item.Openid, xiaoxihao = 3008, ArrList = xia, roomid = r.RoomID, operating = "30081" + "," + thisuser.ZS_Fw }; Gongyong.roommsg.Add(msgri); } else { item.SendData.Add(new ArraySegment <byte>(CreateHead.CreateMessage(GameInformationBase.BASEAGREEMENTNUMBER + 3008, xia.Length, requestInfo.MessageNum, xia))); r.DQHY = item.ZS_Fw; r.DQcz = "30081" + "," + thisuser.ZS_Fw; r.PaiHSCZ = mj; userp.session.TrySend(item.SendData); session.Logger.Debug("方位------" + item.ZS_Fw + "--碰--" + chu.Mj.PaiHS); } } if (UmjList.Count == 3) { index++; var returngang = GangMSG.CreateBuilder(); returngang.SetFw(thisuser.ZS_Fw); returngang.SetMj(chu.Mj); returngang.SetType(1); byte[] xia = ReturnGang.CreateBuilder().AddGang(returngang).Build().ToByteArray(); if (huList.Count > 0 && hzs_fw != item.ZS_Fw) { RoomMsgWirte msgri = new RoomMsgWirte() { ArrList = xia, xiaoxihao = 5022, openid = item.Openid, roomid = r.RoomID, operating = "30082,1" + "," + thisuser.ZS_Fw }; Gongyong.roommsg.Add(msgri); } else { item.SendData.Add(new ArraySegment <byte>(CreateHead.CreateMessage(GameInformationBase.BASEAGREEMENTNUMBER + 5022, xia.Length, requestInfo.MessageNum, xia))); r.DQHY = item.ZS_Fw; r.DQcz = "30082,1" + "," + thisuser.ZS_Fw; r.PaiHSCZ = mj; userp.session.TrySend(item.SendData); session.Logger.Debug("方位------" + item.ZS_Fw + "--杠--" + chu.Mj.PaiHS); } } } } } } } if (huList.Count > 0) { r.Is_Hu = true; session.Logger.Debug(huList); if (huList.Count > 1 || huList[0].HuType == 4) { var sendh = SendHu.CreateBuilder(); foreach (var item in huList) { if (!sendh.HasFWZ) { sendh.SetFWZ(item.HuIndex); } if (!sendh.HasFWB) { sendh.SetFWB(item.PaoIndex); } sendh.SetType(item.HuType); sendh.SetMJ(chu.Mj); if (!sendh.HasOpenid) { sendh.SetOpenid(item.OpenID); } if (!sendh.HasRoomid) { sendh.SetRoomid(r.RoomID); } sendh.AddDXInfo(DuoXiangHu.CreateBuilder().SetDXFW(item.HuIndex).SetDXType(item.HuType)); } byte[] rbyte = sendh.Build().ToByteArray(); //Gongyong.userlist.Find(u => u.openid == item.Openid).session.TrySend(new ArraySegment<byte>(CreateHead.CreateMessage(GameInformationBase.BASEAGREEMENTNUMBER + 5016, rbyte.Length, requestInfo.MessageNum, rbyte))); int messageNum = (GameInformationBase.BASEAGREEMENTNUMBER + 5016); //热炮必胡,所以需要服务器自己返回胡牌的信息。 new GetH().ExecuteCommand(Gongyong.userlist.Find(u => u.openid == huList[0].OpenID).session, new ProtobufRequestInfo { Body = rbyte, Key = messageNum.ToString(), Messagelength = rbyte.Length, MessageNum = messageNum, MessageResNum = 0 }); return; } else { var sendh = ReturnHByType.CreateBuilder(); sendh.SetFWZ(huList[0].HuIndex); sendh.SetFWB(huList[0].PaoIndex); sendh.SetType(huList[0].HuType); sendh.SetMJ(chu.Mj); r.DQHY = huList[0].HuIndex; byte[] rbyte = sendh.Build().ToByteArray(); var sendData = new ArraySegment <byte>(CreateHead.CreateMessage(GameInformationBase.BASEAGREEMENTNUMBER + 5015, rbyte.Length, requestInfo.MessageNum, rbyte)); mjuserss.Find(w => w.Openid.Equals(huList[0].OpenID)).SendData.Add(sendData); Gongyong.userlist.Find(u => u.openid == huList[0].OpenID).session.TrySend(sendData); } } else { r.Is_Hu = false; } thisuser.chuda.Add(mj); thisuser.Mtype = 0;//不将自己的摸牌类型修改 会导致碰牌后的出牌也被判断成热炮 ///下发出的牌 if (index > 0) { returnmsg.SetMj(chu.Mj); returnmsg.SetFW(thisuser.ZS_Fw); byte[] ball = returnmsg.Build().ToByteArray(); foreach (var newitems in mjuserss) { UserInfo user = Gongyong.userlist.Find(u => u.openid == newitems.Openid); user.session.TrySend(new ArraySegment <byte>(CreateHead.CreateMessage(GameInformationBase.BASEAGREEMENTNUMBER + 3009, ball.Length, requestInfo.MessageNum, ball))); } //牌局回放 r.gameOperationProcess.AddGameOperationInfo( GameOperationInfo.CreateBuilder() .SetSerialNumber(r.gameOperationProcess.GameOperationInfoCount) .SetOperationFW(thisuser.ZS_Fw) .SetOperationType(2) .AddMJ(chu.Mj) ); } ///下发冲锋鸡消息 if (index == 0) { if (mj.PaiHs == 8 && r.is_wgj) { int wgjc = 0; foreach (var item in mjuserss) { int Pcount = item.Peng.FindAll(u => u.PaiHs == 8).Count; int Ccount = item.chuda.FindAll(u => u.PaiHs == 8).Count; if (item.ZS_Fw == thisuser.ZS_Fw) { Ccount = Ccount - 1; } if (!string.IsNullOrEmpty(item.Gong)) { item.Gong.Remove(item.Gong.Length - 1, 1); string[] G = item.Gong.Split(','); foreach (var items in G) { string[] GOne = items.Split('|'); if (GOne[0] == "8") { wgjc++; } } } if (Pcount > 0 || Ccount > 0) { wgjc++; } } if (wgjc == 0) { thisuser.is_cfwg = true; returnmsg.SetMsg("CFWG"); } else { returnmsg.SetMsg(""); } } if (mj.PaiHs == 11) { int cfjc = 0; foreach (var item in mjuserss) { int Pcount = item.Peng.FindAll(u => u.PaiHs == 11).Count; int Ccount = item.chuda.FindAll(u => u.PaiHs == 11).Count; if (item.ZS_Fw == thisuser.ZS_Fw) { Ccount = Ccount - 1; } if (!string.IsNullOrEmpty(item.Gong)) { item.Gong.Remove(item.Gong.Length - 1, 1); string[] G = item.Gong.Split(','); foreach (var items in G) { string[] GOne = items.Split('|'); if (GOne[0] == "11") { cfjc++; } } } if (Pcount > 0 || Ccount > 0) { cfjc++; } } if (cfjc == 0) { thisuser.Is_cfj = true; returnmsg.SetMsg("CFJ"); } else { returnmsg.SetMsg(""); } } returnmsg.SetMj(chu.Mj); returnmsg.SetFW(thisuser.ZS_Fw); byte[] ball = returnmsg.Build().ToByteArray(); var paiCount = ReturnPaiCount.CreateBuilder(); if (r.RoomPai.Count == 108) { switch (r.room_peo) { case 2: if (r.RoomPai.Count == 108) { paiCount.SetPaiCount(81); } break; case 3: if (r.RoomPai.Count == 108) { paiCount.SetPaiCount(68); } break; case 4: if (r.RoomPai.Count == 108) { paiCount.SetPaiCount(55); } break; default: break; } } else { paiCount.SetPaiCount(r.RoomPai.Count); } byte[] returnPaiCount = paiCount.Build().ToByteArray(); var sby = ReturnHyUser.CreateBuilder(); foreach (var items in mjuserss) { UserInfo user = Gongyong.userlist.Find(u => u.openid == items.Openid); bool is_send = user.session.TrySend(new ArraySegment <byte>(CreateHead.CreateMessage(GameInformationBase.BASEAGREEMENTNUMBER + 3009, ball.Length, requestInfo.MessageNum, ball))); PGH.SetMo(1); // user.session.TrySend(new ArraySegment<byte>(CreateHead.CreateMessage(GameInformationBase.BASEAGREEMENTNUMBER + 7006, returnPaiCount.Length, requestInfo.MessageNum, returnPaiCount))); //if (is_send) //{ // session.Logger.Debug("方位------" + items.ZS_Fw + "--发送成功-- 3009"); //} //else //{ // session.Logger.Debug("方位------" + items.ZS_Fw + "--发送失败-- 3009"); //} session.Logger.Debug("方位------" + items.ZS_Fw + "--发送-- 3009" + "牌" + chu.Mj.PaiHS); if (thisuser.ZS_Fw == r.room_peo) { if (items.ZS_Fw == 1) { PGH.SetFw(items.ZS_Fw); items.Mtype = 0; byte[] xia = PGH.Build().ToByteArray(); items.SendData.Add(new ArraySegment <byte>(CreateHead.CreateMessage(GameInformationBase.BASEAGREEMENTNUMBER + 3008, xia.Length, requestInfo.MessageNum, xia))); user.session.TrySend(items.SendData); r.DQHY = items.ZS_Fw; r.DQcz = "30083"; session.Logger.Debug("方位------" + items.ZS_Fw + "--摸牌--"); } } else { if (items.ZS_Fw == thisuser.ZS_Fw + 1) { PGH.SetFw(items.ZS_Fw); items.Mtype = 0; byte[] xia = PGH.Build().ToByteArray(); items.SendData.Add(new ArraySegment <byte>(CreateHead.CreateMessage(GameInformationBase.BASEAGREEMENTNUMBER + 3008, xia.Length, requestInfo.MessageNum, xia))); user.session.TrySend(items.SendData); r.DQHY = items.ZS_Fw; r.DQcz = "30083"; session.Logger.Debug("方位------" + items.ZS_Fw + "--摸牌-- "); } } #region 旧摸牌 /* if (thisuser.ZS_Fw == 4) * { * if (items.ZS_Fw == 1) * { * PGH.SetFw(items.ZS_Fw); * byte[] xia = PGH.Build().ToByteArray(); * * r.DQHY = items.ZS_Fw; * r.DQcz = "30083"; * user.session.TrySend(new ArraySegment<byte>(CreateHead.CreateMessage(GameInformationBase.BASEAGREEMENTNUMBER + 3008, xia.Length, requestInfo.MessageNum, xia))); * } * } * else * { * if (hStart == 0) * { * if (r.room_peo == 2) * { * if (thisuser.ZS_Fw == 2 || items.ZS_Fw - 1 == thisuser.ZS_Fw) * { * * if (items.ZS_Fw != thisuser.ZS_Fw) * { * PGH.SetFw(items.ZS_Fw); * items.Mtype = 0; * byte[] xia = PGH.Build().ToByteArray(); * items.SendData.Add(new ArraySegment<byte>(CreateHead.CreateMessage(GameInformationBase.BASEAGREEMENTNUMBER + 3008, xia.Length, requestInfo.MessageNum, xia))); * user.session.TrySend(items.SendData); * r.DQHY = items.ZS_Fw; * r.DQcz = "30083"; * session.Logger.Debug("方位------" + thisuser.ZS_Fw + "--出--" + chu.Mj.PaiHS); * } * * } * } * else if (r.room_peo == 3) * { * if (thisuser.ZS_Fw == 3) * { * if (items.ZS_Fw == 1) * { * PGH.SetFw(items.ZS_Fw); * byte[] xia = PGH.Build().ToByteArray(); * r.DQHY = items.ZS_Fw; * r.DQcz = "30083"; * items.Mtype = 0; * items.SendData.Add(new ArraySegment<byte>(CreateHead.CreateMessage(GameInformationBase.BASEAGREEMENTNUMBER + 3008, xia.Length, requestInfo.MessageNum, xia))); * user.session.TrySend(items.SendData); * } * } * else * { * if (items.ZS_Fw - 1 == thisuser.ZS_Fw) * { * PGH.SetFw(items.ZS_Fw); * byte[] xia = PGH.Build().ToByteArray(); * r.DQHY = items.ZS_Fw; * r.DQcz = "30083"; * items.Mtype = 0; * items.SendData.Add(new ArraySegment<byte>(CreateHead.CreateMessage(GameInformationBase.BASEAGREEMENTNUMBER + 3008, xia.Length, requestInfo.MessageNum, xia))); * user.session.TrySend(items.SendData); * } * } * } * else * { * if (thisuser.ZS_Fw == 4) * { * if (items.ZS_Fw == 1) * { * PGH.SetFw(items.ZS_Fw); * byte[] xia = PGH.Build().ToByteArray(); * r.DQHY = items.ZS_Fw; * r.DQcz = "30083"; * items.Mtype = 0; * items.SendData.Add(new ArraySegment<byte>(CreateHead.CreateMessage(GameInformationBase.BASEAGREEMENTNUMBER + 3008, xia.Length, requestInfo.MessageNum, xia))); * user.session.TrySend(items.SendData); * } * } * else * { * if (items.ZS_Fw - 1 == thisuser.ZS_Fw) * { * PGH.SetFw(items.ZS_Fw); * byte[] xia = PGH.Build().ToByteArray(); * r.DQHY = items.ZS_Fw; * r.DQcz = "30083"; * items.Mtype = 0; * items.SendData.Add(new ArraySegment<byte>(CreateHead.CreateMessage(GameInformationBase.BASEAGREEMENTNUMBER + 3008, xia.Length, requestInfo.MessageNum, xia))); * user.session.TrySend(items.SendData); * } * } * } * } * } */ #endregion } //牌局回放 出牌 r.gameOperationProcess.AddGameOperationInfo( GameOperationInfo.CreateBuilder() .SetSerialNumber(r.gameOperationProcess.GameOperationInfoCount) .SetOperationFW(thisuser.ZS_Fw) .SetOperationType(2) .AddMJ(chu.Mj) .SetMJType(returnmsg.Msg) ); // Thread.Sleep(100); sby.SetFw(r.DQHY); sby.SetCz(r.DQcz); byte[] hybyte = sby.Build().ToByteArray(); foreach (var item in mjuserss) { UserInfo user = Gongyong.userlist.Find(u => u.openid == item.Openid); user.IsActive = true; user.session.TrySend(new ArraySegment <byte>(CreateHead.CreateMessage(GameInformationBase.BASEAGREEMENTNUMBER + 7004, hybyte.Length, requestInfo.MessageNum, hybyte))); } } ThreadUtility.StartManagedThread(Gongyong.mulist.Find(w => w.ZS_Fw == r.DQHY && w.RoomID == r.RoomID).Openid, r.RoomID, r.DQcz); }
/// <summary> /// 继续游戏 /// </summary> /// <param name="session"></param> /// <param name="requestInfo"></param> public void ExecuteCommand(GameSession session, ProtobufRequestInfo requestInfo) { if (!Gongyong.userlist.Any(w => w.session.SessionID.Equals(session.SessionID))) { session.Logger.Debug("JX_Game : 非法连接"); session.Close(); return; } var getdata = SendGetGame.ParseFrom(requestInfo.Body); Room r = Gongyong.roomlist.Find(u => u.RoomID == getdata.RoomID); if (r == null) { return; } if (r.startgame != 2) { return; } List <mjuser> listuser = Gongyong.mulist.FindAll(u => u.RoomID == getdata.RoomID); Room_JX room = new Room_JX(); room = Gongyong.room_JX.Find(u => u.room_id == getdata.RoomID); if (room == null) { room = new Room_JX() { room_id = getdata.RoomID, room_peo = 1, UsersFW = new List <int>() { getdata.Fw } }; Gongyong.room_JX.Add(room); } else { if (!room.UsersFW.Any(w => w == getdata.Fw))//已点击过继续游戏的玩家不能再次进入计算 { room.room_peo += 1; room.UsersFW.Add(getdata.Fw); } } if (room.room_peo == r.room_peo) { //发送当前局数的信息 foreach (var item in listuser) { new CardsLogic().Clear(item, r); } CardsLogic logic = new CardsLogic(); r.startgame = 1; int number = 0;//发牌次数,从0开始计数 foreach (var item in listuser) { //UserInfo user = Gongyong.userlist.Find(u => u.openid == item.Openid); //ReturnStart startgame = ReturnStart.CreateBuilder().SetStart(1).Build(); //byte[] bstart = startgame.ToByteArray(); //user.session.TrySend(new ArraySegment<byte>(CreateHead.CreateMessage(GameInformationBase.BASEAGREEMENTNUMBER + 2008, bstart.Length, requestInfo.MessageNum, bstart))); item.SendData.Clear(); ReturnStartGame.Builder sendmj = ReturnStartGame.CreateBuilder(); ReturnGang.Builder ReturnGangMSG = ReturnGang.CreateBuilder(); List <model.ServerMaJiang> Ruturnjsmj = new List <model.ServerMaJiang>(); item.paixinfs = 5; Gongyong.mulist.Remove(item); if (r.IsYuanQue) { item.QYM = 3; } //logic.GetMyCards(requestInfo, sendmj, ReturnGangMSG, Ruturnjsmj, session, getdata.RoomID, item, item.Openid, ref number); var dcount = r.Dcount; logic.GetMyCards(requestInfo, sendmj, ReturnGangMSG, Ruturnjsmj, session, getdata.RoomID, item, item.Openid, ref dcount); } if (listuser.Any(w => w.Is_tianHu)) { var user = listuser.Find(w => w.Is_tianHu); var humj = user.majiangs.Last(); var hupai = ReturnHByType.CreateBuilder().SetFWZ(user.ZS_Fw).SetMJ(MaJiang.CreateBuilder().SetPaiHS(humj.PaiHs).SetPaiID(humj.PaiId)).SetType(1); byte[] data = hupai.Build().ToByteArray(); if (listuser.Any(w => w.Is_tiant)) { RoomMsgWirte msgri = new RoomMsgWirte() { openid = user.Openid, xiaoxihao = 5015, ArrList = data, roomid = user.RoomID , operating = "30080" }; Gongyong.roommsg.Add(msgri); } else { var userSend = Gongyong.userlist.Find(w => w.openid.Equals(user.Openid)); userSend.session.TrySend(new ArraySegment <byte>(CreateHead.CreateMessage(GameInformationBase.BASEAGREEMENTNUMBER + 5015, data.Length, requestInfo.MessageNum, data))); } // userSendJ.session.TrySend(new ArraySegment<byte>(CreateHead.CreateMessage(GameInformationBase.BASEAGREEMENTNUMBER + 5015, data.Length, requestInfo.MessageNum, data))); } Gongyong.room_JX.Remove(Gongyong.room_JX.Find(w => w.room_id == getdata.RoomID)); } }
public void ExecuteCommand(GameSession session, ProtobufRequestInfo requestInfo) { if (!Gongyong.userlist.Any(w => w.session.SessionID.Equals(session.SessionID))) { session.Logger.Debug("StartGame : 非法连接"); session.Close(); return; } var result = SendConfirmationStarts.ParseFrom(requestInfo.Body); session.Logger.Debug(result); var userInfo = Gongyong.mulist.Find(u => u.RoomID == result.RoomID && u.Openid == result.Openid); if (userInfo == null) { return; } userInfo.ConfirmationStarts = true; List <mjuser> mjList = Gongyong.mulist.FindAll(u => u.RoomID == result.RoomID); var r = Gongyong.roomlist.Find(w => w.RoomID == result.RoomID); if (r.startgame == 1) { return; } if (mjList.Count != r.room_peo) { return; } foreach (var item in mjList) { if (!item.ConfirmationStarts) { return; } } r.startgame = 1; ///查找当前玩家集合 session.Logger.Debug("全部确认,开始游戏发牌" + mjList.Count); CardsLogic logic = new CardsLogic(); int number = 0;//发牌次数,从0开始计数 //switch (r.room_peo) //{ // case "2T": // if (r.RoomPai.Count == 108) // { // r.RoomPai.RemoveRange(0, 27); // } // break; // case "3T": // if (r.RoomPai.Count == 108) // { // r.RoomPai.RemoveRange(0, 40); // } // break; // case "4T": // if (r.RoomPai.Count == 108) // { // r.RoomPai.RemoveRange(0, 53); // } // break; // default: // break; //} var dcount = r.Dcount; foreach (var item in mjList) { ReturnStartGame.Builder sendmj = ReturnStartGame.CreateBuilder(); ReturnGang.Builder ReturnGangMSG = ReturnGang.CreateBuilder(); List <model.ServerMaJiang> Ruturnjsmj = new List <model.ServerMaJiang>(); item.paixinfs = 5; Gongyong.mulist.Remove(item); if (r.IsYuanQue) { item.QYM = 3; } logic.GetMyCards(requestInfo, sendmj, ReturnGangMSG, Ruturnjsmj, session, result.RoomID, item, item.Openid, ref dcount); var user = Gongyong.userlist.Find(w => w.openid.Equals(item.Openid)); byte[] stringnew = ReturnPaiCount.CreateBuilder().SetPaiCount(r.RoomPai.Count).Build().ToByteArray(); user.session.TrySend(new ArraySegment <byte>(CreateHead.CreateMessage(GameInformationBase.BASEAGREEMENTNUMBER + 7006, stringnew.Length, requestInfo.MessageNum, stringnew))); } if (mjList.Any(w => w.Is_tianHu)) { var user = mjList.Find(w => w.Is_tianHu); var humj = user.majiangs.Last(); var hupai = ReturnHByType.CreateBuilder().SetFWZ(user.ZS_Fw).SetMJ(MaJiang.CreateBuilder().SetPaiHS(humj.PaiHs).SetPaiID(humj.PaiId)).SetType(1); byte[] data = hupai.Build().ToByteArray(); if (mjList.Any(w => w.Is_tiant)) { model.RoomMsgWirte msgri = new RoomMsgWirte() { openid = user.Openid, xiaoxihao = 5015, ArrList = data, roomid = user.RoomID, operating = "30070" }; Gongyong.roommsg.Add(msgri); } else { var userSend = Gongyong.userlist.Find(w => w.openid.Equals(user.Openid)); userSend.session.TrySend(new ArraySegment <byte>(CreateHead.CreateMessage(GameInformationBase.BASEAGREEMENTNUMBER + 5015, data.Length, requestInfo.MessageNum, data))); } // userSendJ.session.TrySend(new ArraySegment<byte>(CreateHead.CreateMessage(GameInformationBase.BASEAGREEMENTNUMBER + 5015, data.Length, requestInfo.MessageNum, data))); } }
public void ExecuteCommand(GameSession session, ProtobufRequestInfo requestInfo) { if (!Gongyong.userlist.Any(w => w.session.SessionID.Equals(session.SessionID))) { session.Logger.Debug("QYM : 非法连接"); session.Close(); return; } ///获取缺一门数据 var getdata = SendQYM.ParseFrom(requestInfo.Body); ///根据openid找到用户 mjuser userrun = Gongyong.mulist.Find(u => u.Openid == getdata.Openid); if (userrun == null) { return; } if (userrun.ByteData == requestInfo.Key) { return; } else { userrun.ByteData = requestInfo.Key; } ///如果用户为空则直接返回 if (userrun == null) { return; } if (userrun.QYM != 0 && !string.IsNullOrEmpty(userrun.QYM.ToString())) { return; } ///设置用户缺的麻将 userrun.QYM = getdata.Type; ///根据房间ID找到当前房间 List <mjuser> userlist = Gongyong.mulist.FindAll(u => u.RoomID == userrun.RoomID); mjuser mjlist = Gongyong.mulist.Find(u => u.RoomID == userrun.RoomID && (u.QYM == 0 || string.IsNullOrEmpty(u.QYM.ToString()))); CardUser cu = Gongyong.FKUser.Find(u => u.roomid == userrun.RoomID); if (mjlist == null) { ThreadUtility.RemoveManagedThread(getdata.Openid);//当用户操作时 取消用户的倒计时 var returndata = ReturnAYM.CreateBuilder(); var mjuserAll = Gongyong.mulist.FindAll(u => u.RoomID == userrun.RoomID); var R = Gongyong.roomlist.Find(u => u.RoomID == userrun.RoomID); Ting t = new Ting(); var ReturnGangMSG = ReturnGang.CreateBuilder(); foreach (var item in mjuserAll) { item.SendData.Clear(); ReturnTTATH.Builder sendmj = ReturnTTATH.CreateBuilder(); UserInfo user = Gongyong.userlist.Find(u => u.openid == item.Openid); //sendmj.AddMj(MaJiang.CreateBuilder()); List <model.ServerMaJiang> listT = new List <model.ServerMaJiang>(); listT.AddRange(item.majiangs.ToArray()); var Ruturnjsmj = new List <model.ServerMaJiang>(); string hxx = t.GetTing(listT); if (hxx != "MJ") { if (cu.win == item.ZS_Fw) { if (hxx == "H") { switch (item.QYM) { case 1: if (item.majiangs.FindAll(u => u.PaiHs < 10).Count <= 0) { sendmj.SetState(214); item.Is_tianHu = true; } break; case 2: if (item.majiangs.FindAll(u => u.PaiHs > 10 && u.PaiHs < 20).Count <= 0) { sendmj.SetState(214); item.Is_tianHu = true; } break; case 3: if (item.majiangs.FindAll(u => u.PaiHs > 20).Count <= 0) { sendmj.SetState(214); item.Is_tianHu = true; } break; default: break; } } else if (R.room_peo < 4) { switch (item.QYM) { case 1: if (item.majiangs.FindAll(u => u.PaiHs < 10).Count <= 0) { ///庄家报听判断 List <model.ServerMaJiang> JPMJ = new List <model.ServerMaJiang>(); JPMJ.AddRange(item.majiangs.ToArray()); Ruturnjsmj = t.ReturnJMJ(JPMJ); //item.Is_tiant = true; } break; case 2: if (item.majiangs.FindAll(u => u.PaiHs > 10 && u.PaiHs < 20).Count <= 0) { ///庄家报听判断 List <model.ServerMaJiang> JPMJ = new List <model.ServerMaJiang>(); JPMJ.AddRange(item.majiangs.ToArray()); Ruturnjsmj = t.ReturnJMJ(JPMJ); //item.Is_tiant = true; } break; case 3: if (item.majiangs.FindAll(u => u.PaiHs > 20).Count <= 0) { ///庄家报听判断 List <model.ServerMaJiang> JPMJ = new List <model.ServerMaJiang>(); JPMJ.AddRange(item.majiangs.ToArray()); Ruturnjsmj = t.ReturnJMJ(JPMJ); //item.Is_tiant = true; } break; default: break; } } else { ///庄家报听判断 List <model.ServerMaJiang> JPMJ = new List <model.ServerMaJiang>(); JPMJ.AddRange(item.majiangs.ToArray()); Ruturnjsmj = t.ReturnJMJ(JPMJ); // item.Is_tiant = true; } } else { if (R.room_peo < 4) { switch (item.QYM) { case 1: if (item.majiangs.FindAll(u => u.PaiHs < 10).Count <= 0) { sendmj.SetState(213); var TT = ReturnTT.CreateBuilder().SetFw(item.ZS_Fw); byte[] TTR = TT.Build().ToByteArray(); List <mjuser> listmjuser = Gongyong.mulist.FindAll(u => u.RoomID == item.RoomID); //foreach (var mjuser in listmjuser) //{ // UserInfo user = Gongyong.userlist.Find(u => u.openid == mjuser.Openid); // user.session.TrySend(new ArraySegment<byte>(CreateHead.CreateMessage(GameInformationBase.BASEAGREEMENTNUMBER + 5013, TTR.Length, GameInformationBase.BASEAGREEMENTNUMBER + 7093, TTR))); //} item.Is_tiant = true; R.DQHY = item.ZS_Fw; R.DQcz = "30071"; item.Is_tiantX = -1; } break; case 2: if (item.majiangs.FindAll(u => u.PaiHs > 10 && u.PaiHs < 20).Count <= 0) { sendmj.SetState(213); var TT = ReturnTT.CreateBuilder().SetFw(item.ZS_Fw); byte[] TTR = TT.Build().ToByteArray(); List <mjuser> listmjuser = Gongyong.mulist.FindAll(u => u.RoomID == item.RoomID); R.DQHY = item.ZS_Fw; R.DQcz = "30071"; item.Is_tiant = true; item.Is_tiantX = -1; } break; case 3: if (item.majiangs.FindAll(u => u.PaiHs > 20).Count <= 0) { sendmj.SetState(213); var TT = ReturnTT.CreateBuilder().SetFw(item.ZS_Fw); byte[] TTR = TT.Build().ToByteArray(); List <mjuser> listmjuser = Gongyong.mulist.FindAll(u => u.RoomID == item.RoomID); item.Is_tiant = true; R.DQHY = item.ZS_Fw; R.DQcz = "30071"; item.Is_tiantX = -1; } break; default: break; } } else { sendmj.SetState(213); var TT = ReturnTT.CreateBuilder().SetFw(item.ZS_Fw); byte[] TTR = TT.Build().ToByteArray(); List <mjuser> listmjuser = Gongyong.mulist.FindAll(u => u.RoomID == item.RoomID); item.Is_tiant = true; item.Is_tiantX = -1; R.DQHY = item.ZS_Fw; R.DQcz = "30071"; } } } if (Ruturnjsmj.Count > 0) { var returntp = ReturnTP.CreateBuilder(); var tmj = MaJiang.CreateBuilder(); foreach (var mjItem in Ruturnjsmj) { tmj.SetPaiHS(mjItem.PaiHs); tmj.SetPaiID(mjItem.PaiId); returntp.AddMj(tmj); } byte[] tmjsr = returntp.Build().ToByteArray(); var data = new ArraySegment <byte>(CreateHead.CreateMessage(GameInformationBase.BASEAGREEMENTNUMBER + 2009, tmjsr.Length, requestInfo.MessageNum, tmjsr)); item.SendData.Add(data); user.session.TrySend(data); } if (sendmj.HasState) { var data = sendmj.Build().ToByteArray(); var dataArray = new ArraySegment <byte>(CreateHead.CreateMessage(GameInformationBase.BASEAGREEMENTNUMBER + 2010, data.Length, requestInfo.MessageNum, data)); item.SendData.Add(dataArray); user.session.TrySend(dataArray); } //验证杠牌 if (cu.win == item.ZS_Fw) { // listT.AddRange(item.majiangs.ToArray()); var listchuan = listT.GroupBy(w => w.PaiHs).Select(w => new { PaiHs = w.Key, Count = w.Count() }); foreach (var gangInfo in listchuan.Where(w => w.Count == 4)) { switch (item.QYM) { case 1: if (gangInfo.PaiHs > 10) { var PGH = ReturnAll.CreateBuilder(); var mjG = MaJiang.CreateBuilder(); mjG.SetPaiHS(gangInfo.PaiHs); mjG.SetPaiID(401); ReturnGangMSG.AddGang(GangMSG.CreateBuilder().SetFw(cu.win).SetMj(mjG).SetType(3)); } break; case 2: if (gangInfo.PaiHs < 10 && gangInfo.PaiHs > 20) { var PGH = ReturnAll.CreateBuilder(); var mjG = MaJiang.CreateBuilder(); mjG.SetPaiHS(gangInfo.PaiHs); mjG.SetPaiID(401); ReturnGangMSG.AddGang(GangMSG.CreateBuilder().SetFw(cu.win).SetMj(mjG).SetType(3)); } break; case 3: if (gangInfo.PaiHs < 20) { var PGH = ReturnAll.CreateBuilder(); var mjG = MaJiang.CreateBuilder(); mjG.SetPaiHS(gangInfo.PaiHs); mjG.SetPaiID(401); ReturnGangMSG.AddGang(GangMSG.CreateBuilder().SetFw(cu.win).SetMj(mjG).SetType(3)); } break; default: break; } } if (ReturnGangMSG.GangCount > 0) { byte[] bytegang = ReturnGangMSG.Build().ToByteArray(); user.session.TrySend(new ArraySegment <byte>(CreateHead.CreateMessage(GameInformationBase.BASEAGREEMENTNUMBER + 5022, bytegang.Length, requestInfo.MessageNum, bytegang))); } } } if (userlist.Any(w => w.Is_tianHu)) { var user = userlist.Find(w => w.Is_tianHu); user.SendData.Clear(); var humj = user.majiangs.Last(); var hupai = ReturnHByType.CreateBuilder().SetFWZ(user.ZS_Fw).SetMJ(MaJiang.CreateBuilder().SetPaiHS(humj.PaiHs).SetPaiID(humj.PaiId)).SetType(1); byte[] data = hupai.Build().ToByteArray(); if (userlist.Any(w => w.Is_tiant)) { RoomMsgWirte msgri = new RoomMsgWirte() { openid = user.Openid, xiaoxihao = 5015, ArrList = data, roomid = user.RoomID , operating = "30070" }; Gongyong.roommsg.Add(msgri); } else { var userSend = Gongyong.userlist.Find(w => w.openid.Equals(user.Openid)); var dataArray = new ArraySegment <byte>(CreateHead.CreateMessage(GameInformationBase.BASEAGREEMENTNUMBER + 5015, data.Length, requestInfo.MessageNum, data)); user.SendData.Add(dataArray); userSend.session.TrySend(dataArray); R.DQHY = user.ZS_Fw; R.DQcz = "30070"; ThreadUtility.StartManagedThread(user.Openid, R.RoomID, R.DQcz); } // userSendJ.session.TrySend(new ArraySegment<byte>(CreateHead.CreateMessage(GameInformationBase.BASEAGREEMENTNUMBER + 5015, data.Length, requestInfo.MessageNum, data))); } else if (userlist.Any(w => w.Is_tiant)) { R.DQHY = 0; R.DQcz = "30071"; foreach (var item in userlist) { ThreadUtility.StartManagedThread(item.Openid, R.RoomID, R.DQcz); } } else { byte[] startHY = ReturnHyUser.CreateBuilder().SetCz("3001").SetFw(cu.win).Build().ToByteArray(); R.DQHY = cu.win; R.DQcz = "3001"; foreach (var item in userlist) { UserInfo user = Gongyong.userlist.Find(u => u.openid == item.Openid); user.IsActive = true; user.session.TrySend(new ArraySegment <byte>(CreateHead.CreateMessage(GameInformationBase.BASEAGREEMENTNUMBER + 7004, startHY.Length, GameInformationBase.BASEAGREEMENTNUMBER + 7093, startHY))); } ThreadUtility.StartManagedThread(userlist.Find(w => w.ZS_Fw == cu.win).Openid, R.RoomID, R.DQcz); } ///下发缺牌信息 foreach (var item in userlist) { var senddata = ReturnQYM.CreateBuilder().SetFw(item.ZS_Fw).SetType(item.QYM); returndata.AddQP(senddata); //牌局回放 缺一门 R.gameOperationProcess.AddGameOperationInfo( GameOperationInfo.CreateBuilder() .SetSerialNumber(R.gameOperationProcess.GameOperationInfoCount) .SetOperationFW(item.ZS_Fw) .SetOperationType(8) .SetQYM(item.QYM) ); } byte[] RBT = returndata.Build().ToByteArray(); foreach (var item in userlist) { UserInfo user = Gongyong.userlist.Find(u => u.openid == item.Openid); var data = new ArraySegment <byte>(CreateHead.CreateMessage(GameInformationBase.BASEAGREEMENTNUMBER + 5012, RBT.Length, requestInfo.MessageNum, RBT)); item.SendData.Add(data); user.session.TrySend(data); } } }
/// <summary> /// /// </summary> /// <param name="requestInfo">请求信息</param> /// <param name="sendmj">返回开始游戏集合</param> /// <param name="ReturnGangMSG">返回杠牌集合信息</param> /// <param name="Ruturnjsmj">返回打出叫牌的集合</param> /// <param name="session">ss请求</param> /// <param name="roomID">房间ID</param> /// <param name="mj">当前玩家</param> /// <param name="number">请求次数</param> /// <param name="openid"></param> public void GetMyCards(ProtobufRequestInfo requestInfo, ReturnStartGame.Builder sendmj, ReturnGang.Builder ReturnGangMSG, List <model.ServerMaJiang> Ruturnjsmj, GameSession session, int roomID, mjuser mj, string openid, ref int number) { ReturnGangMSG = ReturnGang.CreateBuilder(); Ruturnjsmj = new List <model.ServerMaJiang>(); ///房间牌堆 List <model.ServerMaJiang> listmj = new List <model.ServerMaJiang>(); CreateMj C = new CreateMj(); mj.MopaiNumber = 0; ///房间牌堆赋值 Room R = new Room(); Room_JX rjx = new Room_JX(); rjx = Gongyong.room_JX.Find(u => u.room_id == roomID); if (rjx != null) { rjx.room_peo = 0; } R = Gongyong.roomlist.Find(u => u.RoomID == roomID); R.MPS++; if (Gongyong.roomlist.Find(u => u.RoomID == roomID).RoomPai.Count == 0) { listmj = C.CreateMJ(R.IsYuanQue); } else { listmj = R.RoomPai; } #if DEBUG /* listmj.Insert(0, new ServerMaJiang { PaiHs = 2, PaiId = 201 }); * listmj.Insert(0, new ServerMaJiang { PaiHs = 2, PaiId = 202 }); * listmj.Insert(0, new ServerMaJiang { PaiHs = 2, PaiId = 203 }); * listmj.Insert(0, new ServerMaJiang { PaiHs = 2, PaiId = 204 }); * listmj.Insert(0, new ServerMaJiang { PaiHs = 1, PaiId = 205 }); * listmj.Insert(0, new ServerMaJiang { PaiHs = 1, PaiId = 206 }); * listmj.Insert(0, new ServerMaJiang { PaiHs = 1, PaiId = 207 }); * listmj.Insert(0, new ServerMaJiang { PaiHs = 1, PaiId = 208 }); * listmj.Insert(0, new ServerMaJiang { PaiHs = 5, PaiId = 209 }); * listmj.Insert(0, new ServerMaJiang { PaiHs = 5, PaiId = 210 }); * listmj.Insert(0, new ServerMaJiang { PaiHs = 6, PaiId = 211 }); * listmj.Insert(0, new ServerMaJiang { PaiHs = 6, PaiId = 212 }); * listmj.Insert(0, new ServerMaJiang { PaiHs = 7, PaiId = 213 }); * listmj.Insert(0, new ServerMaJiang { PaiHs = 7, PaiId = 214 }); */ #endif R.startgame = 1; CardUser cu = Gongyong.FKUser.Find(u => u.roomid == roomID); if (cu == null) { cu = new CardUser(); cu.roomid = roomID; cu.win = 1; cu.dong = 0; cu.xi = 0; cu.nan = 0; cu.bei = 0; cu.jushu = 0; cu.dongM = 0; cu.xiM = 0; cu.nan = 0; cu.beiM = 0; cu.lianzCount = 1; Gongyong.FKUser.Add(cu); } else { cu.dongM = 0; cu.xiM = 0; cu.beiM = 0; } // int x = 0; int y = 0; #region 根据玩家方位判断玩家手牌 string logs = ""; for (int i = 0; i < listmj.Count; i++) { logs += listmj[i].PaiHs + ","; } session.Logger.Debug("牌堆" + logs); //int x = 0; //int y = 0; if (mj.ZS_Fw == cu.win) { // x = 0; y = 14; } else { // x = 0; y = 13; } #endregion ///组装下发数据 foreach (var item in listmj.Take(y)) { MaJiang fanmj = MaJiang.CreateBuilder().SetPaiHS(item.PaiHs).SetPaiID(item.PaiId).Build(); mj.majiangs.Add(item); int count = mj.majiangs.Count; sendmj.AddMj(fanmj); } // number += y; listmj.RemoveRange(0, y); R.RoomPai = listmj; mj.majiangs.Sort((a, b) => - b.PaiHs.CompareTo(a.PaiHs)); Gongyong.mulist.Add(mj); Ting t = new Ting(); List <model.ServerMaJiang> listT = new List <model.ServerMaJiang>(); listT.AddRange(mj.majiangs.ToArray()); UserInfo userSendJ = Gongyong.userlist.Find(u => u.openid == openid); int PaiHS = 0; if (R.room_peo == 4 || R.IsYuanQue) { if (cu.win == mj.ZS_Fw) { foreach (var item in listT) { List <model.ServerMaJiang> listchuan = listT.FindAll(u => u.PaiHs == item.PaiHs); if (listchuan.Count == 4) { if (PaiHS != item.PaiHs) { var PGH = ReturnAll.CreateBuilder(); var mjG = MaJiang.CreateBuilder(); mjG.SetPaiHS(item.PaiHs); mjG.SetPaiID(item.PaiId); ReturnGangMSG.AddGang(GangMSG.CreateBuilder().SetFw(cu.win).SetMj(mjG).SetType(3)); } PaiHS = item.PaiHs; } } if (ReturnGangMSG.GangCount > 0) { byte[] bytegang = ReturnGangMSG.Build().ToByteArray(); userSendJ.session.TrySend(new ArraySegment <byte>(CreateHead.CreateMessage(GameInformationBase.BASEAGREEMENTNUMBER + 5022, bytegang.Length, requestInfo.MessageNum, bytegang))); } } } var ttAthState = ReturnTTATH.CreateBuilder(); if (cu.win == mj.ZS_Fw) { if (t.GetTing(listT) == "H") { if (R.room_peo < 4) { switch (mj.QYM) { case 1: if (mj.majiangs.FindAll(u => u.PaiHs < 10).Count <= 0) { // mj.Is_tiantX = -1; ttAthState.SetState(214); mj.Is_tianHu = true; } break; case 2: if (mj.majiangs.FindAll(u => u.PaiHs > 10 && u.PaiHs < 20).Count <= 0) { // mj.Is_tiantX = -1; ttAthState.SetState(214); mj.Is_tianHu = true; } break; case 3: if (mj.majiangs.FindAll(u => u.PaiHs > 20).Count <= 0) { //mj.Is_tiantX = -1; ttAthState.SetState(214); mj.Is_tianHu = true; } break; default: break; } } else { ttAthState.SetState(214); // mj.Is_tiantX = -1; mj.Is_tianHu = true; } } else { if (R.room_peo < 4) { switch (mj.QYM) { case 1: if (mj.majiangs.FindAll(u => u.PaiHs < 10).Count <= 0) { ///庄家报听判断 List <model.ServerMaJiang> JPMJ = new List <model.ServerMaJiang>(); JPMJ.AddRange(mj.majiangs.ToArray()); Ruturnjsmj = t.ReturnJMJ(JPMJ); } break; case 2: if (mj.majiangs.FindAll(u => u.PaiHs > 10 && u.PaiHs < 20).Count <= 0) { ///庄家报听判断 List <model.ServerMaJiang> JPMJ = new List <model.ServerMaJiang>(); JPMJ.AddRange(mj.majiangs.ToArray()); Ruturnjsmj = t.ReturnJMJ(JPMJ); } break; case 3: if (mj.majiangs.FindAll(u => u.PaiHs > 20).Count <= 0) { ///庄家报听判断 List <model.ServerMaJiang> JPMJ = new List <model.ServerMaJiang>(); JPMJ.AddRange(mj.majiangs.ToArray()); Ruturnjsmj = t.ReturnJMJ(JPMJ); } break; default: break; } } else { ///庄家报听判断 List <model.ServerMaJiang> JPMJ = new List <model.ServerMaJiang>(); JPMJ.AddRange(mj.majiangs.ToArray()); Ruturnjsmj = t.ReturnJMJ(JPMJ); } } } else { ///判断天听 if (t.GetTing(listT) != "MJ") { if (R.room_peo < 4) { switch (mj.QYM) { case 1: if (mj.majiangs.FindAll(u => u.PaiHs < 10).Count <= 0) { ttAthState.SetState(213); mj.Is_tiantX = -1; mj.Is_tiant = true; } break; case 2: if (mj.majiangs.FindAll(u => u.PaiHs > 10 && u.PaiHs < 20).Count <= 0) { ttAthState.SetState(213); mj.Is_tiantX = -1; mj.Is_tiant = true; } break; case 3: if (mj.majiangs.FindAll(u => u.PaiHs > 20).Count <= 0) { ttAthState.SetState(213); mj.Is_tiantX = -1; mj.Is_tiant = true; } break; default: break; } } else { ttAthState.SetState(213); mj.Is_tiantX = -1; mj.Is_tiant = true; } } } if (Ruturnjsmj.Count > 0) { var returntp = ReturnTP.CreateBuilder(); var tmj = MaJiang.CreateBuilder(); foreach (var mjItem in Ruturnjsmj) { tmj.SetPaiHS(mjItem.PaiHs); tmj.SetPaiID(mjItem.PaiId); returntp.AddMj(tmj); } byte[] tmjsr = returntp.Build().ToByteArray(); userSendJ.session.TrySend(new ArraySegment <byte>(CreateHead.CreateMessage(GameInformationBase.BASEAGREEMENTNUMBER + 2009, tmjsr.Length, requestInfo.MessageNum, tmjsr))); } sendmj.SetChuuser(cu.win); sendmj.SetGamenumber(number); //牌局回放 发牌 R.gameOperationProcess.AddGameOperationInfo(GameOperationInfo.CreateBuilder() .SetOperationFW(mj.ZS_Fw) .AddRangeMJ(sendmj.MjList) .SetSerialNumber(R.gameOperationProcess.GameOperationInfoCount) .SetOperationType(0) .SetChuUser(cu.win) ); byte[] sendbyte = sendmj.Build().ToByteArray(); userSendJ.session.TrySend(new ArraySegment <byte>(CreateHead.CreateMessage(GameInformationBase.BASEAGREEMENTNUMBER + 2006, sendbyte.Length, requestInfo.MessageNum, sendbyte))); if (ttAthState.HasState) { byte[] sendbytes = ttAthState.Build().ToByteArray(); userSendJ.session.TrySend(new ArraySegment <byte>(CreateHead.CreateMessage(GameInformationBase.BASEAGREEMENTNUMBER + 2010, sendbytes.Length, requestInfo.MessageNum, sendbytes))); } ///判断房间人数满足 并且没有天听用户才发生活跃用户 if (R.MPS == R.room_peo) { List <mjuser> listmjuserstart = Gongyong.mulist.FindAll(u => u.RoomID == mj.RoomID); var userbool = Gongyong.mulist.FindAll(u => u.RoomID == R.RoomID && u.Is_tiant == true); if (userbool.Count == 0 && (R.room_peo == 4 || R.IsYuanQue))//当原缺或者四人桌,没有人天听的时候 为庄家挂上倒计时出牌 { byte[] startHY = ReturnHyUser.CreateBuilder().SetCz("3001").SetFw(cu.win).Build().ToByteArray(); R.DQHY = cu.win; R.DQcz = "3001"; foreach (var item in listmjuserstart) { UserInfo user = Gongyong.userlist.Find(u => u.openid == item.Openid); user.IsActive = true; user.session.TrySend(new ArraySegment <byte>(CreateHead.CreateMessage(GameInformationBase.BASEAGREEMENTNUMBER + 7004, startHY.Length, GameInformationBase.BASEAGREEMENTNUMBER + 7093, startHY))); } if (number == 0) { ThreadUtility.StartManagedThread(listmjuserstart.Find(w => w.ZS_Fw == cu.win).Openid, R.RoomID, R.DQcz); } } else if (userbool.Count > 0)//当有天听时, 为每个天听用户挂上倒计时 { R.DQHY = 0; R.DQcz = "30071"; if (number == 0) { foreach (var item in userbool) { ThreadUtility.StartManagedThread(item.Openid, R.RoomID, R.DQcz); } } } else//需要选择缺一门时 为每个用户挂上倒计时 { R.DQHY = 0; R.DQcz = "3002"; if (number == 0) { foreach (var item in listmjuserstart) { ThreadUtility.StartManagedThread(item.Openid, R.RoomID, R.DQcz); } } } foreach (var item in listmjuserstart) { UserInfo user = Gongyong.userlist.Find(u => u.openid == item.Openid); byte[] returnzhuang = ReturnZhuang.CreateBuilder().SetZhuang(cu.win).SetSeizi(cu.Points).SetZhuangCount(cu.lianzCount).Build().ToByteArray(); user.session.TrySend(new ArraySegment <byte>(CreateHead.CreateMessage(GameInformationBase.BASEAGREEMENTNUMBER + 5020, returnzhuang.Length, GameInformationBase.BASEAGREEMENTNUMBER + 7093, returnzhuang))); } // ThreadUtility.StartManagedThread(R.RoomID.ToString(), R.RoomID); StringBuilder mjrz = new StringBuilder(); //foreach (var item in mj.majiangs) //{ // mjrz.Append(item.PaiHs + ","); //} //session.Logger.Debug("方位------" + mj.ZS_Fw + "----" + mjrz); number++; } }