Search in sources :

Example 21 with TournamentPlayer

use of mage.game.tournament.TournamentPlayer in project mage by magefree.

the class BoosterDraftEliminationTournament method draft.

protected void draft() {
    draft = new BoosterDraft((DraftOptions) options.getLimitedOptions(), getSets());
    for (TournamentPlayer player : players.values()) {
        draft.addPlayer(player.getPlayer());
        player.setState(TournamentPlayerState.DRAFTING);
    }
    tableEventSource.fireTableEvent(EventType.START_DRAFT, null, draft);
}
Also used : BoosterDraft(mage.game.draft.BoosterDraft) TournamentPlayer(mage.game.tournament.TournamentPlayer) DraftOptions(mage.game.draft.DraftOptions)

Example 22 with TournamentPlayer

use of mage.game.tournament.TournamentPlayer in project mage by magefree.

the class TableController method replaceDraftPlayer.

public synchronized boolean replaceDraftPlayer(Player oldPlayer, String name, PlayerType playerType, int skill) {
    Optional<Player> newPlayerOpt = createPlayer(name, playerType, skill);
    if (!newPlayerOpt.isPresent() || table.getState() != TableState.DRAFTING) {
        return false;
    }
    Player newPlayer = newPlayerOpt.get();
    TournamentPlayer oldTournamentPlayer = tournament.getPlayer(oldPlayer.getId());
    tournament.removePlayer(oldPlayer.getId());
    tournament.addPlayer(newPlayer, playerType);
    TournamentPlayer newTournamentPlayer = tournament.getPlayer(newPlayer.getId());
    newTournamentPlayer.setState(oldTournamentPlayer.getState());
    newTournamentPlayer.setReplacedTournamentPlayer(oldTournamentPlayer);
    managerFactory.draftManager().getController(table.getId()).ifPresent(controller -> controller.replacePlayer(oldPlayer, newPlayer));
    return true;
}
Also used : MatchPlayer(mage.game.match.MatchPlayer) Player(mage.players.Player) DraftPlayer(mage.game.draft.DraftPlayer) TournamentPlayer(mage.game.tournament.TournamentPlayer) TournamentPlayer(mage.game.tournament.TournamentPlayer)

Example 23 with TournamentPlayer

use of mage.game.tournament.TournamentPlayer in project mage by magefree.

the class TableController method submitDeck.

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()) {
            // so the construct panel closes after submit
            return true;
        }
    } else if (table.getMatch() != null) {
        MatchPlayer mPlayer = table.getMatch().getPlayer(playerId);
        if (mPlayer == null || mPlayer.hasQuit()) {
            // so the construct panel closes after submit
            return true;
        }
        if (table.isTournamentSubTable()) {
            TournamentPlayer tournamentPlayer = table.getTournament().getPlayer(mPlayer.getPlayer().getId());
            if (tournamentPlayer != null) {
                // reset sideboarding state
                tournamentPlayer.setStateInfo("");
            }
        }
    }
    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)) {
        Optional<User> _user = managerFactory.userManager().getUser(userId);
        if (!_user.isPresent()) {
            return false;
        }
        StringBuilder sb = new StringBuilder("Invalid deck for the selected ").append(table.getValidator().getName()).append(" format. \n\n");
        List<DeckValidatorError> errorsList = table.getValidator().getErrorsListSorted();
        errorsList.stream().forEach(error -> {
            sb.append(error.getGroup()).append(": ").append(error.getMessage()).append("\n");
        });
        sb.append("\n\nAdd enough cards and try again!");
        _user.get().showUserMessage("Submit deck", sb.toString());
        return false;
    }
    submitDeck(userId, playerId, deck);
    return true;
}
Also used : DeckValidatorError(mage.cards.decks.DeckValidatorError) TournamentPlayer(mage.game.tournament.TournamentPlayer) MatchPlayer(mage.game.match.MatchPlayer) Deck(mage.cards.decks.Deck)

Example 24 with TournamentPlayer

use of mage.game.tournament.TournamentPlayer in project mage by magefree.

the class User method getGameInfo.

public String getGameInfo() {
    StringBuilder sb = new StringBuilder();
    int draft = 0, match = 0, sideboard = 0, tournament = 0, construct = 0, waiting = 0;
    for (Map.Entry<UUID, Table> tableEntry : tables.entrySet()) {
        if (tableEntry != null) {
            Table table = tableEntry.getValue();
            if (table != null) {
                if (table.isTournament()) {
                    if (tableEntry.getKey() != null) {
                        TournamentPlayer tournamentPlayer = table.getTournament().getPlayer(tableEntry.getKey());
                        if (tournamentPlayer != null) {
                            if (!tournamentPlayer.isEliminated()) {
                                switch(table.getState()) {
                                    case WAITING:
                                    case STARTING:
                                    case READY_TO_START:
                                        waiting++;
                                        break;
                                    case CONSTRUCTING:
                                        construct++;
                                        break;
                                    case DRAFTING:
                                        draft++;
                                        break;
                                    case DUELING:
                                        tournament++;
                                        break;
                                }
                                switch(getUserState()) {
                                    case Disconnected:
                                        tournamentPlayer.setDisconnectInfo(" (discon. " + getDisconnectDuration() + ')');
                                        break;
                                    case Offline:
                                        tournamentPlayer.setDisconnectInfo(" Offline");
                                        break;
                                    default:
                                        tournamentPlayer.setDisconnectInfo("");
                                }
                            }
                        } else {
                            // can happen if tournamet has just ended
                            logger.debug(userName + " tournament player missing - tableId:" + table.getId(), null);
                            tablesToDelete.add(tableEntry.getKey());
                        }
                    } else {
                        logger.error(userName + " tournament key missing - tableId: " + table.getId(), null);
                    }
                } else {
                    switch(table.getState()) {
                        case WAITING:
                        case STARTING:
                        case READY_TO_START:
                            waiting++;
                            break;
                        case SIDEBOARDING:
                            sideboard++;
                            break;
                        case DUELING:
                            match++;
                            break;
                    }
                }
            }
        }
    }
    if (!tablesToDelete.isEmpty()) {
        for (UUID keyId : tablesToDelete) {
            removeTable(keyId);
        }
        tablesToDelete.clear();
    }
    if (waiting > 0) {
        sb.append("Wait: ").append(waiting).append(' ');
    }
    if (match > 0) {
        sb.append("Match: ").append(match).append(' ');
    }
    if (sideboard > 0) {
        sb.append("Sideb: ").append(sideboard).append(' ');
    }
    if (draft > 0) {
        sb.append("Draft: ").append(draft).append(' ');
    }
    if (construct > 0) {
        sb.append("Const: ").append(construct).append(' ');
    }
    if (tournament > 0) {
        sb.append("Tourn: ").append(tournament).append(' ');
    }
    if (!watchedGames.isEmpty()) {
        sb.append("Watch: ").append(watchedGames.size()).append(' ');
    }
    return sb.toString();
}
Also used : Table(mage.game.Table) TournamentPlayer(mage.game.tournament.TournamentPlayer) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap)

Example 25 with TournamentPlayer

use of mage.game.tournament.TournamentPlayer in project mage by magefree.

the class TournamentController method isTournamentStillValid.

/**
 * Check tournaments that are not already finished, if they are in a still
 * valid state
 *
 * @param tableState state of the tournament table
 * @return true - if tournament is valid false - if tournament is not valid
 * and should be removed
 */
public boolean isTournamentStillValid(TableState tableState) {
    int activePlayers = 0;
    for (Entry<UUID, UUID> entry : userPlayerMap.entrySet()) {
        TournamentPlayer tournamentPlayer = tournament.getPlayer(entry.getValue());
        if (tournamentPlayer != null) {
            if (!tournamentPlayer.hasQuit()) {
                if (tournamentPlayer.getPlayer().isHuman()) {
                    Optional<User> user = managerFactory.userManager().getUser(entry.getKey());
                    if (!user.isPresent()) {
                        logger.debug("Tournament user is missing but player active -> start quit - tournamentId: " + tournament.getId() + " state: " + tableState.toString());
                        // active tournament player but the user is no longer online
                        quit(entry.getKey());
                    } else {
                        activePlayers++;
                    }
                }
            }
        } else {
            // tournament player is missing
            logger.debug("Tournament player is missing - tournamentId: " + tournament.getId() + " state: " + tableState.toString());
        }
    }
    for (TournamentPlayer tournamentPlayer : tournament.getPlayers()) {
        if (!tournamentPlayer.getPlayer().isHuman()) {
            if (!tournamentPlayer.hasQuit()) {
                activePlayers++;
            }
        }
    }
    if (activePlayers < 2 && tableState != TableState.WAITING) {
        logger.debug("Tournament has less than 2 active players - tournamentId: " + tournament.getId() + " state: " + tableState.toString());
        return false;
    }
    return true;
}
Also used : User(mage.server.User) TournamentPlayer(mage.game.tournament.TournamentPlayer) UUID(java.util.UUID)

Aggregations

TournamentPlayer (mage.game.tournament.TournamentPlayer)32 TournamentPairing (mage.game.tournament.TournamentPairing)10 ArrayList (java.util.ArrayList)7 DraftOptions (mage.game.draft.DraftOptions)6 Round (mage.game.tournament.Round)6 RoundPairings (mage.game.tournament.pairing.RoundPairings)6 SwissPairingMinimalWeightMatching (mage.game.tournament.pairing.SwissPairingMinimalWeightMatching)6 UUID (java.util.UUID)5 Table (mage.game.Table)5 User (mage.server.User)5 PlayerStub (org.mage.test.stub.PlayerStub)5 TournamentStub (org.mage.test.stub.TournamentStub)5 Deck (mage.cards.decks.Deck)4 GameException (mage.game.GameException)4 MatchPlayer (mage.game.match.MatchPlayer)4 Test (org.junit.Test)4 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)3 TableManager (mage.server.managers.TableManager)3 Entry (java.util.Map.Entry)2 Optional (java.util.Optional)2