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);