Esempio n. 1
0
        public void MessageReceive(UserToken token, SocketModel message)
        {
            if (!CacheFactory.user.IsOnline(token))
            {
                return;
            }
            switch (message.command)
            {
            //请求开始匹配
            case MatchProtocol.STARTMATCH_CREQ:
            {
                //获取请求匹配的结果
                ResponseStartMatchInfo result = BizFactory.match.StartMatch(token, (SConst.GameType)message.GetMessage <int>());
                token.write(TypeProtocol.MATCH, MatchProtocol.STARTMATCH_SRES, result);
            }
            break;

            //请求离开匹配
            case MatchProtocol.LEAVEMATCH_CREQ:
            {
                int result = BizFactory.match.LeaveMatch(token);
                token.write(TypeProtocol.MATCH, MatchProtocol.LEAVEMATCH_SRES, result);
            }
            break;
            }
        }
Esempio n. 2
0
        public void MessageReceive(UserToken token, SocketModel message)
        {
            //如果用户不在线,返回
            if (!CacheFactory.user.IsOnLine(token))
            {
                return;
            }
            switch (message.command)
            {
            //请求开始匹配
            case MatchProtocol.STARTMATCH_CREQ:
            {
                //DebugUtil.Instance.LogToTime("用户请求开始匹配");
                //创建一个匹配结果
                ResponseStartMatchInfo result = BizFactory.match.StartMatch(token, (SConst.GameType)message.GetMessage <int>());
                token.write(TypeProtocol.MATCH, MatchProtocol.STARTMATCH_SRES, result);
            }
            break;

            //请求离开匹配
            case MatchProtocol.LEAVEMATCH_CREQ:
            {
                int result = BizFactory.match.LeaveMatch(token);
                token.write(TypeProtocol.MATCH, MatchProtocol.LEAVEMATCH_SRES, result);
            }
            break;
            }
        }
Esempio n. 3
0
        /// <summary>
        /// 添加匹配到匹配对列
        /// </summary>
        /// <param name="userid"></param>
        /// <param name="roomtype"></param>
        public void AddMatch(int userid, SConst.GameType roomtype, ref ResponseStartMatchInfo info)
        {
            #region 如果当前有匹配对列
            if (MatchInfo.Count > 0)
            {
                //创建一条匹配对列房间号的列表
                List <int> Roomid = new List <int>(MatchInfo.Keys);
                for (int i = 0; i < Roomid.Count; i++)
                {
                    //如果匹配对列和将要进行的游戏类型一致
                    if (MatchInfo[Roomid [i]].GameType == roomtype)
                    {
                        //如果当前对列中有队伍未满员
                        if (MatchInfo[Roomid[i]].Team.Count < MatchInfo[Roomid[i]].MaxPlayer)
                        {
                            //将玩家添加到匹配对列中
                            MatchInfo[Roomid[i]].Team.Add(userid);
                            //添加返回给客户端的信息
                            info.PlayerCount = MatchInfo[Roomid[i]].Team.Count;
                            info.MaxPlayer   = MatchInfo[Roomid[i]].MaxPlayer;
                            info.Type        = roomtype;
                            //添加玩家和房间号的映射
                            UserToMatch.Add(userid, Roomid[i]);

                            DebugUtil.Instance.LogToTime(userid + "请求加入匹配对列成功,对列号为:" + Roomid[i]);
                            IsFinish(Roomid[i]);
                            return;
                        }
                    }
                }
            }
            #endregion
            #region 创建一个新的匹配对列
            //创建一个新的匹配对列
            MatchInfoModel model = new MatchInfoModel();
            //设定当前具有玩家数量来开启游戏
            model.MaxPlayer = 2;
            model.RoomId    = GetMatchId();
            model.GameType  = roomtype;
            model.Team.Add(userid);
            //添加返回给客户端的信息
            info.PlayerCount = model.Team.Count;
            info.MaxPlayer   = model.MaxPlayer;
            info.Type        = roomtype;
            //添加房间号和房间的映射
            MatchInfo.Add(model.RoomId, model);
            //添加玩家和房间号的映射
            UserToMatch.Add(userid, model.RoomId);
            //添加游戏是否开始的映射
            if (!IsStartGame.ContainsKey(model.RoomId))
            {
                IsStartGame.Add(model.RoomId, false);
            }
            DebugUtil.Instance.LogToTime(userid + "请求创建匹配对列成功,对列号为:" + model.RoomId);
            IsFinish(model.RoomId);
            #endregion
        }
Esempio n. 4
0
        /// <summary>
        /// 请求开始匹配
        /// </summary>
        /// <param name="token">用户连接对象</param>
        /// <param name="type">房间类型</param>
        /// <returns>0 请求开始匹配成功</returns>
        /// <returns>-1 当前金币余额不足</returns>
        /// <returns>-2 当前玩家已在匹配列表</returns>
        /// <returns>-3 当前玩家无效</returns>
        public ResponseStartMatchInfo StartMatch(UserToken token, SConst.GameType type)
        {
            //通过连接获取账号
            roleinfo user = cache.CacheFactory.user.Get(token);
            ResponseStartMatchInfo info = new ResponseStartMatchInfo();

            if (user == null)
            {
                info.Status = -3;
                DebugUtil.Instance.LogToTime(token.conn.RemoteEndPoint + "请求开始匹配失败,连接无效");
                return(info);
            }
            int uid   = user.id;
            int ucoin = user.coin;

            //获取进入房间需要的最少的金币
            int coin = cache.CacheFactory.match.GetRoomCoinAtType(type);

            if (ucoin < coin)
            {
                info.Status = -1;
                DebugUtil.Instance.LogToTime(uid + "请求开始匹配失败,当前金币余额不足,余额为:" + ucoin);
                return(info);
            }
            //获取是否在匹配对列中
            int matchid = cache.CacheFactory.match.IsOnMatchArray(uid);

            if (matchid > 0)
            {
                info.Status = -2;
                DebugUtil.Instance.LogToTime(uid + "请求开始匹配");
                return(info);
            }
            //创建一个匹配对列,并返回匹配成功
            cache.CacheFactory.match.AddMatch(uid, type, ref info);
            info.Status = 0;
            DebugUtil.Instance.LogToTime(uid + "请求开始匹配成功,创建一个匹配对列");
            return(info);
        }
Esempio n. 5
0
        /// <summary>
        /// 请求开始匹配
        /// </summary>
        /// <param name="token">用户连接对象</param>
        /// <param name="type">房间类型</param>
        /// <returns>0 请求开始匹配成功</returns>
        /// <returns>-1 当前金币余额不足</returns>
        /// <returns>-2 当前玩家已在匹配列表</returns>
        /// <returns>-3 连接无效/returns>
        public ResponseStartMatchInfo StartMatch(UserToken token, SConst.GameType type)
        {
            ResponseStartMatchInfo info = new ResponseStartMatchInfo();
            RoleInfo user = CacheFactory.user.Get(token);

            if (user == null)
            {
                info.Status = -3;
                DebugUtil.Instance.LogToTime(token.conn.RemoteEndPoint + "请求开始匹配失败,连接无效");
                return(info);
            }
            int uid   = user.id;
            int ucoin = user.coin;
            //获取进入房间需要的最小的金币
            int coin = CacheFactory.match.GetRoomCoinAtType(type);

            if (ucoin < coin)
            {
                info.Status = -1;
                DebugUtil.Instance.LogToTime(uid + "请求开始匹配失败,余额不足,当前余额" + ucoin);
                return(info);
            }
            //获取是否在匹配队列中
            int matchid = CacheFactory.match.IsOnMatchArray(uid);

            if (matchid > 0)
            {
                info.Status = -2;
                DebugUtil.Instance.LogToTime(uid + "请求开始匹配失败当前已在队列中" + matchid);
                return(info);
            }
            //创建一个匹配队列,并返回匹配成功
            info.Status = 0;
            CacheFactory.match.AddMatch(uid, type, ref info);
            DebugUtil.Instance.LogToTime(uid + "请求开始匹配成功,创建一个匹配队列");
            return(info);
        }
Esempio n. 6
0
 public void StartMatch(ResponseStartMatchInfo info)
 {
     MatchCountText.text    = "正在匹配中… " + info.PlayerCount + "/" + info.MaxPlayer;
     MatchGameTypeText.text = GameApp.Instance.GameConst.GameName[(int)info.Type];
     TimeCount = 0;
 }
Esempio n. 7
0
    public void MessageReceive(SocketModel model)
    {
        switch (model.command)
        {
        //0离开成功 -1游戏已经开始 -2不在房间内
        case MatchProtocol.LEAVEMATCH_SRES:
        {
            switch (model.GetMessage <int>())
            {
            case 0:
            case -2:
                //离开匹配成功后,加载主界面,关闭匹配界面
                GameApp.Instance.GameLevelManagerScript.CloseSystemUI(GameResources.SystemUIType.MATCHPANEL);
                break;

            case -1:
                GameApp.Instance.CommonHintDlgScript.OpenHint("游戏已经开始");
                break;
            }
        }
        break;

        //0开始匹配 -1当前余额不足 -2玩家已经在房间中
        case MatchProtocol.STARTMATCH_SRES:
        {
            //接受匹配结果
            ResponseStartMatchInfo m = model.GetMessage <ResponseStartMatchInfo>();
            switch (m.Status)
            {
            //匹配成功
            case 0:
                //加载匹配页面
                GameApp.Instance.GameLevelManagerScript.LoadSyStemUI(GameResources.SystemUIType.MATCHPANEL, delegate() {
                        GameObject go;
                        if (GameApp.Instance.GameLevelManagerScript.SystemUICache.TryGetValue(GameResources.SystemUIType.MATCHPANEL, out go))
                        {
                            if (!go.GetComponent <UI_match>())
                            {
                                go.AddComponent <UI_match>();
                            }
                            //刷新匹配界面信息
                            go.GetComponent <UI_match>().StartMatch(m);
                        }
                    });
                break;

            case -1:
                GameApp.Instance.CommonHintDlgScript.OpenHint("当前余额不足");
                break;

            case -2:
                GameApp.Instance.CommonHintDlgScript.OpenHint("已经在其他房间中,不可进行匹配");
                break;
            }
        }
        break;

        case MatchProtocol.MATCHCLOSE_BRQ:
        {
            GameApp.Instance.TimeManagerScript.AddShedule(delegate()
                {
                    GameApp.Instance.CommonHintDlgScript.OpenHint("游戏将于五秒后自动返回大厅");
                    this.Write(TypeProtocol.USER, UserProtocol.GETINFO_CREQ, null);
                }, 5000);
        }
        break;

        case MatchProtocol.MATCHFINISH_BRQ:
        {
            //TODO:LODE BATTLE
            //匹配成功加载battle场景
            GameApp.Instance.GameLevelManagerScript.LoadScene(GameResources.SceneName.BATTLE);
            GameApp.Instance.GameLevelManagerScript.CloseSystemUI(GameResources.SystemUIType.MATCHPANEL);
        }
        break;

        case MatchProtocol.MATCHINFO_BRQ:
        {
            //刷新接收到的匹配信息
            MatchInfoModel m = model.GetMessage <MatchInfoModel>();
            if (GameApp.Instance.UI_matchScript != null)
            {
                GameApp.Instance.UI_matchScript.UpdateRoomRoleInfo(m);
            }
        }
        break;
        }
    }