增加插队机制

This commit is contained in:
zhl 2021-01-19 11:08:17 +08:00
parent fc57e1da34
commit 9c49d2b2d3

View File

@ -3,7 +3,7 @@ import {BaseConst} from "../constants/BaseConst";
interface MatchmakingGroup {
averageRank: number;
clients: ClientStat[],
clients: ClientStat[];
priority?: boolean;
ready?: boolean;
@ -20,6 +20,7 @@ interface ClientStat {
group?: MatchmakingGroup;
rank: number;
confirmed?: boolean;
priority?: boolean;
}
export class RankedLobbyRoom extends Room {
@ -96,6 +97,10 @@ export class RankedLobbyRoom extends Room {
client.leave();
}
})
this.onMessage('gogogo', (client: Client, message: any) => {
const stat = this.stats.find(obj => obj.clients.has(client.sessionId));
stat.priority = true;
})
/**
* Redistribute clients into groups at every interval
@ -231,6 +236,12 @@ export class RankedLobbyRoom extends Room {
if (stat.group && stat.group.ready) {
continue;
}
if (currentGroup.count + stat.clients.size > this.maxClients) {
continue;
}
if (stat.priority) {
currentGroup.priority = true;
}
/**
* Force this client to join a group, even if rank is incompatible
@ -241,7 +252,6 @@ export class RankedLobbyRoom extends Room {
// ) {
// currentGroup.priority = true;
// }
if (
currentGroup.averageRank > 0 &&
!currentGroup.priority
@ -319,7 +329,7 @@ export class RankedLobbyRoom extends Room {
score: avaScore,
count: this.numClientsToMatch - group.count
});
// TODO: 预处理数据, 确定座次
// 预处理数据, 确定座次
let hasGroup = false;
for (let client of group.clients) {
if (client.clients.size > 1) {