Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DRAW-220 Draw 데이터 비정상적으로 나오는 케이스 수정 #66

Merged
merged 2 commits into from
Aug 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -83,10 +83,7 @@ internal class MafiaGameRoomService(
}

private fun generateColor(gameInfo: MafiaGameInfo?): String {
if (gameInfo == null) return COLOR_LIST.first()

val alreadyUsedColors =
gameInfo.room.players.map { it.color }.toList()
val alreadyUsedColors = gameInfo?.room?.players?.map { it.color }?.toList() ?: emptyList()

return COLOR_LIST
.filterNot { alreadyUsedColors.contains(it) }
Expand Down
29 changes: 21 additions & 8 deletions domain/src/main/kotlin/com/xorker/draw/mafia/MafiaPhase.kt
Original file line number Diff line number Diff line change
Expand Up @@ -59,19 +59,32 @@ sealed class MafiaPhase {
}

fun getDraw(): List<Map<String, Any>> {
return if (drawData.isEmpty()) {
emptyList()
} else {
drawData.take(drawData.size - 1).map { it.second }
if (drawData.isEmpty()) {
return emptyList()
}

val currentUser = turnList[turnInfo.turn]

if (drawData.last().first == currentUser.userId) {
return drawData.take(drawData.size - 1).map { it.second }
}

return drawData.map { it.second }
}

fun getCurrentDraw(): Map<String, Any> {
return if (drawData.isEmpty()) {
emptyMap()
} else {
drawData.last().second
if (drawData.isEmpty()) {
return emptyMap()
}

val currentUser = turnList[turnInfo.turn]

val last = drawData.last()
if (last.first == currentUser.userId) {
return last.second
}

return emptyMap()
}
}

Expand Down
Loading