*
* @param gameId
* @return
*/
public boolean startGame(int gameId) {
Game game = Game.findById(gameId);
if (game == null) {
return false;
} else if (!game.getOwner().equals(UserManager.getCurrentLoggedInUser())) {
play.Logger.warn("attemt to start game not owned.");
return false;
} else {
DateTime dt = new DateTime();
//game length is in days
int randStartDaysAgo = (int) (Math.random() * ApplicationConstants.MAX_DAYS_BACK)
+ game.getGameLength()
+ ApplicationConstants.DAYS_PADDING_FROM_REALITY;
dt = dt.minusDays(randStartDaysAgo);
Timestamp temp = new Timestamp(dt.getMillis());// the start of game is one year ago
while (!TimeKeeper.isTradingDay(temp)) {
temp = new Timestamp(temp.getTime() + TimeKeeper.aDayInMS);
play.Logger.info("Skipping... " + temp);
}
game.setVirtualStartDate(temp);
game.setRealStartTime(new Timestamp(System.currentTimeMillis()));
game.setGameStatus(GameStatusEnum.STARTED.getValue());
game.save();
return true;
}
}