/// <summary>
        /// 碰刚
        /// </summary>
        /// <param name="messageOperationType"></param>
        /// <param name="mahjong"></param>
        public void SetPengGang(int messageOperationType, MahjongInfo mahjong)
        {
            Log.Debug("显示碰后杠");
            GameObject obj   = CommonUtil.getGameObjByBundle("Item_Gang_Card");
            int        index = Logic_NJMJ.getInstance().GetIndex(this.handCards, mahjong);

            this.RemoveCard(index);
            UpdateCards();

            //显示碰
            GameObject gameObject = GameObject.Instantiate(obj, this.pengObj.transform);

            for (int i = 0; i < 2; i++)
            {
                gameObject.transform.GetChild(i).GetComponent <Image>().sprite =
                    CommonUtil.getSpriteByBundle("Image_Top_Card", "card_" + mahjong.weight);
            }

            GameObject lastPengObj = null;

            if (pengDic.TryGetValue(mahjong.weight, out lastPengObj))
            {
                gameObject.transform.SetSiblingIndex(lastPengObj.transform.GetSiblingIndex());
                gameObject.transform.localPosition = lastPengObj.transform.localPosition;
                GameObject.Destroy(lastPengObj);
                pengDic.Remove(mahjong.weight);
            }
        }
        /// <summary>
        /// 卡牌精灵更新
        /// </summary>
        public void CardsSpriteUpdate(List <MahjongInfo> mahjongInfos, float interval)
        {
            if (mahjongInfos.Count == 0)
            {
                return;
            }

            Logic_NJMJ.getInstance().SortMahjong(mahjongInfos);
        }
Exemple #3
0
        public void CanTing(List <MahjongInfo> list)
        {
            List <MahjongInfo> checkTingPaiList = Logic_NJMJ.getInstance().checkTingPaiList(list);

            if (checkTingPaiList?.Count != 0)
            {
                Log.Debug("玩家停牌");
            }
        }
Exemple #4
0
        protected override async Task Run(Gamer gamer, Actor_GamerCheat message)
        {
            try
            {
                Log.Info("收到作弊:" + JsonHelper.ToJson(message));
                if (string.IsNullOrEmpty(message.Info))
                {
                    return;
                }
                string[]      split         = message.Info.Split(' ');
                RoomComponent roomComponent = Game.Scene.GetComponent <RoomComponent>();
                Room          room          = roomComponent.Get(gamer.RoomID);

                HandCardsComponent handCardsComponent = gamer.GetComponent <HandCardsComponent>();

                if (handCardsComponent == null)
                {
                    handCardsComponent = gamer.AddComponent <HandCardsComponent>();
                }

                if (split.Length == 13)
                {
                    List <MahjongInfo> mahjongInfos = new List <MahjongInfo>();
                    foreach (var item in split)
                    {
                        mahjongInfos.Add(new MahjongInfo()
                        {
                            m_weight = (Consts.MahjongWeight)Convert.ToInt32(item),
                            weight   = (byte)Convert.ToInt32(item)
                        });
                    }

                    handCardsComponent.library = mahjongInfos;
                    Logic_NJMJ.getInstance().SortMahjong(handCardsComponent.library);

                    Actor_GamerCheat actorCheat = new Actor_GamerCheat();
                    actorCheat.handCards = mahjongInfos;

                    room.GamerBroadcast(gamer, actorCheat);
                }
                else if (split.Length == 1)
                {
                    int num = Convert.ToInt32(split[0]);
                    room.NextGrabCard = new MahjongInfo()
                    {
                        m_weight = (Consts.MahjongWeight)num,
                        weight   = (byte)num
                    };
                }
            }
            catch (Exception e)
            {
                Log.Error(e);
            }
            await Task.CompletedTask;
        }
Exemple #5
0
        public bool CanGang(List <MahjongInfo> list, MahjongInfo mahjongInfo)
        {
            if (Logic_NJMJ.getInstance().isCanGang(mahjongInfo, list))
            {
                gangBtn.gameObject.SetActive(true);
                return(true);
            }

            return(false);
        }
Exemple #6
0
        public static Logic_NJMJ getInstance()
        {
            if (s_instance == null)
            {
                s_instance = new Logic_NJMJ();
                s_instance.initMahjongList();
                s_instance.initHuaCount();
            }

            return(s_instance);
        }
Exemple #7
0
        public bool CanHu(List <MahjongInfo> list, MahjongInfo mahjongInfo)
        {
            List <MahjongInfo> temp = new List <MahjongInfo>(list);

            temp.Add(mahjongInfo);
            if (Logic_NJMJ.getInstance().isHuPai(temp))
            {
                gangBtn.gameObject.SetActive(true);
                return(true);
            }

            return(false);
        }
        public void AddCards(List <MahjongInfo> mahjongs)
        {
            Logic_NJMJ.getInstance().SortMahjong(mahjongs);
            handCards.Clear();
            ItemCards.Clear();
            GameHelp.DeleteAllItem(CardBottom);

            for (int i = 0; i < mahjongs.Count; i++)
            {
                if (i > 12)
                {
                    AddCard(mahjongs[i], (mahjongs.Count - 1) * postionX + 30, 0, i);
                }
                else
                {
                    AddCard(mahjongs[i], postionX * i, postionY * i, i);
                }
            }

            handCards = mahjongs;
        }
Exemple #9
0
        /// <summary>
        /// 发牌
        /// </summary>
        /// <param name="self"></param>
        public static void DealCards(this GameControllerComponent self)
        {
            if (self == null)
            {
                Log.Error("当前为null:GameControllerComponent.DealCards");
                return;
            }

            temp.Clear();

            Room room = self.GetParent <Room>();

            Gamer[] gamers = room.GetAll();

            DeskComponent deskComponent = room.GetComponent <DeskComponent>();

            foreach (var gamer in gamers)
            {
                HandCardsComponent handCardsComponent = gamer.GetComponent <HandCardsComponent>();

                //发牌前有拍了
                if (handCardsComponent.GetAll().Count > 0)
                {
//                    Log.Debug("发牌前有牌了:" + handCardsComponent.GetAll().Count);
                    temp.Add(null);
                }
                else
                {
//                    Log.Debug("发牌前没有拍");
                    temp.Add(handCardsComponent.GetAll());
                }
            }

            Logic_NJMJ.getInstance().FaMahjong(temp, deskComponent.RestLibrary);

            foreach (var card in deskComponent.RestLibrary)
            {
                card.weight = (byte)card.m_weight;
            }
        }
Exemple #10
0
        public static bool CanHu(this Room self, MahjongInfo mahjongInfo, List <MahjongInfo> list)
        {
            List <MahjongInfo> temp = new List <MahjongInfo>(list);

            temp.Add(mahjongInfo);

            try
            {
                if (Logic_NJMJ.getInstance().isHuPai(temp))
                {
                    return(true);
                }
            }
            catch (Exception e)
            {
                Log.Error("胡牌错误:" + e);
                Log.Info(JsonHelper.ToJson(temp));
            }


            return(false);
        }
        public static async Task GamerReady(Gamer gamer, Actor_GamerReady message)
        {
            try
            {
                Log.Info($"收到玩家{gamer.UserID}准备");
                RoomComponent roomComponent = Game.Scene.GetComponent <RoomComponent>();
                Room          room          = roomComponent.Get(gamer.RoomID);

                if (room == null || gamer == null || gamer.IsReady || room.State == RoomState.Game)
                {
                    return;
                }

                gamer.IsReady = true;
                //消息广播给其他人
                room?.Broadcast(new Actor_GamerReady()
                {
                    Uid = gamer.UserID
                });

                Gamer[] gamers = room.GetAll();
                //房间内有4名玩家且全部准备则开始游戏
                if (room.Count == 4 && gamers.Where(g => g.IsReady).Count() == 4)
                {
                    room.State = RoomState.Game;
                    room.CurrentJuCount++;
                    room.IsGameOver = false;
                    room.RoomDispose();

                    #region 好友房扣钥匙

                    if (room.IsFriendRoom && room.CurrentJuCount == 1)
                    {
                        RoomConfig roomConfig = room.GetComponent <GameControllerComponent>().RoomConfig;
                        await DBCommonUtil.DeleteFriendKey(roomConfig.MasterUserId, roomConfig.KeyCount, "好友房房主扣除钥匙");
                    }
                    #endregion
                    //设置比下胡
                    if (room.LastBiXiaHu)
                    {
                        room.IsBiXiaHu = true;
                    }
                    else
                    {
                        room.IsBiXiaHu = false;
                    }
                    room.LastBiXiaHu = false;


                    if (roomComponent.gameRooms.TryGetValue(room.Id, out var itemRoom))
                    {
                        roomComponent.gameRooms.Remove(room.Id);
                    }

                    roomComponent.gameRooms.Add(room.Id, room);
                    roomComponent.idleRooms.Remove(room.Id);
                    //添加用户
                    room.UserIds.Clear();
                    //初始玩家开始状态
                    foreach (var _gamer in gamers)
                    {
                        room.UserIds.Add(_gamer.UserID);

                        if (_gamer.GetComponent <HandCardsComponent>() == null)
                        {
                            _gamer.AddComponent <HandCardsComponent>();
                        }

                        _gamer.IsReady = false;
                    }

                    Log.Info($"{room.Id}房间开始,玩家:{JsonHelper.ToJson(room.UserIds)}");


                    GameControllerComponent  gameController  = room.GetComponent <GameControllerComponent>();
                    OrderControllerComponent orderController = room.GetComponent <OrderControllerComponent>();
                    DeskComponent            deskComponent   = room.GetComponent <DeskComponent>();

                    Gamer bankerGamer = null;
                    HandCardsComponent bankerHandCards = null;
                    if (room.IsLianZhuang)
                    {
                        if (room.huPaiUid != 0 && room.huPaiUid == room.BankerGamer?.UserID)
                        {
                            bankerGamer              = room.Get(room.huPaiUid);
                            bankerHandCards          = bankerGamer.GetComponent <HandCardsComponent>();
                            bankerHandCards.IsBanker = true;
                            room.BankerGamer         = bankerGamer;
                            //连庄
                            room.LastBiXiaHu = true;
                        }
                        else
                        {
                            int gamerSeat = room.GetGamerSeat(room.BankerGamer.UserID);
                            int currentSeat;
                            if (gamerSeat == 3)
                            {
                                currentSeat = 0;
                            }
                            else
                            {
                                currentSeat = ++gamerSeat;
                            }

                            bankerGamer              = room.gamers[currentSeat];
                            bankerHandCards          = bankerGamer.GetComponent <HandCardsComponent>();
                            bankerHandCards.IsBanker = true;
                            room.BankerGamer         = bankerGamer;
                        }
                    }
                    else
                    {
                        if (room.IsFriendRoom)
                        {
                            GameControllerComponent controllerComponent = room.GetComponent <GameControllerComponent>();
                            long masterUserId = controllerComponent.RoomConfig.MasterUserId;
                            bankerGamer = room.Get(masterUserId);
                        }
                        else
                        {
                            //随机庄家
                            int number = RandomHelper.RandomNumber(0, 12);
                            int i      = number % 4;
                            bankerGamer = room.gamers[i];
                        }
                        bankerHandCards          = bankerGamer.GetComponent <HandCardsComponent>();
                        bankerHandCards.IsBanker = true;
                        room.BankerGamer         = bankerGamer;
                    }

                    //发牌
                    gameController.DealCards();
                    orderController.Start(bankerGamer.UserID);

                    //去除花牌
                    foreach (var _gamer in gamers)
                    {
                        HandCardsComponent handCardsComponent = _gamer.GetComponent <HandCardsComponent>();
                        List <MahjongInfo> handCards          = handCardsComponent.GetAll();

                        for (int j = handCards.Count - 1; j >= 0; j--)
                        {
                            MahjongInfo mahjongInfo = handCards[j];

                            if (mahjongInfo.m_weight >= Consts.MahjongWeight.Hua_HongZhong)
                            {
                                handCards.RemoveAt(j);
                                mahjongInfo.weight = (byte)mahjongInfo.m_weight;
                                handCardsComponent.FaceCards.Add(mahjongInfo);
                                handCardsComponent.FaceGangCards.Add(mahjongInfo);
                            }
                        }

                        //加牌
                        int handCardsCount = handCards.Count;
                        for (int j = 0; j < 13 - handCardsCount; j++)
                        {
                            GetCardNotFace(deskComponent, handCardsComponent);
                        }
                    }

                    //庄家多发一张牌
                    GetCardNotFace(deskComponent, bankerHandCards);

//	                List<MahjongInfo> infos = bankerHandCards.GetAll();
//	                bankerHandCards.library = new List<MahjongInfo>(list);

                    //给客户端传送数据
                    Actor_StartGame actorStartGame = new Actor_StartGame();
                    foreach (var itemGame in gamers)
                    {
                        GamerData          gamerData          = new GamerData();
                        HandCardsComponent handCardsComponent = itemGame.GetComponent <HandCardsComponent>();

                        List <MahjongInfo> mahjongInfos = handCardsComponent.library;
                        foreach (var mahjongInfo in mahjongInfos)
                        {
                            mahjongInfo.weight = (byte)mahjongInfo.m_weight;
                        }

                        gamerData.UserID    = itemGame.UserID;
                        gamerData.handCards = mahjongInfos;
                        gamerData.faceCards = handCardsComponent.FaceCards;
                        if (handCardsComponent.IsBanker)
                        {
                            gamerData.IsBanker = true;
                        }

                        gamerData.SeatIndex     = room.seats[itemGame.UserID];
                        gamerData.OnlineSeconds = await DBCommonUtil.GetRestOnlineSeconds(itemGame.UserID);

                        actorStartGame.GamerDatas.Add(gamerData);
                    }

                    actorStartGame.restCount = deskComponent.RestLibrary.Count;
                    GameControllerComponent gameControllerComponent = room.GetComponent <GameControllerComponent>();

                    if (room.IsFriendRoom)
                    {
                        actorStartGame.RoomType       = 3;
                        actorStartGame.CurrentJuCount = room.CurrentJuCount;
                    }
                    else
                    {
                        actorStartGame.RoomType = (int)gameControllerComponent.RoomConfig.Id;
                    }
                    //发送消息
                    room.Broadcast(actorStartGame);
//	                Log.Debug("发送开始:" + JsonHelper.ToJson(actorStartGame));

                    //排序
                    var startTime = DateTime.Now;
                    foreach (var _gamer in gamers)
                    {
                        HandCardsComponent handCardsComponent = _gamer.GetComponent <HandCardsComponent>();
                        //排序
                        handCardsComponent.Sort();
                        handCardsComponent.GrabCard = handCardsComponent.GetAll()[handCardsComponent.GetAll().Count - 1];
                        //设置玩家在线开始时间
                        _gamer.StartTime = startTime;
                        //await DBCommonUtil.RecordGamerTime(startTime, true, _gamer.UserID);
                    }

                    foreach (var _gamer in room.GetAll())
                    {
                        HandCardsComponent handCardsComponent = _gamer.GetComponent <HandCardsComponent>();

                        List <MahjongInfo> cards = handCardsComponent.GetAll();

                        if (handCardsComponent.IsBanker)
                        {
                            if (Logic_NJMJ.getInstance().isHuPai(cards))
                            {
                                //ToDo 胡牌
                                Actor_GamerCanOperation canOperation = new Actor_GamerCanOperation();
                                canOperation.Uid           = _gamer.UserID;
                                _gamer.IsCanHu             = true;
                                canOperation.OperationType = 2;
                                room.GamerBroadcast(_gamer, canOperation);
                                _gamer.isGangFaWanPai = true;
                            }
                        }
                        else
                        {
                            //检查听牌
                            List <MahjongInfo> checkTingPaiList = Logic_NJMJ.getInstance().checkTingPaiList(cards);
                            if (checkTingPaiList.Count > 0)
                            {
                                Log.Info($"{_gamer.UserID}听牌:");
                                _gamer.isFaWanPaiTingPai = true;
                            }
                        }
                    }

                    //等客户端掷骰子
                    //是否超时
                    await Game.Scene.GetComponent <TimerComponent>().WaitAsync(10 * 1000);

                    room.StartTime();
                    //扣服务费
                    if (!room.IsFriendRoom)
                    {
                        //不要动画
                        GameHelp.CostServiceCharge(room, false);
                    }
                }
            }
            catch (Exception e)
            {
                Log.Error(e);
            }

            await Task.CompletedTask;
        }
 /// <summary>
 /// 手牌排序
 /// </summary>
 /// <param name="self"></param>
 public static void Sort(this HandCardsComponent self)
 {
     Logic_NJMJ.getInstance().SortMahjong(self.library);
 }
Exemple #13
0
        public static async Task PlayCard(Gamer gamer, Actor_GamerPlayCard message)
        {
            RoomComponent roomComponent = Game.Scene.GetComponent <RoomComponent>();
            Room          room          = roomComponent.Get(gamer.RoomID);

            if (room == null || room.IsGameOver)
            {
                return;
            }

            try
            {
                MahjongInfo mahjongInfo = new MahjongInfo()
                {
                    weight   = (byte)message.weight,
                    m_weight = (Consts.MahjongWeight)message.weight
                };

                //加锁
                if (room.IsPlayingCard)
                {
                    Log.Warning("当前正在出牌,不能再出牌了");
                    return;
                }
                room.IsPlayingCard = true;

                GameControllerComponent  gameController  = room.GetComponent <GameControllerComponent>();
                OrderControllerComponent orderController = room.GetComponent <OrderControllerComponent>();
                DeskComponent            deskComponent   = room.GetComponent <DeskComponent>();

                HandCardsComponent handCardsComponent = gamer.GetComponent <HandCardsComponent>();
                if (handCardsComponent == null)
                {
                    return;
                }
                List <MahjongInfo> mahjongInfos = handCardsComponent.GetAll();

                if (orderController.CurrentAuthority != gamer.UserID)
                {
                    Log.Warning("没有轮到当前玩家出牌:" + gamer.UserID);
                    Log.Warning("当前出牌玩家:" + orderController.CurrentAuthority);
                    room.IsPlayingCard = false;
                    return;
                }

                int index = -1;
                for (int i = 0; i < mahjongInfos.Count; i++)
                {
                    if (mahjongInfos[i].m_weight == mahjongInfo.m_weight)
                    {
                        index = i;
                        break;
                    }
                }

                if (index >= 0)
                {
                    //停止倒计时
                    room?.tokenSource?.Cancel();
                    Log.Info($"玩家{gamer.UserID}出牌:" + mahjongInfo.m_weight);
                    //当前出的牌
                    deskComponent.CurrentCard      = mahjongInfo;
                    deskComponent.CurrentAuthority = gamer.UserID;
                    handCardsComponent.PlayCards.Add(mahjongInfo);
                    mahjongInfos.RemoveAt(index);
                    room.my_lastMahjong = mahjongInfo;
                    Actor_GamerPlayCard actorGamerPlayCard = new Actor_GamerPlayCard()
                    {
                        weight = message.weight,
                        Uid    = gamer.UserID,
                        index  = message.index
                    };

                    room.Broadcast(actorGamerPlayCard);

                    gamer.IsCanHu   = false;
                    gamer.IsCanPeng = false;
                    gamer.IsCanGang = false;

                    #region 4个人连续出同样的牌,第一个出牌的人立即支付其他三人

                    List <MahjongInfo> list = new List <MahjongInfo>();
                    foreach (var _gamer in room.GetAll())
                    {
                        HandCardsComponent cardsComponent = _gamer.GetComponent <HandCardsComponent>();

                        if (cardsComponent.PlayCards.Count > 0)
                        {
                            list.Add(cardsComponent.PlayCards[cardsComponent.PlayCards.Count - 1]);
                        }
                    }

                    if (list.Count == 4)
                    {
                        bool flag = true;

                        for (int i = 1; i < list.Count; i++)
                        {
                            if (list[0].m_weight != list[i].m_weight)
                            {
                                flag = false;
                                break;
                            }
                        }

                        if (flag)
                        {
                            Gamer nextGamer = orderController.FindNextGamer(gamer.UserID);

                            //罚分
                            foreach (var _gamer in room.GetAll())
                            {
                                if (_gamer.UserID == nextGamer.UserID)
                                {
                                    GameHelp.ChangeGamerGold(room, _gamer, -10 * gameController.RoomConfig.Multiples * 3);
                                }
                                else
                                {
                                    GameHelp.ChangeGamerGold(room, _gamer, 10 * gameController.RoomConfig.Multiples);
                                }

                                room.GamerBroadcast(_gamer, new Actor_ShowAnimType()
                                {
                                    Type  = 3,
                                    Count = 0
                                });
                            }
                            room.LastBiXiaHu = true;
                        }
                    }
                    #endregion

                    #region 一个人出4张一样的牌
                    //4个人出一样的牌
                    int temp = 0;
                    foreach (var playCard in handCardsComponent.PlayCards)
                    {
                        if (playCard.m_weight == mahjongInfo.m_weight)
                        {
                            temp++;
                        }
                    }
                    if (temp == 4)
                    {
                        //罚分
                        foreach (var _gamer in room.GetAll())
                        {
                            if (_gamer.UserID == gamer.UserID)
                            {
                                GameHelp.ChangeGamerGold(room, _gamer, -10 * gameController.RoomConfig.Multiples * 3);
                            }
                            else
                            {
                                GameHelp.ChangeGamerGold(room, _gamer, 10 * gameController.RoomConfig.Multiples);
                            }

                            room.GamerBroadcast(_gamer, new Actor_ShowAnimType()
                            {
                                Type  = 3,
                                Count = 0
                            });
                        }

                        room.LastBiXiaHu = true;
                    }
                    #endregion

                    #region 一人前四次出牌打出东南西北(不必按顺序),则其他每名玩家立即支付给该玩家

                    if (handCardsComponent.PlayCards.Count == 4)
                    {
                        int Feng_Dong = handCardsComponent.PlayCards.Count(a => a.m_weight == Consts.MahjongWeight.Feng_Dong);
                        int Feng_Nan  = handCardsComponent.PlayCards.Count(a => a.m_weight == Consts.MahjongWeight.Feng_Nan);
                        int Feng_Xi   = handCardsComponent.PlayCards.Count(a => a.m_weight == Consts.MahjongWeight.Feng_Xi);
                        int Feng_Bei  = handCardsComponent.PlayCards.Count(a => a.m_weight == Consts.MahjongWeight.Feng_Bei);

                        if (Feng_Dong == 1 && Feng_Nan == 1 && Feng_Xi == 1 && Feng_Bei == 1)
                        {
                            //四连风
                            foreach (var _gamer in room.GetAll())
                            {
                                if (_gamer.UserID == gamer.UserID)
                                {
                                    GameHelp.ChangeGamerGold(room, _gamer, 5 * gameController.RoomConfig.Multiples * 3);
                                }
                                else
                                {
                                    GameHelp.ChangeGamerGold(room, _gamer, -5 * gameController.RoomConfig.Multiples);
                                }

                                room.GamerBroadcast(_gamer, new Actor_ShowAnimType()
                                {
                                    Type  = 2,
                                    Count = 0
                                });
                            }
                        }
                    }

                    #endregion

                    #region 等待客户端有没有人碰杠胡
                    //等待客户端有没有人碰
                    bool isNeedWait = false;

                    foreach (var _gamer in room.GetAll())
                    {
                        if (_gamer == null)
                        {
                            continue;
                        }
                        if (_gamer.UserID == gamer.UserID)
                        {
                            continue;
                        }

                        HandCardsComponent currentCards = _gamer.GetComponent <HandCardsComponent>();

                        List <MahjongInfo> cards = _gamer.GetComponent <HandCardsComponent>().GetAll();

                        if (Logic_NJMJ.getInstance().isCanPeng(mahjongInfo, cards))
                        {
                            Actor_GamerCanOperation canOperation = new Actor_GamerCanOperation();
                            canOperation.Uid = _gamer.UserID;

                            _gamer.IsCanPeng           = true;
                            isNeedWait                 = true;
                            canOperation.OperationType = 0;
                            //Log.Info($"{_gamer.UserID}可碰:"+JsonHelper.ToJson(canOperation));
                            room.GamerBroadcast(_gamer, canOperation);
                        }

                        //明杠
                        if (Logic_NJMJ.getInstance().isCanGang(mahjongInfo, cards))
                        {
                            Actor_GamerCanOperation canOperation = new Actor_GamerCanOperation();
                            canOperation.Uid = _gamer.UserID;

                            _gamer.IsCanGang           = true;
                            isNeedWait                 = true;
                            canOperation.OperationType = 1;
                            //Log.Info($"{_gamer.UserID}可杠" + JsonHelper.ToJson(canOperation));
                            room.GamerBroadcast(_gamer, canOperation);
                        }

                        if (room.CanHu(mahjongInfo, cards))
                        {
                            _gamer.huPaiNeedData.my_lastMahjong    = room.my_lastMahjong;
                            _gamer.huPaiNeedData.restMahjongCount  = deskComponent.RestLibrary.Count;
                            _gamer.huPaiNeedData.isSelfZhuaPai     = orderController.CurrentAuthority == _gamer.UserID;
                            _gamer.huPaiNeedData.isZhuangJia       = currentCards.IsBanker;
                            _gamer.huPaiNeedData.isGetYingHuaBuPai = _gamer.isGetYingHuaBuPai;
                            _gamer.huPaiNeedData.isGangEndBuPai    = _gamer.isGangEndBuPai;
                            _gamer.huPaiNeedData.isGangFaWanPai    = _gamer.isGangFaWanPai;
                            _gamer.huPaiNeedData.isFaWanPaiTingPai = _gamer.isFaWanPaiTingPai;
                            _gamer.huPaiNeedData.my_yingHuaList    = currentCards.FaceCards;
                            _gamer.huPaiNeedData.my_gangList       = currentCards.GangCards;
                            _gamer.huPaiNeedData.my_pengList       = currentCards.PengCards;
                            List <List <MahjongInfo> > tempList = new List <List <MahjongInfo> >();
                            for (int i = 0; i < room.GetAll().Length; i++)
                            {
                                if (_gamer.UserID == room.GetAll()[i].UserID)
                                {
                                    continue;
                                }
                                tempList.Add(room.GetAll()[i].GetComponent <HandCardsComponent>().PengCards);
                            }

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

                            List <MahjongInfo> infos = new List <MahjongInfo>(cards);
                            infos.Add(mahjongInfo);

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

                            Log.Info(JsonHelper.ToJson(_gamer.huPaiNeedData));
                            Log.Info(JsonHelper.ToJson(huPaiTypes));

                            if (huPaiTypes.Count > 0)
                            {
                                //判断小胡,4个花以上才能胡
                                if (huPaiTypes[0] == Consts.HuPaiType.Normal)
                                {
                                    if (currentCards.PengGangCards.Count > 0 || currentCards.PengCards.Count > 0)
                                    {
                                        if (currentCards.FaceCards.Count >= 4)
                                        {
                                            _gamer.IsCanHu = true;
                                            isNeedWait     = true;
                                            Actor_GamerCanOperation canOperation = new Actor_GamerCanOperation();
                                            canOperation.Uid           = _gamer.UserID;
                                            canOperation.OperationType = 2;
                                            room.GamerBroadcast(_gamer, canOperation);
                                        }
                                    }
                                }
                                else
                                {
                                    _gamer.IsCanHu = true;
                                    isNeedWait     = true;
                                    Actor_GamerCanOperation canOperation = new Actor_GamerCanOperation();
                                    canOperation.Uid           = _gamer.UserID;
                                    canOperation.OperationType = 2;
                                    room.GamerBroadcast(_gamer, canOperation);
                                }
                            }
                        }
                    }

                    #endregion
                    if (isNeedWait)
                    {
                        room.IsNeedWaitOperate = true;
                        room.StartOperateTime();
                    }
                    //没人可以操作就直接发牌
                    else
                    {
                        room.IsNeedWaitOperate = false;
                        //发牌
                        room.GamerGrabCard();
                        room.IsPlayingCard = false;
                    }
                }
                else
                {
                    Log.Warning("玩家出牌不存在:" + message.weight);
                    room.IsPlayingCard = false;
                }
            }
            catch (Exception e)
            {
                Log.Error(e);
                room.IsPlayingCard = false;
            }

            await Task.CompletedTask;
        }
Exemple #14
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();
        }
        protected override async Task Run(Gamer gamer, Actor_GamerOperation message)
        {
            try
            {
                RoomComponent roomComponent = Game.Scene.GetComponent <RoomComponent>();
                Room          room          = roomComponent.Get(gamer.RoomID);

                room.IsOperate         = true;
                room.IsPlayingCard     = false;
                room.IsNeedWaitOperate = false;
                if (room.IsGameOver)
                {
                    return;
                }

                DeskComponent            deskComponent   = room.GetComponent <DeskComponent>();
                OrderControllerComponent orderController = room.GetComponent <OrderControllerComponent>();
                GameControllerComponent  gameController  = room.GetComponent <GameControllerComponent>();

                Gamer currentGamer = room.Get(orderController.CurrentAuthority);

                HandCardsComponent handCards = gamer.GetComponent <HandCardsComponent>();
                if (handCards == null)
                {
                    return;
                }
                List <MahjongInfo> mahjongInfos = handCards.GetAll();
                Log.Info($"玩家{gamer.UserID}碰或刚{message.OperationType},当前出牌:{deskComponent.CurrentCard.m_weight}");

                //胡牌
                int huaCount = 0;
                if (message.OperationType == 2)
                {
                    //自摸
                    bool isFinish = false;
                    if (orderController.CurrentAuthority == gamer.UserID)
                    {
                        if (Logic_NJMJ.getInstance().isHuPai(mahjongInfos))
                        {
                            huaCount = HuPai(gamer, room, mahjongInfos, true);

                            room.huPaiUid = gamer.UserID;
                            isFinish      = true;
                        }
                    }
                    //放炮
                    else
                    {
                        if (room.CanHu(deskComponent.CurrentCard, mahjongInfos))
                        {
                            List <MahjongInfo> temp = new List <MahjongInfo>(mahjongInfos);
                            temp.Add(deskComponent.CurrentCard);
                            huaCount        = HuPai(gamer, room, temp, false);
                            isFinish        = true;
                            room.huPaiUid   = gamer.UserID;
                            room.fangPaoUid = orderController.CurrentAuthority;
                        }
                    }

                    if (isFinish)
                    {
                        //游戏结束结算
                        await gameController.GameOver(huaCount);
                    }

                    gamer.IsCanHu   = false;
                    gamer.IsCanPeng = false;
                    gamer.IsCanGang = false;
                }
                //放弃
                else if (message.OperationType == 3)
                {
                    Log.Debug("放弃:" + gamer.UserID);
                    gamer.IsCanHu   = false;
                    gamer.IsCanPeng = false;
                    gamer.IsCanGang = false;
                    if (orderController.CurrentAuthority == gamer.UserID)
                    {
                        //room.tokenSource.Cancel();
                    }
                    else
                    {
                        room.tokenSource.Cancel();
                        Log.Info($"{gamer.UserID}取消,发牌");
                        room.GamerGrabCard();
                    }
                }
                else
                {
                    Actor_GamerOperation gamerOperation = new Actor_GamerOperation();
                    gamerOperation.Uid    = gamer.UserID;
                    gamerOperation.weight = deskComponent.CurrentCard.weight;

                    //有没有人胡牌
                    while (true)
                    {
                        if (!GetCanHu(room, gamer))
                        {
                            break;
                        }
                        await Game.Scene.GetComponent <TimerComponent>().WaitAsync(1000);
                    }

                    //游戏结束
                    if (room.IsGameOver)
                    {
                        Log.Warning("游戏结束不能碰刚");
                        return;
                    }

                    // 碰
                    if (message.OperationType == 0)
                    {
                        if (Logic_NJMJ.getInstance().isCanPeng(deskComponent.CurrentCard, mahjongInfos))
                        {
                            room.tokenSource.Cancel();
                            //Log.Info("11111");

                            gamerOperation.OperationType = 0;
                            gamerOperation.OperatedUid   = deskComponent.CurrentAuthority;
                            room.Broadcast(gamerOperation);

                            //更新手牌
                            for (int i = 0; i < 2; i++)
                            {
                                int index = Logic_NJMJ.getInstance().GetIndex(mahjongInfos, deskComponent.CurrentCard);
                                mahjongInfos.RemoveAt(index);
                            }
                            //Log.Info("222222");
                            handCards.PengCards.Add(deskComponent.CurrentCard);
                            currentGamer.GetComponent <HandCardsComponent>().PlayCards.Remove(deskComponent.CurrentCard);

                            //添加碰的人
                            PengOrBar pengOrBar = ComponentFactory.Create <PengOrBar>();
                            pengOrBar.OperateType = OperateType.Peng;
                            pengOrBar.Weight      = deskComponent.CurrentCard.weight;
                            pengOrBar.UserId      = deskComponent.CurrentAuthority;
                            pengOrBar.BarType     = BarType.None;

                            handCards.PengOrBars.Add(pengOrBar);

                            Log.Debug("PengOrBars:" + handCards.PengOrBars.Count);

                            //碰完当前玩家出牌
                            orderController.CurrentAuthority = gamer.UserID;
                            room.StartTime();
                        }
                    }
                    // 杠
                    else
                    {
                        HandCardsComponent handCardsComponent = gamer.GetComponent <HandCardsComponent>();
                        gamerOperation.OperationType = message.OperationType;

                        bool isSuccess = false;
                        //明杠
                        if (Logic_NJMJ.getInstance().isCanGang(deskComponent.CurrentCard, mahjongInfos))
                        {
                            isSuccess = true;

                            //更新手牌
                            for (int i = 0; i < 3; i++)
                            {
                                int index = Logic_NJMJ.getInstance().GetIndex(mahjongInfos, deskComponent.CurrentCard);
                                mahjongInfos.RemoveAt(index);
                            }

                            handCards.GangCards.Add(deskComponent.CurrentCard);

                            currentGamer.GetComponent <HandCardsComponent>().PlayCards.Remove(deskComponent.CurrentCard);

                            //杠扣钱
                            GameHelp.ChangeGamerGold(room, gamer, 20 * gameController.RoomConfig.Multiples);
                            GameHelp.ChangeGamerGold(room, currentGamer, -20 * gameController.RoomConfig.Multiples);

                            //添加明杠
                            gamerOperation.OperatedUid = deskComponent.CurrentAuthority;
                            PengOrBar pengOrBar = ComponentFactory.Create <PengOrBar>();
                            pengOrBar.OperateType = OperateType.Bar;
                            pengOrBar.Weight      = deskComponent.CurrentCard.weight;
                            pengOrBar.UserId      = deskComponent.CurrentAuthority;
                            pengOrBar.BarType     = BarType.LightBar;
                            handCards.PengOrBars.Add(pengOrBar);
                        }
                        //暗杠
                        else if (Logic_NJMJ.getInstance().IsAnGang(handCardsComponent.GetAll(), out var weight))
                        {
                            isSuccess                    = true;
                            gamerOperation.weight        = (int)weight;
                            gamerOperation.OperationType = 4;

                            MahjongInfo info = new MahjongInfo()
                            {
                                weight   = (byte)weight,
                                m_weight = (Consts.MahjongWeight)weight
                            };
                            //更新手牌
                            for (int i = 0; i < 4; i++)
                            {
                                int index = Logic_NJMJ.getInstance().GetIndex(mahjongInfos, info);
                                mahjongInfos.RemoveAt(index);
                            }

                            handCards.GangCards.Add(info);
                            //杠扣钱
                            foreach (var _gamer in room.GetAll())
                            {
                                if (_gamer.UserID == gamer.UserID)
                                {
                                    GameHelp.ChangeGamerGold(room, _gamer, 10 * gameController.RoomConfig.Multiples * 3);
                                }
                                else
                                {
                                    GameHelp.ChangeGamerGold(room, _gamer, -10 * gameController.RoomConfig.Multiples);
                                }
                            }

                            //添加暗杠
                            gamerOperation.OperatedUid = 0;
                            PengOrBar pengOrBar = ComponentFactory.Create <PengOrBar>();
                            pengOrBar.OperateType = OperateType.Bar;
                            pengOrBar.Weight      = (int)weight;
                            pengOrBar.UserId      = 0;
                            pengOrBar.BarType     = BarType.DarkBar;
                            handCards.PengOrBars.Add(pengOrBar);
                        }
                        //碰杠
                        else if (Logic_NJMJ.getInstance().IsPengGang(handCardsComponent.PengCards, handCardsComponent.GetAll(), out var weight1))
                        {
                            isSuccess                    = true;
                            gamerOperation.weight        = weight1;
                            gamerOperation.OperationType = 5;

                            MahjongInfo info = new MahjongInfo()
                            {
                                weight   = (byte)weight1,
                                m_weight = (Consts.MahjongWeight)weight1
                            };
                            //更新手牌
                            for (int i = 0; i < 1; i++)
                            {
                                int index = Logic_NJMJ.getInstance().GetIndex(mahjongInfos, info);
                                mahjongInfos.RemoveAt(index);
                            }

                            handCardsComponent.PengCards.Remove(info);

                            handCards.GangCards.Add(info);
                            handCards.PengGangCards.Add(info);

                            //添加碰杠

                            PengOrBar pengOrBar = null;
                            foreach (var item in handCardsComponent.PengOrBars)
                            {
                                if (item.Weight == weight1 && item.OperateType == OperateType.Peng)
                                {
                                    pengOrBar = item;
                                }
                            }

                            if (pengOrBar == null)
                            {
                                Log.Error("碰刚的牌没有碰过");
                                return;
                            }
                            pengOrBar.OperateType      = OperateType.Bar;
                            pengOrBar.BarType          = BarType.PengBar;
                            gamerOperation.OperatedUid = pengOrBar.UserId;
                            //杠扣钱
                            foreach (var _gamer in room.GetAll())
                            {
                                if (_gamer.UserID == gamer.UserID)
                                {
                                    GameHelp.ChangeGamerGold(room, _gamer, 20 * gameController.RoomConfig.Multiples);
                                }
                                else if (_gamer.UserID == pengOrBar.UserId)
                                {
                                    GameHelp.ChangeGamerGold(room, _gamer, -20 * gameController.RoomConfig.Multiples);
                                }
                            }
                        }

                        if (isSuccess)
                        {
                            room.Broadcast(gamerOperation);

                            //杠完之后不能
                            gamer.isFaWanPaiTingPai = false;
                            gamer.isGangEndBuPai    = true;
                            gamer.isGetYingHuaBuPai = false;
                            //杠完后是本人出牌
                            orderController.CurrentAuthority = gamer.UserID;
                            //杠完之后抓牌
                            await room.GrabMahjongNoHua(gamer);

                            #region 比下胡 累计2个暗杠或3个明杠(同一个玩家)

                            int lightCount = handCards.PengOrBars.Count(c => c.BarType == BarType.LightBar);
                            int darkCount  = handCards.PengOrBars.Count(c => c.BarType == BarType.DarkBar);
                            if (lightCount >= 3 || darkCount >= 2)
                            {
                                room.LastBiXiaHu = true;
                            }

                            #endregion
                        }
                        else
                        {
                            Log.Debug("不能杠");
                        }
                    }
                }
            }
            catch (Exception e)
            {
                Log.Error(e);
            }

            await Task.CompletedTask;
        }
        public void SetPeng(int type, MahjongInfo mahjong, long operatedUid)
        {
            GameObject obj = null;

            if (type == 0)
            {
                obj = CommonUtil.getGameObjByBundle("Item_Peng_Card");
                //更新手牌
                for (int i = 0; i < 2; i++)
                {
                    int index = Logic_NJMJ.getInstance().GetIndex(this.handCards, mahjong);
                    this.RemoveCard(index);
                }
            }
            //明杠
            else if (type == 1)
            {
                obj = CommonUtil.getGameObjByBundle("Item_Gang_Card");
                //更新手牌
                for (int i = 0; i < 3; i++)
                {
                    int index = Logic_NJMJ.getInstance().GetIndex(this.handCards, mahjong);
                    this.RemoveCard(index);
                }
            }
            //暗杆
            else if (type == 4)
            {
                obj = CommonUtil.getGameObjByBundle("Item_Gang_Card");
                for (int i = 0; i < 4; i++)
                {
                    int index = Logic_NJMJ.getInstance().GetIndex(this.handCards, mahjong);
                    this.RemoveCard(index);
                }
            }
            //碰刚
            else if (type == 5)
            {
                obj = CommonUtil.getGameObjByBundle("Item_Gang_Card");
                for (int i = 0; i < 1; i++)
                {
                    int index = Logic_NJMJ.getInstance().GetIndex(this.handCards, mahjong);
                    this.RemoveCard(index);
                }
            }

            UpdateCards();

            //设置谁碰刚
            UI             uiRoom         = Game.Scene.GetComponent <UIComponent>().Get(UIType.UIRoom);
            GamerComponent gamerComponent = uiRoom.GetComponent <GamerComponent>();

            Log.Info("operatedUid:" + operatedUid);
            int gamerSeat = gamerComponent.Get(operatedUid).GetComponent <HandCardsComponent>().SeatIndex;
            int mySeat    = SeatIndex;

            int offset = gamerSeat - mySeat;

            if (offset < 0)
            {
                offset += 4;
            }
            if (offset == 1)
            {
                offset = 3;
            }
            else if (offset == 3)
            {
                offset = 1;
            }

            Log.Info("offset:" + offset);

            //显示碰
            GameObject gameObject = GameObject.Instantiate(obj, this.pengObj.transform);

            for (int i = 1; i < 4; i++)
            {
                Image image = gameObject.transform.Find("Item_" + i).GetComponent <Image>();
                //暗杠显示
                if (type == 4)
                {
                    if (i == 2)
                    {
                        image.sprite = CommonUtil.getSpriteByBundle("Image_Top_Card", "card_" + mahjong.weight);
                    }
                    else
                    {
                        image.sprite = CommonUtil.getSpriteByBundle("Image_Top_Card", "card_back");
                    }
                }
                else
                {
                    if (i == offset)
                    {
                        image.sprite = CommonUtil.getSpriteByBundle("Image_Top_Card", "card_back");
                    }
                    else
                    {
                        image.sprite = CommonUtil.getSpriteByBundle("Image_Top_Card", "card_" + mahjong.weight);
                    }
                }
            }

            if (type == 0)
            {
                pengDic.Add(mahjong.weight, gameObject);
            }

            Vector3 localPosition = this.CardBottom.transform.localPosition;

            this.CardBottom.transform.localPosition =
                new Vector3(localPosition.x + (postionX) * 2f, localPosition.y + (postionY) * 2f, localPosition.z);
        }
        /// <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);
        }
Exemple #18
0
        /// <summary>
        /// 碰刚
        /// </summary>
        /// <param name="messageOperationType"></param>
        /// <param name="mahjong"></param>
        public void SetPengGang(int messageOperationType, MahjongInfo mahjong, long operatedUid)
        {
            Log.Debug("显示碰后杠");
            GameObject obj   = CommonUtil.getGameObjByBundle("Item_Gang_Card");
            int        index = Logic_NJMJ.getInstance().GetIndex(this.handCards, mahjong);

            this.RemoveCard(index);
            UpdateCards();

            //设置谁碰刚
            UI             uiRoom         = Game.Scene.GetComponent <UIComponent>().Get(UIType.UIRoom);
            GamerComponent gamerComponent = uiRoom.GetComponent <GamerComponent>();
            int            gamerSeat      = gamerComponent.GetGamerSeat(operatedUid);
            int            mySeat         = gamerComponent.GetGamerSeat(PlayerInfoComponent.Instance.uid);

            int offset = gamerSeat - mySeat;

            if (offset < 0)
            {
                offset += 4;
            }
            if (offset == 1)
            {
                offset = 3;
            }
            else if (offset == 3)
            {
                offset = 1;
            }

            //显示碰
            GameObject gameObject = GameObject.Instantiate(obj, this.pengObj.transform);

            for (int i = 1; i < 4; i++)
            {
                Image image = gameObject.transform.Find("Item_" + i).GetComponent <Image>();
                if (i == offset)
                {
                    image.sprite = CommonUtil.getSpriteByBundle("Image_Top_Card", "card_back");
                }
                else
                {
                    image.sprite = CommonUtil.getSpriteByBundle("Image_Top_Card", "card_" + mahjong.weight);
                }
            }

            // for (int i = 0; i < 2; i++)
            // {
            //     gameObject.transform.GetChild(i).GetComponent<Image>().sprite =
            //             CommonUtil.getSpriteByBundle("Image_Top_Card", "card_" + mahjong.weight);
            // }

            GameObject lastPengObj = null;

            if (pengDic.TryGetValue(mahjong.weight, out lastPengObj))
            {
                gameObject.transform.SetSiblingIndex(lastPengObj.transform.GetSiblingIndex());
                gameObject.transform.localPosition = lastPengObj.transform.localPosition;
                GameObject.Destroy(lastPengObj);
                pengDic.Remove(mahjong.weight);
            }
        }
Exemple #19
0
        /// <summary>
        /// 抓牌
        /// </summary>
        /// <param name="room"></param>
        /// <returns></returns>
        public static MahjongInfo GrabMahjong(this Room room)
        {
            try
            {
                OrderControllerComponent orderController = room.GetComponent <OrderControllerComponent>();
                var currentGamer = room.Get(orderController.CurrentAuthority);
                HandCardsComponent cardsComponent = currentGamer.GetComponent <HandCardsComponent>();
                DeskComponent      deskComponent  = room.GetComponent <DeskComponent>();

                if (deskComponent.RestLibrary.Count == 0)
                {
                    Log.Info("没牌了");
                    return(null);
                }

                MahjongInfo grabMahjong;
                if (room.NextGrabCard != null)
                {
                    grabMahjong = new MahjongInfo()
                    {
                        m_weight = room.NextGrabCard.m_weight,
                        weight   = room.NextGrabCard.weight
                    };

                    room.NextGrabCard = null;
                    Log.Debug("发作弊牌:" + grabMahjong.m_weight);
                }
                else
                {
                    int number = RandomHelper.RandomNumber(0, deskComponent.RestLibrary.Count);
                    grabMahjong = deskComponent.RestLibrary[number];
                    deskComponent.RestLibrary.RemoveAt(number);

                    Log.Info($"{currentGamer.UserID}发牌:" + grabMahjong.m_weight);
                }

                //花牌返回
                if (grabMahjong.m_weight >= Consts.MahjongWeight.Hua_HongZhong)
                {
                    return(grabMahjong);
                }

                //发牌
                cardsComponent.AddCard(grabMahjong);
                room.my_lastMahjong     = grabMahjong;
                cardsComponent.GrabCard = grabMahjong;

                Logic_NJMJ.getInstance().SortMahjong(cardsComponent.GetAll());

                //发送抓牌消息
                ActorMessageSenderComponent actorMessageSenderComponent = Game.Scene.GetComponent <ActorMessageSenderComponent>();

                foreach (Gamer _gamer in room.gamers)
                {
                    if (_gamer == null || _gamer.isOffline)
                    {
                        continue;
                    }
                    UnitGateComponent   unitGateComponent = _gamer?.GetComponent <UnitGateComponent>();
                    Actor_GamerGrabCard actorGamerGrabCard;
                    if (_gamer.UserID == orderController.CurrentAuthority)
                    {
                        actorGamerGrabCard = new Actor_GamerGrabCard()
                        {
                            Uid    = currentGamer.UserID,
                            weight = (int)grabMahjong.m_weight
                        };
                    }
                    else
                    {
                        actorGamerGrabCard = new Actor_GamerGrabCard()
                        {
                            Uid = currentGamer.UserID,
                        };
                    }
                    actorMessageSenderComponent.GetWithActorId(unitGateComponent.GateSessionActorId).Send(actorGamerGrabCard);
                }

                //发完牌判断是否胡牌
                foreach (Gamer _gamer in room.gamers)
                {
                    if (_gamer == null || _gamer.isOffline)
                    {
                        continue;
                    }

                    if (_gamer.UserID == orderController.CurrentAuthority)
                    {
                        HandCardsComponent handCardsComponent = _gamer.GetComponent <HandCardsComponent>();

                        //判断胡牌
                        if (Logic_NJMJ.getInstance().isHuPai(handCardsComponent.GetAll()))
                        {
                            _gamer.huPaiNeedData.my_lastMahjong    = room.my_lastMahjong;
                            _gamer.huPaiNeedData.restMahjongCount  = deskComponent.RestLibrary.Count;
                            _gamer.huPaiNeedData.isSelfZhuaPai     = orderController.CurrentAuthority == _gamer.UserID;
                            _gamer.huPaiNeedData.isZhuangJia       = handCardsComponent.IsBanker;
                            _gamer.huPaiNeedData.isGetYingHuaBuPai = _gamer.isGetYingHuaBuPai;
                            _gamer.huPaiNeedData.isGangEndBuPai    = _gamer.isGangEndBuPai;
                            _gamer.huPaiNeedData.isGangFaWanPai    = _gamer.isGangFaWanPai;
                            _gamer.huPaiNeedData.isFaWanPaiTingPai = _gamer.isFaWanPaiTingPai;
                            _gamer.huPaiNeedData.my_yingHuaList    = handCardsComponent.FaceCards;
                            _gamer.huPaiNeedData.my_gangList       = handCardsComponent.GangCards;
                            _gamer.huPaiNeedData.my_pengList       = handCardsComponent.PengCards;
                            List <List <MahjongInfo> > tempList = new List <List <MahjongInfo> >();
                            for (int i = 0; i < room.GetAll().Length; i++)
                            {
                                if (_gamer.UserID == room.GetAll()[i].UserID)
                                {
                                    continue;
                                }
                                tempList.Add(room.GetAll()[i].GetComponent <HandCardsComponent>().PengCards);
                            }

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

                            List <Consts.HuPaiType> huPaiTypes = Logic_NJMJ.getInstance().getHuPaiType(handCardsComponent.GetAll(),
                                                                                                       _gamer.huPaiNeedData);
                            Log.Info(JsonHelper.ToJson(_gamer.huPaiNeedData));
                            Log.Info(JsonHelper.ToJson(huPaiTypes));

                            if (huPaiTypes.Count > 0)
                            {
                                //判断小胡,4个花以上才能胡
                                if (huPaiTypes[0] == Consts.HuPaiType.Normal)
                                {
                                    if (handCardsComponent.PengGangCards.Count > 0 || handCardsComponent.PengCards.Count > 0)
                                    {
                                        if (handCardsComponent.FaceCards.Count >= 4)
                                        {
                                            _gamer.IsCanHu = true;
                                            Actor_GamerCanOperation canOperation = new Actor_GamerCanOperation();
                                            canOperation.Uid           = _gamer.UserID;
                                            canOperation.OperationType = 2;
                                            room.GamerBroadcast(_gamer, canOperation);
                                        }
                                    }
                                }
                                else
                                {
                                    _gamer.IsCanHu = true;
                                    Actor_GamerCanOperation canOperation = new Actor_GamerCanOperation();
                                    canOperation.Uid           = _gamer.UserID;
                                    canOperation.OperationType = 2;
                                    room.GamerBroadcast(_gamer, canOperation);
                                }
                            }
                        }

                        //暗杠
                        if (Logic_NJMJ.getInstance().IsAnGang(handCardsComponent.GetAll(), out var weight))
                        {
                            _gamer.IsCanGang = true;
                            Actor_GamerCanOperation canOperation = new Actor_GamerCanOperation();
                            canOperation.Uid           = _gamer.UserID;
                            canOperation.OperationType = 4;
                            room.GamerBroadcast(_gamer, canOperation);
                        }
                        //碰杠
                        else if (Logic_NJMJ.getInstance().IsPengGang(handCardsComponent.PengCards, handCardsComponent.GetAll(), out var weight2))
                        {
                            _gamer.IsCanGang = true;
                            Actor_GamerCanOperation canOperation = new Actor_GamerCanOperation();
                            canOperation.Uid           = _gamer.UserID;
                            canOperation.OperationType = 5;
                            room.GamerBroadcast(_gamer, canOperation);
                        }
                    }
                }

                return(grabMahjong);
            }
            catch (Exception e)
            {
                Log.Error(e);
                return(null);
            }
        }
Exemple #20
0
        /// <summary>
        /// 给当前玩家发一张不是花牌的牌
        /// </summary>
        /// <param name="room"></param>
        /// <param name="currentGamer"></param>
        /// <returns></returns>
        public static async Task <MahjongInfo> GrabMahjongNoHua(this Room room, Gamer currentGamer)
        {
            GameControllerComponent gameController = room.GetComponent <GameControllerComponent>();
            HandCardsComponent      cardsComponent = currentGamer.GetComponent <HandCardsComponent>();
            var grabMahjong = GrabMahjong(room);

            if (grabMahjong == null)
            {
                Log.Info("没牌流局了");
                await gameController.GameOver(0);

                return(null);
            }
            while (grabMahjong.m_weight >= Consts.MahjongWeight.Hua_HongZhong)
            {
                Actor_GamerBuHua actorGamerBuHua = new Actor_GamerBuHua()
                {
                    Uid    = currentGamer.UserID,
                    weight = grabMahjong.weight
                };
                room.Broadcast(actorGamerBuHua);

                //从手牌中删除花牌
                Log.Info($"{currentGamer.UserID}补花,{grabMahjong.m_weight}");
                cardsComponent.FaceCards.Add(grabMahjong);
                cardsComponent.FaceGangCards.Add(grabMahjong);

                #region 花杠
                int temp = 0;
                foreach (var faceCard in cardsComponent.FaceCards)
                {
                    if (faceCard.m_weight == grabMahjong.m_weight)
                    {
                        temp++;
                    }
                }

                Logic_NJMJ.getInstance().SortMahjong(cardsComponent.FaceCards);
                //春夏秋冬
                for (int i = 0; i < cardsComponent.FaceGangCards.Count - 3; i++)
                {
                    if (cardsComponent.FaceCards[i + 3].m_weight - cardsComponent.FaceCards[i + 2].m_weight == 2 &&
                        cardsComponent.FaceCards[i + 2].m_weight - cardsComponent.FaceCards[i + 1].m_weight == 2 &&
                        cardsComponent.FaceCards[i + 1].m_weight - cardsComponent.FaceCards[i].m_weight == 2)
                    {
                        temp = 4;
                        cardsComponent.FaceGangCards.RemoveAt(i + 3);
                        cardsComponent.FaceGangCards.RemoveAt(i + 2);
                        cardsComponent.FaceGangCards.RemoveAt(i + 1);
                        cardsComponent.FaceGangCards.RemoveAt(i);
                    }
                }

                if (temp == 4)
                {
                    foreach (var _gamer in room.GetAll())
                    {
                        if (_gamer.UserID == currentGamer.UserID)
                        {
                            GameHelp.ChangeGamerGold(room, _gamer, 20 * gameController.RoomConfig.Multiples * 3);
                        }
                        else
                        {
                            GameHelp.ChangeGamerGold(room, _gamer, -20 * gameController.RoomConfig.Multiples);
                        }
                    }

                    room.LastBiXiaHu = true;
                }

                #endregion
                currentGamer.isGangEndBuPai    = false;
                currentGamer.isGetYingHuaBuPai = true;

                grabMahjong = GrabMahjong(room);

                if (grabMahjong == null)
                {
                    Log.Info("没牌流局了");
                    await gameController.GameOver(0);

                    return(null);;
                }
            }

            room.StartTime();
            return(grabMahjong);
        }
        protected override async void Run(ETModel.Session session, Actor_GamerReconnet message)
        {
            try
            {
                Log.Info($"断线重连:");
                SoundsHelp.Instance.IsOpenSound(false);

                GameObject mask = GameObject.Instantiate(CommonUtil.getGameObjByBundle("Image_Desk_Card", "RoomMask"), GameObject.Find("Global/UI/CommonCanvas").transform);

                //进入
                List <GamerInfo> Gamers = new List <GamerInfo>();
                foreach (var item in message.Gamers)
                {
                    GamerInfo gamerInfo = new GamerInfo();
                    gamerInfo.UserID     = item.UserID;
                    gamerInfo.SeatIndex  = item.SeatIndex;
                    gamerInfo.IsReady    = true;
                    gamerInfo.playerInfo = item.playerInfo;
                    Gamers.Add(gamerInfo);

                    //将出的牌加入到手牌中
                    item.handCards.AddRange(item.playCards);

                    foreach (var card in item.pengCards)
                    {
                        item.handCards.Add(card);
                        item.handCards.Add(card);
                    }

                    foreach (var card in item.gangCards)
                    {
                        item.handCards.Add(card);
                        item.handCards.Add(card);
                        item.handCards.Add(card);
                    }

                    Logic_NJMJ.getInstance().SortMahjong(item.handCards);

                    Log.Info($"{item.UserID} 手牌:{item.handCards.Count}");
                }

                Actor_GamerEnterRoom actorGamerEnterRoom = new Actor_GamerEnterRoom()
                {
                    Gamers   = Gamers,
                    RoomType = message.RoomType,
                };
                if (message.RoomType == 3)
                {
                    actorGamerEnterRoom.RoomId       = message.RoomId;
                    actorGamerEnterRoom.MasterUserId = message.MasterUserId;
                    actorGamerEnterRoom.JuCount      = message.JuCount;
                    actorGamerEnterRoom.Multiples    = message.Multiples;
                }
                await Actor_GamerEnterRoomHandler.GamerEnterRoom(actorGamerEnterRoom);

                //开始游戏
                var actorStartGame = new Actor_StartGame();
                actorStartGame.GamerDatas = message.Gamers;
                actorStartGame.restCount  = message.RestCount;
                actorStartGame.RoomType   = message.RoomType;
                if (actorStartGame.RoomType == 3)
                {
                    actorStartGame.CurrentJuCount = message.CurrentJuCount;
                }

                Actor_StartGameHandler.StartGame(actorStartGame, true);

                //碰刚
                foreach (var item in message.Gamers)
                {
                    for (int i = 0; i < item.pengCards.Count; i++)
                    {
                        MahjongInfo          card           = item.pengCards[i];
                        Actor_GamerOperation gamerOperation = new Actor_GamerOperation();
                        gamerOperation.Uid           = item.UserID;
                        gamerOperation.weight        = card.weight;
                        gamerOperation.OperationType = 0;
                        gamerOperation.OperatedUid   = item.OperatedPengUserIds[i];
                        Actor_GamerOperateHandler.GamerOperation(gamerOperation, true);
                    }

                    for (int i = 0; i < item.gangCards.Count; i++)
                    {
                        MahjongInfo          card = item.gangCards[i];
                        long                 operatedGangUserIds = item.OperatedGangUserIds[i];
                        Actor_GamerOperation gamerOperation      = new Actor_GamerOperation();
                        gamerOperation.Uid           = item.UserID;
                        gamerOperation.weight        = card.weight;
                        gamerOperation.OperationType = 1;
                        gamerOperation.OperatedUid   = operatedGangUserIds;

                        if (operatedGangUserIds == 0)
                        {
                            gamerOperation.OperationType = 4;
                        }
                        Actor_GamerOperateHandler.GamerOperation(gamerOperation, true);
                    }
                }

                //打牌
                foreach (var item in message.Gamers)
                {
                    Log.Debug($"{item.UserID} 重连出牌");
                    for (int i = 0; i < item.playCards.Count; i++)
                    {
                        MahjongInfo         card     = item.playCards[i];
                        int                 index    = Logic_NJMJ.getInstance().GetIndex(item.handCards, card);
                        Actor_GamerPlayCard playCard = new Actor_GamerPlayCard();
                        playCard.Uid    = item.UserID;
                        playCard.weight = card.weight;
                        playCard.index  = index;
//                        await ETModel.Game.Scene.GetComponent<TimerComponent>().WaitAsync(100);
                        Actor_GamerPlayCardHandler.PlayCard(playCard);
//                        item.handCards.RemoveAt(index);
                    }
                }

                //托管恢复
                UI              uiRoom          = Game.Scene.GetComponent <UIComponent>().Get(UIType.UIRoom);
                GamerComponent  gamerComponent  = uiRoom.GetComponent <GamerComponent>();
                UIRoomComponent uiRoomComponent = uiRoom.GetComponent <UIRoomComponent>();
                foreach (var item in message.Gamers)
                {
                    if (item.IsTrusteeship)
                    {
                        if (item.UserID == PlayerInfoComponent.Instance.uid)
                        {
                            uiRoomComponent.ShowTrustship();
                        }
                        else
                        {
                            GamerUIComponent gamerUIComponent = gamerComponent.Get(item.UserID).GetComponent <GamerUIComponent>();
                            gamerUIComponent.ShowTrust();
                        }
                    }
                }

                await ETModel.Game.Scene.GetComponent <TimerComponent>().WaitAsync(3000);

                int openSound = PlayerPrefs.GetInt("isOpenSound", 1);
                SoundsHelp.Instance.IsOpenSound(openSound == 1);
                GameObject.Destroy(mask);
            }
            catch (Exception e)
            {
                Log.Error(e);
            }
        }