Exemple #1
0
        /// <summary>
        /// 斗地主游戏开始
        /// </summary>
        public static void GameStart(this Room self)
        {
            //更改房间状态 从空闲房间移除 添加到游戏中房间列表
            LandMatchComponent Match = Game.Scene.GetComponent <LandMatchComponent>();

            Match.FreeLandlordsRooms.Remove(self.Id);
            Match.GamingLandlordsRooms.Add(self.Id, self);
            //出牌控制组件
            self.AddComponent <OrderControllerComponent>();

            //更该玩家状态
            for (int i = 0; i < self.gamers.Length; i++)
            {
                Gamer gamer = self.gamers[i];
                Match.Waiting.Remove(gamer.UserID);
                Match.Playing.Add(gamer.UserID, self);
            }
            //添加开始斗地主游戏需要的组件
            //牌库组件
            self.AddComponent <DeckComponent>();

            //添加开始斗地主游戏需要的组件
            self.AddComponent <GameControllerComponent, RoomConfig>(GateHelper.GetLandlordsConfig(RoomLevel.Lv100));

            //开始游戏
            self.GetComponent <GameControllerComponent>().StartGame();
        }
        protected override async void Run(Session session, C2G_StartMatch_Landlords_Req message, Action <G2C_StartMatch_Landlords_Back> reply)
        {
            G2C_StartMatch_Landlords_Back response = new G2C_StartMatch_Landlords_Back();

            try
            {
                Log.Debug("玩家开始匹配");
                //验证Session
                if (!GateHelper.SignSession(session))
                {
                    response.Error = ErrorCode.ERR_SignError;
                    reply(response);
                    return;
                }

                User user = session.GetComponent <SessionUserComponent>().User;

                //验证玩家是否符合进入房间要求,默认为100底分局
                RoomConfig roomConfig = GateHelper.GetLandlordsConfig(RoomLevel.Lv100);
                UserInfo   userInfo   = await Game.Scene.GetComponent <DBProxyComponent>().Query <UserInfo>(user.UserID);

                if (userInfo.Money < roomConfig.MinThreshold)
                {
                    response.Error = ErrorCode.ERR_UserMoneyLessError;
                    reply(response);
                    return;
                }

                reply(response);

                //获取斗地主专用Map服务器的Session
                //通知Map服务器创建新的Gamer
                Session LandlordsSession = GateHelper.GetLandlordsSession();
                LandlordsSession.Send(new G2M_EnterMatch_Landords()
                {
                    UserID          = user.UserID,
                    ActorIDofUser   = user.InstanceId,
                    ActorIDofClient = user.SelfGateSessionID
                });
            }
            catch (Exception e)
            {
                ReplyError(response, e, reply);
            }
        }
Exemple #3
0
        protected override async ETTask Run(Session session, C2G_StartMatch_Req request, G2C_StartMatch_Back response, Action reply)
        {
            try
            {
                Log.Debug("玩家开始匹配");
                //验证Session
                if (!GateHelper.SignSession(session))
                {
                    response.Error = ErrorCode.ERR_SignError;
                    reply();
                    return;
                }
                //获取Gate服务器上绑定的User对象
                User user = session.GetComponent <SessionUserComponent>().User;
                //验证玩家是否符合进入房间要求,默认为100底分局
                RoomConfig roomConfig = GateHelper.GetLandlordsConfig(RoomLevel.Lv100);
                //获取User对象的UserInfo(用户信息)数据
                UserInfo userInfo = await Game.Scene.GetComponent <DBProxyComponent>().Query <UserInfo>(user.UserID);

                //判断此对象的金币是否符合准备要求
                if (userInfo.Douzi < roomConfig.MinThreshold)
                {
                    response.Error = ErrorCode.ERR_UserMoneyLessError;
                    reply();
                    return;
                }
                reply();

                //获取斗地主Map服务器的Session
                //通知Map服务器创建地图上的Gamer,发送请求匹配通知
                Session mapSession = GateHelper.GetMapSession();
                mapSession.Send(new EnterMatchs_G2M()
                {
                    UserID   = user.UserID,
                    GActorID = user.InstanceId,
                    CActorID = user.GateSessionID
                });

                await ETTask.CompletedTask;
            }
            catch (Exception e)
            {
                ReplyError(response, e, reply);
            }
        }