Beispiel #1
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);
        }
Beispiel #2
0
        public void CallBack(object state)
        {
            var roomInfo = Gongyong.roomlist.Find(w => w.RoomID == roomID);

            if (roomInfo == null)
            {
                return;
            }
            var muInfo = Gongyong.mulist.Find(w => w.Openid.Equals(openID));

            if (muInfo == null)
            {
                return;
            }

            //lock (ThreadUtility.myObject)
            //{ }
            if (roomInfo.QuickCard)//只有快速出牌才会有10秒出牌roomInfo.DQHY== mulist.ZS_Fw
            {
                var info     = new ProtobufRequestInfo();
                var userInfo = Gongyong.userlist.Find(w => w.openid.Equals(muInfo.Openid));
                if (currentOperation.IndexOf("30071") >= 0 && muInfo.Is_tiantX == -1)//天听
                {
                    userInfo.session.Logger.Debug("10秒后自动30071:" + userInfo.openid);
                    info = new ProtobufRequestInfo();
                    // var userInfo = Gongyong.userlist.Find(w => w.openid.Equals(muInfo.Openid));
                    var guo = SendPeng.CreateBuilder()
                              .SetState(2)
                              .SetOpenid(userInfo.openid)
                              .SetRoomid(roomID)
                              .SetTypes(4);
                    info = new ProtobufRequestInfo();

                    guo.SetFW(roomInfo.DQHY);
                    info.Body          = guo.Build().ToByteArray();
                    info.Key           = "14001";
                    info.Messagelength = info.Body.Length;
                    info.MessageNum    = 14001;
                    info.MessageResNum = 0;
                    new Gang().ExecuteCommand(userInfo.session, info);
                }
                else if (currentOperation.IndexOf("3002") >= 0 && muInfo.QYM == 0)
                {
                    userInfo.session.Logger.Debug("10秒后自动3002:" + userInfo.openid);
                    //foreach (var item in Gongyong.mulist.FindAll(w =>w.RoomID==roomID&& w.QYM == 0))
                    //{  }
                    info     = new ProtobufRequestInfo();
                    userInfo = Gongyong.userlist.Find(w => w.openid.Equals(muInfo.Openid));
                    var qym    = muInfo.majiangs.Select(w => new { Tong = (w.PaiHs < 10 ? 1 : 0), Tiao = (w.PaiHs > 10 && w.PaiHs < 20 ? 1 : 0), Wan = (w.PaiHs > 20 ? 1 : 0) });//遍历所有花色
                    var mydata = from r in qym
                                 group r by new { r.Tiao, r.Tong, r.Wan } into g
                        select new { key = g.Key, number = g.Count() };           //统计花色
                    var key = mydata.OrderBy(w => w.number).FirstOrDefault().key; //取出最少的花色
                    info.Body          = SendQYM.CreateBuilder().SetType(key.Tiao == 1 ? 2 : (key.Tong == 1 ? 1 : 3)).SetOpenid(muInfo.Openid).Build().ToByteArray();
                    info.Key           = "15011";
                    info.Messagelength = info.Body.Length;
                    info.MessageNum    = 14001;
                    info.MessageResNum = 0;
                    new QYM().ExecuteCommand(userInfo.session, info);
                }
                else if (roomInfo.DQHY == muInfo.ZS_Fw)
                {
                    // var muInfo = Gongyong.mulist.Find(w => w.ZS_Fw == roomInfo.DQHY && w.RoomID == roomID);

                    info = new ProtobufRequestInfo();
                    if (currentOperation.Equals("30083"))
                    {
                        if (muInfo.ByteData == "13002")//因为摸牌逻辑比较多处理时间长,
                        {
                            return;
                        }
                        if (userInfo != null)
                        {
                            var mp   = SendMP.CreateBuilder().SetMType(0).SetOpenid(muInfo.Openid).SetRoomid(roomID).Build();
                            var data = mp.ToByteArray();
                            info.Body          = data;
                            info.Key           = "13002";
                            info.Messagelength = data.Length;
                            info.MessageNum    = 13002;
                            info.MessageResNum = 0;
                            new MoPai().ExecuteCommand(userInfo.session, info);
                            userInfo.session.Logger.Debug("10秒后自动摸牌" + mp);
                        }
                    }

                    if (currentOperation.IndexOf("30082") >= 0)//杠牌
                    {
                        userInfo.session.Logger.Debug("10秒后自动30082:" + userInfo.openid);
                        var guo = SendPeng.CreateBuilder()
                                  .SetState(2)
                                  .SetMj(MaJiang.CreateBuilder()
                                         .SetPaiHS(roomInfo.PaiHSCZ.PaiHs)
                                         .SetPaiID(roomInfo.PaiHSCZ.PaiId))
                                  .SetOpenid(userInfo.openid)
                                  .SetRoomid(roomID)
                                  .SetTypes(2);
                        info = new ProtobufRequestInfo();
                        var dqcz = currentOperation.Split(',');
                        switch (dqcz[1])
                        {
                        case "1":
                            guo.SetFW(int.Parse(dqcz[2])).SetGtype("M");
                            break;

                        case "2":
                            guo.SetFW(roomInfo.DQHY).SetGtype("Z");
                            break;

                        case "3":
                            guo.SetFW(roomInfo.DQHY).SetGtype("A");
                            break;

                        case "4":
                            guo.SetFW(roomInfo.DQHY).SetGtype("h");
                            break;
                        }
                        info.Body          = guo.Build().ToByteArray();
                        info.Key           = "14001";
                        info.Messagelength = info.Body.Length;
                        info.MessageNum    = 14001;
                        info.MessageResNum = 0;
                        new Gang().ExecuteCommand(userInfo.session, info);
                    }
                    else if (currentOperation.IndexOf("30081") >= 0)//碰
                    {
                        userInfo.session.Logger.Debug("10秒后自动30081:" + userInfo.openid);
                        var guo = SendPeng.CreateBuilder()
                                  .SetState(2)
                                  .SetMj(MaJiang.CreateBuilder()
                                         .SetPaiHS(roomInfo.PaiHSCZ.PaiHs)
                                         .SetPaiID(roomInfo.PaiHSCZ.PaiId))
                                  .SetOpenid(userInfo.openid)
                                  .SetRoomid(roomID)
                                  .SetTypes(1);
                        info = new ProtobufRequestInfo();
                        var dqcz = currentOperation.Split(',');
                        guo.SetFW(int.Parse(dqcz[1]));
                        info.Body          = guo.Build().ToByteArray();
                        info.Key           = "14001";
                        info.Messagelength = info.Body.Length;
                        info.MessageNum    = 14001;
                        info.MessageResNum = 0;
                        new Gang().ExecuteCommand(userInfo.session, info);
                    }

                    else if (currentOperation.IndexOf("30070") >= 0)//天胡
                    {
                        userInfo.session.Logger.Debug("10秒后自动30070:" + userInfo.openid);
                        var guo = SendPeng.CreateBuilder()
                                  .SetState(2)
                                  .SetOpenid(userInfo.openid)
                                  .SetRoomid(roomID)
                                  .SetTypes(5);
                        info = new ProtobufRequestInfo();
                        var dqcz = currentOperation.Split(',');
                        guo.SetFW(roomInfo.DQHY);
                        info.Body          = guo.Build().ToByteArray();
                        info.Key           = "14001";
                        info.Messagelength = info.Body.Length;
                        info.MessageNum    = 14001;
                        info.MessageResNum = 0;
                        new Gang().ExecuteCommand(userInfo.session, info);
                    }
                    else if (currentOperation.IndexOf("30080") >= 0)//胡
                    {
                        userInfo.session.Logger.Debug("30080:" + userInfo.openid);
                        var guo = SendPeng.CreateBuilder()
                                  .SetState(2)
                                  .SetOpenid(userInfo.openid)
                                  .SetRoomid(roomID)
                                  .SetTypes(3).SetMj(MaJiang.CreateBuilder()
                                                     .SetPaiHS(roomInfo.PaiHSCZ.PaiHs)
                                                     .SetPaiID(roomInfo.PaiHSCZ.PaiId));
                        info = new ProtobufRequestInfo();
                        // var dqcz = currentOperation.Split(',');
                        guo.SetFW(roomInfo.DQHY);
                        info.Body          = guo.Build().ToByteArray();
                        info.Key           = "14001";
                        info.Messagelength = info.Body.Length;
                        info.MessageNum    = 14001;
                        info.MessageResNum = 0;
                        new Gang().ExecuteCommand(userInfo.session, info);
                    }
                    else if (currentOperation.IndexOf("3001") >= 0)//出牌
                    {
                        userInfo.session.Logger.Debug("10秒后自动3001:" + userInfo.openid);
                        var chu = SendCP.CreateBuilder()
                                  .SetRoomid(roomID)
                                  .SetOpenid(userInfo.openid)
                                  .SetType(0);
                        switch (muInfo.QYM)
                        {
                        case 1:
                            if (muInfo.majiangs.Any(u => u.PaiHs < 10))
                            {
                                var mj = muInfo.majiangs.Find(u => u.PaiHs < 10);
                                chu.SetMj(MaJiang.CreateBuilder()
                                          .SetPaiHS(mj.PaiHs)
                                          .SetPaiID(mj.PaiId));
                            }
                            else
                            {
                                chu.SetMj(MaJiang.CreateBuilder()
                                          .SetPaiHS(muInfo.majiangs.Last().PaiHs)
                                          .SetPaiID(muInfo.majiangs.Last().PaiId));
                            }
                            break;

                        case 2:
                            if (muInfo.majiangs.Any(u => u.PaiHs > 10 && u.PaiHs < 20))
                            {
                                var mj = muInfo.majiangs.Find(u => u.PaiHs > 10 && u.PaiHs < 20);
                                chu.SetMj(MaJiang.CreateBuilder()
                                          .SetPaiHS(mj.PaiHs)
                                          .SetPaiID(mj.PaiId));
                            }
                            else
                            {
                                chu.SetMj(MaJiang.CreateBuilder()
                                          .SetPaiHS(muInfo.majiangs.Last().PaiHs)
                                          .SetPaiID(muInfo.majiangs.Last().PaiId));
                            }
                            break;

                        case 3:
                            if (muInfo.majiangs.Any(u => u.PaiHs > 20))
                            {
                                var mj = muInfo.majiangs.Find(u => u.PaiHs > 20);
                                chu.SetMj(MaJiang.CreateBuilder()
                                          .SetPaiHS(mj.PaiHs)
                                          .SetPaiID(mj.PaiId));
                            }
                            else
                            {
                                chu.SetMj(MaJiang.CreateBuilder()
                                          .SetPaiHS(muInfo.majiangs.Last().PaiHs)
                                          .SetPaiID(muInfo.majiangs.Last().PaiId));
                            }
                            break;

                        default:
                            chu.SetMj(MaJiang.CreateBuilder()
                                      .SetPaiHS(muInfo.majiangs.Last().PaiHs)
                                      .SetPaiID(muInfo.majiangs.Last().PaiId));
                            break;
                        }

                        info               = new ProtobufRequestInfo();
                        info.Body          = chu.Build().ToByteArray();
                        info.Key           = "13001";
                        info.Messagelength = info.Body.Length;
                        info.MessageNum    = 14001;
                        info.MessageResNum = 0;
                        new ChuPai().ExecuteCommand(userInfo.session, info);
                    }

                    //if (roomInfo.DQHY == muInfo.ZS_Fw)
                    //    this.CallBack(null);
                    if (userInfo.session != null && userInfo.session.Connected)//发送托管请求
                    {
                        var data = ReturnManaged.CreateBuilder().SetState(1).Build().ToByteArray();
                        userInfo.session.TrySend(new ArraySegment <byte>(CreateHead.CreateMessage(GameInformationBase.BASEAGREEMENTNUMBER + 2011, data.Length, 0, data)));
                    }
                }
            }
            //  GC.Collect();
            // MyTimer.Dispose();
            // this.Dispose();
        }