/// <summary>
        /// 向客户端发地主牌
        /// </summary>
        public static void CardsOnTable(this GameControllerComponent self, long id)
        {
            Room room = self.GetParent <Room>();
            OrderControllerComponent orderController = room.GetComponent <OrderControllerComponent>();
            HandCardsComponent       handCards       = room.GetGamerFromUserID(id).GetComponent <HandCardsComponent>();

            orderController.Start(id);

            for (int i = 0; i < 3; i++)
            {
                Card card = self.DealLord(room);
                handCards.AddCard(card);
            }

            //更新玩家身份
            foreach (var gamer in room.gamers)
            {
                Identity gamerIdentity = gamer.UserID == id ? Identity.Landlord : Identity.Farmer;
                self.UpdateInIdentity(gamer, gamerIdentity);
            }

            //广播地主消息
            room.Broadcast(new Actor_SetLandlord_Ntt()
            {
                UserID = id, LordCards = To.RepeatedField(room.LordCards)
            });

            //广播地主先手出牌消息
            room.Broadcast(new Actor_AuthorityPlayCard_Ntt()
            {
                UserID = id, IsFirst = true
            });
        }
Beispiel #2
0
        /// <summary>
        /// 发地主牌
        /// </summary>
        /// <param name="self"></param>
        /// <param name="id"></param>
        public static void CardsOnTable(this GameControllerComponent self, long id)
        {
            Room room = self.GetParent <Room>();
            DeskCardsCacheComponent  deskCardsCache  = room.GetComponent <DeskCardsCacheComponent>();
            OrderControllerComponent orderController = room.GetComponent <OrderControllerComponent>();
            HandCardsComponent       handCards       = room.Get(id).GetComponent <HandCardsComponent>();

            orderController.Start(id);

            for (int i = 0; i < 3; i++)
            {
                Card card = deskCardsCache.Deal();
                handCards.AddCard(card);
            }

            //更新玩家身份
            foreach (var gamer in room.GetAll())
            {
                Identity gamerIdentity = gamer.UserID == id ? Identity.Landlord : Identity.Farmer;
                self.UpdateInIdentity(gamer, gamerIdentity);
            }

            //广播地主消息
            room.Broadcast(new M2C_SetLandlord()
            {
                UserID = id, LordCards = deskCardsCache.LordCards.ToArray()
            });

            //广播地主先手出牌消息
            room.Broadcast(new M2C_AuthorityPlayCard()
            {
                UserID = id, IsFirst = true
            });
        }
Beispiel #3
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);
            }
        }