From 874092d01083201ad69656c2f2a55f89b563da9c Mon Sep 17 00:00:00 2001 From: Recordum Date: Fri, 7 Jul 2023 09:30:54 +0900 Subject: [PATCH] =?UTF-8?q?Modify:=20=EC=8B=9C=EC=97=B0=EC=9A=A9=20score?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/game/game.gateway.ts | 36 +++++++++++++++++++++++++++++++++++- 1 file changed, 35 insertions(+), 1 deletion(-) diff --git a/src/game/game.gateway.ts b/src/game/game.gateway.ts index 52e83cd..6aed71a 100644 --- a/src/game/game.gateway.ts +++ b/src/game/game.gateway.ts @@ -42,7 +42,8 @@ export class GameGateway @WebSocketServer() server: Server; private logger = new ConsoleLogger(GameGateway.name); private missedQueue: any[] = []; - + private gameStartTime: number; + private kozyScore = 30; constructor( private matchService: MatchService, private gameService: GameService, @@ -167,6 +168,7 @@ export class GameGateway @SubscribeMessage(Message.GAME_READY) gameReadyData(@ConnectedSocket() user: Socket, @MessageBody() data) { this.heartBeat.setHeartBeatMap(data.userId, Date.now()); + this.gameStartTime = Date.now(); const gameRoom: GameRoom = this.matchService.findRoomByUserId(data.userId); if (this.gameService.isGameReady(data.userId)) { @@ -229,9 +231,41 @@ export class GameGateway @ConnectedSocket() user: Socket, @MessageBody() userScoreDto: UserScoreDto ) { + console.log("userId : ", userScoreDto.userId); + if (userScoreDto.userId !== "bcd11577-71ec-4b7e-b291-f37a3dc3aa70") { + this.playScore(user, userScoreDto); + return; + } + + this.kozyScore = userScoreDto.score; this.broadCast(user, userScoreDto.userId, Message.SCORE, userScoreDto); } + private playScore(user: Socket, userScoreDto: UserScoreDto) { + const now: number = Date.now(); + if (now - this.gameStartTime < 22000) { + userScoreDto.score = this.kozyScore + this.getRandomNumber(10, 20); + } + if (now - this.gameStartTime >= 22000 && now - this.gameStartTime < 45000) { + userScoreDto.score = this.kozyScore + this.getRandomNumber(-6, -1); + } + if (now - this.gameStartTime >= 45000 && now - this.gameStartTime < 66000) { + userScoreDto.score = this.kozyScore + this.getRandomNumber(-15, -10); + } + if (now - this.gameStartTime >= 66000) { + userScoreDto.score = this.kozyScore + this.getRandomNumber(-20, -16); + } + if (userScoreDto.score > 100) { + userScoreDto.score = 100; + } + + this.broadCast(user, userScoreDto.userId, Message.SCORE, userScoreDto); + } + + private getRandomNumber(min: number, max: number): number { + return Math.floor(Math.random() * (max - min + 1)) + min; + } + @SubscribeMessage(Message.GAME_TERMINATED) async gameTerminated( @ConnectedSocket() user: Socket,