private void sideboard() { table.sideboard(); setupTimeout(Match.SIDEBOARD_TIME); if (table.isTournamentSubTable()) { for (MatchPlayer matchPlayer : match.getPlayers()) { if (!matchPlayer.hasQuit()) { TournamentPlayer tournamentPlayer = table.getTournament().getPlayer(matchPlayer.getPlayer().getId()); if (tournamentPlayer != null) { tournamentPlayer.setStateInfo("sideboarding"); } } } } match.sideboard(); cancelTimeout(); if (table.isTournamentSubTable()) { for (MatchPlayer matchPlayer : match.getPlayers()) { TournamentPlayer tournamentPlayer = table.getTournament().getPlayer(matchPlayer.getPlayer().getId()); if (tournamentPlayer != null && tournamentPlayer.getStateInfo().equals("sideboarding")) { tournamentPlayer.setStateInfo(""); } } } }
public synchronized void startMatch() { if (table.getState().equals(TableState.STARTING)) { try { if (table.isTournamentSubTable()) { logger.info( "Tourn. match started id:" + match.getId() + " tournId: " + table.getTournament().getId()); } else { User user = UserManager.getInstance().getUser(userId); logger.info( "MATCH started [" + match.getName() + "] " + match.getId() + "(" + user.getName() + ")"); logger.debug( "- " + match.getOptions().getGameType() + " - " + match.getOptions().getDeckType()); } match.startMatch(); startGame(null); } catch (GameException ex) { logger.fatal("Error starting match ", ex); match.endGame(); } } }
void cleanUp() { if (!table.isTournamentSubTable()) { for (Map.Entry<UUID, UUID> entry : userPlayerMap.entrySet()) { User user = UserManager.getInstance().getUser(entry.getKey()); if (user != null) { user.removeTable(entry.getValue()); } } } ChatManager.getInstance().destroyChatSession(chatId); }
private void matchEnd() { if (match != null) { for (Entry<UUID, UUID> entry : userPlayerMap.entrySet()) { MatchPlayer matchPlayer = match.getPlayer(entry.getValue()); // opponent(s) left during sideboarding if (matchPlayer != null) { if (!matchPlayer.hasQuit()) { User user = UserManager.getInstance().getUser(entry.getKey()); if (user != null) { if (table.getState().equals(TableState.SIDEBOARDING)) { StringBuilder sb = new StringBuilder(); if (table.isTournamentSubTable()) { sb.append("Your tournament match of round "); sb.append(table.getTournament().getRounds().size()); sb.append(" is over. "); } else { sb.append("Match [").append(match.getName()).append("] is over. "); } if (match.getPlayers().size() > 2) { sb.append("All your opponents have lost or quit the match."); } else { sb.append("Your opponent has quit the match."); } user.showUserMessage("Match info", sb.toString()); } // remove table from user - table manager holds table for display of finished matches if (!table.isTournamentSubTable()) { user.removeTable(entry.getValue()); } } } } } // free resources no longer needed match.cleanUpOnMatchEnd( ConfigSettings.getInstance().isSaveGameActivated(), table.isTournament()); } }
public boolean watchTable(UUID userId) { if (table.isTournament()) { UserManager.getInstance().getUser(userId).ccShowTournament(table.getTournament().getId()); return true; } else { if (table.isTournamentSubTable() && !table.getTournament().getOptions().isWatchingAllowed()) { return false; } if (table.getState() != TableState.DUELING) { return false; } // you can't watch your own game if (userPlayerMap.get(userId) != null) { return false; } return UserManager.getInstance().getUser(userId).ccWatchGame(match.getGame().getId()); } }
public synchronized boolean submitDeck(UUID userId, DeckCardLists deckList) throws MageException { UUID playerId = userPlayerMap.get(userId); if (table.isTournament()) { TournamentPlayer player = tournament.getPlayer(playerId); if (player == null || player.hasQuit()) { return true; // so the construct panel closes after submit } } else if (table.getMatch() != null) { MatchPlayer mPlayer = table.getMatch().getPlayer(playerId); if (mPlayer == null || mPlayer.hasQuit()) { return true; // so the construct panel closes after submit } if (table.isTournamentSubTable()) { TournamentPlayer tournamentPlayer = table.getTournament().getPlayer(mPlayer.getPlayer().getId()); if (tournamentPlayer != null) { tournamentPlayer.setStateInfo(""); // reset sideboarding state } } } if (table.getState() != TableState.SIDEBOARDING && table.getState() != TableState.CONSTRUCTING) { return false; } Deck deck = Deck.load(deckList, false, false); if (table.getState() == TableState.SIDEBOARDING && table.getMatch() != null) { MatchPlayer mPlayer = table.getMatch().getPlayer(playerId); if (mPlayer != null) { deck.setName(mPlayer.getDeck().getName()); } } if (!Main.isTestMode() && !table.getValidator().validate(deck)) { throw new InvalidDeckException( "Invalid deck for this format", table.getValidator().getInvalid()); } submitDeck(userId, playerId, deck); return true; }
public synchronized void leaveTable(UUID userId) { if (table == null) { logger.error("No table object - userId: " + userId); return; } if (table.isTournament() && tournament == null) { logger.error("No tournament object - userId: " + userId + " table: " + table.getId()); return; } if (table != null && this.userId != null && this.userId.equals(userId) // tourn. sub tables have no creator user && (table.getState().equals(TableState.WAITING) || table.getState().equals(TableState.READY_TO_START))) { // table not started yet and user is the owner, remove the table TableManager.getInstance().removeTable(table.getId()); } else { UUID playerId = userPlayerMap.get(userId); if (playerId != null) { if (table.getState() == TableState.WAITING || table.getState() == TableState.READY_TO_START) { table.leaveNotStartedTable(playerId); if (table.isTournament()) { tournament.removePlayer(playerId); } else { match.quitMatch(playerId); } User user = UserManager.getInstance().getUser(userId); if (user != null) { ChatManager.getInstance() .broadcast( chatId, user.getName(), "has left the table", ChatMessage.MessageColor.BLUE, true, ChatMessage.MessageType.STATUS, ChatMessage.SoundToPlay.PlayerLeft); if (!table.isTournamentSubTable()) { user.removeTable(playerId); } } else { logger.debug("User not found - userId: " + userId + " tableId:" + table.getId()); } userPlayerMap.remove(userId); } else if (!table.getState().equals(TableState.FINISHED)) { if (table.isTournament()) { logger.debug("Quit tournament sub tables for userId: " + userId); TableManager.getInstance().userQuitTournamentSubTables(tournament.getId(), userId); logger.debug( "Quit tournament Id: " + table.getTournament().getId() + "(" + table.getTournament().getTournamentState() + ")"); TournamentManager.getInstance().quit(tournament.getId(), userId); } else { MatchPlayer matchPlayer = match.getPlayer(playerId); if (matchPlayer != null && !match.hasEnded() && !matchPlayer.hasQuit()) { Game game = match.getGame(); if (game != null && !game.hasEnded()) { Player player = match.getPlayer(playerId).getPlayer(); if (player != null && player.isInGame()) { GameManager.getInstance().quitMatch(game.getId(), userId); } match.quitMatch(playerId); } else { if (table.getState().equals(TableState.SIDEBOARDING)) { if (!matchPlayer.isDoneSideboarding()) { // submit deck to finish sideboarding and trigger match start / end matchPlayer.submitDeck(matchPlayer.getDeck()); } } match.quitMatch(playerId); } } } } } else { logger.error("No playerId found for userId: " + userId); } } }
public synchronized boolean joinTable( UUID userId, String name, String playerType, int skill, DeckCardLists deckList, String password) throws MageException { User user = UserManager.getInstance().getUser(userId); if (user == null) { return false; } if (userPlayerMap.containsKey(userId) && playerType.equals("Human")) { user.showUserMessage( "Join Table", new StringBuilder("You can join a table only one time.").toString()); return false; } if (table.getState() != TableState.WAITING) { user.showUserMessage("Join Table", "No available seats."); return false; } // check password if (!table.getMatch().getOptions().getPassword().isEmpty() && playerType.equals("Human")) { if (!table.getMatch().getOptions().getPassword().equals(password)) { user.showUserMessage("Join Table", "Wrong password."); return false; } } Seat seat = table.getNextAvailableSeat(playerType); if (seat == null) { user.showUserMessage("Join Table", "No available seats."); return false; } Deck deck = Deck.load(deckList, false, false); if (!Main.isTestMode() && !table.getValidator().validate(deck)) { StringBuilder sb = new StringBuilder("You (") .append(name) .append(") have an invalid deck for the selected ") .append(table.getValidator().getName()) .append(" Format. \n\n"); for (Map.Entry<String, String> entry : table.getValidator().getInvalid().entrySet()) { sb.append(entry.getKey()).append(": ").append(entry.getValue()).append("\n"); } sb.append("\n\nSelect a deck that is appropriate for the selected format and try again!"); user.showUserMessage("Join Table", sb.toString()); if (isOwner(userId)) { logger.debug( "New table removed because owner submitted invalid deck tableId " + table.getId()); TableManager.getInstance().removeTable(table.getId()); } return false; } // Check quit ratio. int quitRatio = table.getMatch().getOptions().getQuitRatio(); if (quitRatio < user.getMatchQuitRatio()) { String message = new StringBuilder("Your quit ratio ") .append(user.getMatchQuitRatio()) .append("% is higher than the table requirement ") .append(quitRatio) .append("%") .toString(); user.showUserMessage("Join Table", message); return false; } // Check power level for table (currently only used for EDH/Commander table) int edhPowerLevel = table.getMatch().getOptions().getEdhPowerLevel(); if (edhPowerLevel > 0 && table.getValidator().getName().toLowerCase().equals("commander")) { int deckEdhPowerLevel = table.getValidator().getEdhPowerLevel(deck); if (deckEdhPowerLevel > edhPowerLevel) { String message = new StringBuilder( "Your deck appears to be too powerful for this table.\n\nReduce the number of extra turn cards, infect, counters, fogs, reconsider your commander. ") .append("\nThe table requirement has a maximum power level of ") .append(edhPowerLevel) .append(" whilst your deck has a calculated power level of ") .append(deckEdhPowerLevel) .toString(); user.showUserMessage("Join Table", message); return false; } } Player player = createPlayer(name, seat.getPlayerType(), skill); if (player == null) { String message = new StringBuilder("Could not create player ") .append(name) .append(" of type ") .append(seat.getPlayerType()) .toString(); logger.warn( new StringBuilder("User: "******" => ") .append(message) .toString()); user.showUserMessage("Join Table", message); return false; } logger.debug( "DECK validated: " + table.getValidator().getName() + " " + player.getName() + " " + deck.getName()); if (!player.canJoinTable(table)) { user.showUserMessage( "Join Table", new StringBuilder("A ") .append(seat.getPlayerType()) .append(" player can't join this table.") .toString()); return false; } match.addPlayer(player, deck); table.joinTable(player, seat); logger.trace(player.getName() + " joined tableId: " + table.getId()); // only inform human players and add them to sessionPlayerMap if (seat.getPlayer().isHuman()) { seat.getPlayer().setUserData(user.getUserData()); if (!table.isTournamentSubTable()) { user.addTable(player.getId(), table); } user.ccJoinedTable(table.getRoomId(), table.getId(), false); userPlayerMap.put(userId, player.getId()); } return true; }