Commit 21ce6360 authored by nanahira's avatar nanahira

fix

parent 391e5fb6
Pipeline #43334 passed with stages
in 1 minute
...@@ -41,6 +41,10 @@ export class HidePlayerNameProvider { ...@@ -41,6 +41,10 @@ export class HidePlayerNameProvider {
return `Player ${client.pos + 1}`; return `Player ${client.pos + 1}`;
} }
getHidPlayerNameFactory(client: Pick<Client, 'pos' | 'name' | 'roomName'>) {
return (sightPlayer?: Client) => this.getHidPlayerName(client, sightPlayer);
}
async init() { async init() {
if (!this.enabled) { if (!this.enabled) {
return; return;
......
...@@ -98,7 +98,6 @@ export class RandomDuelProvider { ...@@ -98,7 +98,6 @@ export class RandomDuelProvider {
private roomManager = this.ctx.get(() => RoomManager); private roomManager = this.ctx.get(() => RoomManager);
private waitForPlayerProvider = this.ctx.get(() => WaitForPlayerProvider); private waitForPlayerProvider = this.ctx.get(() => WaitForPlayerProvider);
private clientKeyProvider = this.ctx.get(() => ClientKeyProvider); private clientKeyProvider = this.ctx.get(() => ClientKeyProvider);
private hidePlayerNameProvider = this.ctx.get(() => HidePlayerNameProvider);
private defaultHostInfoProvider = this.ctx.get(() => DefaultHostInfoProvider); private defaultHostInfoProvider = this.ctx.get(() => DefaultHostInfoProvider);
private hidePlayerName = this.ctx.get(() => HidePlayerNameProvider); private hidePlayerName = this.ctx.get(() => HidePlayerNameProvider);
...@@ -259,7 +258,7 @@ export class RandomDuelProvider { ...@@ -259,7 +258,7 @@ export class RandomDuelProvider {
} }
const room = await this.roomManager.findOrCreateByName(roomName); const room = await this.roomManager.findOrCreateByName(roomName);
room.randomType = randomType; room.randomType = randomType;
room.hidePlayerNames = this.hidePlayerNameProvider.enabled; room.hidePlayerNames = this.hidePlayerName.enabled;
room.randomDuelDeprecated = joinState.deprecated; room.randomDuelDeprecated = joinState.deprecated;
room.checkChatBadword = true; room.checkChatBadword = true;
room.noHost = true; room.noHost = true;
...@@ -751,48 +750,55 @@ export class RandomDuelProvider { ...@@ -751,48 +750,55 @@ export class RandomDuelProvider {
const clientScoreText = await this.getScoreDisplay( const clientScoreText = await this.getScoreDisplay(
this.getClientKey(client), this.getClientKey(client),
this.hidePlayerName.getHidPlayerName(client, client),
); );
const nameFactory = this.hidePlayerName.getHidPlayerNameFactory(client);
for (const player of players) { for (const player of players) {
if (clientScoreText) { if (clientScoreText) {
await player.sendChat(clientScoreText, ChatColor.GREEN); await player.sendChat(
clientScoreText(nameFactory(player)),
ChatColor.GREEN,
);
} }
if (player === client) { if (player === client) {
continue; continue;
} }
const playerScoreText = await this.getScoreDisplay( const playerScoreText = await this.getScoreDisplay(
this.getClientKey(player), this.getClientKey(player),
this.hidePlayerName.getHidPlayerName(player, client),
); );
if (playerScoreText) { if (playerScoreText) {
await client.sendChat(playerScoreText, ChatColor.GREEN); await client.sendChat(
playerScoreText(this.hidePlayerName.getHidPlayerName(player, client)),
ChatColor.GREEN,
);
} }
} }
} }
private async getScoreDisplay(name: string, displayName: string) { private async getScoreDisplay(name: string) {
const repo = this.ctx.database?.getRepository(RandomDuelScore); const repo = this.ctx.database?.getRepository(RandomDuelScore);
if (!repo || !name) { if (!repo || !name) {
return ''; return undefined;
} }
const score = await repo.findOneBy({ name }); const score = await repo.findOneBy({ name });
if (!score) { return (displayName: string) => {
return `${displayName} #{random_score_blank}`; if (!score) {
} return `${displayName} #{random_score_blank}`;
}
const total = score.winCount + score.loseCount; const total = score.winCount + score.loseCount;
if (score.winCount < 2 && total < 3) { if (score.winCount < 2 && total < 3) {
return `${displayName} #{random_score_not_enough}`; return `${displayName} #{random_score_not_enough}`;
} }
const safeTotal = total > 0 ? total : 1; const safeTotal = total > 0 ? total : 1;
const winRate = Math.ceil((score.winCount / safeTotal) * 100); const winRate = Math.ceil((score.winCount / safeTotal) * 100);
const fleeRate = Math.ceil((score.fleeCount / safeTotal) * 100); const fleeRate = Math.ceil((score.fleeCount / safeTotal) * 100);
if (score.winCombo >= 2) { if (score.winCombo >= 2) {
return `#{random_score_part1}${displayName} #{random_score_part2} ${winRate}#{random_score_part3} ${fleeRate}#{random_score_part4_combo}${score.winCombo}#{random_score_part5_combo}`; return `#{random_score_part1}${displayName} #{random_score_part2} ${winRate}#{random_score_part3} ${fleeRate}#{random_score_part4_combo}${score.winCombo}#{random_score_part5_combo}`;
} }
return `#{random_score_part1}${displayName} #{random_score_part2} ${winRate}#{random_score_part3} ${fleeRate}#{random_score_part4}`; return `#{random_score_part1}${displayName} #{random_score_part2} ${winRate}#{random_score_part3} ${fleeRate}#{random_score_part4}`;
};
} }
private get recordMatchScoresEnabled() { private get recordMatchScoresEnabled() {
......
...@@ -328,6 +328,8 @@ export class Reconnect { ...@@ -328,6 +328,8 @@ export class Reconnect {
} }
} }
private hidePlayerName = this.ctx.get(() => HidePlayerNameProvider);
private async sendPreReconnectInfo( private async sendPreReconnectInfo(
client: Client, client: Client,
room: Room, room: Room,
...@@ -361,7 +363,7 @@ export class Reconnect { ...@@ -361,7 +363,7 @@ export class Reconnect {
if (player) { if (player) {
await client.send( await client.send(
new YGOProStocHsPlayerEnter().fromPartial({ new YGOProStocHsPlayerEnter().fromPartial({
name: player.name, name: this.hidePlayerNameProvider.getHidPlayerName(player, client),
pos: player.pos, pos: player.pos,
}), }),
); );
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment