Ejemplo n.º 1
0
    /// <summary>
    /// 生成随机麻将牌
    /// </summary>
    private void GenerateMaJiang()
    {
        for (int i = 0; i < 16; i++)
        {
            listMajiangManual.Add(0);
        }

        //产生随数
        int[] random = new int[9];
        listMajiangAuto = new List <int>();
        random          = MaJiang.shuffle(random);
        listMajiangAuto.AddRange(random);
        random = MaJiang.shuffle(random);
        listMajiangAuto.AddRange(random);
        InitLoadMaJing(majiangPlane);
    }
Ejemplo n.º 2
0
    /// <summary>
    /// 显示排序结果
    /// </summary>
    /// <param name="list"></param>
    public static void ShowSort(List <Hashtable> list, Text txtOriginal)
    {
        //获取结果面板
        List <Hashtable> list2 = MaJiang.Comparison(list);

        txtOriginal.text = "";
        StringBuilder sb = new StringBuilder();

        //最终结果
        for (int i = list.Count - 1; i >= 0; i--)
        {
            foreach (var item in list2)
            {
                if (Convert.ToInt32(list[i]["First"]) == Convert.ToInt32(item["First"]) && Convert.ToInt32(list[i]["Second"]) == Convert.ToInt32(item["Second"]))
                {
                    string point = "";
                    if (Convert.ToBoolean(item["Pairs"]))
                    {
                        point = "对子:" + item["First"];
                    }
                    else
                    {
                        point = item["Point"].ToString();
                    }
                    sb.Append(item["Sorting"] + "(" + point + ")     ");
                    //将排序值存入HashList
                }
            }
        }

        foreach (var item in list2)
        {
            Debug.Log(Environment.NewLine + item["First"] + ":" + item["Second"] + "对子:" + item["Pairs"] + "点数:" + item["Point"] + "序号:" + item["Sorting"]);
        }

        showOriginal(sb.ToString(), txtOriginal);
    }
Ejemplo n.º 3
0
        public void ExecuteCommand(GameSession session, ProtobufRequestInfo requestInfo)
        {
            string userWinLose = string.Empty;//玩家输赢记录。房间信息表


            if (!Gongyong.userlist.Any(w => w.session.SessionID.Equals(session.SessionID)))
            {
                session.Logger.Debug("GetH : 非法连接");
                session.Close();
                return;
            }
            var getdata = SendHu.ParseFrom(requestInfo.Body);

            Room r = Gongyong.roomlist.Find(u => u.RoomID == getdata.Roomid);

            if (r == null)
            {
                return;
            }
            if (!r.Is_Hu)
            {
                session.Logger.Debug("房间并无胡牌");
                return;
            }
            ThreadUtility.RemoveManagedThreadByRoomID(r.RoomID);
            CardUser card = Gongyong.FKUser.Find(u => u.roomid == getdata.Roomid);

            model.ServerMaJiang mjfh = new model.ServerMaJiang();
            var jp     = ReturnFJ.CreateBuilder();
            var muuser = Gongyong.mulist.Find(u => u.Openid.Equals(getdata.Openid) && u.RoomID == getdata.Roomid);

            if (muuser == null)
            {
                return;
            }
            muuser.Is_jiao = true;
            if (muuser.ByteData == requestInfo.Key)
            {
                return;
            }
            else
            {
                muuser.ByteData = requestInfo.Key;
            }

            var huType = ReturnHType.CreateBuilder().SetFWZ(getdata.FWZ).SetFWB(getdata.FWB).SetMJ(getdata.MJ).SetType(getdata.Type);

            if (getdata.DXInfoCount > 1)
            {
                huType.AddRangeDXInfo(getdata.DXInfoList);
            }
            byte[] HType = huType.Build().ToByteArray();
            if (getdata.Type != 1 && getdata.Type != 5)
            {
                model.ServerMaJiang mjh = new model.ServerMaJiang()
                {
                    PaiHs = getdata.MJ.PaiHS,
                    PaiId = getdata.MJ.PaiID
                };

                var roomUsers = Gongyong.mulist.FindAll(u => u.RoomID == getdata.Roomid);
                if (getdata.DXInfoCount > 1)
                {
                    for (int i = 0; i < getdata.DXInfoList.Count; i++)
                    {
                        foreach (var item in roomUsers)
                        {
                            if (item.ZS_Fw == getdata.DXInfoList[i].DXFW)//如果当期玩家为一炮多响的玩家之一,则在手牌中加上 放炮的牌
                            {
                                item.majiangs.Add(mjh);
                            }
                        }
                    }
                }
                else
                {
                    roomUsers.Find(u => u.ZS_Fw == getdata.FWZ).majiangs.Add(mjh);
                }
            }

            if (getdata.Type == 1 || getdata.Type == 5)
            {
                Gongyong.mulist.Find(u => u.ZS_Fw == getdata.FWZ && u.RoomID == getdata.Roomid).zm_count += 1;
            }
            else
            {
                var mjInfo = Gongyong.mulist.Find(u => u.ZS_Fw == getdata.FWB && u.RoomID == getdata.Roomid);
                mjInfo.dp_count += 1;
                mjInfo.chuda.RemoveAll(w => w.PaiHs == getdata.MJ.PaiHS && w.PaiId == getdata.MJ.PaiID);
            }


            ///没有翻鸡牌
            if (r.RoomPai.Count == 0)
            {
                mjfh.PaiHs = -1;
                mjfh.PaiId = 0;
            }
            else
            {
                mjfh = r.RoomPai[0];
            }



            jp.SetHS(mjfh.PaiHs);
            ///清除牌
            r.RoomPai.Clear();

            List <mjuser>     mjlist      = Gongyong.mulist.FindAll(u => u.RoomID == getdata.Roomid);
            var               settle      = ReturnJS.CreateBuilder();
            var               returnallmj = ReturnUserSPai.CreateBuilder();
            List <UserSettle> listjs      = new List <UserSettle>();

            listjs = new Ting().Settle(r.RoomID, mjfh, getdata);
            var senddjs = ReturnDJS.CreateBuilder();

            if (getdata.DXInfoCount <= 1)
            {
                if (getdata.FWZ != card.win)
                {
                    card.win        = getdata.FWZ;
                    card.lianzCount = 1;
                }
                else// (getdata.FWZ == card.win)
                {
                    card.lianzCount += 1;
                }
            }
            else
            {//连庄情况 ,庄家放炮,胡牌的庄, 一炮多响情况 就是 胡牌的最近的人是庄
             //一炮多响非连庄,  谁放炮 谁是庄
                if (r.is_lianz)
                {
                    int zhuang = 0;
                    if (getdata.FWB == card.win)
                    {
                        if (getdata.FWB == 4)
                        {
                            zhuang = 1;
                        }
                        else
                        {
                            zhuang = getdata.FWB + 1;
                        }
                        for (int i = 1; i <= 4; i++)
                        {
                            if (getdata.FWB == 4)
                            {
                                zhuang = 1;
                            }
                            if (getdata.DXInfoList.Any(w => w.DXFW == zhuang))
                            {
                                card.win = zhuang;
                                break;
                            }
                            zhuang++;
                        }
                    }
                    else
                    {
                        card.lianzCount += 1;
                    }
                }
                else
                {
                    card.win = getdata.FWB;
                }                               //非连庄谁放炮谁 是庄
            }

            foreach (var item in mjlist)
            {
                var jsddr = UserAJS.CreateBuilder();
                #region 旧代码
                //if (item.ZS_Fw == getdata.FWZ)
                //{
                //    ///判断清一色
                //    //if (item.majiangs[item.majiangs.Count - 1].PaiHs - item.majiangs[0].PaiHs < 8)
                //    //{
                //    //    int paihs = item.majiangs[0].PaiHs;
                //    //    int qyshs = 0;
                //    //    int qy = 0;
                //    //    if (paihs < 10)
                //    //    {
                //    //        qyshs = 1;
                //    //    }
                //    //    else if (paihs > 10 && paihs < 20)
                //    //    {
                //    //        qyshs = 2;
                //    //    }
                //    //    else
                //    //    {
                //    //        qyshs = 3;
                //    //    }

                //    //    switch (qyshs)
                //    //    {

                //    //        case 1:
                //    //            int count = item.Peng.FindAll(u => u.PaiHs > 10).Count;
                //    //            if (count > 0)
                //    //            {
                //    //                qy++;
                //    //            }
                //    //            if (!string.IsNullOrEmpty(item.Gong))
                //    //            {
                //    //                string gong = string.Copy(item.Gong);
                //    //                string[] arr = gong.Remove(gong.Length - 1, 1).Split(',');
                //    //                foreach (var itemgong in arr)
                //    //                {
                //    //                    if (int.Parse(itemgong[0].ToString()) > 10)
                //    //                    {
                //    //                        qy++;
                //    //                    }
                //    //                }
                //    //            }

                //    //            break;
                //    //        case 2:

                //    //            int countt = item.Peng.FindAll(u => u.PaiHs < 10 || u.PaiHs > 20).Count;
                //    //            if (countt > 0)
                //    //            {
                //    //                qy++;
                //    //            }
                //    //            if (!string.IsNullOrEmpty(item.Gong))
                //    //            {
                //    //                string gong = string.Copy(item.Gong);
                //    //                string[] arr = gong.Remove(gong.Length - 1, 1).Split(',');
                //    //                foreach (var itemgong in arr)
                //    //                {
                //    //                    if (int.Parse(itemgong[0].ToString()) < 10 || int.Parse(itemgong[0].ToString()) > 20)
                //    //                    {
                //    //                        qy++;
                //    //                    }
                //    //                }
                //    //            }

                //    //            break;
                //    //        case 3:

                //    //            int countw = item.Peng.FindAll(u => u.PaiHs < 20).Count;
                //    //            if (countw > 0)
                //    //            {
                //    //                qy++;
                //    //            }
                //    //            if (!string.IsNullOrEmpty(item.Gong))
                //    //            {
                //    //                string gong = string.Copy(item.Gong);
                //    //                string[] arr = gong.Remove(gong.Length - 1, 1).Split(',');
                //    //                foreach (var itemgong in arr)
                //    //                {
                //    //                    if (int.Parse(itemgong[0].ToString()) < 20)
                //    //                    {
                //    //                        qy++;
                //    //                    }
                //    //                }
                //    //            }

                //    //            break;
                //    //        default:
                //    //            break;
                //    //    }
                //    //    if (qy == 0)
                //    //    {
                //    //        item.paixinfs = 10;
                //    //    }

                //    //}
                //}
                #endregion


                UserInfo user    = Gongyong.userlist.Find(u => u.openid == item.Openid);
                var      usermjs = UserSPai.CreateBuilder();
                usermjs.SetFw(item.ZS_Fw);
                var returnmj = MaJiang.CreateBuilder();
                foreach (var itemmj in item.majiangs)
                {
                    returnmj.SetPaiHS(itemmj.PaiHs);
                    returnmj.SetPaiID(itemmj.PaiId);
                    usermjs.AddMj(returnmj);
                }
                returnallmj.AddUsp(usermjs);
                UserInfo gamer = Gongyong.userlist.Find(u => u.openid == item.Openid);
                var      users = Userinfo.CreateBuilder().SetHeadimg(gamer.headimg).SetNickname(gamer.nickname).SetOpenid(gamer.openid).SetSex(int.Parse(gamer.sex)).SetUserFW(item.ZS_Fw).SetUserBean(0).SetUserGold(0).SetUserID(gamer.UserID).Build();
                ///分数加减
                foreach (var items in listjs)
                {
                    if (items.openid == item.Openid)
                    {
                        var usersone = UserJS.CreateBuilder();

                        foreach (var itrmj in items.jp)
                        {
                            var jpone = JiPaiF.CreateBuilder().SetPaiHS(itrmj.PaiHS).SetType(itrmj.type).SetCount(itrmj.PaiScare);
                            usersone.AddJp(jpone);
                        }
                        foreach (var itemD in items.gang)
                        {
                            var jpdou = Dou.CreateBuilder().SetCount(itemD.DScare).SetType(itemD.DType);
                            usersone.AddDc(jpdou);
                        }
                        if (getdata.HasFWB)
                        {
                            var info = mjlist.Find(w => w.ZS_Fw == getdata.FWB && w.Openid.Equals(items.openid));
                            if (info != null)
                            {
                                if (items.pai_type != 11)
                                {
                                    items.pai_type = 11;
                                }
                            }
                        }
                        usersone.SetIsPao(items.pai_type);
                        usersone.SetIsJiao(items.is_jiao);
                        usersone.SetFS(items.scare);
                        usersone.SetUserinfo(users);
                        usersone.SetDyFs(items.dy_fs);
                        var HuLeiXin = getdata.DXInfoList.FirstOrDefault(w => w.DXFW == item.ZS_Fw);
                        if (HuLeiXin != null)
                        {
                            usersone.SetHuType(HuLeiXin.DXType);
                        }

                        settle.AddJs(usersone);


                        switch (item.ZS_Fw)
                        {
                        case 1:
                            card.dong += items.scare;
                            break;

                        case 2:
                            card.nan += items.scare;
                            break;

                        case 3:
                            card.xi += items.scare;
                            break;

                        case 4:
                            card.bei += items.scare;
                            break;

                        default:
                            break;
                        }
                    }
                }



                ///牌局结束,返回大结算
                if (r.Dcount == r.count)
                {
                    new CardsLogic().Clear(item, r);
                    jsddr.SetUser(users);
                    jsddr.SetZdou(item.zwd_count);
                    jsddr.SetZimo(item.zm_count);
                    jsddr.SetAndou(item.ad_count);
                    jsddr.SetMdou(item.MD_count);
                    jsddr.SetDianpao(item.dp_count);

                    //switch (item.ZS_Fw)
                    //{
                    //    case 1:
                    //        jsddr.SetScare(card.dong);
                    //        break;
                    //    case 2:
                    //        jsddr.SetScare(card.nan);
                    //        break;
                    //    case 3:
                    //        jsddr.SetScare(card.xi);
                    //        break;
                    //    case 4:
                    //        jsddr.SetScare(card.bei);
                    //        break;
                    //    default:
                    //        break;
                    //}
                    jsddr.SetScare(card.GetScoreByPosition(item.ZS_Fw));
                    senddjs.AddUserjs(jsddr);
                    senddjs.SetState(1);

                    RedisUtility.Remove(RedisUtility.GetKey(GameInformationBase.COMMUNITYUSERGAME, gamer.openid, gamer.unionid));

                    if (!string.IsNullOrEmpty(userWinLose))
                    {
                        userWinLose += "|";
                    }
                    userWinLose += user.UserID + "," + jsddr.Scare;
                }
            }
            //牌局回放 翻鸡
            var gameOperationInfoFJ = GameOperationInfo.CreateBuilder().AddMJ(MaJiang.CreateBuilder().SetPaiHS(jp.HS).SetPaiID(0)).SetOperationType(9);

            StringBuilder logtxt = new StringBuilder();

            logtxt.Append("胡牌" + getdata.ToString());
            foreach (var item in mjlist)
            {
                item.SendData.Clear();
                logtxt.Append(string.Join(",", item.majiangs.Select(w => w.PaiHs)));
                UserInfo user         = Gongyong.userlist.Find(u => u.openid == item.Openid);
                var      sendData5021 = new ArraySegment <byte>(CreateHead.CreateMessage(GameInformationBase.BASEAGREEMENTNUMBER + 5021, HType.Length, requestInfo.MessageNum, HType));
                item.SendData.Add(sendData5021);

                byte[] allsp = returnallmj.Build().ToByteArray();

                byte[] jpr = jp.Build().ToByteArray();
                //7005 返回翻鸡牌
                var sendData7005 = new ArraySegment <byte>(CreateHead.CreateMessage(GameInformationBase.BASEAGREEMENTNUMBER + 7005, jpr.Length, requestInfo.MessageNum, jpr));
                item.SendData.Add(sendData7005);

                //7008 : 玩家手牌集合
                var sendData7008 = new ArraySegment <byte>(CreateHead.CreateMessage(GameInformationBase.BASEAGREEMENTNUMBER + 7008, allsp.Length, requestInfo.MessageNum, allsp));
                item.SendData.Add(sendData7008);

                byte[] settlebyte = settle.Build().ToByteArray();
                r.gameOperationProcess.SetJieSuanInfo(ByteString.CopyFrom(settlebyte));
                //7009 : 返回结算信息(全体)
                var sendData = new ArraySegment <byte>(CreateHead.CreateMessage(GameInformationBase.BASEAGREEMENTNUMBER + 7009, settlebyte.Length, requestInfo.MessageNum, settlebyte));
                item.SendData.Add(sendData);

                if (r.Dcount == r.count)
                {
                    byte[] senddjsbyte = senddjs.Build().ToByteArray();
                    //5014 : 大结算信息
                    var sendData5014 = new ArraySegment <byte>(CreateHead.CreateMessage(GameInformationBase.BASEAGREEMENTNUMBER + 5014, senddjsbyte.Length, requestInfo.MessageNum, senddjsbyte));
                    item.SendData.Add(sendData5014);
                }
                foreach (var senddata in item.SendData)
                {
                    user.session.TrySend(senddata);
                }
            }
            session.Logger.Debug(logtxt);
            //牌局回放 胡牌
            var gameOperationInfo = GameOperationInfo.CreateBuilder()
                                    .SetSerialNumber(r.gameOperationProcess.GameOperationInfoCount)
                                    .SetOperationFW(huType.FWZ)
                                    .SetOperationType(5)
                                    .SetTingHuType(muuser.Is_tianHu ? 1 : 0)
                                    .SetPaoFW(huType.FWB);

            if (getdata.DXInfoCount > 1)
            {
                gameOperationInfo.AddRangeDXInfo(getdata.DXInfoList);
            }
            r.gameOperationProcess.AddGameOperationInfo(gameOperationInfo);
            gameOperationInfoFJ.SetSerialNumber(r.gameOperationProcess.GameOperationInfoCount).SetOperationFW(0);
            r.gameOperationProcess.AddGameOperationInfo(gameOperationInfoFJ);
            try
            {
                CardsLogic.AddboarddetailsTB(r);
            }
            catch (Exception ex)
            {
                session.Logger.Error(ex);
            }
            ///对局结束 清空所有信息
            if (r.Dcount == r.count)
            {
                Gongyong.mulist.RemoveAll(u => u.RoomID == r.RoomID);
                Gongyong.FKUser.RemoveAll(u => u.roomid == r.RoomID);
                Gongyong.roomlist.RemoveAll(u => u.RoomID == r.RoomID);
                RedisUtility.Remove(RedisUtility.GetKey(GameInformationBase.COMMUNITYROOMINFO, r.RoomID.ToString(), ""));
                new RoomInfoDAL().UpdateEndRoomInfoByRoomInfoID(new RoomInfo {
                    RoomInfoID = r.RoomInfoID, EndTime = DateTime.Now, EndStatus = 0, UserWinLose = userWinLose
                });
                foreach (var item in mjlist)
                {
                    UserInfo user = Gongyong.userlist.Find(u => u.openid == item.Openid);
                    new userRecordLOGDAL().Add(new userRecordlogLOG {
                        UserID = user.UserID, RoomInfoID = r.RoomInfoID, UserWinLose = userWinLose, EndTime = DateTime.Now, CreateDate = r.CreateDate, RoomID = r.RoomID
                    });
                }
                r.startgame = 0;
            }
            else
            {
                if (r != null)
                {
                    r.RoomPai   = new CreateMj().CreateMJ(r.IsYuanQue);
                    r.Dcount   += 1;
                    r.startgame = 2;
                }
            }
        }
Ejemplo n.º 4
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("JX_Game : 非法连接");
                session.Close();
                return;
            }
            var getdata = SendGetGame.ParseFrom(requestInfo.Body);


            Room r = Gongyong.roomlist.Find(u => u.RoomID == getdata.RoomID);



            if (r == null)
            {
                return;
            }
            if (r.startgame != 2)
            {
                return;
            }
            List <mjuser> listuser = Gongyong.mulist.FindAll(u => u.RoomID == getdata.RoomID);
            Room_JX       room     = new Room_JX();

            room = Gongyong.room_JX.Find(u => u.room_id == getdata.RoomID);
            if (room == null)
            {
                room = new Room_JX()
                {
                    room_id  = getdata.RoomID,
                    room_peo = 1,
                    UsersFW  = new List <int>()
                    {
                        getdata.Fw
                    }
                };


                Gongyong.room_JX.Add(room);
            }
            else
            {
                if (!room.UsersFW.Any(w => w == getdata.Fw))//已点击过继续游戏的玩家不能再次进入计算
                {
                    room.room_peo += 1;
                    room.UsersFW.Add(getdata.Fw);
                }
            }

            if (room.room_peo == r.room_peo)
            {
                //发送当前局数的信息
                foreach (var item in listuser)
                {
                    new CardsLogic().Clear(item, r);
                }
                CardsLogic logic = new CardsLogic();
                r.startgame = 1;
                int number = 0;//发牌次数,从0开始计数
                foreach (var item in listuser)
                {
                    //UserInfo user = Gongyong.userlist.Find(u => u.openid == item.Openid);
                    //ReturnStart startgame = ReturnStart.CreateBuilder().SetStart(1).Build();
                    //byte[] bstart = startgame.ToByteArray();
                    //user.session.TrySend(new ArraySegment<byte>(CreateHead.CreateMessage(GameInformationBase.BASEAGREEMENTNUMBER + 2008, bstart.Length, requestInfo.MessageNum, bstart)));

                    item.SendData.Clear();
                    ReturnStartGame.Builder    sendmj        = ReturnStartGame.CreateBuilder();
                    ReturnGang.Builder         ReturnGangMSG = ReturnGang.CreateBuilder();
                    List <model.ServerMaJiang> Ruturnjsmj    = new List <model.ServerMaJiang>();
                    item.paixinfs = 5;
                    Gongyong.mulist.Remove(item);
                    if (r.IsYuanQue)
                    {
                        item.QYM = 3;
                    }
                    //logic.GetMyCards(requestInfo, sendmj, ReturnGangMSG, Ruturnjsmj, session, getdata.RoomID, item, item.Openid, ref number);
                    var dcount = r.Dcount;
                    logic.GetMyCards(requestInfo, sendmj, ReturnGangMSG, Ruturnjsmj, session, getdata.RoomID, item, item.Openid, ref dcount);
                }
                if (listuser.Any(w => w.Is_tianHu))
                {
                    var user = listuser.Find(w => w.Is_tianHu);

                    var    humj  = user.majiangs.Last();
                    var    hupai = ReturnHByType.CreateBuilder().SetFWZ(user.ZS_Fw).SetMJ(MaJiang.CreateBuilder().SetPaiHS(humj.PaiHs).SetPaiID(humj.PaiId)).SetType(1);
                    byte[] data  = hupai.Build().ToByteArray();
                    if (listuser.Any(w => w.Is_tiant))
                    {
                        RoomMsgWirte msgri = new RoomMsgWirte()
                        {
                            openid      = user.Openid,
                            xiaoxihao   = 5015,
                            ArrList     = data,
                            roomid      = user.RoomID
                            , operating = "30080"
                        };
                        Gongyong.roommsg.Add(msgri);
                    }
                    else
                    {
                        var userSend = Gongyong.userlist.Find(w => w.openid.Equals(user.Openid));
                        userSend.session.TrySend(new ArraySegment <byte>(CreateHead.CreateMessage(GameInformationBase.BASEAGREEMENTNUMBER + 5015, data.Length, requestInfo.MessageNum, data)));
                    }
                    // userSendJ.session.TrySend(new ArraySegment<byte>(CreateHead.CreateMessage(GameInformationBase.BASEAGREEMENTNUMBER + 5015, data.Length, requestInfo.MessageNum, data)));
                }
                Gongyong.room_JX.Remove(Gongyong.room_JX.Find(w => w.room_id == getdata.RoomID));
            }
        }
Ejemplo n.º 5
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();
        }
Ejemplo n.º 6
0
        public void ExecuteCommand(GameSession session, ProtobufRequestInfo requestInfo)
        {
            if (!Gongyong.userlist.Any(w => w.session.SessionID.Equals(session.SessionID)))
            {
                session.Logger.Debug("StartGame : 非法连接");
                session.Close();
                return;
            }
            var result = SendConfirmationStarts.ParseFrom(requestInfo.Body);

            session.Logger.Debug(result);
            var userInfo = Gongyong.mulist.Find(u => u.RoomID == result.RoomID && u.Openid == result.Openid);

            if (userInfo == null)
            {
                return;
            }
            userInfo.ConfirmationStarts = true;
            List <mjuser> mjList = Gongyong.mulist.FindAll(u => u.RoomID == result.RoomID);
            var           r      = Gongyong.roomlist.Find(w => w.RoomID == result.RoomID);

            if (r.startgame == 1)
            {
                return;
            }
            if (mjList.Count != r.room_peo)
            {
                return;
            }


            foreach (var item in mjList)
            {
                if (!item.ConfirmationStarts)
                {
                    return;
                }
            }
            r.startgame = 1;
            ///查找当前玩家集合
            session.Logger.Debug("全部确认,开始游戏发牌" + mjList.Count);

            CardsLogic logic  = new CardsLogic();
            int        number = 0;//发牌次数,从0开始计数



            //switch (r.room_peo)
            //{
            //    case "2T":
            //        if (r.RoomPai.Count == 108)
            //        {
            //            r.RoomPai.RemoveRange(0, 27);
            //        }
            //        break;
            //    case "3T":
            //        if (r.RoomPai.Count == 108)
            //        {
            //            r.RoomPai.RemoveRange(0, 40);
            //        }
            //        break;
            //    case "4T":
            //        if (r.RoomPai.Count == 108)
            //        {
            //            r.RoomPai.RemoveRange(0, 53);
            //        }
            //        break;
            //    default:
            //        break;
            //}
            var dcount = r.Dcount;

            foreach (var item in mjList)
            {
                ReturnStartGame.Builder    sendmj        = ReturnStartGame.CreateBuilder();
                ReturnGang.Builder         ReturnGangMSG = ReturnGang.CreateBuilder();
                List <model.ServerMaJiang> Ruturnjsmj    = new List <model.ServerMaJiang>();
                item.paixinfs = 5;
                Gongyong.mulist.Remove(item);
                if (r.IsYuanQue)
                {
                    item.QYM = 3;
                }
                logic.GetMyCards(requestInfo, sendmj, ReturnGangMSG, Ruturnjsmj, session, result.RoomID, item, item.Openid, ref dcount);
                var user = Gongyong.userlist.Find(w => w.openid.Equals(item.Openid));

                byte[] stringnew = ReturnPaiCount.CreateBuilder().SetPaiCount(r.RoomPai.Count).Build().ToByteArray();
                user.session.TrySend(new ArraySegment <byte>(CreateHead.CreateMessage(GameInformationBase.BASEAGREEMENTNUMBER + 7006, stringnew.Length, requestInfo.MessageNum, stringnew)));
            }
            if (mjList.Any(w => w.Is_tianHu))
            {
                var user = mjList.Find(w => w.Is_tianHu);

                var    humj  = user.majiangs.Last();
                var    hupai = ReturnHByType.CreateBuilder().SetFWZ(user.ZS_Fw).SetMJ(MaJiang.CreateBuilder().SetPaiHS(humj.PaiHs).SetPaiID(humj.PaiId)).SetType(1);
                byte[] data  = hupai.Build().ToByteArray();
                if (mjList.Any(w => w.Is_tiant))
                {
                    model.RoomMsgWirte msgri = new RoomMsgWirte()
                    {
                        openid    = user.Openid,
                        xiaoxihao = 5015,
                        ArrList   = data,
                        roomid    = user.RoomID,
                        operating = "30070"
                    };
                    Gongyong.roommsg.Add(msgri);
                }
                else
                {
                    var userSend = Gongyong.userlist.Find(w => w.openid.Equals(user.Openid));
                    userSend.session.TrySend(new ArraySegment <byte>(CreateHead.CreateMessage(GameInformationBase.BASEAGREEMENTNUMBER + 5015, data.Length, requestInfo.MessageNum, data)));
                }
                // userSendJ.session.TrySend(new ArraySegment<byte>(CreateHead.CreateMessage(GameInformationBase.BASEAGREEMENTNUMBER + 5015, data.Length, requestInfo.MessageNum, data)));
            }
        }
Ejemplo n.º 7
0
        public void ExecuteCommand(GameSession session, ProtobufRequestInfo requestInfo)
        {
            if (!Gongyong.userlist.Any(w => w.session.SessionID.Equals(session.SessionID)))
            {
                session.Logger.Debug("ConnData : 非法连接");
                session.Close();
                return;
            }
            var getinfo = SendConnData.ParseFrom(requestInfo.Body);

            var userInfo = Gongyong.userlist.Find(u => u.openid == getinfo.Openid);

            if (userInfo == null)
            {
                session.Close();
            }
            userInfo.session = session;

            mjuser mj = Gongyong.mulist.Find(u => u.Openid == getinfo.Openid);

            if (mj == null)
            {
                return;
            }
            List <mjuser> mjlist  = Gongyong.mulist.FindAll(u => u.RoomID == mj.RoomID);
            var           roommsg = ReturnRoomMsg.CreateBuilder();

            Room rm = Gongyong.roomlist.Find(u => u.RoomID == mj.RoomID);

            if (rm == null)
            {
                return;
            }
            var userinfo = Userinfo.CreateBuilder();
            ///返回重连状态
            //  var ifconn = ReturnRecon.CreateBuilder().SetState(1).Build();
            ///返回房间用户信息
            var userinfobyroom = ReturnUserInfo.CreateBuilder();
            var mjhy           = MaJiang.CreateBuilder();
            var hyyh           = ReturnHyUser.CreateBuilder();

            if (!string.IsNullOrEmpty(rm.DQHY.ToString()))
            {
                hyyh.SetFw(rm.DQHY);
            }
            else
            {
                hyyh.SetFw(0);
            }


            if (!string.IsNullOrEmpty(rm.DQcz))
            {
                hyyh.SetCz(rm.DQcz);
            }
            else
            {
                hyyh.SetCz("");
            }

            if (rm.PaiHSCZ != null)
            {
                mjhy.SetPaiID(rm.PaiHSCZ.PaiId);
                mjhy.SetPaiHS(rm.PaiHSCZ.PaiHs);
            }
            else
            {
                mjhy.SetPaiID(0);
                mjhy.SetPaiHS(0);
            }
            hyyh.SetMj(mjhy);

            var         returndata   = ReturnConnData.CreateBuilder();
            List <byte> returnzhuang = new List <byte>();
            List <model.ServerMaJiang> Ruturnjsmj = new List <model.ServerMaJiang>();
            int myFW = 0;

            foreach (mjuser mjuseritem in mjlist)
            {
                var MJ = MaJiang.CreateBuilder();
                ///手牌集合
                var shoupai = UserShou.CreateBuilder();
                //碰牌集合
                var pengpai = UserPeng.CreateBuilder();
                ///出牌集合
                var chupai = UserChu.CreateBuilder();
                ///杠
                var gangpai = UserGang.CreateBuilder();


                var userzrj = JpConn.CreateBuilder();
                userzrj.SetFW(mjuseritem.ZS_Fw);
                if (mjuseritem.Is_cfj == true)
                {
                    userzrj.SetCFJ(1);
                }

                if (mjuseritem.Is_zrj == -1)
                {
                    userzrj.SetCFJ(2);
                }


                if (mjuseritem.is_cfwg == true)
                {
                    userzrj.SetWGJ(1);
                }

                if (mjuseritem.is_zrwg == -1)
                {
                    userzrj.SetWGJ(2);
                }

                /**********************返回房间用户信息************************************************/
                UserInfo user = Gongyong.userlist.Find(u => u.openid == mjuseritem.Openid);
                userinfo.SetOpenid(user.openid);
                userinfo.SetNickname(user.nickname);
                userinfo.SetHeadimg(user.headimg);
                userinfo.SetSex(int.Parse(user.sex));
                userinfo.SetUserBean(0);
                userinfo.SetUserGold(0);
                userinfo.SetUserFW(mjuseritem.ZS_Fw);
                userinfo.SetUserID(user.UserID);
                CardUser card = Gongyong.FKUser.Find(u => u.roomid == mjuseritem.RoomID);
                if (card != null)
                {
                    userinfo.SetCumulativeScore(card.GetScoreByPosition(mjuseritem.ZS_Fw));
                    //if (returnzhuang.Count == 0)
                    //    returnzhuang.AddRange(ReturnZhuang.CreateBuilder().SetZhuang(card.win).Build().ToByteArray());
                    if (!returndata.HasZhuang)
                    {
                        returndata.SetZhuang(ReturnZhuang.CreateBuilder().SetZhuang(card.win).SetSeizi(card.Points).SetZhuangCount(card.lianzCount));
                    }
                    shoupai.SetScare(card.GetScoreByPosition(mjuseritem.ZS_Fw));
                }
                else
                {
                    shoupai.SetScare(0);
                }
                userinfobyroom.AddUserinfo(userinfo);
                /***********************返回手牌集合***************************************/
                // int paicount = 0;
                if (mjuseritem.Openid == getinfo.Openid)
                {
                    //foreach (var item in mjuseritem.majiangs)
                    //{
                    //    paicount++;
                    //    MJ.SetPaiHS(item.PaiHs);
                    //    MJ.SetPaiID(item.PaiId);
                    //    shoupai.AddMj(MJ);
                    //}
                    myFW = mjuseritem.ZS_Fw;
                    shoupai.AddRangeMj(mjuseritem.majiangs.Select(w => MaJiang.CreateBuilder().SetPaiHS(w.PaiHs).SetPaiID(w.PaiId).Build()));
                    List <model.ServerMaJiang> majongList = new List <model.ServerMaJiang>();
                    majongList.AddRange(mjuseritem.majiangs.ToArray());
                    if (mjuseritem.majiangs.Count == 14 && mjuseritem.MopaiNumber <= 1 && mjuseritem.Peng.Count == 0 && string.IsNullOrEmpty(mjuseritem.Gong))
                    {
                        Ruturnjsmj = new Ting().ReturnJMJ(majongList);
                    }
                }
                else
                {
                    //foreach (var item in mjuseritem.majiangs)
                    //{
                    //    paicount++;
                    //    MJ.SetPaiHS(0);
                    //    MJ.SetPaiID(0);
                    //    shoupai.AddMj(MJ);
                    //}
                    shoupai.AddRangeMj(mjuseritem.majiangs.Select(w => MaJiang.CreateBuilder().SetPaiHS(0).SetPaiID(0).Build()));
                }
                shoupai.SetFW(mjuseritem.ZS_Fw);
                shoupai.SetPcount(mjuseritem.majiangs.Count);
                shoupai.SetQYM(mjuseritem.QYM);
                shoupai.SetTianting(mjuseritem.Is_tiantX);
                shoupai.SetBaoting(mjuseritem.Is_baotin ? 1 : 0);
                /*****碰牌集合*****************************/
                foreach (var itemP in mjuseritem.Peng)
                {
                    MJ.SetPaiHS(itemP.PaiHs);
                    MJ.SetPaiID(itemP.PaiId);
                    pengpai.AddMj(MJ);
                }
                pengpai.SetFW(mjuseritem.ZS_Fw);

                /****************出牌集合*********************************/
                foreach (var itemC in mjuseritem.chuda)
                {
                    MJ.SetPaiHS(itemC.PaiHs);
                    MJ.SetPaiID(itemC.PaiId);
                    chupai.AddMj(MJ);
                }
                chupai.SetFW(mjuseritem.ZS_Fw);

                gangpai.SetFW(mjuseritem.ZS_Fw);
                if (!string.IsNullOrEmpty(mjuseritem.Gong))
                {
                    gangpai.SetGang(mjuseritem.Gong);
                }
                else
                {
                    gangpai.SetGang("");
                }
                returndata.AddChu(chupai);
                returndata.AddPeng(pengpai);
                returndata.AddGang(gangpai);
                returndata.AddShoupai(shoupai);
                returndata.AddJp(userzrj);


                //chupai.Clear();
                //pengpai.Clear();
                //gangpai.Clear();
                //shoupai.Clear();
            }
            roommsg.SetCount(rm.count).SetIsBenji(rm.is_benji == true ? 1 : 0).SetIsShangxiaji(rm.is_shangxiaji == true ? 1 : 0).SetIsWgj(rm.is_wgj == true ? 1 : 0).SetIsXinqiji(rm.is_xinqiji == true ? 1 : 0).SetIsYikousan(rm.is_yikousan == true ? 1 : 0).SetRoomPeo(rm.room_peo).SetIsLianzhuang(rm.is_lianz == true ? 1 : 0).SetIsYuanque(rm.IsYuanQue?1:0);
            returndata.SetRoomID(mj.RoomID);

            returndata.SetHyUser(hyyh);
            returndata.SetMessage(roommsg);
            returndata.SetUserInfo(userinfobyroom);
            //byte[] hyczall = hyyh.Build().ToByteArray();
            //session.TrySend(new ArraySegment<byte>(CreateHead.CreateMessage(GameInformationBase.BASEAGREEMENTNUMBER + 7004, hyczall.Length, requestInfo.MessageNum, hyczall)));
            //byte[] roommsgb = roommsg.Build().ToByteArray();
            //session.TrySend(new ArraySegment<byte>(CreateHead.CreateMessage(GameInformationBase.BASEAGREEMENTNUMBER + 7003, roommsgb.Length, requestInfo.MessageNum, roommsgb)));


            //byte[] cState = ifconn.ToByteArray();
            //session.TrySend(new ArraySegment<byte>(CreateHead.CreateMessage(GameInformationBase.BASEAGREEMENTNUMBER + 6001, cState.Length, requestInfo.MessageNum, cState)));

            //byte[] uData = userinfobyroom.Build().ToByteArray();
            //session.TrySend(new ArraySegment<byte>(CreateHead.CreateMessage(GameInformationBase.BASEAGREEMENTNUMBER + 2005, uData.Length, requestInfo.MessageNum, uData)));
            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);
                }
                returndata.SetTp(returntp);
                //byte[] tmjsr = returntp.Build().ToByteArray();
                //session.TrySend(new ArraySegment<byte>(CreateHead.CreateMessage(GameInformationBase.BASEAGREEMENTNUMBER + 2009, tmjsr.Length, requestInfo.MessageNum, tmjsr)));
            }

            // session.TrySend(new ArraySegment<byte>(CreateHead.CreateMessage(GameInformationBase.BASEAGREEMENTNUMBER + 5020, returnzhuang.Count, GameInformationBase.BASEAGREEMENTNUMBER + 7093, returnzhuang.ToArray())));
            //if (mj.SendData != null)
            //    session.TrySend(mj.SendData);
            if (mj.SendData != null)
            {
                returndata.AddRangeSendData(mj.SendData.Select(w => ByteString.CopyFrom(w.ToArray())));
            }
            if (rm.LastMoMJ != null)
            {
                returndata.SetLastMomj(MaJiang.CreateBuilder().SetPaiHS(rm.LastMoMJ.PaiHs).SetPaiID(rm.LastMoMJ.PaiId));
            }
            if (rm.LastChuMJ != null)
            {
                returndata.SetLastChumj(MaJiang.CreateBuilder().SetPaiHS(rm.LastChuMJ.PaiHs).SetPaiID(rm.LastChuMJ.PaiId));
            }
            returndata.SetGameNumber(rm.Dcount);
            var jxRoom = Gongyong.room_JX.Find(u => u.room_id == returndata.RoomID);

            if (jxRoom == null)
            {
                returndata.SetJiXuYouXi(0);
            }
            else
            {
                returndata.SetJiXuYouXi(jxRoom.UsersFW.Any(w => w == myFW) ? 1 : 0);
            }
            returndata.SetPaiCount(rm.RoomPai.Count);
            if (!returndata.HasZhuang)
            {
                returndata.SetZhuang(ReturnZhuang.CreateBuilder().SetZhuang(1).SetSeizi("").SetZhuangCount(1));
            }
            byte[] rData = returndata.Build().ToByteArray();
            session.TrySend(new ArraySegment <byte>(CreateHead.CreateMessage(GameInformationBase.BASEAGREEMENTNUMBER + 7001, rData.Length, requestInfo.MessageNum, rData)));
            Gongyong.msg.RemoveAll(w => w.openid.Equals(userInfo.openid));
            session.Logger.Debug("断线重连结束" + userInfo.openid);
        }
Ejemplo n.º 8
0
 void Awake()
 {
     instance = this;
 }
Ejemplo n.º 9
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(" 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);
        }
Ejemplo n.º 10
0
        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);
                }
            }
        }
Ejemplo n.º 11
0
    /// <summary>
    /// 左移算法
    /// </summary>
    private string MoveComputer(string type, int dir)
    {
        List <Hashtable>         oldList = null;
        List <Hashtable>         result;
        List <List <Hashtable> > finalList = new List <List <Hashtable> >();

        for (int num = 0; num < 1; num++)
        {
            switch (dir)
            {
            case 0:
                //右移
                LoopComputer.ClockwiseeMove(listMajiangAuto);
                break;

            case 1:
                //左移
                LoopComputer.InverseMove(listMajiangAuto);
                break;

            default:
                break;
            }

            switch (type)
            {
            case "SquatOut":
                //蹲出
                oldList = SquatOut(majiangPlane);
                break;

            case "FlatOut":
                //蹲出
                oldList = FlatOut(majiangPlane);
                break;

            case "JumpOut":
                //蹲出
                oldList = JumpOut(majiangPlane);
                break;

            default:
                break;
            }
            result = MaJiang.Comparison(oldList);
#if UNITY_EDITOR
            for (int i = 0; i < listMajiangAuto.Count - 2; i++)
            {
                //显示指定的牌
                ShowContent.ChangValue(i, listMajiangAuto[i], majiangPlane);
            }
#endif
            // ShowSort(oldList);
            List <Hashtable> resultList = AutoComputer(oldList, result, num, 1);
            finalList.Add(resultList);
        }
        Debug.Log(finalList.Count);
        string showValue = "";
        int    count     = 0;
        foreach (var item in finalList)
        {
            string valueSort = "";
            foreach (var table in item)
            {
                valueSort += table["Sorting"];
            }
            string[] outDoor = dicResult["outDoor"];
            foreach (var itemOutDoor in outDoor)
            {
                if (valueSort == itemOutDoor)
                {
                    Debug.Log("出门" + valueSort);
                    count++;
                    showValue += MoveNum(valueSort + "->", count, "出门", dir);
                }
            }
            string[] endDoor = dicResult["endDoor"];
            foreach (var itemEndDoor in endDoor)
            {
                if (valueSort == itemEndDoor)
                {
                    Debug.Log("末门" + valueSort);
                    count++;
                    showValue += MoveNum(valueSort + "->", count, "末门", dir);
                }
            }
            string[] banker = dicResult["banker"];
            foreach (var itemBanker in banker)
            {
                if (valueSort == itemBanker)
                {
                    Debug.Log("庄家" + valueSort);
                    count++;
                    showValue += MoveNum(valueSort + "->", count, "庄家", dir);
                }
            }
            Debug.Log(valueSort);
        }
        return(showValue);
    }
Ejemplo n.º 12
0
        /// <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++;
            }
        }