* @return
* @throws java.lang.Exception
*/
public GameState getGameState(Integer id) throws Exception {
GameState gameState = new GameState();
FixedTimeChallengeGame game = (FixedTimeChallengeGame) FixedTimeChallengeGame.find
.where().eq("id", id).findUnique();
//save new virtual current date if no gotten
if (game.getVirtualStartDate() != null) {
game.setVirtualCurrentDate(TimeKeeper.convert(game));
game.save();
}
User player = UserManager.getCurrentLoggedInUser();
// set the game state
List<GamePlayer> gamePlayers = game.getPlayers();
gameState.setPlayers(gamePlayers);
gameState.setNumOfDays(game.getGameLength());
gameState.setCurrentDay(game.getVirtualCurrentDate() == null ? 0 : GameUtil.getCurrentDay(game));
if (gameState.getCurrentDay() > gameState.getNumOfDays()) {
game.setGameStatus(enums.GameStatusEnum.END.toString());
game.save();
}
gameState.setGame(game);
GamePlayer currentGamePlayer = game.getPlayerInGame(player);
gameState.setCurrentPlayer(currentGamePlayer);
if (currentGamePlayer != null) {
gameState.setMyPortfolio(currentGamePlayer.getPortfolios());
}
gameState.setGameOwner(game.getPlayerInGame(game.getOwner()));
return gameState;
}