Beispiel #1
0
        /// <summary>
        /// 添加一个匹配,添加到匹配队列
        /// </summary>
        /// <param name="userid"></param>
        /// <param name="type"></param>
        public void AddMatch(int userid, SeverConst.GameType type, ref ResponseStartMatchModel info)
        {
            //创建一个新的匹配模型
            Lazy <MatchModel> model = null;

            if (matchDict.Count > 0)
            {
                //创建一条匹配队列的房间号列表
                List <int> roomID = new List <int>(matchDict.Keys);
                for (int i = 0; i < roomID.Count; i++)
                {
                    //当目前游戏类型和匹配的类型相同
                    if (matchDict[roomID[i]].Value.Type == type)
                    {
                        //当房间人数未满
                        if (matchDict[roomID[i]].Value.Team.Count < matchDict[roomID[i]].Value.MaxPlayer)
                        {
                            //添加返回给客户端的信息
                            matchDict[roomID[i]].Value.Team.Add(userid);
                            info.PlayerCount = model.Value.Team.Count;
                            info.MaxPlayer   = model.Value.MaxPlayer;
                            info.Type        = model.Value.Type;
                            //添加玩家到房间的映射
                            user2MatchDict.TryAdd(userid, model.Value.RoomID);
                            DebugUtil.Instance.Log2Time(string.Format("{0} 请求链接匹配失败,队列号", model.Value.RoomID));
                            IsFnish(roomID[i]);
                            return;
                        }
                    }
                }
            }
            else//创建一个新的队列
            {
                model = new Lazy <MatchModel>();
                //设定当前开局的数量
                model.Value.MaxPlayer = 2;
                model.Value.RoomID    = GetMatchId();
                model.Value.Type      = type;
                model.Value.Team.Add(userid);
                //添加返回给客户端的信息
                info.PlayerCount = model.Value.Team.Count;
                info.MaxPlayer   = model.Value.MaxPlayer;
                info.Type        = model.Value.Type;
                //添加房间号和房间的映射
                matchDict.TryAdd(model.Value.RoomID, model);
                //添加玩家和房间号的映射
                user2MatchDict.TryAdd(userid, model.Value.RoomID);
                //游戏是否开始的映射
                if (!isStartGameDict.ContainsKey(model.Value.RoomID))
                {
                    isStartGameDict.TryAdd(model.Value.RoomID, false);
                }
                IsFnish(model.Value.RoomID);
            }
        }
Beispiel #2
0
        /// <summary>
        /// 获取进入房间的最小货币数量
        /// </summary>
        /// <param name="type"></param>
        /// <returns></returns>
        public int GetRoomCoinAtType(SeverConst.GameType type)
        {
            switch (type)
            {
            case SeverConst.GameType.WinThree:
                break;

            case SeverConst.GameType.FightLine:
                break;

            default: return(1000000000);
            }

            return(0);
        }
Beispiel #3
0
        /// <summary>
        /// 请求开始匹配
        /// </summary>
        /// <param name="token">用户连接对象</param>
        /// <param name="type">房间类型</param>
        /// <returns> 0 请求开始匹配成功 </returns>
        /// <returns>-1 当前金币余额不足 </returns>
        /// <returns>-2 当前玩家已在匹配列表 </returns>
        public ResponseStartMatchModel StartMatch(UserToken token, SeverConst.GameType type)
        {
            ResponseStartMatchModel rsmm = new ResponseStartMatchModel();
            RoleInfo user = CacheProxy.User.Get(token);

            if (user == null)
            {
                rsmm.Status = -3;
                DebugUtil.Instance.Log2Time(string.Format("{0} 请求链接匹配失败,连接失败", token.conn.RemoteEndPoint));
                return(rsmm);
            }
            int uid   = user.Id;
            int uCoin = user.Coin;
            //获取进去房间需要的最新金币
            int coin = CacheProxy.Match.GetRoomCoinAtType(type);

            if (uCoin < coin)
            {
                rsmm.Status = -1;
                DebugUtil.Instance.Log2Time(string.Format("{0} 请求链接匹配失败,余额不足", token.conn.RemoteEndPoint));
                return(rsmm);
            }

            //获取是否在匹配队列中
            int matchid = CacheProxy.Match.IsInMatchLine(user.Id);

            if (matchid > 0)
            {
                rsmm.Status = -2;
                DebugUtil.Instance.Log2Time(string.Format("{0} 请求链接匹配失败,当前已在队列中", token.conn.RemoteEndPoint));
                return(rsmm);
            }
            rsmm.Status = 0;
            CacheProxy.Match.AddMatch(uid, type, ref rsmm);
            DebugUtil.Instance.Log2Time(string.Format("{0} 匹配成功", token.conn.RemoteEndPoint));
            return(rsmm);
        }