增加插队机制

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 { interface MatchmakingGroup {
averageRank: number; averageRank: number;
clients: ClientStat[], clients: ClientStat[];
priority?: boolean; priority?: boolean;
ready?: boolean; ready?: boolean;
@ -20,6 +20,7 @@ interface ClientStat {
group?: MatchmakingGroup; group?: MatchmakingGroup;
rank: number; rank: number;
confirmed?: boolean; confirmed?: boolean;
priority?: boolean;
} }
export class RankedLobbyRoom extends Room { export class RankedLobbyRoom extends Room {
@ -96,6 +97,10 @@ export class RankedLobbyRoom extends Room {
client.leave(); 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 * Redistribute clients into groups at every interval
@ -231,6 +236,12 @@ export class RankedLobbyRoom extends Room {
if (stat.group && stat.group.ready) { if (stat.group && stat.group.ready) {
continue; 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 * Force this client to join a group, even if rank is incompatible
@ -241,7 +252,6 @@ export class RankedLobbyRoom extends Room {
// ) { // ) {
// currentGroup.priority = true; // currentGroup.priority = true;
// } // }
if ( if (
currentGroup.averageRank > 0 && currentGroup.averageRank > 0 &&
!currentGroup.priority !currentGroup.priority
@ -319,7 +329,7 @@ export class RankedLobbyRoom extends Room {
score: avaScore, score: avaScore,
count: this.numClientsToMatch - group.count count: this.numClientsToMatch - group.count
}); });
// TODO: 预处理数据, 确定座次 // 预处理数据, 确定座次
let hasGroup = false; let hasGroup = false;
for (let client of group.clients) { for (let client of group.clients) {
if (client.clients.size > 1) { if (client.clients.size > 1) {