Exemplo n.º 1
0
        /// <summary>
        /// 创建玩家对象
        /// </summary>
        public static Gamer Create(GamerInfo info)
        {
            Gamer gamer = ComponentFactory.Create <Gamer>();

            gamer.UserID = info.UserID;
            return(gamer);
        }
Exemplo n.º 2
0
        public Gamer AddGamerUI(GamerInfo info)
        {
            if (gamers.ContainsKey(info.SeatID))
            {
                return(null);
            }
            Gamer gamer = GamerFactory.Create(info);

            Add(gamer, info.SeatID);
            return(gamer);
        }
Exemplo n.º 3
0
        /// <summary>
        /// 再添加其他玩家
        /// </summary>
        public void AddGamer(GamerInfo info, int posIndex)
        {
            Gamer gamer = GamerComponent.AddGamerUI(info);

            if (gamer != null)
            {
                gamer.AddComponent <UICowCow_GamerInfoComponent, GameObject, GamerInfo, int>(UIRoomGamer, info, posIndex);
                gamer.AddComponent <UICowCow_SSGamerResultComponent, GameObject>(SmallSettlement.SmallBG);
                gamer.AddComponent <UICowCow_BSGamerResultComponent, GameObject>(BigSettlement.BigBG);
            }
        }
        protected override async Task Run(Room room, Actor_PlayerEnterRoom_Ntt message)
        {
            try
            {
                DBProxyComponent dbProxy = Game.Scene.GetComponent <DBProxyComponent>();
                Gamer            gamer   = room.Get(message.UserID);
                if (gamer == null)
                {
                    //创建房间玩家对象
                    gamer = GamerFactory.Create(message.PlayerID, message.UserID, room.RoomId, (ushort)room.Count);
                    await gamer.AddComponent <MailBoxComponent>().AddLocation();

                    gamer.AddComponent <UnitGateComponent, long>(message.SessionID);

                    //设置转接ID
                    Session session           = Game.Scene.GetComponent <NetOuterComponent>().Get(message.SessionID);
                    session.GetUser().ActorID = gamer.Id;

                    room.Add(gamer);

                    Actor_GamerEnterRoom_Ntt broadcastMessage = new Actor_GamerEnterRoom_Ntt();
                    foreach (Gamer item in room.GetAll())
                    {
                        if (item == null)
                        {
                            //添加空位
                            broadcastMessage.users.Add(null);
                            continue;
                        }
                        UserInfo userInfo = await dbProxy.Query <UserInfo>(item.UserID, false);

                        GamerInfo info = new GamerInfo()
                        {
                            ChairID = item.uChairID, NickName = userInfo.NickName, Loses = userInfo.Loses, Money = userInfo.Money, Wins = userInfo.Wins
                        };
                        broadcastMessage.users.Add(info);
                    }
                    room.Broadcast(broadcastMessage);

                    Log.Info($"玩家{message.UserID}进入房间");
                }
                else
                {
                    Log.Info("断线重连?????");
                }
            }
            catch (Exception e)
            {
                Log.Info($"创建房间错误:{e.Message}");
            }
        }
        /// <summary>
        /// 加入房间
        /// </summary>
        /// <param name="self"></param>
        /// <param name="room"></param>
        /// <param name="matcher"></param>
        public static void JoinRoom(this LandlordsComponent self, LandlordsRoom room, Gamer gamer)
        {
            //玩家可能掉线
            if (gamer == null)
            {
                return;
            }

            //玩家加入房间 成为已经进入房间的玩家
            //绑定玩家与房间 以后可以通过玩家UserID找到所在房间
            self.Waiting[gamer.UserID] = room;
            //为玩家添加座位
            room.Add(gamer);
            //房间广播
            Log.Info($"玩家{gamer.UserID}进入房间");
            Actor_GamerEnterRoom_Ntt broadcastMessage = new Actor_GamerEnterRoom_Ntt();

            foreach (Gamer _gamer in room.gamers)
            {
                if (_gamer == null)
                {
                    //添加空位
                    broadcastMessage.Gamers.Add(new GamerInfo());
                    continue;
                }

                //添加玩家信息
                //GamerInfo info = new GamerInfo() { UserID = _gamer.UserID, IsReady = room.IsGamerReady(gamer) };
                GamerInfo info = new GamerInfo()
                {
                    UserID = _gamer.UserID
                };
                broadcastMessage.Gamers.Add(info);
            }
            //广播房间内玩家消息 每次有人进入房间都会收到一次广播
            room.Broadcast(broadcastMessage);

            //通知Gate服务器玩家匹配成功 参数:Gamer的InstanceId
            //Gate服务器将Actor类消息转发给Gamer
            ActorMessageSenderComponent actorProxyComponent = Game.Scene.GetComponent <ActorMessageSenderComponent>();
            ActorMessageSender          gamerActorProxy     = actorProxyComponent.Get(gamer.ActorIDofUser);

            gamerActorProxy.Send(new Actor_LandlordsMatchSucess()
            {
                ActorIDofGamer = gamer.InstanceId
            });
        }
Exemplo n.º 6
0
        /// <summary>
        /// 加入房间
        /// </summary>
        public static void JoinRoom(this LandMatchComponent self, Room room, Gamer gamer)
        {
            //玩家可能掉线
            if (gamer == null)
            {
                return;
            }

            //玩家加入房间 成为已经进入房间的玩家
            //绑定玩家与房间 以后可以通过玩家UserID找到所在房间
            self.Waiting[gamer.UserID] = room;
            //为玩家添加座位
            room.Add(gamer);
            //房间广播
            Log.Info($"玩家{gamer.UserID}进入房间");
            Actor_GamerEnterRoom_Ntt broadcastMessage = new Actor_GamerEnterRoom_Ntt();

            foreach (Gamer _gamer in room.gamers)
            {
                if (_gamer == null)
                {
                    //添加空位
                    broadcastMessage.Gamers.Add(new GamerInfo());
                    continue;
                }

                //添加玩家信息
                //GamerInfo info = new GamerInfo() { UserID = _gamer.UserID, IsReady = room.IsGamerReady(gamer) };
                GamerInfo info = new GamerInfo()
                {
                    UserID = _gamer.UserID
                };
                broadcastMessage.Gamers.Add(info);
            }
            //广播房间内玩家消息 每次有人进入房间都会收到一次广播
            room.Broadcast(broadcastMessage);

            //向Gate上的User发送匹配成功
            //ActorMessageSender actorProxy = Game.Scene.GetComponent<ActorMessageSenderComponent>().Get(gamer.GActorID);
            //actorProxy.Send(new Actor_MatchSucess_M2G() { GamerID = gamer.InstanceId });
            Session GetGateSession = MapHelper.GetGateSession();

            GetGateSession.Send(new T_MatchSucess_M2G()
            {
                UserID = gamer.UserID, GamerID = gamer.InstanceId
            });
        }
Exemplo n.º 7
0
        public void Awake(GameObject parent, GamerInfo info, int posIndex)
        {
            res = ETModel.Game.Scene.GetComponent <ResourcesComponent>();
            res.LoadBundle(UICowCowAB.CowCow_Texture);
            res.LoadBundle(UICowCowAB.CowCow_SoundOther);
            microphone     = Game.Scene.GetComponent <MicrophoneComponent>();
            this.Status    = (UIGamerStatus)info.Status;
            this.gamerName = info.Name;
            UIGameInfo     = GamerFactory.Create(UICowCowType.CowCowGamerInfo);
            UIGameInfo.transform.SetParent(parent.transform, false);
            UIGameInfo.name = UICowCowType.CowCowGamerInfo;
            ReferenceCollector rc = UIGameInfo.GetComponent <ReferenceCollector>();

            Image headIcon = rc.Get <GameObject>("HeadIcon").GetComponent <Image>();

            headIcon.transform.localPosition = GamerData.Pos[posIndex].HeadPos;
            Text gamerNames = rc.Get <GameObject>("Names").GetComponent <Text>();

            coin     = rc.Get <GameObject>("Coin").GetComponent <Text>();
            status   = rc.Get <GameObject>("Status").GetComponent <Text>();
            cowType  = rc.Get <GameObject>("CowType").GetComponent <Text>();
            HandCard = rc.Get <GameObject>("HandCard").GetComponent <CanvasGroup>();
            HandCard.transform.localPosition = GamerData.Pos[posIndex].CardPos;
            for (int i = 0; i < cards.Length; i++)
            {
                cards[i] = rc.Get <GameObject>("Card" + i).GetComponent <Image>();
            }
            promptBtn = rc.Get <GameObject>("PromptBtn").GetComponent <Button>();
            submitBtn = rc.Get <GameObject>("SubmitBtn").GetComponent <Button>();

            emoji      = rc.Get <GameObject>("Emoji").GetComponent <Image>();
            chatBG     = rc.Get <GameObject>("ChatBG").GetComponent <CanvasGroup>();
            chatText   = rc.Get <GameObject>("ChatText").GetComponent <Text>();
            bankerIcon = rc.Get <GameObject>("BankerIcon").GetComponent <Image>();
            chatBG.transform.localPosition = GamerData.Pos[posIndex].ChatPosData.Pos;
            chatBG.transform.Rotate(GamerData.Pos[posIndex].ChatPosData.Rotate);
            chatText.transform.Rotate(GamerData.Pos[posIndex].ChatPosData.Rotate);


            promptBtn.onClick.Add(OnPrompt);
            submitBtn.onClick.Add(OnSubmit);
            gamerNames.text = info.Name;
            this.SetCoin(info.Coin.ToString());
            this.Sex = info.Sex;
            //headIcon.sprite = info.HeadIcon;
        }
Exemplo n.º 8
0
        protected override void Run(ETModel.Session session, Actor_GamerEnterRoom_Ntt message)
        {
            UI uiRoom = Game.Scene.GetComponent <UIComponent>().Get(UIType.LandlordsRoom);
            LandlordsRoomComponent landlordsRoomComponent = uiRoom.GetComponent <LandlordsRoomComponent>();
            GamerComponent         gamerComponent         = uiRoom.GetComponent <GamerComponent>();

            //从匹配状态中切换为准备状态
            if (landlordsRoomComponent.Matching)
            {
                landlordsRoomComponent.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)
                    {
                        //玩家在本地玩家右边
                        landlordsRoomComponent.AddGamer(gamer, 2);
                    }
                    else
                    {
                        //玩家在本地玩家左边
                        landlordsRoomComponent.AddGamer(gamer, 0);
                    }
                }
            }
        }
Exemplo n.º 9
0
        protected override void Run(ETModel.Session session, Actor_GamerEnterRoom_Ntt message)
        {
            GameDataComponent GameData = Game.Scene.GetComponent <GameDataComponent>();

            for (int i = 0; i < message.users.Count; i++)
            {
                GamerInfo user = message.users[i];
                //如果User为空  如果已经添加了此玩家的信息               如果是自己的信息
                if (user == null || GameData.IsExist(user.ChairID) || user.ChairID == GameTools.GetUser().ChairId)
                {
                    continue;
                }
                Gamer gamer = GamerFactory.CreateOther(user.ChairID, false);
                gamer.Loses    = user.Loses;
                gamer.Money    = user.Money;
                gamer.NickName = user.NickName;
                gamer.Wins     = user.Wins;
                GameData.Add(user.ChairID, gamer);
                Log.Debug($"存储新来的玩家的信息:{gamer.NickName}");
            }

            Game.EventSystem.Run(EventIdType.UpdateView);
        }
Exemplo n.º 10
0
        /// <summary>
        /// 先讲自己克隆出来
        /// </summary>
        public void AddLocalGamer(GamerInfo info)
        {
            if (info.UserID != ETModel.Game.Scene.GetComponent <ClientComponent>().User.UserID)
            {
                return;
            }
            Gamer gamer = GamerComponent.AddGamerUI(info);

            if (gamer != null)
            {
                gamer.AddComponent <UICowCow_GamerInfoComponent, GameObject, GamerInfo, int>(UIRoomGamer, info, 0);
                gamer.AddComponent <UICowCow_SSGamerResultComponent, GameObject>(SmallSettlement.SmallBG);
                gamer.AddComponent <UICowCow_BSGamerResultComponent, GameObject>(BigSettlement.BigBG);
            }
            if (GamerComponent.LocalGamer == null)
            {
                GamerComponent.Init(info.UserID);
                if (GamerComponent.LocalGamer.GetComponent <UICowCow_GamerInfoComponent>().Status == UIGamerStatus.Down)
                {
                    ShowHideReadyButton(true);
                }
            }
        }
        protected override async Task Run(Room room, Actor_PlayerEnterRoom_Req message, Action <Actor_PlayerEnterRoom_Ack> reply)
        {
            Actor_PlayerEnterRoom_Ack response = new Actor_PlayerEnterRoom_Ack();

            try
            {
                Gamer gamer = room.Get(message.UserID);
                if (gamer == null)
                {
                    //创建房间玩家对象
                    gamer = GamerFactory.Create(message.PlayerID, message.UserID);
                    await gamer.AddComponent <MailBoxComponent>().AddLocation();

                    gamer.AddComponent <UnitGateComponent, long>(message.SessionID);

                    //加入到房间
                    room.Add(gamer);

                    Actor_GamerEnterRoom_Ntt broadcastMessage = new Actor_GamerEnterRoom_Ntt();
                    foreach (Gamer _gamer in room.GetAll())
                    {
                        if (_gamer == null)
                        {
                            //添加空位
                            broadcastMessage.Gamers.Add(null);
                            continue;
                        }

                        //添加玩家信息
                        GamerInfo info = new GamerInfo()
                        {
                            UserID = _gamer.UserID, IsReady = _gamer.IsReady
                        };
                        broadcastMessage.Gamers.Add(info);
                    }

                    //广播房间内玩家消息
                    room.Broadcast(broadcastMessage);

                    Log.Info($"玩家{message.UserID}进入房间");
                }
                else
                {
                    //玩家重连
                    gamer.isOffline = false;
                    gamer.PlayerID  = message.PlayerID;
                    gamer.GetComponent <UnitGateComponent>().GateSessionActorId = message.SessionID;

                    //玩家重连移除托管组件
                    gamer.RemoveComponent <TrusteeshipComponent>();

                    Actor_GamerEnterRoom_Ntt broadcastMessage = new Actor_GamerEnterRoom_Ntt();
                    foreach (Gamer _gamer in room.GetAll())
                    {
                        if (_gamer == null)
                        {
                            //添加空位
                            broadcastMessage.Gamers.Add(null);
                            continue;
                        }

                        //添加玩家信息
                        GamerInfo info = new GamerInfo()
                        {
                            UserID = _gamer.UserID, IsReady = _gamer.IsReady
                        };
                        broadcastMessage.Gamers.Add(info);
                    }

                    //发送房间玩家信息
                    ActorMessageSender actorProxy = gamer.GetComponent <UnitGateComponent>().GetActorMessageSender();
                    actorProxy.Send(broadcastMessage);

                    List <GamerCardNum>      gamersCardNum   = new List <GamerCardNum>();
                    List <GamerState>        gamersState     = new List <GamerState>();
                    GameControllerComponent  gameController  = room.GetComponent <GameControllerComponent>();
                    OrderControllerComponent orderController = room.GetComponent <OrderControllerComponent>();
                    DeskCardsCacheComponent  deskCardsCache  = room.GetComponent <DeskCardsCacheComponent>();

                    foreach (Gamer _gamer in room.GetAll())
                    {
                        HandCardsComponent handCards = _gamer.GetComponent <HandCardsComponent>();
                        gamersCardNum.Add(new GamerCardNum()
                        {
                            UserID = _gamer.UserID,
                            Num    = _gamer.GetComponent <HandCardsComponent>().GetAll().Length
                        });
                        gamersState.Add(new GamerState()
                        {
                            UserID            = _gamer.UserID,
                            Identity          = (byte)handCards.AccessIdentity,
                            GrabLandlordState = orderController.GamerLandlordState.ContainsKey(_gamer.UserID)
                            ? orderController.GamerLandlordState[_gamer.UserID]
                            : false
                        });
                    }

                    //发送游戏开始消息
                    Actor_GameStart_Ntt gameStartNotice = new Actor_GameStart_Ntt()
                    {
                        HandCards     = gamer.GetComponent <HandCardsComponent>().GetAll(),
                        GamersCardNum = gamersCardNum
                    };
                    actorProxy.Send(gameStartNotice);

                    Card[] lordCards = null;

                    if (gamer.GetComponent <HandCardsComponent>().AccessIdentity == Identity.None)
                    {
                        //广播先手玩家
                        actorProxy.Send(new Actor_AuthorityGrabLandlord_Ntt()
                        {
                            UserID = orderController.CurrentAuthority
                        });
                    }
                    else
                    {
                        if (gamer.UserID == orderController.CurrentAuthority)
                        {
                            //发送可以出牌消息
                            bool isFirst = gamer.UserID == orderController.Biggest;
                            actorProxy.Send(new Actor_AuthorityPlayCard_Ntt()
                            {
                                UserID = orderController.CurrentAuthority, IsFirst = isFirst
                            });
                        }
                        lordCards = deskCardsCache.LordCards.ToArray();
                    }
                    //发送重连数据
                    Actor_GamerReconnect_Ntt reconnectNotice = new Actor_GamerReconnect_Ntt()
                    {
                        Multiples   = room.GetComponent <GameControllerComponent>().Multiples,
                        GamersState = gamersState,
                        DeskCards   = new KeyValuePair <long, Card[]>(orderController.Biggest, deskCardsCache.library.ToArray()),
                        LordCards   = lordCards,
                    };
                    actorProxy.Send(reconnectNotice);

                    Log.Info($"玩家{message.UserID}重连");
                }

                response.GamerID = gamer.Id;

                reply(response);
            }
            catch (Exception e)
            {
                ReplyError(response, e, reply);
            }
        }
Exemplo n.º 12
0
        protected override void Run(ETModel.Session session, Actor_GamerEnterRoom_Ntt message)
        {
            UI uiRoom = Game.Scene.GetComponent <UIComponent>().Get(UIType.LandlordsRoom);
            LandlordsRoomComponent landlordsRoomComponent = uiRoom.GetComponent <LandlordsRoomComponent>();

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

            //服务端发过来3个GamerInfo 当前玩家为其中一个
            //{"Parser":{},"UserID":382339254124924,"IsReady":false}
            int localGamerIndex = -1;

            for (int i = 0; i < message.Gamers.Count; i++)
            {
                if (message.Gamers[i].UserID == LandlordsRoomComponent.LocalGamer.UserID)
                {
                    localGamerIndex = i;
                }
            }

            if (localGamerIndex == -1)
            {
                Log.Error("难道是旁观模式?");
            }

            //添加未显示玩家
            for (int i = 0; i < message.Gamers.Count; i++)
            {
                //如果服务端发来了默认空GamerInfo 跳过
                //{"Parser":{},"UserID":0,"IsReady":false}]}
                GamerInfo gamerInfo = message.Gamers[i];
                if (gamerInfo.UserID == 0)
                {
                    continue;
                }
                //如果这个ID的玩家不在桌上
                if (landlordsRoomComponent.GetGamer(gamerInfo.UserID) == null)
                {
                    Gamer gamer = ETModel.ComponentFactory.Create <Gamer, long>(gamerInfo.UserID);
                    //并没有判断玩家是否已准备

                    //localGamerIndex % 3可以理解为当前玩家在3个玩家(Gamers)中的顺序
                    //localGamerIndex + 1指当前玩家的下一个玩家的相对顺序
                    //如果本地玩家序列为2 localGamerIndex + 1) % 3=0 序列为0的玩家显示在2号位
                    if ((localGamerIndex + 1) % 3 == i)
                    {
                        //玩家在本地玩家右边
                        landlordsRoomComponent.AddGamer(gamer, 2);
                    }
                    else
                    {
                        //玩家在本地玩家左边
                        landlordsRoomComponent.AddGamer(gamer, 0);
                    }
                }
            }
        }
Exemplo n.º 13
0
        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);
            }
        }
Exemplo n.º 14
0
        /// <summary>
        /// 加入房间Actor
        /// </summary>
        /// <param name="self"></param>
        /// <param name="userId"></param>
        public static async Task BroadGamerEnter(this Room self, long userId)
        {
            List <GamerInfo> gamerInfos  = new List <GamerInfo>();
            long             roomType    = self.GetComponent <GameControllerComponent>().RoomConfig.Id;
            GamerInfo        currentInfo = null;

            for (int i = 0; i < self.GetAll().Length; i++)
            {
                Gamer _gamer = self.GetAll()[i];
                if (_gamer == null)
                {
                    continue;
                }
                GamerInfo gamerInfo = new GamerInfo();
                gamerInfo.UserID    = _gamer.UserID;
                gamerInfo.SeatIndex = self.GetGamerSeat(_gamer.UserID);
                gamerInfo.IsReady   = _gamer.IsReady;

                if (_gamer.playerBaseInfo == null)
                {
                    _gamer.playerBaseInfo = await DBCommonUtil.getPlayerBaseInfo(gamerInfo.UserID);
                }

                PlayerInfo playerInfo = PlayerInfoFactory.Create(_gamer.playerBaseInfo);
                gamerInfo.playerInfo = playerInfo;

                if (gamerInfo.UserID == userId)
                {
                    currentInfo = gamerInfo;
                }

                gamerInfos.Add(gamerInfo);
            }

            foreach (var _gamer in self.GetAll())
            {
                if (_gamer == null || _gamer.isOffline)
                {
                    continue;
                }

                //第一次进入
                if (_gamer.UserID == userId)
                {
                    Actor_GamerEnterRoom actorGamerEnterRoom = new Actor_GamerEnterRoom()
                    {
                        RoomType = (int)roomType,
                        Gamers   = gamerInfos,
                    };

                    if (roomType == 3)
                    {
                        GameControllerComponent gameControllerComponent = self.GetComponent <GameControllerComponent>();
                        actorGamerEnterRoom.RoomId         = gameControllerComponent.RoomConfig.FriendRoomId;
                        actorGamerEnterRoom.MasterUserId   = gameControllerComponent.RoomConfig.MasterUserId;
                        actorGamerEnterRoom.JuCount        = gameControllerComponent.RoomConfig.JuCount;
                        actorGamerEnterRoom.Multiples      = gameControllerComponent.RoomConfig.Multiples;
                        actorGamerEnterRoom.CurrentJuCount = self.CurrentJuCount;
                    }

                    self.GamerBroadcast(_gamer, actorGamerEnterRoom);
                }
                //有人加入
                else
                {
                    Actor_GamerJionRoom actorGamerJionRoom = new Actor_GamerJionRoom()
                    {
                        Gamer = currentInfo
                    };

                    self.GamerBroadcast(_gamer, actorGamerJionRoom);
                }
            }
        }
Exemplo n.º 15
0
        protected override async Task Run(Room room, MH2MP_PlayerEnterRoom message, Action <MP2MH_PlayerEnterRoom> reply)
        {
            MP2MH_PlayerEnterRoom response = new MP2MH_PlayerEnterRoom();

            try
            {
                Gamer gamer = room.Get(message.UserID);
                if (gamer == null)
                {
                    //创建房间玩家对象
                    gamer = GamerFactory.Create(message.PlayerID, message.UserID);
                    await gamer.AddComponent <ActorComponent>().AddLocation();

                    gamer.AddComponent <UnitGateComponent, long>(message.SessionID);

                    //加入到房间
                    room.Add(gamer);

                    M2C_GamerEnterRoom broadcastMessage = new M2C_GamerEnterRoom();
                    foreach (Gamer _gamer in room.GetAll())
                    {
                        if (_gamer == null)
                        {
                            //添加空位
                            broadcastMessage.Gamers.Add(null);
                            continue;
                        }

                        //添加玩家信息
                        GamerInfo info = new GamerInfo()
                        {
                            UserID = _gamer.UserID, IsReady = _gamer.IsReady
                        };
                        broadcastMessage.Gamers.Add(info);
                    }

                    //广播房间内玩家消息
                    room.Broadcast(broadcastMessage);

                    Log.Info($"玩家{message.UserID}进入房间");
                }
                else
                {
                    //玩家重连 todo处理牛牛玩家重连逻辑
                    gamer.isOffline = false;
                    gamer.PlayerID  = message.PlayerID;
                    gamer.GetComponent <UnitGateComponent>().GateSessionId = message.SessionID;

                    //玩家重连移除托管组件
                    gamer.RemoveComponent <TrusteeshipComponent>();

                    M2C_GamerEnterRoom broadcastMessage = new M2C_GamerEnterRoom();
                    foreach (Gamer _gamer in room.GetAll())
                    {
                        if (_gamer == null)
                        {
                            //添加空位
                            broadcastMessage.Gamers.Add(null);
                            continue;
                        }

                        //添加玩家信息
                        GamerInfo info = new GamerInfo()
                        {
                            UserID = _gamer.UserID, IsReady = _gamer.IsReady
                        };
                        broadcastMessage.Gamers.Add(info);
                    }

                    //发送房间玩家信息
                    ActorProxy actorProxy = gamer.GetComponent <UnitGateComponent>().GetActorProxy();
                    actorProxy.Send(broadcastMessage);

                    Dictionary <long, Identity> gamersIdentity  = new Dictionary <long, Identity>();
                    Dictionary <long, int>      gamersCardsNum  = new Dictionary <long, int>();
                    GameControllerComponent     gameController  = room.GetComponent <GameControllerComponent>();
                    OrderControllerComponent    orderController = room.GetComponent <OrderControllerComponent>();
                    DeskCardsCacheComponent     deskCardsCache  = room.GetComponent <DeskCardsCacheComponent>();

                    foreach (Gamer _gamer in room.GetAll())
                    {
                        HandCardsComponent handCards = _gamer.GetComponent <HandCardsComponent>();
                        gamersCardsNum.Add(_gamer.UserID, handCards.CardsCount);
                        gamersIdentity.Add(_gamer.UserID, handCards.AccessIdentity);
                    }

                    //发送游戏开始消息
                    M2C_GameStart gameStartNotice = new M2C_GameStart()
                    {
                        GamerCards    = gamer.GetComponent <HandCardsComponent>().GetAll(),
                        GamerCardsNum = gamersCardsNum
                    };
                    actorProxy.Send(gameStartNotice);

                    Card[] lordCards = null;
                    if (gamer.GetComponent <HandCardsComponent>().AccessIdentity == Identity.None)
                    {
                        //广播先手玩家
                        actorProxy.Send(new M2C_AuthorityGrabLandlord()
                        {
                            UserID = orderController.CurrentAuthority
                        });
                    }
                    else
                    {
                        if (gamer.UserID == orderController.CurrentAuthority)
                        {
                            //发送可以出牌消息
                            bool isFirst = gamer.UserID == orderController.Biggest;
                            actorProxy.Send(new M2C_AuthorityPlayCard()
                            {
                                UserID = orderController.CurrentAuthority, IsFirst = isFirst
                            });
                        }
                        lordCards = deskCardsCache.LordCards.ToArray();
                    }
                    //发送重连数据
                    M2C_GamerReconnect_ANtt reconnectNotice = new M2C_GamerReconnect_ANtt()
                    {
                        Multiples              = room.GetComponent <GameControllerComponent>().Multiples,
                        GamersIdentity         = gamersIdentity,
                        DeskCards              = new KeyValuePair <long, Card[]>(orderController.Biggest, deskCardsCache.library.ToArray()),
                        LordCards              = lordCards,
                        GamerGrabLandlordState = orderController.GamerLandlordState
                    };
                    actorProxy.Send(reconnectNotice);

                    Log.Info($"玩家{message.UserID}重连");
                }

                response.GamerID = gamer.Id;

                reply(response);
            }
            catch (Exception e)
            {
                ReplyError(response, e, reply);
            }
        }
        public static async Task GamerContinue(Gamer gamer)
        {
            try
            {
                Log.Info($"玩家{gamer.UserID}继续游戏");

                RoomComponent roomComponent = Game.Scene.GetComponent <RoomComponent>();
                Room          room          = roomComponent.Get(gamer.RoomID);
                if (room == null)
                {
                    return;
                }

                GameControllerComponent  gameControllerComponent  = room.GetComponent <GameControllerComponent>();
                OrderControllerComponent orderControllerComponent = room.GetComponent <OrderControllerComponent>();

                gamer.ReadyTimeOut = 0;
                List <GamerInfo> Gamers = new List <GamerInfo>();
                for (int i = 0; i < room.GetAll().Length; i++)
                {
                    Gamer _gamer = room.GetAll()[i];
                    if (_gamer == null)
                    {
                        continue;
                    }
                    GamerInfo gamerInfo = new GamerInfo();
                    gamerInfo.UserID    = _gamer.UserID;
                    gamerInfo.SeatIndex = room.GetGamerSeat(_gamer.UserID);
                    gamerInfo.IsReady   = _gamer.IsReady;
                    PlayerBaseInfo playerBaseInfo = await DBCommonUtil.getPlayerBaseInfo(gamerInfo.UserID);

                    //判断金币是否不够
                    if (!room.IsFriendRoom)
                    {
                        if (playerBaseInfo.GoldNum < gameControllerComponent.RoomConfig.MinThreshold)
                        {
                            room.GamerBroadcast(_gamer, new Actor_GamerReadyTimeOut()
                            {
                                Message = "金币不足"
                            });
                            room.Remove(_gamer.UserID);
                            _gamer.Dispose();
                            if (room.Count == 0)
                            {
                                GameHelp.RoomDispose(room);
                                return;
                            }
                            continue;
                        }
                    }

                    PlayerInfo playerInfo = PlayerInfoFactory.Create(playerBaseInfo);
                    gamerInfo.playerInfo = playerInfo;

                    Gamers.Add(gamerInfo);
                }

                Actor_GamerEnterRoom actorGamerEnterRoom = new Actor_GamerEnterRoom()
                {
                    RoomType = (int)gameControllerComponent.RoomConfig.Id,
                    Gamers   = Gamers
                };
                if (room.IsFriendRoom)
                {
                    actorGamerEnterRoom.RoomId         = gameControllerComponent.RoomConfig.FriendRoomId;
                    actorGamerEnterRoom.MasterUserId   = gameControllerComponent.RoomConfig.MasterUserId;
                    actorGamerEnterRoom.JuCount        = gameControllerComponent.RoomConfig.JuCount;
                    actorGamerEnterRoom.Multiples      = gameControllerComponent.RoomConfig.Multiples;
                    actorGamerEnterRoom.CurrentJuCount = room.CurrentJuCount;
                }

                room.Broadcast(actorGamerEnterRoom);

//                if (room.IsFriendRoom)
//                {
                await Actor_GamerReadyHandler.GamerReady(gamer, new Actor_GamerReady()
                {
                });

//                }
            }
            catch (Exception e)
            {
                Log.Error(e);
            }

            await Task.CompletedTask;
        }
Exemplo n.º 17
0
        protected override async void Run(Session session, C2G_CowCowJoinGameRoomGate message, Action <G2C_CowCowJoinGameRoomGate> reply)
        {
            G2C_CowCowJoinGameRoomGate response = new G2C_CowCowJoinGameRoomGate();

            try
            {
                Log.WriteLine($"Session:{session.Id},userId:{message.UserID}");
                UserInfo userInfo = Game.Scene.GetComponent <UserInfoComponent>().Get(message.UserID);
                Room     room     = Game.Scene.GetComponent <RoomComponent>().Get(message.RoomID);
                if (room == null)
                {
                    response.Error   = ErrorCode.ERR_NotRoomNumberError;
                    response.Message = "房间号不存在";
                    reply(response);
                    return;
                }

                //超过七个人
                if (room.GamerCount >= room.PeopleCount)
                {
                    response.Error   = ErrorCode.ERR_RoomPeopleFullError;
                    response.Message = "房间人已满";
                    reply(response);
                    return;
                }

                response.GameName  = room.GameName;
                response.Bureau    = room.Bureau;
                response.RuleBit   = room.RuleBit;
                response.RoomID    = room.RoomID;
                response.CurBureau = room.CurBureau;

                Gamer gamer = GamerFactory.Create(message.UserID, session.InstanceId);
                await gamer.AddComponent <MailBoxComponent>().AddLocation();

                gamer.UserID    = message.UserID; //玩家账号
                gamer.Name      = "闲家" + userInfo.NickName;
                gamer.HeadIcon  = userInfo.HeadIcon;
                gamer.Sex       = userInfo.Sex;
                gamer.Coin      = 0;
                gamer.RoomID    = room.RoomID;
                gamer.Status    = GamerStatus.Down;
                gamer.IsOffline = false;
                gamer.Identity  = Identity.None;
                room.Add(gamer);
                Game.Scene.GetComponent <RoomComponent>().Add(gamer.UserID, room.RoomID);

                Dictionary <int, Gamer>           gamers   = room.GetAll();
                Actor_CowCowJoinGameRoomGroupSend allGamer = new Actor_CowCowJoinGameRoomGroupSend();
                allGamer.LocalGamerInfo          = new GamerInfo();
                allGamer.LocalGamerInfo.Coin     = gamer.Coin;
                allGamer.LocalGamerInfo.Name     = gamer.Name;
                allGamer.LocalGamerInfo.HeadIcon = gamer.HeadIcon;
                allGamer.LocalGamerInfo.SeatID   = gamer.SeatID;
                allGamer.LocalGamerInfo.Sex      = gamer.Sex;
                allGamer.LocalGamerInfo.Status   = (int)gamer.Status;
                allGamer.LocalGamerInfo.UserID   = gamer.UserID;
                allGamer.GamerInfo = new RepeatedField <GamerInfo>();
                foreach (Gamer g in gamers.Values)
                {
                    GamerInfo gamerInfo = new GamerInfo();
                    gamerInfo.Coin     = g.Coin;
                    gamerInfo.Name     = g.Name;
                    gamerInfo.HeadIcon = g.HeadIcon;
                    gamerInfo.SeatID   = g.SeatID;
                    gamerInfo.Sex      = g.Sex;
                    gamerInfo.Status   = (int)g.Status;
                    gamerInfo.UserID   = g.UserID;

                    allGamer.GamerInfo.Add(gamerInfo);
                }

                reply(response);

                room.Broadcast(allGamer);
            }
            catch (Exception e)
            {
                ReplyError(response, e, reply);
            }
        }
Exemplo n.º 18
0
        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);
            }
        }