Esempio n. 1
0
        /// <summary>
        /// 创建战斗的房间
        /// </summary>
        /// <param name="team1"></param>
        /// <param name="team2"></param>
        public void CreateRoom(List <DtoSelect> team1, List <DtoSelect> team2)
        {
            BattleRoom room = null;

            if (RoomQue.Count <= 0)
            {
                room = new BattleRoom(Index++, team1.Count + team2.Count);
            }
            else
            {
                room = RoomQue.Dequeue();
            }

            // 初始化房间数据
            room.Init(team1, team2);
            // 添加映射
            foreach (DtoSelect item in team1)
            {
                PlayerRoomDict.Add(item.PlayerId, room.Id);
            }
            foreach (DtoSelect item in team2)
            {
                PlayerRoomDict.Add(item.PlayerId, room.Id);
            }
            RoomDict.Add(room.Id, room);
        }
Esempio n. 2
0
        /// <summary>
        /// 玩家进入匹配队列
        /// 这里只实现1v1的情况
        /// </summary>
        /// <param name="playerId"></param>
        /// <param name="peer"></param>
        /// <returns>房间</returns>
        public MatchRoom StartMatch(MobaPeer peer, int playerId)
        {
            // 存在等待的房间
            foreach (MatchRoom item in RoomDict.Values)
            {
                if (item.IsFull)
                {
                    continue;
                }

                item.EnterRoom(peer, playerId);
                // 绑定玩家和房间的映射
                PlayerRoomDict.Add(playerId, item.Id);
                return(item);
            }
            // 不存在等待的房间
            MatchRoom room = null;

            // 有可复用的房间
            if (RoomQue.Count > 0)
            {
                // 添加映射
                room = RoomQue.Dequeue();
                RoomDict.Add(room.Id, room);
                PlayerRoomDict.Add(playerId, room.Id);
                // 玩家进入房间
                room.EnterRoom(peer, playerId);
                return(room);
            }
            // 没有可复用的房间
            else
            {
                // 这里固定房间只进两个人
                room = new MatchRoom(Index, 2);
                Index++;
                // 添加映射
                RoomDict.Add(room.Id, room);
                PlayerRoomDict.Add(playerId, room.Id);
                // 玩家进入房间
                room.EnterRoom(peer, playerId);
                return(room);
            }
        }
Esempio n. 3
0
        /// <summary>
        /// 开始选人
        /// </summary>
        public void CreateRoom(List <int> team1, List <int> team2)
        {
            SelectRoom room;

            // 获取房间
            if (RoomQue.Count <= 0)
            {
                room = new SelectRoom(Index++, team1.Count + team2.Count);
            }
            else
            {
                room = RoomQue.Dequeue();
            }
            room.InitRoom(team1, team2);
            // 绑定玩家id和房间id
            foreach (int item in team1)
            {
                PlayerRoomDict.Add(item, room.Id);
            }
            foreach (int item in team2)
            {
                PlayerRoomDict.Add(item, room.Id);
            }
            // 绑定房间id和房间
            RoomDict.Add(room.Id, room);

            // 创建完成 开启定时任务 通知玩家在10s之内进入房间 否则 房间自动销毁
            room.StartSchedule(DateTime.UtcNow.AddSeconds(ServerConfig.SelectRoomTimeOff), () =>
            {
                if (!room.IsAllEnter)
                {
                    // 通知所有玩家房间被销毁了
                    room.Brocast(OperationCode.DestroySelect, null);
                    // 销毁房间
                    DestroyRoom(room.Id);
                }
            });
        }