Search in sources :

Example 1 with TableManager

use of mage.server.managers.TableManager 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 2 with TableManager

use of mage.server.managers.TableManager 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)

Aggregations

GameException (mage.game.GameException)2 Table (mage.game.Table)2 TournamentPlayer (mage.game.tournament.TournamentPlayer)2 TableManager (mage.server.managers.TableManager)2 UUID (java.util.UUID)1