Search in sources :

Example 6 with TournamentPlayer

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

the class TournamentController method checkToReplaceDraftPlayerByAi.

private boolean checkToReplaceDraftPlayerByAi(UUID userId, TournamentPlayer leavingPlayer) {
    int humans = 0;
    for (TournamentPlayer tPlayer : tournament.getPlayers()) {
        if (tPlayer.getPlayer().isHuman()) {
            humans++;
        }
    }
    // replace player that quits with draft bot
    if (humans > 1) {
        Optional<User> user = managerFactory.userManager().getUser(userId);
        managerFactory.tableManager().getController(tableId).ifPresent(tableController -> {
            String replacePlayerName = "Draftbot";
            if (user.isPresent()) {
                replacePlayerName = "Draftbot (" + user.get().getName() + ')';
            }
            tableController.replaceDraftPlayer(leavingPlayer.getPlayer(), replacePlayerName, PlayerType.COMPUTER_DRAFT_BOT, 5);
            if (user.isPresent()) {
                user.get().removeDraft(leavingPlayer.getPlayer().getId());
                user.get().removeTable(leavingPlayer.getPlayer().getId());
                user.get().removeTournament(leavingPlayer.getPlayer().getId());
            }
            managerFactory.chatManager().broadcast(chatId, "", leavingPlayer.getPlayer().getLogName() + " was replaced by draftbot", MessageColor.BLACK, true, null, MessageType.STATUS, null);
        });
        return true;
    }
    return false;
}
Also used : User(mage.server.User) TournamentPlayer(mage.game.tournament.TournamentPlayer)

Example 7 with TournamentPlayer

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

the class TournamentController method startMultiplayerMatch.

private void startMultiplayerMatch(MultiplayerRound round, MatchOptions matchOptions) {
    try {
        TableManager tableManager = managerFactory.tableManager();
        Table table = tableManager.createTable(managerFactory.gamesRoomManager().getMainRoomId(), matchOptions);
        table.setTournamentSubTable(true);
        table.setTournament(tournament);
        table.setState(TableState.WAITING);
        if (round.getAllPlayers().stream().allMatch(tournamentPlayer -> getPlayerUserId(tournamentPlayer.getPlayer().getId()).isPresent())) {
            for (TournamentPlayer player : round.getAllPlayers()) {
                tableManager.addPlayer(getPlayerUserId(player.getPlayer().getId()).get(), table.getId(), player);
            }
            table.setState(TableState.STARTING);
            tableManager.startTournamentSubMatch(null, table.getId());
            tableManager.getMatch(table.getId()).ifPresent(match -> {
                match.setTableId(tableId);
                round.setMatch(match);
                round.setTableId(table.getId());
                for (TournamentPlayer player : round.getAllPlayers()) {
                    player.setState(TournamentPlayerState.DUELING);
                }
            });
        }
    } catch (GameException ex) {
        logger.fatal("TournamentController startMatch error", ex);
    }
}
Also used : Table(mage.game.Table) TournamentPlayer(mage.game.tournament.TournamentPlayer) TableManager(mage.server.managers.TableManager) GameException(mage.game.GameException)

Example 8 with TournamentPlayer

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

the class TournamentController method join.

public synchronized void join(UUID userId) {
    UUID playerId = userPlayerMap.get(userId);
    if (playerId == null) {
        if (logger.isDebugEnabled()) {
            managerFactory.userManager().getUser(userId).ifPresent(user -> logger.debug(user.getName() + " shows tournament panel  tournamentId: " + tournament.getId()));
        }
        return;
    }
    if (tournamentSessions.containsKey(playerId)) {
        logger.debug("player reopened tournament panel userId: " + userId + " tournamentId: " + tournament.getId());
        return;
    }
    // first join of player
    TournamentSession tournamentSession = new TournamentSession(managerFactory, tournament, userId, tableId, playerId);
    tournamentSessions.put(playerId, tournamentSession);
    Optional<User> _user = managerFactory.userManager().getUser(userId);
    if (_user.isPresent()) {
        User user = _user.get();
        user.addTournament(playerId, tournament.getId());
        TournamentPlayer player = tournament.getPlayer(playerId);
        player.setJoined();
        logger.debug("player " + player.getPlayer().getName() + " - client has joined tournament " + tournament.getId());
        managerFactory.chatManager().broadcast(chatId, "", player.getPlayer().getLogName() + " has joined the tournament", MessageColor.BLACK, true, null, MessageType.STATUS, null);
        checkStart();
    } else {
        logger.error("User not found  userId: " + userId + "   tournamentId: " + tournament.getId());
    }
}
Also used : User(mage.server.User) TournamentPlayer(mage.game.tournament.TournamentPlayer) UUID(java.util.UUID)

Example 9 with TournamentPlayer

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

the class TournamentController method startMatch.

private void startMatch(TournamentPairing pair, MatchOptions matchOptions) {
    try {
        TableManager tableManager = managerFactory.tableManager();
        Table table = tableManager.createTable(managerFactory.gamesRoomManager().getMainRoomId(), matchOptions);
        table.setTournamentSubTable(true);
        table.setTournament(tournament);
        table.setState(TableState.WAITING);
        TournamentPlayer player1 = pair.getPlayer1();
        TournamentPlayer player2 = pair.getPlayer2();
        UUID user1Uuid = null;
        UUID user2Uuid = null;
        if (player1.getPlayerType() == PlayerType.HUMAN) {
            Optional<UUID> user1Id = getPlayerUserId(player1.getPlayer().getId());
            if (!user1Id.isPresent()) {
                logger.fatal("Player 1 not found");
            } else {
                user1Uuid = user1Id.get();
            }
        }
        if (player2.getPlayerType() == PlayerType.HUMAN) {
            Optional<UUID> user2Id = getPlayerUserId(player2.getPlayer().getId());
            if (!user2Id.isPresent()) {
                logger.fatal("Player 2 not found");
            } else {
                user2Uuid = user2Id.get();
            }
        }
        tableManager.addPlayer(user1Uuid, table.getId(), player1);
        tableManager.addPlayer(user2Uuid, table.getId(), player2);
        table.setState(TableState.STARTING);
        tableManager.startTournamentSubMatch(null, table.getId());
        tableManager.getMatch(table.getId()).ifPresent(match -> {
            match.setTableId(tableId);
            pair.setMatch(match);
            pair.setTableId(table.getId());
            player1.setState(TournamentPlayerState.DUELING);
            player2.setState(TournamentPlayerState.DUELING);
        });
    } catch (GameException ex) {
        logger.fatal("TournamentController startMatch error", ex);
    }
}
Also used : Table(mage.game.Table) TournamentPlayer(mage.game.tournament.TournamentPlayer) TableManager(mage.server.managers.TableManager) UUID(java.util.UUID) GameException(mage.game.GameException)

Example 10 with TournamentPlayer

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

the class TournamentController method checkPlayersState.

private void checkPlayersState() {
    for (TournamentPlayer tournamentPlayer : tournament.getPlayers()) {
        if (!tournamentPlayer.isEliminated() && tournamentPlayer.getPlayer().isHuman()) {
            if (tournamentSessions.containsKey(tournamentPlayer.getPlayer().getId())) {
                if (tournamentSessions.get(tournamentPlayer.getPlayer().getId()).isKilled()) {
                    tournamentPlayer.setEliminated();
                    tournamentPlayer.setStateInfo("disconnected");
                }
            } else {
                tournamentPlayer.setEliminated();
                tournamentPlayer.setStateInfo("no tournament session");
            }
        }
    }
}
Also used : TournamentPlayer(mage.game.tournament.TournamentPlayer)

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