//---------------------------------------------------------------------------------------------------------------------- /// <summary> /// 清空本脚本所涉及的所有集合,更改 /// </summary> public static void ClearAllListsAndChanges() { nowFW = 0; HYFw = 0; recon = false;//? cfj = false; cfwgj = false; CardsNumber = 0; isTT = false; isHhouTing = false; isClosed = false; queType = QueType.no; IsTingPai = false; isRealTing = false; IsDingQue = false; IsDingQueClick = false; IsDingQueGang = false; IsGang = false; pengInfo = null; huPaiInfo = null; returnHByType = null; returnTP = null; cunGang = null; jieSanOpenid = null; GroupID = 0; isStartGame = false; TT_bl = false; gameName = ""; cunHtypeType = 0; addStatus = 0; }
/// <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) { 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="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); }
/// <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++; } }