/// <summary>
        /// 出牌
        /// </summary>
        private async void OnPlay()
        {
            CardHelper.Sort(currentSelectCards);
            Actor_GamerPlayCard_Req request = new Actor_GamerPlayCard_Req();

            request.Cards.AddRange(currentSelectCards);
            Actor_GamerPlayCard_Ack response = await SessionComponent.Instance.Session.Call(request) as Actor_GamerPlayCard_Ack;

            //出牌错误提示
            GamerUIComponent gamerUI = Game.Scene.GetComponent <UIComponent>().Get(UIType.LandlordsRoom).GetComponent <GamerComponent>().LocalGamer.GetComponent <GamerUIComponent>();

            if (response.Error == ErrorCode.ERR_PlayCardError)
            {
                gamerUI.SetPlayCardsError();
            }
        }
        /// <summary>
        /// 出牌
        /// </summary>
        private async void OnPlay()
        {
            CardHelper.Sort(currentSelectCards);
            C2M_GamerPlayCard request = new C2M_GamerPlayCard()
            {
                Cards = currentSelectCards.ToArray()
            };
            M2C_GamerPlayCard response = await SessionWrapComponent.Instance.Session.Call(request) as M2C_GamerPlayCard;

            //出牌错误提示
            GamerUIComponent gamerUI = Game.Scene.GetComponent <UIComponent>().Get(UIType.UIRoom).GetComponent <GamerComponent>().LocalGamer.GetComponent <GamerUIComponent>();

            if (response.Error == ErrorCode.ERR_PlayCardError)
            {
                gamerUI.SetPlayCardsError();
            }
        }
        /// <summary>
        /// 出牌
        /// </summary>
        private async void OnPlay()
        {
            CardHelper.Sort(currentSelectCards);
            Actor_GamerPlayCard_Req request = new Actor_GamerPlayCard_Req();

            foreach (var a in currentSelectCards)
            {
                request.Cards.Add(a);
            }
            Actor_GamerPlayCard_Back response = (Actor_GamerPlayCard_Back)await SessionComponent.Instance.Session.Call(request);

            //出牌错误提示
            LandlordsGamerPanelComponent gamerUI = LandlordsRoomComponent.LocalGamer.GetComponent <LandlordsGamerPanelComponent>();

            if (response.Error == ErrorCode.ERR_PlayCardError)
            {
                gamerUI.SetPlayCardsError();
            }
        }
        /// <summary>
        /// 创建玩家结算信息
        /// </summary>
        /// <returns></returns>
        public GameObject CreateGamerContent(Gamer gamer, Identity winnerIdentity, long baseScore, int multiples, long score)
        {
            //实例化prefab
            GameObject newContent = UnityEngine.Object.Instantiate(contentPrefab);

            newContent.transform.SetParent(gamerContent.transform, false);

            //获取玩家身份/设置头像
            Identity gamerIdentity  = gamer.GetComponent <HandCardsComponent>().AccessIdentity;
            Sprite   identitySprite = CardHelper.GetCardSprite($"Identity_{Enum.GetName(typeof(Identity), gamerIdentity)}");

            newContent.Get <GameObject>("Identity").GetComponent <Image>().sprite = identitySprite;

            //设置昵称/底分/倍数/积分
            string nickName      = gamer.GetComponent <LandlordsGamerPanelComponent>().NickName;
            Text   nickNameText  = newContent.Get <GameObject>("NickName").GetComponent <Text>();
            Text   baseScoreText = newContent.Get <GameObject>("BaseScore").GetComponent <Text>();
            Text   multiplesText = newContent.Get <GameObject>("Multiples").GetComponent <Text>();
            Text   scoreText     = newContent.Get <GameObject>("Score").GetComponent <Text>();

            nickNameText.text  = nickName;
            baseScoreText.text = baseScore.ToString();
            multiplesText.text = multiples.ToString();
            scoreText.text     = score.ToString();

            //本地玩家的统计结果高亮
            if (gamer.UserID == LandlordsRoomComponent.LocalGamer.UserID)
            {
                nickNameText.color  = Color.red;
                baseScoreText.color = Color.red;
                multiplesText.color = Color.red;
                scoreText.color     = Color.red;
            }

            return(newContent);
        }
Exemple #5
0
 public void SeeSelfCards(int n)
 {
     submitCard.Multiple = n;
     for (int i = 0; i < cardList.Count; i++)
     {
         this.cards[i].sprite = (Sprite)res.GetAsset(UICowCowAB.CowCow_Texture, CardHelper.GetCardAssetName(cardList[i]));
     }
     this.ShowHidePromptButton(true);
 }
        protected override void Run(ETModel.Session session, Actor_SetLandlord_Ntt message)
        {
            UI uiRoom = Game.Scene.GetComponent <UIComponent>().Get(UIType.LandlordsRoom);
            LandlordsRoomComponent room = uiRoom.GetComponent <LandlordsRoomComponent>();
            Gamer gamer = room.GetGamer(message.UserID);

            if (gamer != null)
            {
                HandCardsComponent handCards = gamer.GetComponent <HandCardsComponent>();
                if (gamer.UserID == LandlordsRoomComponent.LocalGamer.UserID)
                {
                    //本地玩家添加手牌
                    Card[] Tcards = new Card[message.LordCards.Count];
                    for (int i = 0; i < message.LordCards.Count; i++)
                    {
                        Tcards[i] = message.LordCards[i];
                    }
                    handCards.AddCards(Tcards);
                }
                else
                {
                    //其他玩家设置手牌数
                    handCards.SetHandCardsNum(20);
                }
            }

            //设置值玩家身份
            foreach (var _gamer in room.gamers)
            {
                HandCardsComponent           handCardsComponent = _gamer.GetComponent <HandCardsComponent>();
                LandlordsGamerPanelComponent gamerUI            = _gamer.GetComponent <LandlordsGamerPanelComponent>();
                if (_gamer.UserID == message.UserID)
                {
                    handCardsComponent.AccessIdentity = Identity.Landlord;
                    gamerUI.SetIdentity(Identity.Landlord);
                }
                else
                {
                    handCardsComponent.AccessIdentity = Identity.Farmer;
                    gamerUI.SetIdentity(Identity.Farmer);
                }
            }

            //重置玩家UI提示
            foreach (var _gamer in room.gamers)
            {
                _gamer.GetComponent <LandlordsGamerPanelComponent>().ResetPrompt();
            }

            //切换地主牌精灵
            GameObject lordPokers = uiRoom.GameObject.Get <GameObject>("Desk").Get <GameObject>("LordPokers");

            for (int i = 0; i < lordPokers.transform.childCount; i++)
            {
                Sprite lordCardSprite = CardHelper.GetCardSprite(message.LordCards[i].GetName());
                lordPokers.transform.GetChild(i).GetComponent <Image>().sprite = lordCardSprite;
            }

            //显示切换游戏模式按钮
            uiRoom.GetComponent <LandlordsRoomComponent>().Interaction.GameStart();
        }
Exemple #7
0
 /// <summary>
 /// 手牌排序
 /// </summary>
 /// <param name="self"></param>
 public static void Sort(this HandCardsComponent self)
 {
     CardHelper.SortCards(self.library);
 }
Exemple #8
0
        protected override async ETTask Run(Gamer gamer, Actor_GamerPlayCard_Req message, Action <Actor_GamerPlayCard_Back> reply)
        {
            Actor_GamerPlayCard_Back response = new Actor_GamerPlayCard_Back();

            try
            {
                LandlordsRoom room = Game.Scene.GetComponent <LandlordsComponent>().GetGamingRoom(gamer);

                GameControllerComponent  gameController  = room.GetComponent <GameControllerComponent>();
                DeskCardsCacheComponent  deskCardsCache  = room.GetComponent <DeskCardsCacheComponent>();
                OrderControllerComponent orderController = room.GetComponent <OrderControllerComponent>();

                //检测是否符合出牌规则
                if (CardHelper.PopEnable(To.Array(message.Cards), out CardsType type))
                {
                    //当前出牌牌型是否比牌桌上牌型的权重更大
                    bool isWeightGreater = CardHelper.GetWeight(To.Array(message.Cards), type) > deskCardsCache.GetTotalWeight();
                    //当前出牌牌型是否和牌桌上牌型的数量一样
                    bool isSameCardsNum = message.Cards.Count == deskCardsCache.GetAll().Length;
                    //当前出牌玩家是否是上局最大出牌者
                    bool isBiggest = orderController.Biggest == orderController.CurrentAuthority;
                    //当前牌桌牌型是否是顺子
                    bool isStraight = deskCardsCache.Rule == CardsType.Straight || deskCardsCache.Rule == CardsType.DoubleStraight || deskCardsCache.Rule == CardsType.TripleStraight;
                    //当前出牌牌型是否和牌桌上牌型一样
                    bool isSameCardsType = type == deskCardsCache.Rule;

                    if (isBiggest ||                                                          //先手出牌玩家
                        type == CardsType.JokerBoom ||                                        //王炸
                        type == CardsType.Boom && isWeightGreater ||                          //更大的炸弹
                        isSameCardsType && isStraight && isSameCardsNum && isWeightGreater || //更大的顺子
                        isSameCardsType && isWeightGreater)                                   //更大的同类型牌
                    {
                        if (type == CardsType.JokerBoom)
                        {
                            //王炸翻4倍
                            gameController.Multiples *= 4;
                            room.Broadcast(new Actor_SetMultiples_Ntt()
                            {
                                Multiples = gameController.Multiples
                            });
                        }
                        else if (type == CardsType.Boom)
                        {
                            //炸弹翻2倍
                            gameController.Multiples *= 2;
                            room.Broadcast(new Actor_SetMultiples_Ntt()
                            {
                                Multiples = gameController.Multiples
                            });
                        }
                    }
                    else
                    {
                        response.Error = ErrorCode.ERR_PlayCardError;
                        reply(response);
                        return;
                    }
                }
                else
                {
                    response.Error = ErrorCode.ERR_PlayCardError;
                    reply(response);
                    return;
                }

                //如果符合将牌从手牌移到出牌缓存区
                deskCardsCache.Clear();
                deskCardsCache.Rule = type;
                HandCardsComponent handCards = gamer.GetComponent <HandCardsComponent>();
                foreach (var card in message.Cards)
                {
                    handCards.PopCard(card);
                    deskCardsCache.AddCard(card);
                }

                reply(response);

                //转发玩家出牌消息
                room.Broadcast(new Actor_GamerPlayCard_Ntt()
                {
                    UserID = gamer.UserID, Cards = message.Cards
                });

                //游戏控制器继续游戏
                gameController.Continue(gamer);

                await ETTask.CompletedTask;
            }
            catch (Exception e)
            {
                ReplyError(response, e, reply);
            }
        }
        protected override void Run(ETModel.Session session, Actor_GameStart_Ntt message)
        {
            UI uiRoom = Game.Scene.GetComponent <UIComponent>().Get(UIType.LandlordsRoom);
            LandlordsRoomComponent room = uiRoom.GetComponent <LandlordsRoomComponent>();

            //初始化玩家UI
            foreach (GamerCardNum gamerCardNum in message.GamersCardNum)
            {
                Gamer gamer = room.GetGamer(gamerCardNum.UserID);
                LandlordsGamerPanelComponent gamerUI = gamer.GetComponent <LandlordsGamerPanelComponent>();
                gamerUI.GameStart();

                HandCardsComponent handCards = gamer.GetComponent <HandCardsComponent>();
                if (handCards != null)
                {
                    handCards.Reset();
                }
                else
                {
                    //Log.Debug("没有可以复用的HandCardsComponent,创建一个。");
                    handCards = gamer.AddComponent <HandCardsComponent, GameObject>(gamerUI.Panel);
                }

                //显示牌背面或者手牌
                handCards.Appear();

                if (gamer.UserID == LandlordsRoomComponent.LocalGamer.UserID)
                {
                    //本地玩家添加手牌
                    Card[] Tcards = new Card[message.HandCards.Count];
                    for (int i = 0; i < message.HandCards.Count; i++)
                    {
                        Tcards[i] = message.HandCards[i];
                    }
                    //Log.Debug("当前玩家手牌数量"+message.HandCards.array.Length.ToString());
                    //array的数量为32 与牌数不符合
                    handCards.AddCards(Tcards);
                }
                else
                {
                    //设置其他玩家手牌数
                    handCards.SetHandCardsNum(gamerCardNum.Num);
                }
            }

            //显示牌桌UI
            GameObject desk = uiRoom.GameObject.Get <GameObject>("Desk");

            desk.SetActive(true);
            GameObject lordPokers = desk.Get <GameObject>("LordPokers");

            //重置地主牌
            Sprite lordSprite = CardHelper.GetCardSprite("None");

            for (int i = 0; i < lordPokers.transform.childCount; i++)
            {
                lordPokers.transform.GetChild(i).GetComponent <Image>().sprite = lordSprite;
            }

            LandlordsRoomComponent uiRoomComponent = uiRoom.GetComponent <LandlordsRoomComponent>();

            //清空选中牌
            uiRoomComponent.Interaction.Clear();
            //设置初始倍率
            uiRoomComponent.SetMultiples(1);
        }
        public void SetGamerSmallSettlement(CowCowSmallSettlementInfo info)
        {
            this.banker.alpha   = info.SeatID == 0 ? 1 : 0;
            this.gamerName.text = Game.Scene.GetComponent <UIComponent>().Get(UICowCowType.CowCowGameRoom).GetComponent <UICowCow_GameRoomComponent>().GamerComponent.Get(info.SeatID).GetComponent <UICowCow_GamerInfoComponent>().gamerName;
            this.bets.text      = info.Multiple.ToString();
            switch ((CowType)info.CardsType)
            {
            case CowType.None:
                this.cardType.text = "无牛";
                break;

            case CowType.HaveCow:
                int num = info.CowNumber % tan;
                if (num == 0)
                {
                    this.cardType.text = "牛牛";
                }
                else
                {
                    this.cardType.text = $"牛{num}";
                }
                break;

            case CowType.FiveFlowerCow:
                this.cardType.text = "五花牛";
                break;

            case CowType.BombCow:
                this.cardType.text = "炸弹牛";
                break;

            case CowType.FiveSmallCow:
                this.cardType.text = "五小牛";
                break;
            }
            this.score.text = info.LoseWin > 0 ? $"+{info.LoseWin}" : $"{info.LoseWin}";
            for (int i = 0; i < this.cards.Length; i++)
            {
                this.cards[i].sprite = (Sprite)this.res.GetAsset(UICowCowAB.CowCow_Texture, CardHelper.GetCardAssetName(info.Cards[i]));
            }
        }
Exemple #11
0
 /// <summary>
 /// 手牌排序
 /// </summary>
 /// <param name="self"></param>
 public static void Sort(this DeskCardsCacheComponent self)
 {
     CardHelper.SortCards(self.library);
 }
Exemple #12
0
 /// <summary>
 /// 获取总权值
 /// </summary>
 /// <param name="self"></param>
 /// <returns></returns>
 public static int GetTotalWeight(this DeskCardsCacheComponent self)
 {
     return(CardHelper.GetWeight(self.library.ToArray(), self.Rule));
 }