From 8f3f270dd734b9cef366954c76db4e74abc84405 Mon Sep 17 00:00:00 2001 From: sunwoong Date: Wed, 31 Jul 2024 00:24:00 +0900 Subject: [PATCH] =?UTF-8?q?DRAW-197=20fix:=20=EB=A7=88=ED=94=BC=EC=95=84?= =?UTF-8?q?=20Vote=20->=20InferAnswer=20=EB=A1=9C=EC=A7=81=20=EC=98=A4?= =?UTF-8?q?=EB=A5=98=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../response/MafiaPhaseMessengerImpl.kt | 24 +++++++++---------- .../phase/MafiaPhasePlayGameProcessor.kt | 3 ++- .../phase/MafiaPhasePlayVoteProcessor.kt | 1 + .../draw/mafia/phase/MafiaPhaseService.kt | 3 ++- .../com/xorker/draw/mafia/MafiaGameOption.kt | 4 ++-- .../com/xorker/draw/mafia/MafiaPhase.kt | 11 +++++++++ 6 files changed, 30 insertions(+), 16 deletions(-) diff --git a/app/websocket/src/main/kotlin/com/xorker/draw/websocket/message/response/MafiaPhaseMessengerImpl.kt b/app/websocket/src/main/kotlin/com/xorker/draw/websocket/message/response/MafiaPhaseMessengerImpl.kt index 762d7a07..6065a6a5 100644 --- a/app/websocket/src/main/kotlin/com/xorker/draw/websocket/message/response/MafiaPhaseMessengerImpl.kt +++ b/app/websocket/src/main/kotlin/com/xorker/draw/websocket/message/response/MafiaPhaseMessengerImpl.kt @@ -11,18 +11,18 @@ import com.xorker.draw.websocket.SessionMessage import com.xorker.draw.websocket.broker.WebSocketBroadcaster import com.xorker.draw.websocket.message.response.dto.MafiaGameInfoBody import com.xorker.draw.websocket.message.response.dto.MafiaGameInfoMessage -import com.xorker.draw.websocket.message.response.dto.MafiaPhaseEndBody -import com.xorker.draw.websocket.message.response.dto.MafiaPhaseEndMessage -import com.xorker.draw.websocket.message.response.dto.MafiaPhaseInferAnswerBody -import com.xorker.draw.websocket.message.response.dto.MafiaPhaseInferAnswerMessage -import com.xorker.draw.websocket.message.response.dto.MafiaPhasePlayingBody -import com.xorker.draw.websocket.message.response.dto.MafiaPhasePlayingMessage -import com.xorker.draw.websocket.message.response.dto.MafiaPhaseReadyBody -import com.xorker.draw.websocket.message.response.dto.MafiaPhaseReadyMessage -import com.xorker.draw.websocket.message.response.dto.MafiaPhaseVoteBody -import com.xorker.draw.websocket.message.response.dto.MafiaPhaseVoteMessage -import com.xorker.draw.websocket.message.response.dto.MafiaPhaseWaitBody -import com.xorker.draw.websocket.message.response.dto.MafiaPhaseWaitMessage +import com.xorker.draw.websocket.message.response.dto.phase.MafiaPhaseEndBody +import com.xorker.draw.websocket.message.response.dto.phase.MafiaPhaseEndMessage +import com.xorker.draw.websocket.message.response.dto.phase.MafiaPhaseInferAnswerBody +import com.xorker.draw.websocket.message.response.dto.phase.MafiaPhaseInferAnswerMessage +import com.xorker.draw.websocket.message.response.dto.phase.MafiaPhasePlayingBody +import com.xorker.draw.websocket.message.response.dto.phase.MafiaPhasePlayingMessage +import com.xorker.draw.websocket.message.response.dto.phase.MafiaPhaseReadyBody +import com.xorker.draw.websocket.message.response.dto.phase.MafiaPhaseReadyMessage +import com.xorker.draw.websocket.message.response.dto.phase.MafiaPhaseVoteBody +import com.xorker.draw.websocket.message.response.dto.phase.MafiaPhaseVoteMessage +import com.xorker.draw.websocket.message.response.dto.phase.MafiaPhaseWaitBody +import com.xorker.draw.websocket.message.response.dto.phase.MafiaPhaseWaitMessage import com.xorker.draw.websocket.message.response.dto.toResponse import java.time.LocalDateTime import org.springframework.stereotype.Component diff --git a/core/src/main/kotlin/com/xorker/draw/mafia/phase/MafiaPhasePlayGameProcessor.kt b/core/src/main/kotlin/com/xorker/draw/mafia/phase/MafiaPhasePlayGameProcessor.kt index 8ca590e0..3b4472af 100644 --- a/core/src/main/kotlin/com/xorker/draw/mafia/phase/MafiaPhasePlayGameProcessor.kt +++ b/core/src/main/kotlin/com/xorker/draw/mafia/phase/MafiaPhasePlayGameProcessor.kt @@ -37,7 +37,8 @@ internal class MafiaPhasePlayGameProcessor( val gameOption = gameInfo.gameOption - val nextTurn = phase.nextTurn(gameOption.round, gameOption.turnCount) + val room = gameInfo.room + val nextTurn = phase.nextTurn(gameOption.round - 1, room.size() - 1) if (nextTurn == null) { nextStep.invoke() diff --git a/core/src/main/kotlin/com/xorker/draw/mafia/phase/MafiaPhasePlayVoteProcessor.kt b/core/src/main/kotlin/com/xorker/draw/mafia/phase/MafiaPhasePlayVoteProcessor.kt index e05298de..2ecf4c00 100644 --- a/core/src/main/kotlin/com/xorker/draw/mafia/phase/MafiaPhasePlayVoteProcessor.kt +++ b/core/src/main/kotlin/com/xorker/draw/mafia/phase/MafiaPhasePlayVoteProcessor.kt @@ -43,6 +43,7 @@ internal class MafiaPhasePlayVoteProcessor( if (candidate.first == mafiaPlayer.userId) { winStep.invoke() + return } } loseStep.invoke() diff --git a/core/src/main/kotlin/com/xorker/draw/mafia/phase/MafiaPhaseService.kt b/core/src/main/kotlin/com/xorker/draw/mafia/phase/MafiaPhaseService.kt index ad9d97f4..ce94bbfb 100644 --- a/core/src/main/kotlin/com/xorker/draw/mafia/phase/MafiaPhaseService.kt +++ b/core/src/main/kotlin/com/xorker/draw/mafia/phase/MafiaPhaseService.kt @@ -5,6 +5,7 @@ import com.xorker.draw.mafia.MafiaGameInfo import com.xorker.draw.mafia.MafiaGameRepository import com.xorker.draw.mafia.MafiaPhase import com.xorker.draw.mafia.MafiaPhaseMessenger +import com.xorker.draw.mafia.assert import com.xorker.draw.mafia.assertIs import com.xorker.draw.room.RoomId import org.springframework.stereotype.Service @@ -94,7 +95,7 @@ internal class MafiaPhaseService( val phase = synchronized(gameInfo) { val votePhase = gameInfo.phase - assertIs(votePhase) + assert(votePhase) mafiaPhaseEndGameProcessor.endGame(gameInfo) } diff --git a/domain/src/main/kotlin/com/xorker/draw/mafia/MafiaGameOption.kt b/domain/src/main/kotlin/com/xorker/draw/mafia/MafiaGameOption.kt index 34632422..02a54a7b 100644 --- a/domain/src/main/kotlin/com/xorker/draw/mafia/MafiaGameOption.kt +++ b/domain/src/main/kotlin/com/xorker/draw/mafia/MafiaGameOption.kt @@ -10,6 +10,6 @@ data class MafiaGameOption( val round: Int = 2, // 전체 라운드 수 val turnTime: Duration = Duration.ofSeconds(5), // 턴 당 최대 시간 val turnCount: Int = 2, // 턴 당 최대 획 수 - val voteTime: Duration = Duration.ofMinutes(10), // 투표 시간 - val answerTime: Duration = Duration.ofMinutes(10), // 정답 입력 시간 + val voteTime: Duration = Duration.ofSeconds(10), // 투표 시간 + val answerTime: Duration = Duration.ofSeconds(10), // 정답 입력 시간 ) diff --git a/domain/src/main/kotlin/com/xorker/draw/mafia/MafiaPhase.kt b/domain/src/main/kotlin/com/xorker/draw/mafia/MafiaPhase.kt index 8283e1bc..efd13178 100644 --- a/domain/src/main/kotlin/com/xorker/draw/mafia/MafiaPhase.kt +++ b/domain/src/main/kotlin/com/xorker/draw/mafia/MafiaPhase.kt @@ -147,3 +147,14 @@ inline fun assertIs(phase: MafiaPhase) { throw InvalidMafiaPhaseException("유효하지 않는 Phase 입니다. 기대값: ${T::class}, 요청값: $phase") } } + +@OptIn(ExperimentalContracts::class) +inline fun assert(phase: MafiaPhase) { + contract { + returns() implies (phase is T1 || phase is T2) + } + + if (phase !is T1 && phase !is T2) { + throw InvalidMafiaPhaseException("유효하지 않는 Phase 입니다. 기대값: ${T1::class} or ${T2::class}, 요청값: $phase") + } +}