Ejemplo n.º 1
0
        public void setData(Actor_GamerHuPai data, GamerComponent gamerComponent, int BeiLv)
        {
            this.huPaiNeedData = data;

            Gamer[] gamers     = gamerComponent.GetAll();
            Gamer   huPaiGamer = gamerComponent.Get(data.Uid);

            for (int i = 0; i < gamers.Length; i++)
            {
                if (gamers[i] == null)
                {
                    continue;
                }
                if (gamers[i].UserID == data.Uid)
                {
                    playerList.Insert(i, winPlayer);
                }
            }

            int huaCount = 0;
            //设置胡牌的花数
            List <int> dataHuPaiTypes = data.HuPaiTypes;

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

            //硬花
            huaCount += data.YingHuaCount;
            //软花
            huaCount += data.RuanHuaCount;

            huaCount += data.BixiaHuCount;
            //基数
            huaCount += 20;
            //砸2
            huaCount *= 2;
            //设置胡牌的人
            for (int i = 0; i < gamers.Length; i++)
            {
                Gamer      gamer      = gamers[i];
                GameObject gameObject = this.playerList[i];
                Image      headImage  = gameObject.transform.Find("head").GetComponent <Image>();
                Text       nameText   = gameObject.transform.Find("name").GetComponent <Text>();
                Text       goldText   = gameObject.transform.Find("Text_gold").GetComponent <Text>();

                //headImage.sprite = CommonUtil.getSpriteByBundle("playericon", gamer.PlayerInfo.Icon);
                HeadManager.setHeadSprite(headImage, gamer.PlayerInfo.Icon);
                nameText.text = gamer.PlayerInfo.Name + "";
                //胡牌的ui
                if (gamer.UserID == data.Uid)
                {
                    Text       huaCountText  = gameObject.Get <GameObject>("Text").GetComponent <Text>();
                    GameObject allhuashutype = gameObject.Get <GameObject>("Allhuashutype");

                    Text obj1 = allhuashutype.transform.GetChild(0).GetComponent <Text>();
                    Text obj2 = allhuashutype.transform.GetChild(1).GetComponent <Text>();
                    Text obj3 = allhuashutype.transform.GetChild(2).GetComponent <Text>();
                    obj1.gameObject.SetActive(true);
                    obj2.gameObject.SetActive(true);
                    obj3.gameObject.SetActive(true);

                    obj1.text = $"硬花{data.YingHuaCount}";
                    obj2.text = $"软花{data.RuanHuaCount}";
                    obj3.text = $"基数{20}";

                    //胡牌类型
                    for (int j = 0; j < dataHuPaiTypes.Count; j++)
                    {
                        Consts.HuPaiType huPaiType = (Consts.HuPaiType)dataHuPaiTypes[j];
                        int    count;
                        string name;
                        Logic_NJMJ.getInstance().HuPaiHuaCount.TryGetValue(huPaiType, out count);
                        Logic_NJMJ.getInstance().HuPaiHuaName.TryGetValue(huPaiType, out name);

                        Text obj = allhuashutype.transform.GetChild(j + 3).gameObject.GetComponent <Text>();
                        obj.gameObject.SetActive(true);
                        obj.text = $"{name}{count}";
                    }

                    if (data.BixiaHuCount > 0)
                    {
                        Text obj4 = allhuashutype.transform.GetChild(dataHuPaiTypes.Count + 3).GetComponent <Text>();
                        obj4.gameObject.SetActive(true);
                        obj4.text = $"比下胡{data.BixiaHuCount}";

                        Text obj5 = allhuashutype.transform.GetChild(dataHuPaiTypes.Count + 4).GetComponent <Text>();
                        obj5.gameObject.SetActive(true);
                        obj5.text = "砸2";
                    }
                    else
                    {
                        Text obj4 = allhuashutype.transform.GetChild(dataHuPaiTypes.Count + 3).GetComponent <Text>();
                        obj4.gameObject.SetActive(true);
                        obj4.text = "砸2";
                    }
                    huaCountText.text = huaCount + "";
                    if (data.IsZiMo)
                    {
                        goldText.text = BeiLv * huaCount * 3 + "";
                    }
                    else
                    {
                        goldText.text = BeiLv * huaCount + "";
                    }
                }
                else
                {
                    if (data.IsZiMo)
                    {
                        if (BeiLv * huaCount == 0)
                        {
                            goldText.text = "0";
                        }
                        else
                        {
                            goldText.text = "-" + BeiLv * huaCount + "";
                        }
                    }
                    else
                    {
                        if (gamer.UserID == data.FangPaoUid)
                        {
                            if (BeiLv * huaCount == 0)
                            {
                                goldText.text = "0";
                            }
                            else
                            {
                                goldText.text = "-" + BeiLv * huaCount + "";
                            }

                            nameText.color = Color.yellow;
                        }
                    }
                }
            }

            if (huPaiNeedData.IsZiMo)
            {
                winPlayer.transform.Find("hupaiType").GetComponent <Image>().sprite =
                    CommonUtil.getSpriteByBundle("image_gameresult", "gameresult_hu");
            }

            SetHuPaiPlayerData();
        }
        /// <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);
        }