Search in sources :

Example 1 with TournamentPlayer

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

the class RandomBoosterDraftSwissTournament method draft.

@Override
protected void draft() {
    draft = new RandomBoosterDraft((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 : RandomBoosterDraft(mage.game.draft.RandomBoosterDraft) TournamentPlayer(mage.game.tournament.TournamentPlayer) DraftOptions(mage.game.draft.DraftOptions)

Example 2 with TournamentPlayer

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

the class RichManDraftEliminationTournament method draft.

protected void draft() {
    draft = new RichManBoosterDraft((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 : TournamentPlayer(mage.game.tournament.TournamentPlayer) RichManBoosterDraft(mage.game.draft.RichManBoosterDraft) DraftOptions(mage.game.draft.DraftOptions)

Example 3 with TournamentPlayer

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

the class TableController method joinTournament.

public synchronized boolean joinTournament(UUID userId, String name, PlayerType playerType, int skill, DeckCardLists deckList, String password) throws GameException {
    if (table.getState() != TableState.WAITING) {
        return false;
    }
    Seat seat = table.getNextAvailableSeat(playerType);
    if (seat == null) {
        throw new GameException("No available seats.");
    }
    Optional<User> _user = managerFactory.userManager().getUser(userId);
    if (!_user.isPresent()) {
        logger.fatal("couldn't get user " + name + " for join tournament userId = " + userId);
        return false;
    }
    User user = _user.get();
    // check password
    if (!table.getTournament().getOptions().getPassword().isEmpty() && playerType == PlayerType.HUMAN) {
        if (!table.getTournament().getOptions().getPassword().equals(password)) {
            user.showUserMessage("Join Table", "Wrong password.");
            return false;
        }
    }
    if (userPlayerMap.containsKey(userId) && playerType == PlayerType.HUMAN) {
        user.showUserMessage("Join Table", "You can join a table only one time.");
        return false;
    }
    Deck deck = null;
    if (!table.getTournament().getTournamentType().isLimited()) {
        if (deckList != null) {
            deck = Deck.load(deckList, false, false);
        } else {
            user.showUserMessage("Join Table", "No valid deck selected!");
            return 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");
            List<DeckValidatorError> errorsList = table.getValidator().getErrorsListSorted();
            errorsList.stream().forEach(error -> {
                sb.append(error.getGroup()).append(": ").append(error.getMessage()).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());
                managerFactory.tableManager().removeTable(table.getId());
            }
            return false;
        }
    }
    // Check quit ratio.
    int quitRatio = table.getTournament().getOptions().getQuitRatio();
    if (quitRatio < user.getTourneyQuitRatio()) {
        String message = new StringBuilder("Your quit ratio ").append(user.getTourneyQuitRatio()).append("% is higher than the table requirement ").append(quitRatio).append('%').toString();
        user.showUserMessage("Join Table", message);
        return false;
    }
    // Check minimum rating.
    int minimumRating = table.getTournament().getOptions().getMinimumRating();
    int userRating;
    if (table.getTournament().getOptions().getMatchOptions().isLimited()) {
        userRating = user.getUserData().getLimitedRating();
    } else {
        userRating = user.getUserData().getConstructedRating();
    }
    if (userRating < minimumRating) {
        String message = new StringBuilder("Your rating ").append(userRating).append(" is lower than the table requirement ").append(minimumRating).toString();
        user.showUserMessage("Join Table", message);
        return false;
    }
    Optional<Player> playerOptional = createPlayer(name, seat.getPlayerType(), skill);
    if (playerOptional.isPresent()) {
        Player player = playerOptional.get();
        if (!player.canJoinTable(table)) {
            user.showUserMessage("Join Table", new StringBuilder("A ").append(seat.getPlayerType()).append(" player can't join this table.").toString());
            return false;
        }
        tournament.addPlayer(player, seat.getPlayerType());
        TournamentPlayer tournamentPlayer = tournament.getPlayer(player.getId());
        if (deck != null && tournamentPlayer != null) {
            tournamentPlayer.submitDeck(deck);
        }
        table.joinTable(player, seat);
        logger.debug("Player " + player.getName() + " id: " + player.getId() + " joined tableId: " + table.getId());
        // only inform human players and add them to sessionPlayerMap
        if (seat.getPlayer().isHuman()) {
            seat.getPlayer().setUserData(user.getUserData());
            user.addTable(player.getId(), table);
            user.ccJoinedTable(table.getRoomId(), table.getId(), true);
            userPlayerMap.put(userId, player.getId());
        }
        return true;
    } else {
        throw new GameException("Playertype " + seat.getPlayerType() + " could not be created.");
    }
}
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) Deck(mage.cards.decks.Deck) DeckValidatorError(mage.cards.decks.DeckValidatorError)

Example 4 with TournamentPlayer

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

the class TableController method sideboard.

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("");
            }
        }
    }
}
Also used : TournamentPlayer(mage.game.tournament.TournamentPlayer) MatchPlayer(mage.game.match.MatchPlayer)

Example 5 with TournamentPlayer

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

the class TournamentController method init.

private void init() {
    tournament.addTableEventListener((Listener<TableEvent>) event -> {
        switch(event.getEventType()) {
            case CHECK_STATE_PLAYERS:
                checkPlayersState();
                break;
            case INFO:
                managerFactory.chatManager().broadcast(chatId, "", event.getMessage(), MessageColor.BLACK, true, null, MessageType.STATUS, null);
                logger.debug(tournament.getId() + " " + event.getMessage());
                break;
            case START_DRAFT:
                startDraft(event.getDraft());
                break;
            case CONSTRUCT:
                if (!isAbort()) {
                    construct();
                } else {
                    endTournament();
                }
                break;
            case START_MATCH:
                if (!isAbort()) {
                    initTournament();
                    startMatch(event.getPair(), event.getMatchOptions());
                }
                break;
            case START_MULTIPLAYER_MATCH:
                if (!isAbort()) {
                    initTournament();
                    MatchOptions matchOptions = event.getMatchOptions();
                    if (matchOptions != null && event.getMultiplayerRound() != null) {
                        for (TournamentPlayer player : event.getMultiplayerRound().getAllPlayers()) {
                            matchOptions.getPlayerTypes().add(player.getPlayerType());
                        }
                    }
                    startMultiplayerMatch(event.getMultiplayerRound(), event.getMatchOptions());
                }
                break;
            case END:
                endTournament();
                break;
        }
    });
    tournament.addPlayerQueryEventListener((Listener<PlayerQueryEvent>) event -> {
        try {
            switch(event.getQueryType()) {
                case CONSTRUCT:
                    construct(event.getPlayerId(), event.getMax());
                    break;
            }
        } catch (MageException ex) {
            logger.fatal("Player event listener error", ex);
        }
    });
    for (TournamentPlayer player : tournament.getPlayers()) {
        if (!player.getPlayer().isHuman()) {
            player.setJoined();
            logger.debug("player " + player.getPlayer().getId() + " has joined tournament " + tournament.getId());
            managerFactory.chatManager().broadcast(chatId, "", player.getPlayer().getLogName() + " has joined the tournament", MessageColor.BLACK, true, null, MessageType.STATUS, null);
        }
    }
    checkStart();
}
Also used : MultiplayerRound(mage.game.tournament.MultiplayerRound) MessageType(mage.view.ChatMessage.MessageType) DraftController(mage.server.draft.DraftController) MessageColor(mage.view.ChatMessage.MessageColor) TableEvent(mage.game.events.TableEvent) ConcurrentMap(java.util.concurrent.ConcurrentMap) Logger(org.apache.log4j.Logger) TableManager(mage.server.managers.TableManager) MatchOptions(mage.game.match.MatchOptions) User(mage.server.User) Draft(mage.game.draft.Draft) TournamentPairing(mage.game.tournament.TournamentPairing) TourneyQuitStatus(mage.game.result.ResultProtos.TourneyQuitStatus) TournamentView(mage.view.TournamentView) TableState(mage.constants.TableState) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) Deck(mage.cards.decks.Deck) UUID(java.util.UUID) MageException(mage.MageException) PlayerType(mage.players.PlayerType) SoundToPlay(mage.view.ChatMessage.SoundToPlay) PlayerQueryEvent(mage.game.events.PlayerQueryEvent) ManagerFactory(mage.server.managers.ManagerFactory) TournamentPlayer(mage.game.tournament.TournamentPlayer) Entry(java.util.Map.Entry) Table(mage.game.Table) Optional(java.util.Optional) TournamentPlayerState(mage.constants.TournamentPlayerState) Listener(mage.game.events.Listener) GameException(mage.game.GameException) Tournament(mage.game.tournament.Tournament) TableEvent(mage.game.events.TableEvent) TournamentPlayer(mage.game.tournament.TournamentPlayer) MageException(mage.MageException) MatchOptions(mage.game.match.MatchOptions) PlayerQueryEvent(mage.game.events.PlayerQueryEvent)

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