Esempio n. 1
0
        protected override void Run(Session session, M2C_GamerEnterRoom message)
        {
            UI uiRoom = Game.Scene.GetComponent <UIComponent>().Get(UIType.UIRoom);
            UIRoomComponent uiRoomComponent = uiRoom.GetComponent <UIRoomComponent>();
            GamerComponent  gamerComponent  = uiRoom.GetComponent <GamerComponent>();

            //从匹配状态中切换为准备状态
            if (uiRoomComponent.Matching)
            {
                uiRoomComponent.Matching = false;
                GameObject matchPrompt = uiRoom.GameObject.Get <GameObject>("MatchPrompt");
                if (matchPrompt.activeSelf)
                {
                    matchPrompt.SetActive(false);
                    uiRoom.GameObject.Get <GameObject>("ReadyButton").SetActive(true);
                }
            }

            int localGamerIndex = message.Gamers.FindIndex(info => info.UserID == gamerComponent.LocalGamer.UserID);

            //添加未显示玩家
            for (int i = 0; i < message.Gamers.Count; i++)
            {
                GamerInfo gamerInfo = message.Gamers[i];
                if (gamerInfo.UserID == 0)
                {
                    continue;
                }
                if (gamerComponent.Get(gamerInfo.UserID) == null)
                {
                    Gamer gamer = GamerFactory.Create(gamerInfo.UserID, gamerInfo.IsReady);
                    if ((localGamerIndex + 1) % 3 == i)
                    {
                        //玩家在本地玩家右边
                        uiRoomComponent.AddGamer(gamer, 2);
                    }
                    else
                    {
                        //玩家在本地玩家左边
                        uiRoomComponent.AddGamer(gamer, 0);
                    }
                }
            }
        }
Esempio n. 2
0
        protected override async void Run(ETModel.Session session, Actor_GamerJionRoom message)
        {
            try
            {
                Log.Debug("有人加入:");
                UI uiRoom  = Game.Scene.GetComponent <UIComponent>().Get(UIType.UIRoom);
                UI uiReady = Game.Scene.GetComponent <UIComponent>().Get(UIType.UIReady);
                if (uiReady == null)
                {
                    return;
                }
                GamerComponent  gamerComponent = uiRoom.GetComponent <GamerComponent>();
                UIRoomComponent roomComponent  = uiRoom.GetComponent <UIRoomComponent>();

                UIReadyComponent uiReadyComponent = uiReady.GetComponent <UIReadyComponent>();
                Gamer            gamer            = GamerFactory.Create(message.Gamer.UserID, message.Gamer.IsReady, message.Gamer.playerInfo);

                GamerUIComponent gamerUiComponent = gamer.GetComponent <GamerUIComponent>();

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

                //设置准备
                if (uiReadyComponent != null)
                {
                    //                        await gamerUiComponent.GetPlayerInfo();
                    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);
                    }
                }
            }
            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);
            }
        }