Ejemplo n.º 1
0
        /// <summary>
        /// 角色进入匹配房间后 需要获取到房间内所有人的信息
        /// </summary>
        /// <param name="uid"></param>
        /// <returns></returns>
        public MatchRoom Enter(int uid , ClientPeer clientPeer)
        {
            //先搜寻是否有等待中的房间
            foreach(MatchRoom room in ridModleDic.Values)
            {
                if (room.IsFull())
                {
                    continue;
                }
                //如果此房间不满
                room.Enter(uid , clientPeer);//角色进入房间
                uidRoomidDic.Add(uid, room.ID);//加入等待用户与房间ID的映射
                return room;
            }

            //如果没有等待中的房间则自己创建房间
            MatchRoom mr = null;
            createRoom(out mr);
            mr.Enter(uid , clientPeer);
            uidRoomidDic.Add(uid, mr.ID);

            return mr;
        }
Ejemplo n.º 2
0
        /// <summary>
        /// 进入匹配队列 进入匹配房间
        /// </summary>
        /// <param name="userId"></param>
        /// <returns></returns>
        public MatchRoom Enter(int userId, ClientPeer client)
        {
            int roomId;

            //遍历一下等待的房间 看一下有没有正在等待的 如果有 我们就把这玩家加进去
            foreach (MatchRoom mr in idModelDict.Values)
            {
                //房间满了 继续
                if (mr.IsFull())
                {
                    continue;
                }
                //没满的话
                mr.Enter(userId, client);
                uidRoomIdDict.Add(userId, mr.Id);
                return(mr);
            }
            //如果调用到这里 代表没进去 ,因为没有等待的房间了
            //自己开个房
            MatchRoom room = null;

            //判断一下是否有重用的房间
            if (roomQueue.Count > 0)
            {
                room = roomQueue.Dequeue();
                room.Enter(userId, client);
                idModelDict.Add(room.Id, room);
                uidRoomIdDict.Add(userId, room.Id);
                //1.给房间添加计时    2.计时到时前10秒的警告
                timer.AddTimeEvent(500000000,
                                   delegate
                {
                    room.Brocast(OpCode.MATCH, MatchCode.MESSAGE_BRO, null);
                });
                timer.AddTimeEvent(600000000,
                                   delegate
                {
                    if (room == null)
                    {
                        return;
                    }
                    room.Brocast(OpCode.MATCH, MatchCode.BACK_BRO, null);
                    Destroy(room);
                }
                                   );
            }
            else
            {
                room   = new MatchRoom(id.Add_Get());
                roomId = room.Id;
                room.Enter(userId, client);
                idModelDict.Add(room.Id, room);
                uidRoomIdDict.Add(userId, room.Id);
                //1.给房间添加计时    2.计时到时前10秒的警告
                timer.AddTimeEvent(500000000,
                                   delegate
                {
                    room.Brocast(OpCode.MATCH, MatchCode.MESSAGE_BRO, null);
                });
                timer.AddTimeEvent(600000000,
                                   delegate
                {
                    if (room == null)
                    {
                        return;
                    }
                    room.Brocast(OpCode.MATCH, MatchCode.BACK_BRO, null);
                    Destroy(room);
                }
                                   );
            }

            return(room);
        }