@Override public GameInfo createGameInfo(Game game) { StringBuilder playersInfo = new StringBuilder(); int counter = 0; for (MatchPlayer matchPlayer : getPlayers()) { if (counter > 0) { playersInfo.append(" - "); } playersInfo.append(matchPlayer.getName()); counter++; } String state; String result; String duelingTime = ""; if (game.hasEnded()) { if (game.getEndTime() != null) { duelingTime = " (" + DateFormat.getDuration((game.getEndTime().getTime() - game.getStartTime().getTime()) / 1000) + ')'; } state = "Finished" + duelingTime; result = game.getWinner(); } else { if (game.getStartTime() != null) { duelingTime = " (" + DateFormat.getDuration((new Date().getTime() - game.getStartTime().getTime()) / 1000) + ')'; } state = "Dueling" + duelingTime; result = ""; } return new GameInfo(0, this.getId(), game.getId(), state, result, playersInfo.toString(), tableId); }
@Override public boolean hasEnded() { // Some workarounds to end match if for unknown reason the match was not ended regularly if (getGame() == null && isDoneSideboarding()) { checkIfMatchEnds(); } if (getGame() != null && getGame().hasEnded()) { for (MatchPlayer matchPlayer : players) { if (matchPlayer.getPlayer().hasQuit() && !matchPlayer.hasQuit()) { logger.warn("MatchPlayer was not set to quit matchId " + this.getId() + " - " + matchPlayer.getName()); matchPlayer.setQuit(true); } } checkIfMatchEnds(); } return endTime != null; }
protected void initGame(Game game) throws GameException { addGame(); // raises only the number shufflePlayers(); for (MatchPlayer matchPlayer : this.players) { if (!matchPlayer.hasQuit() && matchPlayer.getDeck() != null) { matchPlayer.getPlayer().init(game); game.loadCards(matchPlayer.getDeck().getCards(), matchPlayer.getPlayer().getId()); game.loadCards(matchPlayer.getDeck().getSideboard(), matchPlayer.getPlayer().getId()); game.addPlayer(matchPlayer.getPlayer(), matchPlayer.getDeck()); // set the priority time left for the match if (games.isEmpty()) { // first game full time matchPlayer.getPlayer().setPriorityTimeLeft(options.getPriorityTime()); } else { if (matchPlayer.getPriorityTimeLeft() > 0) { matchPlayer.getPlayer().setPriorityTimeLeft(matchPlayer.getPriorityTimeLeft()); } } } else { if (matchPlayer.getDeck() == null) { logger.error("Match: " + this.getId() + " " + matchPlayer.getName() + " has no deck."); } } } game.setPriorityTime(options.getPriorityTime()); }