Esempio n. 1
0
        public bool Create(CSUser user, int numTeams, int numPlayerPerTeam, out uint roomID)
        {
            roomID = 0;

            //是否已在房间
            if (this._userIDToBattleUser.ContainsKey(user.gcNID))
            {
                return(false);
            }

            var room = RoomPool.Pop(this);

            room.Setup(numTeams, numPlayerPerTeam);

            BattleUser battleUser = new BattleUser(user.gcNID);

            if (!room.AddUser(battleUser))
            {
                RoomPool.Push(room);
                return(false);
            }
            this._userIDToBattleUser[user.gcNID] = battleUser;
            this._userToRoom[user.gcNID]         = room;
            this._idToRoom[room.id] = room;
            this.CheckRoom(room);
            roomID = room.id;
            return(true);
        }
Esempio n. 2
0
        private void CheckRoom(Room room)
        {
            if (!room.isFull)
            {
                return;
            }
            var battleUserInfo = room.GetBattleUserInfo();

            while (room.currUserCount > 0)
            {
                var user = room.GetUserAt(room.currUserCount - 1);
                room.RemoveUserAt(room.currUserCount - 1);
                this._userIDToBattleUser.Remove(user.id);
                this._userToRoom.Remove(user.id);
            }
            this._idToRoom.Remove(room.id);
            RoomPool.Push(room);

            CS.instance.battleEntry.BeginBattle(battleUserInfo.users, battleUserInfo.tUsers);
        }
Esempio n. 3
0
 public bool Leave(CSUser user)
 {
     if (!this._userToRoom.TryGetValue(user.gcNID, out Room room))
     {
         return(false);
     }
     if (!this._userIDToBattleUser.TryGetValue(user.gcNID, out BattleUser battleUser))
     {
         return(false);
     }
     if (!room.RemoveUser(battleUser))
     {
         return(false);
     }
     this._userIDToBattleUser.Remove(user.gcNID);
     this._userToRoom.Remove(user.gcNID);
     if (room.isEmpty)
     {
         this._idToRoom.Remove(room.id);
         RoomPool.Push(room);
     }
     return(true);
 }