Exemplo n.º 1
0
        /// <summary>
        /// 添加玩家 没有空位时检查游戏开始
        /// </summary>
        /// <param name="gamer"></param>
        public static void Add(this Moba5V5Room self, Gamer gamer)
        {
            int seatIndex = self.GetEmptySeat();

            //玩家需要获取一个座位坐下
            if (seatIndex >= 0)
            {
                self.gamers[seatIndex]   = gamer;
                self.isReadys[seatIndex] = false;
                self.seats[gamer.UserID] = seatIndex;
            }
            else
            {
                Log.Error("房间已满无法加入");
            }

            //房间满员时 通知客户端加载场景
            if (self.GetEmptySeat() == -1)
            {
                //为房间添加游戏组件
                if (self.GetComponent <MobaControllerComponent>() == null)
                {
                    self.AddComponent <MobaControllerComponent>().RoomReady();
                }
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// 检查匹配状态 每当有新排队玩家加入时执行一次
        /// </summary>
        /// <param name="self"></param>
        public static void MatchingCheck(this Moba5V5Component self)
        {
            //如果有空房间 且 正在排队的玩家>0
            Moba5V5Room room = self.GetFreeRoom();

            if (room != null)
            {
                while (self.MatchingQueue.Count > 0 && room.Count < self.StartNumber)
                {
                    self.JoinRoom(room, self.MatchingQueue.Dequeue());
                }
            } //else 如果没有空房间 且 正在排队的玩家>=开局人数
            else if (self.MatchingQueue.Count >= self.StartNumber)
            {
                //创建新房间
                room = ComponentFactory.Create <Moba5V5Room>();
                room.AddComponent <MailBoxComponent>();
                self.FreeRooms.Add(room.Id, room);

                while (self.MatchingQueue.Count > 0 && room.Count < self.StartNumber)
                {
                    self.JoinRoom(room, self.MatchingQueue.Dequeue());
                }
            }
        }