Search in sources :

Example 1 with TableView

use of mage.view.TableView in project mage by magefree.

the class GameChooser method createTestGame.

// GEN-LAST:event_btnNewTournamentActionPerformed
private void createTestGame(String gameName, String gameType, boolean useMonteCarloAI) {
    TableView table;
    try {
        String testDeckFile = "test.dck";
        File f = new File(testDeckFile);
        if (!f.exists()) {
            // default test deck
            testDeckFile = DeckUtil.writeTextToTempFile("" + "5 Swamp" + System.lineSeparator() + "5 Forest" + System.lineSeparator() + "5 Island" + System.lineSeparator() + "5 Mountain" + System.lineSeparator() + "5 Plains");
        }
        DeckCardLists testDeck = DeckImporter.importDeckFromFile(testDeckFile, false);
        PlayerType aiType = useMonteCarloAI ? PlayerType.COMPUTER_MONTE_CARLO : PlayerType.COMPUTER_MAD;
        MatchOptions options = new MatchOptions(gameName, gameType, false, 2);
        options.getPlayerTypes().add(PlayerType.HUMAN);
        options.getPlayerTypes().add(aiType);
        options.setDeckType("Limited");
        options.setAttackOption(MultiplayerAttackOption.LEFT);
        options.setRange(RangeOfInfluence.ALL);
        options.setWinsNeeded(1);
        options.setMatchTimeLimit(MatchTimeLimit.NONE);
        options.setFreeMulligans(2);
        options.setSkillLevel(SkillLevel.CASUAL);
        options.setRollbackTurnsAllowed(true);
        options.setQuitRatio(100);
        options.setMinimumRating(0);
        String serverAddress = SessionHandler.getSession().getServerHostname().orElse("");
        options.setBannedUsers(IgnoreList.getIgnoredUsers(serverAddress));
        table = SessionHandler.createTable(roomId, options);
        SessionHandler.joinTable(roomId, table.getTableId(), "Human", PlayerType.HUMAN, 1, testDeck, "");
        SessionHandler.joinTable(roomId, table.getTableId(), "Computer", aiType, 5, testDeck, "");
        SessionHandler.startMatch(roomId, table.getTableId());
    } catch (HeadlessException ex) {
        handleError(ex);
    }
}
Also used : DeckCardLists(mage.cards.decks.DeckCardLists) PlayerType(mage.players.PlayerType) MatchOptions(mage.game.match.MatchOptions) File(java.io.File) TableView(mage.view.TableView)

Example 2 with TableView

use of mage.view.TableView in project mage by magefree.

the class UserNameSorter method createTable.

@Override
public TableView createTable(UUID userId, MatchOptions options) {
    Table table = managerFactory.tableManager().createTable(this.getRoomId(), userId, options);
    tables.put(table.getId(), table);
    return new TableView(table);
}
Also used : Table(mage.game.Table) TableView(mage.view.TableView)

Example 3 with TableView

use of mage.view.TableView in project mage by magefree.

the class UserNameSorter method update.

private void update() {
    List<Table> allTables = new ArrayList<>(tables.values());
    allTables.sort(new TableListSorter());
    List<MatchView> matchList = new ArrayList<>();
    List<TableView> tableList = new ArrayList<>();
    for (Table table : allTables) {
        if (table.getState() != TableState.FINISHED) {
            tableList.add(new TableView(table));
        } else if (matchList.size() < 50) {
            matchList.add(new MatchView(table));
        } else {
            // more since 50 matches finished since this match so removeUserFromAllTablesAndChat it
            if (table.isTournament()) {
                managerFactory.tournamentManager().removeTournament(table.getTournament().getId());
            }
            this.removeTable(table.getId());
        }
    }
    tableView = tableList;
    matchView = matchList;
    List<UsersView> users = new ArrayList<>();
    for (User user : managerFactory.userManager().getUsers()) {
        if (user.getUserState() != User.UserState.Offline && !user.getName().equals("Admin")) {
            try {
                users.add(new UsersView(user.getUserData().getFlagName(), user.getName(), user.getMatchHistory(), user.getMatchQuitRatio(), user.getTourneyHistory(), user.getTourneyQuitRatio(), user.getGameInfo(), user.getPingInfo(), user.getUserData().getGeneralRating(), user.getUserData().getConstructedRating(), user.getUserData().getLimitedRating()));
            } catch (Exception ex) {
                LOGGER.fatal("User update exception: " + user.getName() + " - " + ex.toString(), ex);
                users.add(new UsersView((user.getUserData() != null && user.getUserData().getFlagName() != null) ? user.getUserData().getFlagName() : "world", user.getName() != null ? user.getName() : "<no name>", user.getMatchHistory() != null ? user.getMatchHistory() : "<no match history>", user.getMatchQuitRatio(), user.getTourneyHistory() != null ? user.getTourneyHistory() : "<no tourney history>", user.getTourneyQuitRatio(), "[exception]", user.getPingInfo() != null ? user.getPingInfo() : "<no ping>", user.getUserData() != null ? user.getUserData().getGeneralRating() : 0, user.getUserData() != null ? user.getUserData().getConstructedRating() : 0, user.getUserData() != null ? user.getUserData().getLimitedRating() : 0));
            }
        }
    }
    users.sort((one, two) -> one.getUserName().compareToIgnoreCase(two.getUserName()));
    List<RoomUsersView> roomUserInfo = new ArrayList<>();
    roomUserInfo.add(new RoomUsersView(users, managerFactory.gameManager().getNumberActiveGames(), managerFactory.threadExecutor().getActiveThreads(managerFactory.threadExecutor().getGameExecutor()), managerFactory.configSettings().getMaxGameThreads()));
    roomUsersView = roomUserInfo;
}
Also used : Table(mage.game.Table) User(mage.server.User) MatchView(mage.view.MatchView) MageException(mage.MageException) GameException(mage.game.GameException) RoomUsersView(mage.view.RoomUsersView) UsersView(mage.view.UsersView) RoomUsersView(mage.view.RoomUsersView) TableView(mage.view.TableView)

Example 4 with TableView

use of mage.view.TableView in project mage by magefree.

the class UpdateSeatsTask method process.

@Override
protected void process(List<TableView> view) {
    TableView tableView = view.get(0);
    if (count == 0) {
        count = getPlayersCount(tableView);
    } else {
        int current = getPlayersCount(tableView);
        if (current != count) {
            if (count > 0) {
                if (current == tableView.getSeats().size()) {
                    MageTray.instance.displayMessage("The game can start.");
                    AudioManager.playGameCanStart();
                } else if (current > count) {
                    MageTray.instance.displayMessage("New player joined your game.");
                    AudioManager.playPlayerJoinedTable();
                } else {
                    MageTray.instance.displayMessage("A player left your game.");
                    AudioManager.playPlayerLeft();
                }
                MageTray.instance.blink();
            }
            count = current;
        }
    }
    dialog.update(tableView);
}
Also used : TableView(mage.view.TableView)

Example 5 with TableView

use of mage.view.TableView in project mage by magefree.

the class UserNameSorter method createTournamentTable.

@Override
public TableView createTournamentTable(UUID userId, TournamentOptions options) {
    Table table = managerFactory.tableManager().createTournamentTable(this.getRoomId(), userId, options);
    tables.put(table.getId(), table);
    return new TableView(table);
}
Also used : Table(mage.game.Table) TableView(mage.view.TableView)

Aggregations

TableView (mage.view.TableView)5 Table (mage.game.Table)3 File (java.io.File)1 MageException (mage.MageException)1 DeckCardLists (mage.cards.decks.DeckCardLists)1 GameException (mage.game.GameException)1 MatchOptions (mage.game.match.MatchOptions)1 PlayerType (mage.players.PlayerType)1 User (mage.server.User)1 MatchView (mage.view.MatchView)1 RoomUsersView (mage.view.RoomUsersView)1 UsersView (mage.view.UsersView)1