From 9b40c5c9c3df609d7c9c6ba6658ab769f49600eb Mon Sep 17 00:00:00 2001 From: jiyun Date: Thu, 28 Dec 2023 16:19:42 +0900 Subject: [PATCH] =?UTF-8?q?fix:=20=EB=94=94=EC=8A=A4=EC=BB=A4=EB=84=A5?= =?UTF-8?q?=ED=8A=B8=EB=8A=94=20=EC=84=9C=EB=B2=84=EA=B0=80=20=EB=8B=A4=20?= =?UTF-8?q?=ED=95=9C=EB=8B=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../dto/emit-event-match-end-param.dto.ts | 2 ++ src/game/dto/game.dto.ts | 19 ++++++++++++------- src/game/game.gateway.ts | 6 ++++++ 3 files changed, 20 insertions(+), 7 deletions(-) diff --git a/src/game/dto/emit-event-match-end-param.dto.ts b/src/game/dto/emit-event-match-end-param.dto.ts index 4d742e4..0f9930d 100644 --- a/src/game/dto/emit-event-match-end-param.dto.ts +++ b/src/game/dto/emit-event-match-end-param.dto.ts @@ -2,6 +2,8 @@ import { GameType } from '../../common/enum'; export class EmitEventMatchEndParamDto { gameType: GameType; + rivalName: string; + rivalAvatar: string; rivalScore: number | null; myScore: number | null; isWin: boolean | null; diff --git a/src/game/dto/game.dto.ts b/src/game/dto/game.dto.ts index a810e6a..aa53092 100644 --- a/src/game/dto/game.dto.ts +++ b/src/game/dto/game.dto.ts @@ -60,19 +60,24 @@ export class GameDto { async setResult() { if (this.gameType === GameType.NONE) { + this.scoreLeft = this.scoreRight = 0; this.winnerId = this.playerLeftId; - this.winnerScore = 0; + this.winnerScore = this.loserScore = 0; this.loserId = this.playerRightId; this.loserScore = 0; return; } if (this.loserId) { - this.loserScore = 0; - this.winnerScore = this.maxScore; - this.winnerId = - this.loserId === this.playerLeftId - ? this.playerRightId - : this.playerLeftId; + const isLoserLeft = this.loserId === this.playerLeftId; + if (isLoserLeft) { + this.scoreLeft = this.loserScore = 0; + this.scoreRight = this.winnerScore = this.maxScore; + this.winnerId = this.playerRightId; + } else { + this.scoreRight = this.loserScore = 0; + this.scoreLeft = this.winnerScore = this.maxScore; + this.winnerId = this.playerLeftId; + } } else { if (this.scoreLeft === this.maxScore) { this.winnerScore = this.scoreLeft; diff --git a/src/game/game.gateway.ts b/src/game/game.gateway.ts index f45859e..f0d4442 100644 --- a/src/game/game.gateway.ts +++ b/src/game/game.gateway.ts @@ -716,6 +716,8 @@ export class GameGateway implements OnGatewayConnection, OnGatewayDisconnect { ) { const leftMatchEndParamDtos: EmitEventMatchEndParamDto = { gameType: gameDto.gameType, + rivalName: right.nickname, + rivalAvatar: right.avatar, rivalScore: gameDto.scoreRight, myScore: gameDto.scoreLeft, isWin: gameDto.scoreLeft > gameDto.scoreRight, @@ -726,6 +728,8 @@ export class GameGateway implements OnGatewayConnection, OnGatewayDisconnect { }; const rightMatchEndParamDtos: EmitEventMatchEndParamDto = { gameType: gameDto.gameType, + rivalName: left.nickname, + rivalAvatar: left.avatar, rivalScore: gameDto.scoreLeft, myScore: gameDto.scoreRight, isWin: gameDto.scoreRight > gameDto.scoreLeft, @@ -739,6 +743,7 @@ export class GameGateway implements OnGatewayConnection, OnGatewayDisconnect { console.log( `${playerSockets.left.id}에 matchEnd 이벤트 보낸다 !!!`, ); + console.log(`내용은: ${JSON.stringify(leftMatchEndParamDtos)}`); this.server .to(playerSockets.left.id) .emit(EVENT_MATCH_END, leftMatchEndParamDtos); @@ -747,6 +752,7 @@ export class GameGateway implements OnGatewayConnection, OnGatewayDisconnect { console.log( `${playerSockets.right.id}에 matchEnd 이벤트 보낸다 !!!`, ); + console.log(`내용은: ${JSON.stringify(rightMatchEndParamDtos)}`); this.server .to(playerSockets.right.id) .emit(EVENT_MATCH_END, rightMatchEndParamDtos);