feat(game): Implement return to lobby functionality and enhance dog life handling

This commit is contained in:
2025-11-19 19:18:41 +01:00
parent e2a5cb9614
commit b260e18223
8 changed files with 143 additions and 45 deletions

View File

@@ -88,12 +88,7 @@ class GameLobby private(
if (event.oldState == MainMenu && event.newState == Lobby) {
return
}
if (event.oldState == Lobby && event.newState == InGame) {
addToQueue(ReloadEvent)
return
} else {
addToQueue(ReloadEvent)
}
addToQueue(ReloadEvent)
users.values.foreach(session => session.updatePlayer(event))
case event: SessionClosed =>
users.values.foreach(session => session.updatePlayer(event))
@@ -198,7 +193,7 @@ class GameLobby private(
throw new CantPlayCardException("You are not in dog life!")
}
if (cardIndex == -1) {
if (!MatchUtil.dogNeedsToPlay(getMatch, getRound)) {
if (MatchUtil.dogNeedsToPlay(getMatch, getRound)) {
throw new CantPlayCardException("You can't skip this round!")
}
logic.playerInputLogic.receivedDog(None)
@@ -233,6 +228,19 @@ class GameLobby private(
logic.playerTieLogic.receivedTieBreakerCard(tieNumber)
}
def returnToLobby(userSession: UserSession): Unit = {
if (users.contains(userSession.id)) {
throw new NotInThisGameException("You are not in this game!")
}
val session = users(userSession.id)
if (session != userSession) {
throw new IllegalArgumentException("User session does not match!")
}
if (!session.host)
throw new NotHostException("Only the host can return to the lobby!")
logic.createSession()
}
//-------------------