@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); }
additonalText.append("You run out of time. "); } else { additonalText.append(matchPlayer.getName()).append(" runs out of time. "); additonalText.append("You lost the match for being idle. "); } else { additonalText.append(matchPlayer.getName()).append(" lost for being idle. "); additonalText.append("You have quit the match. "); } else { additonalText.append(matchPlayer.getName()).append(" has quit the match. "); matchInfo = "You won the match!"; } else { matchInfo = new StringBuilder(matchWinner.getName()).append(" won the match!").toString();
StringBuilder sb2 = new StringBuilder(); for (MatchPlayer matchPlayer: match.getPlayers()) { sb1.append(matchPlayer.getName()); if(matchPlayer.hasQuit()) { if (matchPlayer.getPlayer().hasTimerTimeout()) { sb2.append(matchPlayer.getName()).append(" ["); sb2.append(matchPlayer.getWins()).append('-'); if (match.getDraws() > 0) {
Optional<User> user = UserManager.instance.getUser(userPlayerEntry.getKey()); if (!user.isPresent() || !user.get().isActive()) { logger.warn("- Active user of match is missing: " + matchPlayer.getName()); logger.warn("-- matchId:" + match.getId()); logger.warn("-- userId:" + userPlayerEntry.getKey());
@Override public void sideboard() { for (MatchPlayer player : this.players) { if (!player.hasQuit()) { if (player.getDeck() != null) { player.setSideboarding(); player.getPlayer().sideboard(this, player.getDeck()); } else { logger.error("Player " + player.getName() + " has no deck: " + player.getPlayer().getId()); } } } synchronized (this) { while (!isDoneSideboarding()) { try { this.wait(); } catch (InterruptedException ex) { } } } }
opponent.append(" - "); opponent.append(mPlayer.getName());
@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()); }
@Override public MatchProto toProto() { MatchProto.Builder builder = MatchProto.newBuilder() .setName(this.getName()) .setGameType(this.getOptions().getGameType()) .setDeckType(this.getOptions().getDeckType()) .setGames(this.getNumGames()) .setDraws(this.getDraws()) .setMatchOptions(this.getOptions().toProto()) .setEndTimeMs((this.getEndTime() != null ? this.getEndTime() : new Date()).getTime()); for (MatchPlayer matchPlayer : this.getPlayers()) { MatchQuitStatus status = !matchPlayer.hasQuit() ? MatchQuitStatus.NO_MATCH_QUIT : matchPlayer.getPlayer().hasTimerTimeout() ? MatchQuitStatus.TIMER_TIMEOUT : matchPlayer.getPlayer().hasIdleTimeout() ? MatchQuitStatus.IDLE_TIMEOUT : MatchQuitStatus.QUIT; builder.addPlayersBuilder() .setName(matchPlayer.getName()) .setHuman(matchPlayer.getPlayer().isHuman()) .setQuit(status) .setWins(matchPlayer.getWins()); } return builder.build(); }