/// <summary>
        ///  胡牌
        /// </summary>
        /// <param name="gamer"></param>
        /// <param name="room"></param>
        /// <param name="mahjongInfos"></param>
        /// <param name="b"></param>
        private static int HuPai(Gamer gamer, Room room, List <MahjongInfo> mahjongInfos, bool isZimo)
        {
            room.IsZimo   = isZimo;
            room.huPaiUid = gamer.UserID;
            if (!isZimo)
            {
                gamer.isGangEndBuPai    = false;
                gamer.isGetYingHuaBuPai = false;
            }

            int huaCount = 0;

            DeskComponent            deskComponent   = room.GetComponent <DeskComponent>();
            OrderControllerComponent orderController = room.GetComponent <OrderControllerComponent>();
            HandCardsComponent       handCards       = gamer.GetComponent <HandCardsComponent>();

            Actor_GamerHuPai actorGamerHuPai = new Actor_GamerHuPai();

            actorGamerHuPai.Uid = gamer.UserID;

            HuPaiNeedData huPaiNeedData = new HuPaiNeedData();

            huPaiNeedData.my_lastMahjong    = room.my_lastMahjong;
            huPaiNeedData.restMahjongCount  = deskComponent.RestLibrary.Count;
            huPaiNeedData.isSelfZhuaPai     = orderController.CurrentAuthority == gamer.UserID;
            huPaiNeedData.isZhuangJia       = handCards.IsBanker;
            huPaiNeedData.isGetYingHuaBuPai = gamer.isGetYingHuaBuPai;
            huPaiNeedData.isGangEndBuPai    = gamer.isGangEndBuPai;
            huPaiNeedData.isGangFaWanPai    = gamer.isGangFaWanPai;
            huPaiNeedData.isFaWanPaiTingPai = gamer.isFaWanPaiTingPai;
            huPaiNeedData.my_yingHuaList    = handCards.FaceCards;
            huPaiNeedData.my_gangList       = handCards.GangCards;
            huPaiNeedData.my_pengList       = handCards.PengCards;

            List <List <MahjongInfo> > temp = new List <List <MahjongInfo> >();

            foreach (var _gamer in room.GetAll())
            {
                _gamer.RemoveComponent <TrusteeshipComponent>();

                if (_gamer.UserID == gamer.UserID)
                {
                    continue;
                }
                HandCardsComponent handCardsComponent = _gamer.GetComponent <HandCardsComponent>();
                temp.Add(handCardsComponent.PengCards);

                //设置其他人的牌
                GamerData gamerData = new GamerData();
                gamerData.handCards = handCardsComponent.GetAll();
                gamerData.UserID    = _gamer.UserID;
                actorGamerHuPai.GamerDatas.Add(gamerData);
            }

            huPaiNeedData.other1_pengList = temp[0];
            huPaiNeedData.other2_pengList = temp[1];
            huPaiNeedData.other3_pengList = temp[2];

            //比下胡
//            if (room.IsLianZhuang)
//            {
//                if (room.BankerGamer.UserID == room.huPaiUid)
//                {
//                    room.LiangZhuangCount++;
//                    actorGamerHuPai.BixiaHuCount = room.LiangZhuangCount * 10;
//                }
//            }
            if (room.IsBiXiaHu)
            {
                actorGamerHuPai.BixiaHuCount = 20;
            }

            List <Consts.HuPaiType> huPaiTypes = Logic_NJMJ.getInstance().getHuPaiType(mahjongInfos, huPaiNeedData);

            foreach (var huPaiType in huPaiTypes)
            {
                if (huPaiType != Consts.HuPaiType.Normal)
                {
                    room.LastBiXiaHu = true;
                }
            }

            //自摸
            actorGamerHuPai.IsZiMo = isZimo;
            if (!isZimo)
            {
                actorGamerHuPai.FangPaoUid = orderController.CurrentAuthority;
                room.Get(orderController.CurrentAuthority).isFangPao = true;
            }
            else
            {
                gamer.isZimo = true;
            }

            //硬花
            actorGamerHuPai.YingHuaCount = handCards.FaceCards.Count;
            //硬花
            huaCount += handCards.FaceCards.Count;
            //软花
            foreach (var pengorbar in handCards.PengOrBars)
            {
                //东南西北风 碰牌
                if (pengorbar.OperateType == OperateType.Peng)
                {
                    if (pengorbar.Weight >= 31 && pengorbar.Weight <= 37)
                    {
                        actorGamerHuPai.RuanHuaCount += 1;
                    }
                }
                else
                {
                    if (pengorbar.BarType == BarType.DarkBar)
                    {
                        //风牌暗杠
                        if (pengorbar.Weight >= 31 && pengorbar.Weight <= 37)
                        {
                            actorGamerHuPai.RuanHuaCount += 3;
                        }
                        //万条筒暗杠
                        else
                        {
                            actorGamerHuPai.RuanHuaCount += 2;
                        }
                    }
                    else
                    {
                        //风牌明杠
                        if (pengorbar.Weight >= 31 && pengorbar.Weight <= 37)
                        {
                            actorGamerHuPai.RuanHuaCount += 2;
                        }
                        //万条筒明杠
                        else
                        {
                            actorGamerHuPai.RuanHuaCount += 1;
                        }
                    }
                }
            }

            int fengKeHuaShu = Logic_NJMJ.getInstance().getFengKeHuaShu(mahjongInfos);

            //将碰刚将入手牌
            foreach (var pengorbar in handCards.PengOrBars)
            {
                if (pengorbar.OperateType == OperateType.Peng)
                {
                    for (int i = 0; i < 3; i++)
                    {
                        mahjongInfos.Add(new MahjongInfo()
                        {
                            m_weight = (Consts.MahjongWeight)pengorbar.Weight,
                            weight   = (byte)pengorbar.Weight
                        });
                    }
                }
                else
                {
                    for (int i = 0; i < 4; i++)
                    {
                        mahjongInfos.Add(new MahjongInfo()
                        {
                            m_weight = (Consts.MahjongWeight)pengorbar.Weight,
                            weight   = (byte)pengorbar.Weight
                        });
                    }
                }
            }

            int queYiMenHuaShu = Logic_NJMJ.getInstance().getQueYiMenHuaShu(mahjongInfos);

            actorGamerHuPai.RuanHuaCount += queYiMenHuaShu;
            actorGamerHuPai.RuanHuaCount += fengKeHuaShu;

            huaCount += actorGamerHuPai.RuanHuaCount;
            //胡牌类型
            foreach (var type in huPaiTypes)
            {
                actorGamerHuPai.HuPaiTypes.Add((int)type);
            }

            room.Broadcast(actorGamerHuPai);

            room.IsGameOver = true;
            gamer.IsCanHu   = false;
            gamer.IsWinner  = true;

            foreach (var item in huPaiTypes)
            {
                Log.Info("有人胡牌:" + item.ToString());
            }

            Log.Info("huPaiNeedData:" + JsonHelper.ToJson(huPaiNeedData));

            //设置胡牌的花数
            for (int j = 0; j < huPaiTypes.Count; j++)
            {
                Consts.HuPaiType huPaiType = (Consts.HuPaiType)huPaiTypes[j];
                int count;
                Logic_NJMJ.getInstance().HuPaiHuaCount.TryGetValue(huPaiType, out count);
                //胡牌花
                huaCount += count;
            }

            //基数
            huaCount += 20;
            huaCount += actorGamerHuPai.BixiaHuCount;
            huaCount *= 2;

            return(huaCount);
        }
Beispiel #2
0
        // 供外部调用:获取胡牌类型
        public List <HuPaiType> getHuPaiType(List <MahjongInfo> list, HuPaiNeedData huPaiNeedData)
        {
            List <MahjongInfo> list_copy = new List <MahjongInfo>();

            for (int i = 0; i < list.Count; i++)
            {
                list_copy.Add(list[i]);
            }

            SortMahjong(list_copy);

            List <HuPaiType> type_list = new List <HuPaiType>();

            // 混一色
            {
                List <MahjongType> tempList = new List <MahjongType>();

                // 手牌
                for (int i = 0; i < list_copy.Count; i++)
                {
                    MahjongType mahjongType = getMahjongType(list_copy[i]);

                    bool isFind = false;
                    for (int j = 0; j < tempList.Count; j++)
                    {
                        if (tempList[j] == mahjongType)
                        {
                            isFind = true;
                            break;
                        }
                    }

                    if (!isFind)
                    {
                        tempList.Add(mahjongType);
                    }
                }

                // 碰掉的牌
                for (int i = 0; i < huPaiNeedData.my_pengList.Count; i++)
                {
                    MahjongType mahjongType = getMahjongType(huPaiNeedData.my_pengList[i]);

                    bool isFind = false;
                    for (int j = 0; j < tempList.Count; j++)
                    {
                        if (tempList[j] == mahjongType)
                        {
                            isFind = true;
                            break;
                        }
                    }

                    if (!isFind)
                    {
                        tempList.Add(mahjongType);
                    }
                }

                // 杠掉的牌
                for (int i = 0; i < huPaiNeedData.my_gangList.Count; i++)
                {
                    MahjongType mahjongType = getMahjongType(huPaiNeedData.my_gangList[i]);

                    bool isFind = false;
                    for (int j = 0; j < tempList.Count; j++)
                    {
                        if (tempList[j] == mahjongType)
                        {
                            isFind = true;
                            break;
                        }
                    }

                    if (!isFind)
                    {
                        tempList.Add(mahjongType);
                    }
                }

                if (tempList.Count == 2)
                {
                    if (((tempList[0] == MahjongType.Feng) && (tempList[1] != MahjongType.Feng)) ||
                        ((tempList[1] == MahjongType.Feng) && (tempList[0] != MahjongType.Feng)))
                    {
                        type_list.Add(HuPaiType.HunYiSe);
                    }
                }
            }

            // 清一色
            {
                List <MahjongType> tempList = new List <MahjongType>();

                // 手牌
                for (int i = 0; i < list_copy.Count; i++)
                {
                    MahjongType mahjongType = getMahjongType(list_copy[i]);

                    bool isFind = false;
                    for (int j = 0; j < tempList.Count; j++)
                    {
                        if (tempList[j] == mahjongType)
                        {
                            isFind = true;
                            break;
                        }
                    }

                    if (!isFind)
                    {
                        tempList.Add(mahjongType);
                    }
                }

                // 碰掉的牌
                for (int i = 0; i < huPaiNeedData.my_pengList.Count; i++)
                {
                    MahjongType mahjongType = getMahjongType(huPaiNeedData.my_pengList[i]);

                    bool isFind = false;
                    for (int j = 0; j < tempList.Count; j++)
                    {
                        if (tempList[j] == mahjongType)
                        {
                            isFind = true;
                            break;
                        }
                    }

                    if (!isFind)
                    {
                        tempList.Add(mahjongType);
                    }
                }

                // 杠掉的牌
                for (int i = 0; i < huPaiNeedData.my_gangList.Count; i++)
                {
                    MahjongType mahjongType = getMahjongType(huPaiNeedData.my_gangList[i]);

                    bool isFind = false;
                    for (int j = 0; j < tempList.Count; j++)
                    {
                        if (tempList[j] == mahjongType)
                        {
                            isFind = true;
                            break;
                        }
                    }

                    if (!isFind)
                    {
                        tempList.Add(mahjongType);
                    }
                }

                if (tempList.Count == 1)
                {
                    if (tempList[0] != MahjongType.Feng)
                    {
                        type_list.Add(HuPaiType.QingYiSe);
                    }
                }
            }

            // 对对胡
            {
                List <MahjongInfo> list_double = selectDouble(list_copy);
                List <MahjongInfo> list_three  = selectThree(list_copy);

                if ((list_double.Count == 1) && ((list_three.Count + huPaiNeedData.my_pengList.Count) == 4))
                {
                    type_list.Add(HuPaiType.DuiDuiHu);
                }
            }

            // 全球独钓
            {
                if (list_copy.Count == 2)
                {
                    type_list.Add(HuPaiType.QuanQiuDuDiao);
                }
            }

            // 七对
            {
                List <MahjongInfo> list_double = selectDouble(list_copy);
                if (list_double.Count == 7)
                {
                    List <MahjongInfo> list_four = new List <MahjongInfo>();
                    for (int i = 0; i < list_double.Count; i++)
                    {
                        for (int j = 0; j < list_double.Count; j++)
                        {
                            if ((i != j) && (list_double[i] == list_double[j]))
                            {
                                bool isFind = false;
                                for (int k = 0; k < list_four.Count; k++)
                                {
                                    if (list_four[k].m_weight == list_double[i].m_weight)
                                    {
                                        isFind = true;
                                        break;
                                    }
                                }

                                if (!isFind)
                                {
                                    list_four.Add(list_double[i]);
                                }
                            }
                        }
                    }

                    // 超超豪华
                    if (list_four.Count >= 3)
                    {
                        type_list.Add(HuPaiType.QiDui_ChaoChaoHaoHua);
                    }
                    // 超豪华
                    else if (list_four.Count >= 2)
                    {
                        type_list.Add(HuPaiType.QiDui_ChaoHaoHua);
                    }
                    // 豪华
                    else if (list_four.Count >= 1)
                    {
                        type_list.Add(HuPaiType.QiDui_HaoHua);
                    }
                    // 普通
                    else
                    {
                        type_list.Add(HuPaiType.QiDui_Normal);
                    }
                }
            }

            // 门清
            {
                bool isQiDui = false;
                for (int i = 0; i < type_list.Count; i++)
                {
                    if ((type_list[i] >= HuPaiType.QiDui_Normal) &&
                        (type_list[i] <= HuPaiType.QiDui_ChaoChaoHaoHua))
                    {
                        isQiDui = true;
                        break;
                    }
                }

                if (!isQiDui)
                {
                    if (huPaiNeedData.my_pengList.Count == 0)
                    {
                        type_list.Add(HuPaiType.MenQing);
                    }
                }
            }

            // 压绝
            {
                bool isYaJue = false;
                for (int i = 0; i < huPaiNeedData.my_pengList.Count; i++)
                {
                    if (huPaiNeedData.my_pengList[i].m_weight == huPaiNeedData.my_lastMahjong.m_weight)
                    {
                        isYaJue = true;
                        break;
                    }
                }

                if (!isYaJue)
                {
                    for (int i = 0; i < huPaiNeedData.other1_pengList.Count; i++)
                    {
                        if (huPaiNeedData.other1_pengList[i].m_weight == huPaiNeedData.my_lastMahjong.m_weight)
                        {
                            isYaJue = true;
                            break;
                        }
                    }
                }

                if (!isYaJue)
                {
                    for (int i = 0; i < huPaiNeedData.other2_pengList.Count; i++)
                    {
                        if (huPaiNeedData.other2_pengList[i].m_weight == huPaiNeedData.my_lastMahjong.m_weight)
                        {
                            isYaJue = true;
                            break;
                        }
                    }
                }

                if (!isYaJue)
                {
                    for (int i = 0; i < huPaiNeedData.other3_pengList.Count; i++)
                    {
                        if (huPaiNeedData.other3_pengList[i].m_weight == huPaiNeedData.my_lastMahjong.m_weight)
                        {
                            isYaJue = true;
                            break;
                        }
                    }
                }

                if (isYaJue)
                {
                    type_list.Add(HuPaiType.YaJue);
                }
            }

            // 无花果
            {
                if (huPaiNeedData.my_yingHuaList.Count == 0)
                {
                    type_list.Add(HuPaiType.WuHuaGuo);
                }
            }

            // 杠后开花
            {
                // 小:抓到硬花补牌后胡牌
                if (huPaiNeedData.isGetYingHuaBuPai)
                {
                    type_list.Add(HuPaiType.GangHouKaiHua_Small);
                }

                // 大:杠完补牌后胡牌
                if (huPaiNeedData.isGangEndBuPai)
                {
                    type_list.Add(HuPaiType.GangHouKaiHua_Big);
                }
            }

            // 天胡
            {
                if (huPaiNeedData.isZhuangJia && huPaiNeedData.isGangFaWanPai && (list_copy.Count == 14))
                {
                    type_list.Add(HuPaiType.TianHu);
                }
            }

            // 地胡
            {
                if (huPaiNeedData.isFaWanPaiTingPai)
                {
                    if ((huPaiNeedData.my_pengList.Count == 0) && (huPaiNeedData.my_gangList.Count == 0))
                    {
                        type_list.Add(HuPaiType.DiHu);
                    }
                }
            }

            // 海底捞月
            {
                if ((huPaiNeedData.restMahjongCount <= (8 * 2)) && huPaiNeedData.isSelfZhuaPai)
                {
                    type_list.Add(HuPaiType.HaiDiLaoYue);
                }
            }

            // 小胡:最普通的胡牌
            if (type_list.Count == 0)
            {
                {
                    type_list.Add(HuPaiType.Normal);
                }
            }

            return(type_list);
        }