private void OnRoomFull(MatchRoom room) { BattleUserInfo roomInfo = room.GetBattleUserInfo(); for (int i = 0; i < room.numUsers; ++i) { MatchRoomUser user = room.GetUserAt(i); room.RemoveUser(user); } this._rooms.Remove(room); MatchRoomPool.Push(room); this.eventHandler(MatchEvent.Type.MatchSuccess, null, roomInfo); }
public void CheckRoom() { //检查每个房间是否有可合并的玩家 for (int i = 0; i < this._rooms.Count - 1; i++) { MatchRoom cur = this._rooms[i]; for (int j = i + 1; j < this._rooms.Count; j++) { MatchRoom nxt = this._rooms[j]; //先检查两个房间是否有重叠的分数区域 //按from的大小排序 MatchRoom r0, r1; if (cur.from < nxt.from) { r0 = cur; r1 = nxt; } else { r0 = nxt; r1 = cur; } //判断重叠,注意to是闭区间 if (r0.to <= r1.@from) { continue; } //重叠 //搜索房间玩家,符合范围的会被抢到当前房间 for (int k = 0; k < nxt.numUsers; ++k) { MatchRoomUser user = nxt.GetUserAt(k); if (user == null) { continue; } //检查玩家分数是否在范围内 if (user.rank >= cur.@from && user.rank < cur.to) { System.Diagnostics.Debug.Assert(nxt.RemoveUser(user)); System.Diagnostics.Debug.Assert(cur.AddUser(user)); this.eventHandler(MatchEvent.Type.RoomInfo, null, cur.GetBattleUserInfo()); if (nxt.isEmpty || cur.isFull) { break; } } } if (nxt.isEmpty) { this._rooms.RemoveAt(j); MatchRoomPool.Push(nxt); --j; } //如果满员则不用继续往下搜索了 if (cur.isFull) { this.OnRoomFull(cur); --i; break; } } } }