示例#1
0
        protected override async void Run(Session session, StartMatch_RT message, Action <StartMatch_RE> reply)
        {
            StartMatch_RE response = new StartMatch_RE();

            try
            {
                //验证玩家ID是否正常
                Player player = Game.Scene.GetComponent <PlayerComponent>().Get(message.PlayerID);
                if (player == null)
                {
                    response.Error = ErrorCode.ERR_StartMatchError;
                    reply(response);
                    return;
                }

                //验证玩家是否符合进入房间要求
                RoomConfig roomConfig = RoomHelper.GetConfig(message.Level);
                UserInfo   userInfo   = await Game.Scene.GetComponent <DBProxyComponent>().Query <UserInfo>(player.UserID);

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

                //向匹配服务器发送匹配请求
                StartConfigComponent config = Game.Scene.GetComponent <StartConfigComponent>();
                string       matchAddress   = config.MatchConfig.GetComponent <InnerConfig>().Address;
                Session      matchSession   = Game.Scene.GetComponent <NetInnerComponent>().Get(matchAddress);
                JoinMatch_RE joinMatchRE    = await matchSession.Call <JoinMatch_RE>(new JoinMatch_RT()
                {
                    PlayerID      = player.Id,
                    UserID        = player.UserID,
                    GateSessionID = session.Id,
                    GateAppID     = config.StartConfig.AppId
                });

                //设置玩家的Actor消息直接发送给匹配对象
                player.ActorID = joinMatchRE.ActorID;

                reply(response);
            }
            catch (Exception e)
            {
                ReplyError(response, e, reply);
            }
        }
示例#2
0
        protected override async void Run(Session session, StartMatchRt message, Action <StartMatchRe> reply)
        {
            StartMatchRe response = new StartMatchRe();

            try
            {
                //验证玩家ID是否正常
                Player player = Game.Scene.GetComponent <PlayerComponent>().Get(message.PlayerId);
                if (player == null)
                {
                    response.Error = ErrorCode.ERR_AccountOrPasswordError;
                    reply(response);
                    return;
                }

                //验证玩家是否符合进入房间要求
                RoomConfig roomConfig = RoomHelper.GetConfig(message.Level);
                UserInfo   userInfo   = await Game.Scene.GetComponent <DBProxyComponent>().Query <UserInfo>(player.UserId);

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

                //向匹配服务器发送匹配请求
                StartConfigComponent config       = Game.Scene.GetComponent <StartConfigComponent>();
                IPEndPoint           matchAddress = config.MatchConfig.GetComponent <InnerConfig>().IPEndPoint;
                Session     matchSession          = Game.Scene.GetComponent <NetInnerComponent>().Get(matchAddress);
                JoinMatchRe joinMatchRe           = await matchSession.Call <JoinMatchRe>(new JoinMatchRt()
                {
                    PlayerId      = player.Id,
                    UserId        = player.UserId,
                    GateSessionId = session.Id,
                    GateAppId     = config.StartConfig.AppId
                });

                //设置玩家的Actor消息直接发送给匹配对象
                player.ActorId = joinMatchRe.ActorId;

                reply(response);
            }
            catch (Exception e)
            {
                ReplyError(response, e, reply);
            }
        }
示例#3
0
文件: RoomFactory.cs 项目: skyole/ET
        public static Room Create(RoomLevel level)
        {
            Room room = EntityFactory.Create <Room>();

            room.AddComponent <RoomJoinKeyComponent>();
            room.AddComponent <DeckComponent>();
            room.AddComponent <DeskCardsCacheComponent>();
            room.AddComponent <OrderControllerComponent>();

            RoomConfig config = RoomHelper.GetConfig(level);
            GameControllerComponent gameController = room.AddComponent <GameControllerComponent, RoomConfig>(config);

            //添加管理,避免被GC释放
            Game.Scene.GetComponent <RoomComponent>().Add(room);
            return(room);
        }