Beispiel #1
0
        public static async void StartGame(Actor_StartGame message, bool isReconnect)
        {
            Log.Debug($"收到开始");

            try
            {
                UI uiRoom = Game.Scene.GetComponent <UIComponent>().Get(UIType.UIRoom);

                if (uiRoom == null)
                {
                    uiRoom = Game.Scene.GetComponent <UIComponent>().Create(UIType.UIRoom);
                }

                Game.Scene.GetComponent <UIComponent>().Remove(UIType.UIReady);
                Game.Scene.GetComponent <UIComponent>().Remove(UIType.UIGameResult);
                GamerComponent  gamerComponent  = uiRoom.GetComponent <GamerComponent>();
                UIRoomComponent uiRoomComponent = uiRoom.GetComponent <UIRoomComponent>();
                UIRoomComponent.ISGaming = true;
                uiRoomComponent.ContinueGamer();
                //好友房设置将退出变成解散
                if (UIRoomComponent.IsFriendRoom)
                {
                    uiRoomComponent.SetFriendSetting(PlayerInfoComponent.Instance.uid);
                    uiRoomComponent.SetCurrentJuCount(message.CurrentJuCount);
                }
                //先掷骰子
                if (!isReconnect)
                {
                    uiRoomComponent.exitBtn.interactable = false;
                    uiRoomComponent.players.SetActive(true);
                    GameObject DiceAnim   = uiRoomComponent.dice.Get <GameObject>("DiceAnim");
                    GameObject DiceBottom = uiRoomComponent.dice.Get <GameObject>("DiceBottom");
                    Image      Dice1      = DiceBottom.transform.Find("Dice1").GetComponent <Image>();
                    Image      Dice2      = DiceBottom.transform.Find("Dice2").GetComponent <Image>();
                    DiceAnim.SetActive(true);
                    SoundsHelp.Instance.playSound_ShaiZi();
                    await ETModel.Game.Scene.GetComponent <TimerComponent>().WaitAsync(2000);

                    DiceAnim.SetActive(false);
                    DiceBottom.SetActive(true);
                    int number1 = RandomHelper.RandomNumber(1, 7);
                    Dice1.sprite = CommonUtil.getSpriteByBundle("Image_Dice", "num_" + number1);
                    int number2 = RandomHelper.RandomNumber(1, 7);
                    Dice2.sprite = CommonUtil.getSpriteByBundle("Image_Dice", "num_" + number2);
                    await ETModel.Game.Scene.GetComponent <TimerComponent>().WaitAsync(1000);


                    //发牌动画

                    List <MahjongInfo> myCard = null;
                    foreach (var gameData in message.GamerDatas)
                    {
                        foreach (var mahjong in gameData.handCards)
                        {
                            mahjong.m_weight = (Consts.MahjongWeight)mahjong.weight;
                        }

                        foreach (var mahjong in gameData.faceCards)
                        {
                            mahjong.m_weight = (Consts.MahjongWeight)mahjong.weight;
                        }

                        foreach (var gamer in gamerComponent.GetAll())
                        {
                            if (gamer.UserID != gameData.UserID)
                            {
                                continue;
                            }
//                            if (gamer.UserID == PlayerInfoComponent.Instance.uid)
//                            {
//                                myCard = new List<MahjongInfo>(gameData.handCards);
//                            }
                            gamer.gameData = gameData;
                            GamerUIComponent gamerUi = gamer.GetComponent <GamerUIComponent>();
                            gamerUi.GameStart();

                            gamer.IsBanker = gameData.IsBanker;
                            HandCardsComponent handCards = gamer.GetComponent <HandCardsComponent>();
                            if (handCards != null)
                            {
                                handCards.Reset();
                            }
                            else
                            {
                                handCards = gamer.AddComponent <HandCardsComponent, GameObject, int, int>(gamerUi.Panel, gamerUi.Index, gameData.SeatIndex);
                            }

                            handCards.myCard = new List <MahjongInfo>(gameData.handCards);
                        }
                    }

                    for (int i = 0; i < 4; i++)
                    {
                        foreach (var gamer in gamerComponent.GetAll())
                        {
                            HandCardsComponent handCards = gamer.GetComponent <HandCardsComponent>();

                            if (PlayerInfoComponent.Instance.uid == gamer.UserID)
                            {
                                handCards.StartDealCardAnim(true);
                            }
                            else
                            {
                                handCards.StartDealCardAnim(false);
                            }
                            await ETModel.Game.Scene.GetComponent <TimerComponent>().WaitAsync(400);
                        }
                    }

                    //自己的牌翻一下
                    foreach (var gamer in gamerComponent.GetAll())
                    {
                        if (gamer.UserID == PlayerInfoComponent.Instance.uid)
                        {
                            HandCardsComponent handCards = gamer.GetComponent <HandCardsComponent>();
                            handCards.FanPai();
                        }
                    }
                    await ETModel.Game.Scene.GetComponent <TimerComponent>().WaitAsync(500);

                    DiceBottom.SetActive(false);
                }

                uiRoomComponent.StartGame(message.restCount);
                uiRoomComponent.exitBtn.interactable = true;
                // uiRoomComponent.SetRoomType(message.RoomType);

                foreach (var gameData in message.GamerDatas)
                {
                    foreach (var mahjong in gameData.handCards)
                    {
                        mahjong.m_weight = (Consts.MahjongWeight)mahjong.weight;
                    }

                    foreach (var mahjong in gameData.faceCards)
                    {
                        mahjong.m_weight = (Consts.MahjongWeight)mahjong.weight;
                    }

                    foreach (var gamer in gamerComponent.GetAll())
                    {
                        if (gamer.UserID != gameData.UserID)
                        {
                            continue;
                        }

                        GamerUIComponent gamerUi = gamer.GetComponent <GamerUIComponent>();
                        gamerUi.GameStart();
                        HandCardsComponent handCards = gamer.GetComponent <HandCardsComponent>();
                        if (handCards != null)
                        {
                            handCards.Reset();
                        }
                        else
                        {
                            handCards = gamer.AddComponent <HandCardsComponent, GameObject, int, int>(gamerUi.Panel, gamerUi.Index, gameData.SeatIndex);
                        }

                        //设置庄家
                        gamer.IsBanker = gameData.IsBanker;
                        gamerUi.SetZhuang();

                        //当前出牌玩家
                        if (gamer.IsBanker)
                        {
                            gamerComponent.CurrentPlayUid = gamer.UserID;
                        }

                        if (gamer.UserID == gamerComponent.LocalGamer.UserID)
                        {
                            //本地玩家添加手牌
                            uiRoomComponent.SetTreasureTime(gameData.OnlineSeconds);
                            handCards.AddCards(gameData.handCards);
                            handCards.ShowBg();
                        }
                        else
                        {
                            handCards.AddOtherCards(gamer.IsBanker);
                        }

                        handCards.SetFaceCards(gameData.faceCards);
                        foreach (var card in gameData.faceCards)
                        {
                            gamerUi.SetBuHua(card.weight);
                        }
                    }
                }

                //时间倒计时
                foreach (var gamer in gamerComponent.GetAll())
                {
                    if (gamer.IsBanker)
                    {
                        uiRoomComponent.ShowTurn(gamer.UserID);
                    }
                }

                uiRoom.GameObject.SetActive(true);
                UIRoomComponent.ISGaming = true;

                uiRoomComponent?.tip?.SetActive(true);
                uiRoomComponent.tip.GetComponentInChildren <Image>().sprite = CommonUtil.getSpriteByBundle("Image_Desk_Card", "shangji_tip");
                await ETModel.Game.Scene.GetComponent <TimerComponent>().WaitAsync(3000);

                if (uiRoomComponent != null)
                {
                    if (uiRoomComponent.tip != null)
                    {
                        uiRoomComponent?.tip?.SetActive(false);
                    }
                }
            }
            catch (Exception e)
            {
                Log.Error(e);
            }
        }
        public static async Task GamerEnterRoom(Actor_GamerEnterRoom message)
        {
            try
            {
                //玩家还在结算画面
                if (Game.Scene.GetComponent <UIComponent>().Get(UIType.UIGameResult) != null || UIRoomComponent.ISGaming)
                {
                    return;
                }

                Log.Info($"收到玩家进入");
                //第一次进入创建UIRoom
                if (Game.Scene.GetComponent <UIComponent>().Get(UIType.UIRoom) == null)
                {
                    CommonUtil.ShowUI(UIType.UIRoom);
                    Game.Scene.GetComponent <UIComponent>().Remove(UIType.UIMain);
                    Game.Scene.GetComponent <UIComponent>().Remove(UIType.UICreateFriendRoom);
                    Game.Scene.GetComponent <UIComponent>().Remove(UIType.UIJoinRoom);
                }

                if (Game.Scene.GetComponent <UIComponent>().Get(UIType.UIReady) == null)
                {
                    CommonUtil.ShowUI(UIType.UIReady);
                }
                UINetLoadingComponent.closeNetLoading();
                UI              uiRoom         = Game.Scene.GetComponent <UIComponent>().Get(UIType.UIRoom);
                UI              uiReady        = Game.Scene.GetComponent <UIComponent>().Get(UIType.UIReady);
                GamerComponent  gamerComponent = uiRoom.GetComponent <GamerComponent>();
                UIRoomComponent roomComponent  = uiRoom.GetComponent <UIRoomComponent>();
                roomComponent.ContinueGamer();
                roomComponent.enterRoomMsg = message;
                roomComponent.SetRoomType(message.RoomType, message.Multiples);
                Gamer[] gamers = gamerComponent.GetAll();

                //清空座位
                for (int i = 0; i < gamers.Length; i++)
                {
                    if (gamers[i] == null)
                    {
                        continue;
                    }

                    if (gamers[i].UserID != 0)
                    {
                        Log.Debug("删除gamer");
                        roomComponent.RemoveGamer(gamers[i].UserID);
                    }
                }

                GamerInfo localGamer = null;
                for (int i = 0; i < message.Gamers.Count; i++)
                {
                    if (message.Gamers[i].UserID == PlayerInfoComponent.Instance.uid)
                    {
                        localGamer = message.Gamers[i];
                        gamerComponent.LocalGamer = GamerFactory.Create(localGamer.UserID, localGamer.IsReady, localGamer.playerInfo);
                        break;
                    }
                }

                if (localGamer == null)
                {
                    return;
                }

                roomComponent.localGamer = localGamer;

                //好友房处理
                if (message.RoomType == 3)
                {
                    UIRoomComponent.IsFriendRoom = true;
                    roomComponent.JuCount        = message.JuCount;
                    uiReady?.GetComponent <UIReadyComponent>()?.ClosePropt();
                    uiReady?.GetComponent <UIReadyComponent>()?.SetFriendRoom(true);
                    uiReady?.GetComponent <UIReadyComponent>()?.ShowWeChat(message.RoomId.ToString());
                    roomComponent.RoomConfig.Multiples = message.Multiples;
                    roomComponent.SetFriendSetting(message.MasterUserId);

                    if (message.CurrentJuCount > 0)
                    {
                        uiReady?.GetComponent <UIReadyComponent>()?.CloseBtn();
                        roomComponent.exitBtn.interactable = false;
                    }
                }
                else
                {
                    uiReady?.GetComponent <UIReadyComponent>()?.SetFriendRoom(false);
                    UIRoomComponent.IsFriendRoom = false;
                }

                for (int i = 0; i < message.Gamers.Count; i++)
                {
                    GamerInfo gamerInfo = message.Gamers[i];
                    Gamer     gamer;
                    if (gamerInfo.UserID == localGamer.UserID)
                    {
                        gamer = gamerComponent.LocalGamer;
                    }
                    else
                    {
                        gamer = GamerFactory.Create(gamerInfo.UserID, gamerInfo.IsReady, gamerInfo.playerInfo);
                    }

                    UIReadyComponent uiReadyComponent = uiReady.GetComponent <UIReadyComponent>();
                    GamerUIComponent gamerUiComponent = gamer.GetComponent <GamerUIComponent>();

                    //排序
                    int index = gamerInfo.SeatIndex - localGamer.SeatIndex;
                    if (index < 0)
                    {
                        index += 4;
                    }

                    //设置准备
                    if (uiReadyComponent != null)
                    {
                        if (gamer?.PlayerInfo != null)
                        {
                            gamerUiComponent?.SetHeadPanel(uiReadyComponent.HeadPanel[index], index);
                            gamerUiComponent?.SetFace(roomComponent.FacePanel[index]);
                            uiReady?.GetComponent <UIReadyComponent>()?.SetPanel(gamer, index);
                            //根据座位的indax添加玩家
                            roomComponent?.AddGamer(gamer, index);
                        }
                    }
                }

                SoundsHelp.Instance.playSound_JinRu();
            }
            catch (Exception e)
            {
                Log.Error(e);
            }
        }