/// <summary> /// 麻将洗牌方法 /// </summary> /// <returns></returns> public List <model.ServerMaJiang> CreateMJ(bool isYuanQue) { List <model.ServerMaJiang> UserMj = new List <model.ServerMaJiang>(); List <int> tempMj = new List <int>(); for (int i = 1; i <= 120; i++) { if (i % 10 != 0) { tempMj.Add(i); } } List <int> AllMj = RandomSortList(tempMj); UserMj.Clear(); int paiCount = 108; //if (isYuanQue) // paiCount = 72; for (int i = 0; i < paiCount; i++) { model.ServerMaJiang mj = new model.ServerMaJiang(); if (AllMj[i] > 0 && AllMj[i] < 40) { mj.PaiHs = AllMj[i] % 10; mj.PaiId = AllMj[i]; } else if (AllMj[i] > 40 && AllMj[i] < 80) { mj.PaiHs = 10 + AllMj[i] % 10; mj.PaiId = AllMj[i]; } else if (!isYuanQue) { mj.PaiHs = 20 + AllMj[i] % 10; mj.PaiId = AllMj[i]; } if (mj.PaiHs != 0) { UserMj.Add(mj); } } return(UserMj); }
/// <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); }
public void ExecuteCommand(GameSession session, ProtobufRequestInfo requestInfo) { string userWinLose = string.Empty;//玩家输赢记录。房间信息表 if (!Gongyong.userlist.Any(w => w.session.SessionID.Equals(session.SessionID))) { session.Logger.Debug("GetH : 非法连接"); session.Close(); return; } var getdata = SendHu.ParseFrom(requestInfo.Body); Room r = Gongyong.roomlist.Find(u => u.RoomID == getdata.Roomid); if (r == null) { return; } if (!r.Is_Hu) { session.Logger.Debug("房间并无胡牌"); return; } ThreadUtility.RemoveManagedThreadByRoomID(r.RoomID); CardUser card = Gongyong.FKUser.Find(u => u.roomid == getdata.Roomid); model.ServerMaJiang mjfh = new model.ServerMaJiang(); var jp = ReturnFJ.CreateBuilder(); var muuser = Gongyong.mulist.Find(u => u.Openid.Equals(getdata.Openid) && u.RoomID == getdata.Roomid); if (muuser == null) { return; } muuser.Is_jiao = true; if (muuser.ByteData == requestInfo.Key) { return; } else { muuser.ByteData = requestInfo.Key; } var huType = ReturnHType.CreateBuilder().SetFWZ(getdata.FWZ).SetFWB(getdata.FWB).SetMJ(getdata.MJ).SetType(getdata.Type); if (getdata.DXInfoCount > 1) { huType.AddRangeDXInfo(getdata.DXInfoList); } byte[] HType = huType.Build().ToByteArray(); if (getdata.Type != 1 && getdata.Type != 5) { model.ServerMaJiang mjh = new model.ServerMaJiang() { PaiHs = getdata.MJ.PaiHS, PaiId = getdata.MJ.PaiID }; var roomUsers = Gongyong.mulist.FindAll(u => u.RoomID == getdata.Roomid); if (getdata.DXInfoCount > 1) { for (int i = 0; i < getdata.DXInfoList.Count; i++) { foreach (var item in roomUsers) { if (item.ZS_Fw == getdata.DXInfoList[i].DXFW)//如果当期玩家为一炮多响的玩家之一,则在手牌中加上 放炮的牌 { item.majiangs.Add(mjh); } } } } else { roomUsers.Find(u => u.ZS_Fw == getdata.FWZ).majiangs.Add(mjh); } } if (getdata.Type == 1 || getdata.Type == 5) { Gongyong.mulist.Find(u => u.ZS_Fw == getdata.FWZ && u.RoomID == getdata.Roomid).zm_count += 1; } else { var mjInfo = Gongyong.mulist.Find(u => u.ZS_Fw == getdata.FWB && u.RoomID == getdata.Roomid); mjInfo.dp_count += 1; mjInfo.chuda.RemoveAll(w => w.PaiHs == getdata.MJ.PaiHS && w.PaiId == getdata.MJ.PaiID); } ///没有翻鸡牌 if (r.RoomPai.Count == 0) { mjfh.PaiHs = -1; mjfh.PaiId = 0; } else { mjfh = r.RoomPai[0]; } jp.SetHS(mjfh.PaiHs); ///清除牌 r.RoomPai.Clear(); List <mjuser> mjlist = Gongyong.mulist.FindAll(u => u.RoomID == getdata.Roomid); var settle = ReturnJS.CreateBuilder(); var returnallmj = ReturnUserSPai.CreateBuilder(); List <UserSettle> listjs = new List <UserSettle>(); listjs = new Ting().Settle(r.RoomID, mjfh, getdata); var senddjs = ReturnDJS.CreateBuilder(); if (getdata.DXInfoCount <= 1) { if (getdata.FWZ != card.win) { card.win = getdata.FWZ; card.lianzCount = 1; } else// (getdata.FWZ == card.win) { card.lianzCount += 1; } } else {//连庄情况 ,庄家放炮,胡牌的庄, 一炮多响情况 就是 胡牌的最近的人是庄 //一炮多响非连庄, 谁放炮 谁是庄 if (r.is_lianz) { int zhuang = 0; if (getdata.FWB == card.win) { if (getdata.FWB == 4) { zhuang = 1; } else { zhuang = getdata.FWB + 1; } for (int i = 1; i <= 4; i++) { if (getdata.FWB == 4) { zhuang = 1; } if (getdata.DXInfoList.Any(w => w.DXFW == zhuang)) { card.win = zhuang; break; } zhuang++; } } else { card.lianzCount += 1; } } else { card.win = getdata.FWB; } //非连庄谁放炮谁 是庄 } foreach (var item in mjlist) { var jsddr = UserAJS.CreateBuilder(); #region 旧代码 //if (item.ZS_Fw == getdata.FWZ) //{ // ///判断清一色 // //if (item.majiangs[item.majiangs.Count - 1].PaiHs - item.majiangs[0].PaiHs < 8) // //{ // // int paihs = item.majiangs[0].PaiHs; // // int qyshs = 0; // // int qy = 0; // // if (paihs < 10) // // { // // qyshs = 1; // // } // // else if (paihs > 10 && paihs < 20) // // { // // qyshs = 2; // // } // // else // // { // // qyshs = 3; // // } // // switch (qyshs) // // { // // case 1: // // int count = item.Peng.FindAll(u => u.PaiHs > 10).Count; // // if (count > 0) // // { // // qy++; // // } // // if (!string.IsNullOrEmpty(item.Gong)) // // { // // string gong = string.Copy(item.Gong); // // string[] arr = gong.Remove(gong.Length - 1, 1).Split(','); // // foreach (var itemgong in arr) // // { // // if (int.Parse(itemgong[0].ToString()) > 10) // // { // // qy++; // // } // // } // // } // // break; // // case 2: // // int countt = item.Peng.FindAll(u => u.PaiHs < 10 || u.PaiHs > 20).Count; // // if (countt > 0) // // { // // qy++; // // } // // if (!string.IsNullOrEmpty(item.Gong)) // // { // // string gong = string.Copy(item.Gong); // // string[] arr = gong.Remove(gong.Length - 1, 1).Split(','); // // foreach (var itemgong in arr) // // { // // if (int.Parse(itemgong[0].ToString()) < 10 || int.Parse(itemgong[0].ToString()) > 20) // // { // // qy++; // // } // // } // // } // // break; // // case 3: // // int countw = item.Peng.FindAll(u => u.PaiHs < 20).Count; // // if (countw > 0) // // { // // qy++; // // } // // if (!string.IsNullOrEmpty(item.Gong)) // // { // // string gong = string.Copy(item.Gong); // // string[] arr = gong.Remove(gong.Length - 1, 1).Split(','); // // foreach (var itemgong in arr) // // { // // if (int.Parse(itemgong[0].ToString()) < 20) // // { // // qy++; // // } // // } // // } // // break; // // default: // // break; // // } // // if (qy == 0) // // { // // item.paixinfs = 10; // // } // //} //} #endregion UserInfo user = Gongyong.userlist.Find(u => u.openid == item.Openid); var usermjs = UserSPai.CreateBuilder(); usermjs.SetFw(item.ZS_Fw); var returnmj = MaJiang.CreateBuilder(); foreach (var itemmj in item.majiangs) { returnmj.SetPaiHS(itemmj.PaiHs); returnmj.SetPaiID(itemmj.PaiId); usermjs.AddMj(returnmj); } returnallmj.AddUsp(usermjs); UserInfo gamer = Gongyong.userlist.Find(u => u.openid == item.Openid); var 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).Build(); ///分数加减 foreach (var items in listjs) { if (items.openid == item.Openid) { var usersone = UserJS.CreateBuilder(); foreach (var itrmj in items.jp) { var jpone = JiPaiF.CreateBuilder().SetPaiHS(itrmj.PaiHS).SetType(itrmj.type).SetCount(itrmj.PaiScare); usersone.AddJp(jpone); } foreach (var itemD in items.gang) { var jpdou = Dou.CreateBuilder().SetCount(itemD.DScare).SetType(itemD.DType); usersone.AddDc(jpdou); } if (getdata.HasFWB) { var info = mjlist.Find(w => w.ZS_Fw == getdata.FWB && w.Openid.Equals(items.openid)); if (info != null) { if (items.pai_type != 11) { items.pai_type = 11; } } } usersone.SetIsPao(items.pai_type); usersone.SetIsJiao(items.is_jiao); usersone.SetFS(items.scare); usersone.SetUserinfo(users); usersone.SetDyFs(items.dy_fs); var HuLeiXin = getdata.DXInfoList.FirstOrDefault(w => w.DXFW == item.ZS_Fw); if (HuLeiXin != null) { usersone.SetHuType(HuLeiXin.DXType); } settle.AddJs(usersone); switch (item.ZS_Fw) { case 1: card.dong += items.scare; break; case 2: card.nan += items.scare; break; case 3: card.xi += items.scare; break; case 4: card.bei += items.scare; break; default: break; } } } ///牌局结束,返回大结算 if (r.Dcount == r.count) { new CardsLogic().Clear(item, r); jsddr.SetUser(users); jsddr.SetZdou(item.zwd_count); jsddr.SetZimo(item.zm_count); jsddr.SetAndou(item.ad_count); jsddr.SetMdou(item.MD_count); jsddr.SetDianpao(item.dp_count); //switch (item.ZS_Fw) //{ // case 1: // jsddr.SetScare(card.dong); // break; // case 2: // jsddr.SetScare(card.nan); // break; // case 3: // jsddr.SetScare(card.xi); // break; // case 4: // jsddr.SetScare(card.bei); // break; // default: // break; //} jsddr.SetScare(card.GetScoreByPosition(item.ZS_Fw)); senddjs.AddUserjs(jsddr); senddjs.SetState(1); RedisUtility.Remove(RedisUtility.GetKey(GameInformationBase.COMMUNITYUSERGAME, gamer.openid, gamer.unionid)); if (!string.IsNullOrEmpty(userWinLose)) { userWinLose += "|"; } userWinLose += user.UserID + "," + jsddr.Scare; } } //牌局回放 翻鸡 var gameOperationInfoFJ = GameOperationInfo.CreateBuilder().AddMJ(MaJiang.CreateBuilder().SetPaiHS(jp.HS).SetPaiID(0)).SetOperationType(9); StringBuilder logtxt = new StringBuilder(); logtxt.Append("胡牌" + getdata.ToString()); foreach (var item in mjlist) { item.SendData.Clear(); logtxt.Append(string.Join(",", item.majiangs.Select(w => w.PaiHs))); UserInfo user = Gongyong.userlist.Find(u => u.openid == item.Openid); var sendData5021 = new ArraySegment <byte>(CreateHead.CreateMessage(GameInformationBase.BASEAGREEMENTNUMBER + 5021, HType.Length, requestInfo.MessageNum, HType)); item.SendData.Add(sendData5021); byte[] allsp = returnallmj.Build().ToByteArray(); byte[] jpr = jp.Build().ToByteArray(); //7005 返回翻鸡牌 var sendData7005 = new ArraySegment <byte>(CreateHead.CreateMessage(GameInformationBase.BASEAGREEMENTNUMBER + 7005, jpr.Length, requestInfo.MessageNum, jpr)); item.SendData.Add(sendData7005); //7008 : 玩家手牌集合 var sendData7008 = new ArraySegment <byte>(CreateHead.CreateMessage(GameInformationBase.BASEAGREEMENTNUMBER + 7008, allsp.Length, requestInfo.MessageNum, allsp)); item.SendData.Add(sendData7008); byte[] settlebyte = settle.Build().ToByteArray(); r.gameOperationProcess.SetJieSuanInfo(ByteString.CopyFrom(settlebyte)); //7009 : 返回结算信息(全体) var sendData = new ArraySegment <byte>(CreateHead.CreateMessage(GameInformationBase.BASEAGREEMENTNUMBER + 7009, settlebyte.Length, requestInfo.MessageNum, settlebyte)); item.SendData.Add(sendData); if (r.Dcount == r.count) { byte[] senddjsbyte = senddjs.Build().ToByteArray(); //5014 : 大结算信息 var sendData5014 = new ArraySegment <byte>(CreateHead.CreateMessage(GameInformationBase.BASEAGREEMENTNUMBER + 5014, senddjsbyte.Length, requestInfo.MessageNum, senddjsbyte)); item.SendData.Add(sendData5014); } foreach (var senddata in item.SendData) { user.session.TrySend(senddata); } } session.Logger.Debug(logtxt); //牌局回放 胡牌 var gameOperationInfo = GameOperationInfo.CreateBuilder() .SetSerialNumber(r.gameOperationProcess.GameOperationInfoCount) .SetOperationFW(huType.FWZ) .SetOperationType(5) .SetTingHuType(muuser.Is_tianHu ? 1 : 0) .SetPaoFW(huType.FWB); if (getdata.DXInfoCount > 1) { gameOperationInfo.AddRangeDXInfo(getdata.DXInfoList); } r.gameOperationProcess.AddGameOperationInfo(gameOperationInfo); gameOperationInfoFJ.SetSerialNumber(r.gameOperationProcess.GameOperationInfoCount).SetOperationFW(0); r.gameOperationProcess.AddGameOperationInfo(gameOperationInfoFJ); try { CardsLogic.AddboarddetailsTB(r); } catch (Exception ex) { session.Logger.Error(ex); } ///对局结束 清空所有信息 if (r.Dcount == r.count) { Gongyong.mulist.RemoveAll(u => u.RoomID == r.RoomID); Gongyong.FKUser.RemoveAll(u => u.roomid == r.RoomID); Gongyong.roomlist.RemoveAll(u => u.RoomID == r.RoomID); RedisUtility.Remove(RedisUtility.GetKey(GameInformationBase.COMMUNITYROOMINFO, r.RoomID.ToString(), "")); new RoomInfoDAL().UpdateEndRoomInfoByRoomInfoID(new RoomInfo { RoomInfoID = r.RoomInfoID, EndTime = DateTime.Now, EndStatus = 0, UserWinLose = userWinLose }); foreach (var item in mjlist) { UserInfo user = Gongyong.userlist.Find(u => u.openid == item.Openid); new userRecordLOGDAL().Add(new userRecordlogLOG { UserID = user.UserID, RoomInfoID = r.RoomInfoID, UserWinLose = userWinLose, EndTime = DateTime.Now, CreateDate = r.CreateDate, RoomID = r.RoomID }); } r.startgame = 0; } else { if (r != null) { r.RoomPai = new CreateMj().CreateMJ(r.IsYuanQue); r.Dcount += 1; r.startgame = 2; } } }
/// <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(" Gang : 非法连接"); session.Close(); return; } var returnmsg = ReturnMsg.CreateBuilder(); var retumsg = ReturnPeng.CreateBuilder(); var sendinfo = SendPeng.ParseFrom(requestInfo.Body); session.Logger.Debug(sendinfo); var jp = ReturnFJ.CreateBuilder(); Room r = Gongyong.roomlist.Find(u => u.RoomID == sendinfo.Roomid); mjuser mjuser = Gongyong.mulist.Find(u => u.RoomID == sendinfo.Roomid && u.Openid == sendinfo.Openid); List <mjuser> mjlist = Gongyong.mulist.FindAll(u => u.RoomID == sendinfo.Roomid); List <model.ServerMaJiang> listmj = new List <model.ServerMaJiang>(); model.ServerMaJiang mjfh = new model.ServerMaJiang(); if (!string.IsNullOrEmpty(mjuser.ByteData) && mjuser.ByteData.Equals(sendinfo.ToString())) { session.Logger.Debug("消息重复"); return; } else { mjuser.ByteData = sendinfo.ToString(); } if (mjuser == null) { session.Logger.Debug("用户不存在"); return; } if (r.DQHY != 0 && r.DQHY != mjuser.ZS_Fw) { session.Logger.Debug("不是活跃用户"); return; } mjuser.SendData.Clear(); ThreadUtility.RemoveManagedThread(mjuser.Openid); //当用户已做操作 取消用户的倒计时 var zrjxx = ReturnZR.CreateBuilder(); List <HuInfo> huList = new List <HuInfo>(); //处理一炮多响新增一个胡牌类型对象 var info = mjlist.FirstOrDefault(w => w.ZS_Fw == sendinfo.FW); bool isDelete = false; if (info != null)//先删除牌,否则过牌时判断冲锋鸡 会有问题 { session.Logger.Debug("删除牌前手牌有 " + info.chuda.Count); isDelete = info.chuda.Remove(info.chuda.Find(w => w.PaiHs == sendinfo.Mj.PaiHS && w.PaiId == sendinfo.Mj.PaiID)); session.Logger.Debug("删除牌前手牌后 " + info.chuda.Count); } ///不是过 if (sendinfo.State == 1) { switch (sendinfo.Types) { ///碰 case 1: if (sendinfo.Mj.PaiHS != r.LastChuMJ.PaiHs || sendinfo.Mj.PaiID != r.LastChuMJ.PaiId) { session.Logger.Debug(r.LastChuMJ + "碰的牌不是最后一张打出的牌" + mjuser.Openid); return; } listmj = mjuser.majiangs.FindAll(u => u.PaiHs == sendinfo.Mj.PaiHS); List <model.ServerMaJiang> listP = mjuser.majiangs.FindAll(u => u.PaiHs == sendinfo.Mj.PaiHS); if (listP.Count < 2) { session.Logger.Debug("碰的牌不够2张" + mjuser.Openid); return; } mjuser.majiangs.Remove(listP[0]); mjuser.majiangs.Remove(listP[1]); mjuser.Peng.AddRange(listmj); mjuser.Peng.Add(listmj[0]); retumsg.SetState(1); retumsg.SetMj(sendinfo.Mj); retumsg.SetFw(mjuser.ZS_Fw); retumsg.SetPfw(sendinfo.FW); int cfj = 0; int wgj = 0; mjuser mjnewusers = Gongyong.mulist.Find(u => u.ZS_Fw == sendinfo.FW && u.RoomID == sendinfo.Roomid); //判断责任鸡 if (sendinfo.Mj.PaiHS == 11) { foreach (var item in mjlist) { int count = item.chuda.FindAll(u => u.PaiHs == 11).Count; if (count > 0) { cfj++; break; } } if (cfj == 0) { mjuser.Is_zrj = 1; mjnewusers.Is_cfj = false; mjnewusers.Is_zrj = -1; zrjxx.SetGtype(1); zrjxx.SetZrfw(mjnewusers.ZS_Fw); zrjxx.SetDzrfw(mjuser.ZS_Fw); } } ///判断责任乌骨 if (r.is_wgj) { if (sendinfo.Mj.PaiHS == 8) { foreach (var item in mjlist) { int count = item.chuda.FindAll(u => u.PaiHs == 8).Count; if (count > 0) { wgj++; break; } } if (wgj == 0) { mjuser.is_zrwg = 1; mjnewusers.is_cfwg = false; mjnewusers.is_zrwg = -1; zrjxx.SetGtype(2); zrjxx.SetZrfw(mjnewusers.ZS_Fw); zrjxx.SetDzrfw(mjuser.ZS_Fw); } } } r.DQHY = mjuser.ZS_Fw; r.DQcz = "3001"; //出牌 //牌局回放 碰牌 r.gameOperationProcess.AddGameOperationInfo( GameOperationInfo.CreateBuilder() .SetSerialNumber(r.gameOperationProcess.GameOperationInfoCount) .SetOperationFW(mjuser.ZS_Fw) .SetOperationType(3) .AddMJ(sendinfo.Mj) .SetPengFW(mjnewusers.ZS_Fw) .SetMJType(mjuser.Is_zrj == 1 ? "ZRJ" : (mjuser.is_zrwg == 1 ? "ZRWG" : "")) ); break; //杠 case 2: int gangType = 0; ///杠类型判断 switch (sendinfo.Gtype) { case "A": //if (r.LastMoMJ != null && (sendinfo.Mj.PaiHS != r.LastMoMJ.PaiHs || sendinfo.Mj.PaiID != r.LastMoMJ.PaiId)) //{ // session.Logger.Debug("M杠的牌不是最后一张摸到的牌" + mjuser.Openid); // return; //} if (mjuser.majiangs.Where(w => w.PaiHs == sendinfo.Mj.PaiHS).Count() < 3) { session.Logger.Debug("A杠的牌不是不够3张" + mjuser.Openid); return; } mjuser.ad_count += 1; gangType = 5; break; case "Z": if (sendinfo.Mj.PaiHS != r.LastMoMJ.PaiHs || sendinfo.Mj.PaiID != r.LastMoMJ.PaiId) { session.Logger.Debug("M杠的牌不是最后一张摸到的牌" + mjuser.Openid); return; } if (!mjuser.Peng.Any(u => u.PaiHs == sendinfo.Mj.PaiHS)) { session.Logger.Debug("Z杠的牌不是不够3张" + mjuser.Openid); return; } mjuser.zwd_count += 1; gangType = 6; break; case "M": if (sendinfo.Mj.PaiHS != r.LastChuMJ.PaiHs || sendinfo.Mj.PaiID != r.LastChuMJ.PaiId) { session.Logger.Debug("M杠的牌不是最后一张打出的牌" + mjuser.Openid); return; } if (mjuser.majiangs.Where(w => w.PaiHs == sendinfo.Mj.PaiHS).Count() < 3) { session.Logger.Debug("M杠的牌不是不够3张" + mjuser.Openid); return; } mjuser.MD_count += 1; gangType = 4; break; case "H": if (mjuser.majiangs.Where(w => w.PaiHs == sendinfo.Mj.PaiHS).Count() < 3 && !mjuser.Peng.Any(u => u.PaiHs == sendinfo.Mj.PaiHS)) { session.Logger.Debug("H杠的牌不是不够3张或者碰牌区没有" + mjuser.Openid); return; } gangType = 7; break; default: break; } mjuser.majiangs.RemoveAll(u => u.PaiHs == sendinfo.Mj.PaiHS); mjuser.Gong += sendinfo.Mj.PaiHS + "|" + sendinfo.FW + "|" + sendinfo.Gtype + ","; retumsg.SetState(2); retumsg.SetMj(sendinfo.Mj); retumsg.SetFw(mjuser.ZS_Fw); retumsg.SetPfw(sendinfo.FW); retumsg.SetGtype(sendinfo.Gtype); //var gangInfo = mjlist.FirstOrDefault(w => w.ZS_Fw == sendinfo.FW); //if (gangInfo != null) // gangInfo.chuda.Remove(gangInfo.chuda.Find(w => w.PaiHs == sendinfo.Mj.PaiHS && w.PaiId == sendinfo.Mj.PaiID)); ///明豆 if (sendinfo.Gtype == "M") { mjuser mjnewuser = Gongyong.mulist.Find(u => u.ZS_Fw == sendinfo.FW && u.RoomID == sendinfo.Roomid); if (sendinfo.Mj.PaiHS == 11) { mjuser.Is_zrj = 1; mjnewuser.Is_cfj = false; mjnewuser.Is_zrj = -1; zrjxx.SetGtype(1); zrjxx.SetZrfw(mjnewuser.ZS_Fw); zrjxx.SetDzrfw(mjuser.ZS_Fw); } if (r.is_wgj) { if (sendinfo.Mj.PaiHS == 8) { mjuser.is_zrwg = 1; mjnewuser.is_cfwg = false; mjnewuser.is_zrwg = -1; zrjxx.SetGtype(2); zrjxx.SetZrfw(mjnewuser.ZS_Fw); zrjxx.SetDzrfw(mjuser.ZS_Fw); } } } ///转弯都抢杠 if (sendinfo.Gtype == "Z") { mjuser.Peng.RemoveAll(u => u.PaiHs == sendinfo.Mj.PaiHS); foreach (var item in mjlist) { if (item.ZS_Fw != mjuser.ZS_Fw) { List <model.ServerMaJiang> mah = new List <model.ServerMaJiang>(); mah.AddRange(item.majiangs.ToArray()); model.ServerMaJiang mjone = new model.ServerMaJiang() { PaiHs = sendinfo.Mj.PaiHS, PaiId = sendinfo.Mj.PaiID }; mah.Add(mjone); if (new Ting().GetTing(mah) == "H") { //var sendh = ReturnHByType.CreateBuilder(); //sendh.SetFWZ(item.ZS_Fw); //sendh.SetFWB(mjuser.ZS_Fw); //sendh.SetType(3); //sendh.SetMJ(sendinfo.Mj); //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 huInfo = new HuInfo(); huInfo.HuIndex = item.ZS_Fw; huInfo.HuType = 3; huInfo.MJ = mjone; huInfo.OpenID = item.Openid; huInfo.PaoIndex = mjuser.ZS_Fw; huInfo.RoomID = r.RoomID; huList.Add(huInfo); item.IsGrabBars = true; item.WasGrabbedUserOpenID = mjuser.Openid; r.DQHY = item.ZS_Fw; } } } //if (mjlist.Any(w => w.IsGrabBars)) // return; } //憨包豆 if (sendinfo.Gtype == "H") { if (mjuser.Peng.Any(u => u.PaiHs == sendinfo.Mj.PaiHS)) { mjuser.Peng.RemoveAll(u => u.PaiHs == sendinfo.Mj.PaiHS); foreach (var item in mjlist) { if (item.ZS_Fw != mjuser.ZS_Fw) { List <model.ServerMaJiang> mah = new List <model.ServerMaJiang>(); mah.AddRange(item.majiangs.ToArray()); model.ServerMaJiang mjone = new model.ServerMaJiang() { PaiHs = sendinfo.Mj.PaiHS, PaiId = sendinfo.Mj.PaiID }; mah.Add(mjone); if (new Ting().GetTing(mah) == "H") { //var sendh = ReturnHByType.CreateBuilder(); //sendh.SetFWZ(item.ZS_Fw); //sendh.SetFWB(mjuser.ZS_Fw); //sendh.SetType(3); //sendh.SetMJ(sendinfo.Mj); //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 huInfo = new HuInfo(); huInfo.HuIndex = item.ZS_Fw; huInfo.HuType = 3; huInfo.MJ = mjone; huInfo.OpenID = item.Openid; huInfo.PaoIndex = mjuser.ZS_Fw; huInfo.RoomID = r.RoomID; huList.Add(huInfo); item.IsGrabBars = true; item.WasGrabbedUserOpenID = mjuser.Openid; r.DQHY = item.ZS_Fw; } } } } } r.DQHY = mjuser.ZS_Fw; //牌局回放 杠牌 r.gameOperationProcess.AddGameOperationInfo( GameOperationInfo.CreateBuilder() .SetSerialNumber(r.gameOperationProcess.GameOperationInfoCount) .SetOperationFW(mjuser.ZS_Fw) .SetOperationType(4) .AddMJ(sendinfo.Mj) .SetPengFW(sendinfo.FW) .SetTingHuType(gangType) .SetMJType(mjuser.Is_zrj == 1 ? "ZRJ" : (mjuser.is_zrwg == 1 ? "ZRWG" : "")) ); break; case 3: //if (r.count == r.Dcount) //{ // Gongyong.roomlist.Remove(r); // Gongyong.mulist.RemoveAll(u => u.RoomID == sendinfo.Roomid); //} //mjfh = r.RoomPai[0]; //jp.SetHS(mjfh.PaiHs); break; default: break; } } //过 else { session.Logger.Debug("过牌"); string mjType = string.Empty; //过类型 if (sendinfo.Types == 1 || (sendinfo.Types == 2 && sendinfo.Gtype.Equals("M")) || (sendinfo.Types == 3 && sendinfo.FW != mjuser.ZS_Fw)) { //判断幺鸡过,是否下发冲锋鸡消息 if (sendinfo.Mj.PaiHS == 11) { bool cfj = true; // List<mjuser> listnewJP = Gongyong.mulist.FindAll(U => U.RoomID == sendinfo.Roomid); foreach (var item in mjlist) { int Ccount = item.chuda.FindAll(u => u.PaiHs == 11).Count; if (Ccount > 0) { cfj = false; } } if (cfj) { returnmsg.SetFW(sendinfo.FW); returnmsg.SetMj(MaJiang.CreateBuilder().SetPaiHS(0).SetPaiID(0)); returnmsg.SetMsg("CFJ"); info.Is_cfj = true; // listnewJP.Find(w => w.ZS_Fw == sendinfo.FW).chuda.Add(new model.ServerMaJiang { PaiHs = 11, PaiId = sendinfo.HasMj ? sendinfo.Mj.PaiID : 211 }); mjType = returnmsg.Msg; byte[] byteball = returnmsg.Build().ToByteArray(); foreach (var item in mjlist) { Gongyong.userlist.Find(u => u.openid == item.Openid).session.TrySend(new ArraySegment <byte>(CreateHead.CreateMessage(GameInformationBase.BASEAGREEMENTNUMBER + 3009, byteball.Length, requestInfo.MessageNum, byteball))); } } } ///判断乌骨鸡过是否下发乌骨鸡消息 if (sendinfo.Mj.PaiHS == 8) { bool WGJ = true; // List<mjuser> listnewJPW = Gongyong.mulist.FindAll(U => U.RoomID == sendinfo.Roomid); foreach (var item in mjlist) { int Ccount = item.chuda.FindAll(u => u.PaiHs == 8).Count; if (Ccount > 0) { WGJ = false; } } if (WGJ) { returnmsg.SetFW(sendinfo.FW); returnmsg.SetMj(MaJiang.CreateBuilder().SetPaiHS(0).SetPaiID(0)); returnmsg.SetMsg("CFWG"); info.is_cfwg = true; // listnewJPW.Find(w => w.ZS_Fw == sendinfo.FW).chuda.Add(new model.ServerMaJiang { PaiHs = 8, PaiId = sendinfo.HasMj ? sendinfo.Mj.PaiID : 208 }); mjType = returnmsg.Msg; byte[] byteball = returnmsg.Build().ToByteArray(); foreach (var item in mjlist) { Gongyong.userlist.Find(u => u.openid == item.Openid).session.TrySend(new ArraySegment <byte>(CreateHead.CreateMessage(GameInformationBase.BASEAGREEMENTNUMBER + 3009, byteball.Length, requestInfo.MessageNum, byteball))); } } } } if (isDelete) { info.chuda.Add(new model.ServerMaJiang { PaiHs = sendinfo.Mj.PaiHS, PaiId = sendinfo.HasMj ? sendinfo.Mj.PaiID : 208 }); } //牌局回放 过牌 if (returnmsg.HasMsg) { r.gameOperationProcess.AddGameOperationInfo( GameOperationInfo.CreateBuilder() .SetSerialNumber(r.gameOperationProcess.GameOperationInfoCount) .SetOperationFW(mjuser.ZS_Fw) .SetOperationType(7) .SetPengFW(returnmsg.FW) .SetMJType(returnmsg.Msg) ); } else { r.gameOperationProcess.AddGameOperationInfo( GameOperationInfo.CreateBuilder() .SetSerialNumber(r.gameOperationProcess.GameOperationInfoCount) .SetOperationFW(mjuser.ZS_Fw) .SetOperationType(7) ); } List <RoomMsgWirte> msglist = new List <RoomMsgWirte>(); msglist = Gongyong.roommsg.FindAll(u => u.roomid == r.RoomID); session.Logger.Debug("过牌判断" + msglist.Count); if (msglist.Count > 0 && sendinfo.Types != 4 && sendinfo.Types != 5) { foreach (var item in msglist) { var userInfo = Gongyong.userlist.Find(u => u.openid == item.openid); if (userInfo != null) { userInfo.session.TrySend(new ArraySegment <byte>(CreateHead.CreateMessage(GameInformationBase.BASEAGREEMENTNUMBER + item.xiaoxihao, item.ArrList.Length, requestInfo.MessageNum, item.ArrList))); r.DQHY = mjlist.Find(u => u.Openid.Equals(item.openid)).ZS_Fw; r.DQcz = item.operating; session.Logger.Debug("过牌后根据之前的消息分配活跃用户" + r.DQHY); } } Gongyong.roommsg.RemoveAll(u => u.roomid == r.RoomID); retumsg.SetState(4); retumsg.SetMj(sendinfo.Mj); } else if (mjuser.IsGrabBars) { session.Logger.Debug("过牌判断抢杠"); mjuser.IsGrabBars = false; var PGH = ReturnAll.CreateBuilder(); PGH.SetMo(1); PGH.SetFw(mjuser.ZS_Fw); PGH.SetMType(1); mjuser.Mtype = 1; byte[] bytegou = PGH.Build().ToByteArray(); var user = Gongyong.userlist.Find(u => u.openid.Equals(mjuser.WasGrabbedUserOpenID)); var mjaure = mjlist.Find(w => w.Openid.Equals(mjuser.WasGrabbedUserOpenID)); r.DQHY = mjaure.ZS_Fw; user.session.TrySend(new ArraySegment <byte>(CreateHead.CreateMessage(GameInformationBase.BASEAGREEMENTNUMBER + 3008, bytegou.Length, requestInfo.MessageNum, bytegou))); } ///下发摸牌出牌消息 else { session.Logger.Debug("过牌摸牌"); var shy = ReturnHyUser.CreateBuilder(); CardUser card = Gongyong.FKUser.Find(u => u.roomid == mjuser.RoomID); if (sendinfo.Types == 4 && mjuser.Is_tiant)//天听过牌 { mjuser.Is_tiantX = 0; mjuser.Is_tiant = false; if (!mjlist.Any(w => w.Is_tiantX == -1)) { r.DQHY = card.win; r.DQcz = "3001"; byte[] startHY = ReturnHyUser.CreateBuilder().SetCz("3001").SetFw(card.win).Build().ToByteArray(); foreach (var item in mjlist) { UserInfo user = Gongyong.userlist.Find(u => u.openid == item.Openid); user.session.TrySend(new ArraySegment <byte>(CreateHead.CreateMessage(GameInformationBase.BASEAGREEMENTNUMBER + 7004, startHY.Length, requestInfo.MessageNum, startHY))); } msglist = Gongyong.roommsg.FindAll(u => u.roomid == r.RoomID); if (msglist.Count > 0) { // Room r = Gongyong.roomlist.Find(u => u.RoomID == r.RoomID); foreach (var msgitem in msglist) { var userInfo = Gongyong.userlist.Find(u => u.openid == msgitem.openid); if (userInfo != null) { var mjUser = mjlist.Find(u => u.Openid.Equals(msgitem.openid)); r.DQHY = mjUser.ZS_Fw; mjUser.SendData.Clear(); var data = new ArraySegment <byte>(CreateHead.CreateMessage(GameInformationBase.BASEAGREEMENTNUMBER + msgitem.xiaoxihao, msgitem.ArrList.Length, requestInfo.MessageNum, msgitem.ArrList)); userInfo.session.TrySend(data); //session.Logger.Debug("过牌后根据之前的消息分配活跃用户" + r.DQHY); } } Gongyong.roommsg.RemoveAll(u => u.roomid == r.RoomID); } } return; } else if (sendinfo.Types == 5 && mjuser.Is_tianHu) { mjuser.Is_tianHu = false; r.DQHY = card.win; r.DQcz = "3001"; byte[] startHY = ReturnHyUser.CreateBuilder().SetCz("3001").SetFw(card.win).Build().ToByteArray(); foreach (var item in mjlist) { UserInfo user = Gongyong.userlist.Find(u => u.openid == item.Openid); user.session.TrySend(new ArraySegment <byte>(CreateHead.CreateMessage(GameInformationBase.BASEAGREEMENTNUMBER + 7004, startHY.Length, requestInfo.MessageNum, startHY))); } return; } else if ((sendinfo.Gtype.ToUpper() != "M" && sendinfo.Types == 2) || (sendinfo.Types == 3 && sendinfo.FW == mjuser.ZS_Fw)) { if (mjuser.majiangs.Any(w => w.PaiId == sendinfo.Mj.PaiID) || sendinfo.Mj.PaiID == 0)// 有些情况在放炮过牌的时候会让过牌的用户出牌,然而应该摸牌 { shy.SetCz("3001"); shy.SetFw(mjuser.ZS_Fw); retumsg.SetState(4); retumsg.SetMj(sendinfo.Mj); retumsg.SetFw(mjuser.ZS_Fw); retumsg.SetPfw(sendinfo.FW); r.DQcz = "3001"; } else { UserInfo user = Gongyong.userlist.Find(u => u.openid == mjuser.Openid); r.DQcz = "30083"; var PGH = ReturnAll.CreateBuilder(); PGH.SetMo(1); PGH.SetFw(mjuser.ZS_Fw); mjuser.Mtype = 0; byte[] bsss = PGH.Build().ToByteArray(); user.session.TrySend(new ArraySegment <byte>(CreateHead.CreateMessage(GameInformationBase.BASEAGREEMENTNUMBER + 3008, bsss.Length, requestInfo.MessageNum, bsss))); } } else //if( (sendinfo.Types == 3 && sendinfo.FW != mjuser.ZS_Fw)) { if (sendinfo.Types == 3 && sendinfo.FW != mjuser.ZS_Fw) { mjuser.IsGuoHu = true; } shy.SetCz("30083"); // int peocount = Convert.ToInt32(r.room_peo.Remove(1, 1)); int peocount = r.room_peo; if (sendinfo.FW == peocount) { r.DQHY = 1; r.DQcz = "30083"; string openid = mjlist.Find(u => u.ZS_Fw == 1).Openid; UserInfo user = Gongyong.userlist.Find(u => u.openid == openid); shy.SetFw(1); var PGH = ReturnAll.CreateBuilder(); PGH.SetMo(1); PGH.SetFw(mjuser.ZS_Fw); mjuser.Mtype = 0; byte[] bsss = PGH.Build().ToByteArray(); user.session.TrySend(new ArraySegment <byte>(CreateHead.CreateMessage(GameInformationBase.BASEAGREEMENTNUMBER + 3008, bsss.Length, requestInfo.MessageNum, bsss))); } else { r.DQHY = sendinfo.FW + 1; r.DQcz = "30083"; string openid = mjlist.Find(u => u.ZS_Fw == sendinfo.FW + 1).Openid; UserInfo user = Gongyong.userlist.Find(u => u.openid == openid); var PGH = ReturnAll.CreateBuilder(); PGH.SetMo(1); mjuser.Mtype = 0; PGH.SetFw(Gongyong.mulist.Find(u => u.ZS_Fw == sendinfo.FW + 1).ZS_Fw); shy.SetFw(Gongyong.mulist.Find(u => u.ZS_Fw == sendinfo.FW + 1).ZS_Fw); byte[] bsss = PGH.Build().ToByteArray(); user.session.TrySend(new ArraySegment <byte>(CreateHead.CreateMessage(GameInformationBase.BASEAGREEMENTNUMBER + 3008, bsss.Length, requestInfo.MessageNum, bsss))); } retumsg.SetState(4); if (sendinfo.Mj.HasPaiHS) { retumsg.SetMj(sendinfo.Mj); } retumsg.SetFw(mjuser.ZS_Fw); retumsg.SetPfw(sendinfo.FW); r.DQcz = "30083"; } byte[] senhy = shy.Build().ToByteArray(); session.Logger.Debug(shy.Build()); foreach (var item in mjlist) { UserInfo user = Gongyong.userlist.Find(u => u.openid == item.Openid); user.IsActive = true; user.session.TrySend(new ArraySegment <byte>(CreateHead.CreateMessage(GameInformationBase.BASEAGREEMENTNUMBER + 7004, senhy.Length, requestInfo.MessageNum, senhy))); } } } if (huList.Count > 0) { if (huList.Count > 1 || huList[0].HuType == 3) { r.Is_Hu = true; 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(sendinfo.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 }); } else { var sendh = ReturnHByType.CreateBuilder(); sendh.SetFWZ(huList[0].HuIndex); sendh.SetFWB(huList[0].PaoIndex); sendh.SetType(huList[0].HuType); sendh.SetMJ(sendinfo.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)); mjlist.Find(w => w.Openid.Equals(huList[0].OpenID)).SendData.Add(sendData); Gongyong.userlist.Find(u => u.openid == huList[0].OpenID).session.TrySend(sendData); } } else if (sendinfo.State == 1 && sendinfo.Types == 2) { r.Is_Hu = false; var PGH = ReturnAll.CreateBuilder(); PGH.SetMo(1); PGH.SetFw(mjuser.ZS_Fw); PGH.SetMType(1); mjuser.Mtype = 1; byte[] bytegou = PGH.Build().ToByteArray(); session.TrySend(new ArraySegment <byte>(CreateHead.CreateMessage(GameInformationBase.BASEAGREEMENTNUMBER + 3008, bytegou.Length, requestInfo.MessageNum, bytegou))); } else if (sendinfo.State == 2)//过牌后 会摸牌,不能强制修改为 出牌 { } else { r.Is_Hu = false; r.DQcz = "3001"; } var settle = ReturnJS.CreateBuilder(); session.Logger.Debug("处理完成下发消息"); foreach (var item in mjlist) { UserInfo user = Gongyong.userlist.Find(u => u.openid == item.Openid); //if (sendinfo.Types == 3 && sendinfo.State == 1) //{ // byte[] jpr = jp.Build().ToByteArray(); // user.session.TrySend(new ArraySegment<byte>(CreateHead.CreateMessage(GameInformationBase.BASEAGREEMENTNUMBER + 7005, jpr.Length, requestInfo.MessageNum, jpr))); // byte[] settlebyte = settle.Build().ToByteArray(); // user.session.TrySend(new ArraySegment<byte>(CreateHead.CreateMessage(GameInformationBase.BASEAGREEMENTNUMBER + 7009, settlebyte.Length, requestInfo.MessageNum, settlebyte))); //} //else //{ byte[] b = retumsg.Build().ToByteArray(); user.session.TrySend(new ArraySegment <byte>(CreateHead.CreateMessage(GameInformationBase.BASEAGREEMENTNUMBER + 4002, b.Length, requestInfo.MessageNum, b))); //} if (zrjxx.Dzrfw != 0) { byte[] zrj = zrjxx.Build().ToByteArray(); user.session.TrySend(new ArraySegment <byte>(CreateHead.CreateMessage(GameInformationBase.BASEAGREEMENTNUMBER + 5018, zrj.Length, requestInfo.MessageNum, zrj))); } } ThreadUtility.StartManagedThread(Gongyong.mulist.Find(w => w.ZS_Fw == r.DQHY && w.RoomID == r.RoomID).Openid, r.RoomID, r.DQcz); }