Search in sources :

Example 1 with TournamentTypeView

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

the class NewTournamentDialog method updateNumSeats.

// GEN-LAST:event_btnCancelActionPerformed
private void updateNumSeats() {
    // int numPlayers = (Integer) this.spnNumPlayers.getValue();
    int numSeats = (Integer) this.spnNumSeats.getValue();
    if (numSeats > 2) {
        TournamentTypeView tournamentType = (TournamentTypeView) cbTournamentType.getSelectedItem();
        if (numSeats >= tournamentType.getMinPlayers()) {
            createPlayers(numSeats - 1);
            spnNumPlayers.setValue(numSeats);
        } else {
            numSeats = tournamentType.getMinPlayers();
            createPlayers(numSeats - 1);
            spnNumPlayers.setValue(numSeats);
            spnNumSeats.setValue(numSeats);
        }
        spnNumWins.setValue(1);
    }
}
Also used : TournamentTypeView(mage.view.TournamentTypeView)

Example 2 with TournamentTypeView

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

the class NewTournamentDialog method getTournamentOptions.

private TournamentOptions getTournamentOptions() {
    TournamentTypeView tournamentType = (TournamentTypeView) cbTournamentType.getSelectedItem();
    int numSeats = (Integer) this.spnNumSeats.getValue();
    TournamentOptions tOptions = new TournamentOptions(this.txtName.getText(), "", numSeats);
    tOptions.setTournamentType(tournamentType.getName());
    tOptions.setPassword(txtPassword.getText());
    tOptions.getPlayerTypes().add(PlayerType.HUMAN);
    tOptions.setWatchingAllowed(cbAllowSpectators.isSelected());
    tOptions.setPlaneChase(cbPlaneChase.isSelected());
    tOptions.setQuitRatio((Integer) spnQuitRatio.getValue());
    tOptions.setMinimumRating((Integer) spnMinimumRating.getValue());
    for (TournamentPlayerPanel player : players) {
        tOptions.getPlayerTypes().add((PlayerType) player.getPlayerType().getSelectedItem());
    }
    if (!tournamentType.isElimination()) {
        tOptions.setNumberRounds((Integer) spnNumRounds.getValue());
    }
    if (tournamentType.isDraft()) {
        DraftOptions options = new DraftOptions();
        options.setTiming((TimingOption) this.cbDraftTiming.getSelectedItem());
        tOptions.setLimitedOptions(options);
    }
    if (tOptions.getLimitedOptions() == null) {
        tOptions.setLimitedOptions(new LimitedOptions());
    }
    if (tournamentType.isLimited()) {
        tOptions.getLimitedOptions().setConstructionTime((Integer) this.spnConstructTime.getValue() * 60);
        tOptions.getLimitedOptions().setIsRandom(tournamentType.isRandom());
        tOptions.getLimitedOptions().setIsRichMan(tournamentType.isRichMan());
        tOptions.getLimitedOptions().setIsJumpstart(tournamentType.isJumpstart());
        if (tournamentType.isJumpstart()) {
            if (!(jumpstartPacksFilename.isEmpty())) {
                String jumpstartPacksData = "";
                try {
                    jumpstartPacksData = new String(Files.readAllBytes(Paths.get(jumpstartPacksFilename)));
                    if (jumpstartPacksData.length() > 300000) {
                        JOptionPane.showMessageDialog(MageFrame.getDesktop(), "Chosen file too big", "Jumpstart Packs data is too long.  Please trim or choose another file.", JOptionPane.ERROR_MESSAGE);
                        jumpstartPacksData = "";
                    }
                } catch (IOException e2) {
                    JOptionPane.showMessageDialog(MageFrame.getDesktop(), e2.getMessage(), "Error loading Jumpstart Packs data", JOptionPane.ERROR_MESSAGE);
                }
                tOptions.getLimitedOptions().setJumpstartPacks(jumpstartPacksData);
            }
        }
        if (tournamentType.isCubeBooster()) {
            tOptions.getLimitedOptions().setDraftCubeName(this.cbDraftCube.getSelectedItem().toString());
            if (!(cubeFromDeckFilename.isEmpty())) {
                Deck cubeFromDeck = new Deck();
                try {
                    cubeFromDeck = Deck.load(DeckImporter.importDeckFromFile(cubeFromDeckFilename, true), true, true);
                } catch (GameException e1) {
                    JOptionPane.showMessageDialog(MageFrame.getDesktop(), e1.getMessage(), "Error loading deck", JOptionPane.ERROR_MESSAGE);
                }
                if (cubeFromDeck != null) {
                    cubeFromDeck.clearLayouts();
                    tOptions.getLimitedOptions().setCubeFromDeck(cubeFromDeck);
                }
            }
        } else if (tournamentType.isRandom() || tournamentType.isRichMan()) {
            this.isRandom = tournamentType.isRandom();
            this.isRichMan = tournamentType.isRichMan();
            tOptions.getLimitedOptions().getSetCodes().clear();
            java.util.List<String> selected = randomPackSelector.getSelectedPacks();
            Collections.shuffle(selected);
            int maxPacks = 3 * (players.size() + 1);
            if (tournamentType.isRichMan()) {
                maxPacks = 36;
            }
            if (selected.size() > maxPacks) {
                StringBuilder infoString = new StringBuilder("More sets were selected than needed. ");
                infoString.append(maxPacks);
                infoString.append(" sets will be randomly chosen.");
                JOptionPane.showMessageDialog(MageFrame.getDesktop(), infoString, "Information", JOptionPane.INFORMATION_MESSAGE);
                tOptions.getLimitedOptions().getSetCodes().addAll(selected.subList(0, maxPacks));
            } else {
                tOptions.getLimitedOptions().getSetCodes().addAll(selected);
            }
        } else {
            for (JPanel panel : packPanels) {
                JComboBox combo = findComboInComponent(panel);
                if (combo != null) {
                    tOptions.getLimitedOptions().getSetCodes().add(((ExpansionInfo) combo.getSelectedItem()).getCode());
                } else {
                    logger.error("Can't find combo component in " + panel.toString());
                }
            }
        }
        tOptions.getMatchOptions().setDeckType("Limited");
        tOptions.getMatchOptions().setGameType("Two Player Duel");
        tOptions.getMatchOptions().setLimited(true);
    } else {
        tOptions.getLimitedOptions().setConstructionTime(0);
        tOptions.getLimitedOptions().setNumberBoosters(0);
        tOptions.getLimitedOptions().setDraftCube(null);
        tOptions.getLimitedOptions().setDraftCubeName("");
        tOptions.getMatchOptions().setDeckType((String) this.cbDeckType.getSelectedItem());
        tOptions.getMatchOptions().setGameType(((GameTypeView) this.cbGameType.getSelectedItem()).getName());
        tOptions.getMatchOptions().setLimited(false);
    }
    String serverAddress = SessionHandler.getSession().getServerHostname().orElse("");
    tOptions.getMatchOptions().setBannedUsers(IgnoreList.getIgnoredUsers(serverAddress));
    tOptions.getMatchOptions().setMatchTimeLimit((MatchTimeLimit) this.cbTimeLimit.getSelectedItem());
    tOptions.getMatchOptions().setSkillLevel((SkillLevel) this.cbSkillLevel.getSelectedItem());
    tOptions.getMatchOptions().setWinsNeeded((Integer) this.spnNumWins.getValue());
    tOptions.getMatchOptions().setFreeMulligans((Integer) this.spnFreeMulligans.getValue());
    tOptions.getMatchOptions().setMullgianType((MulliganType) this.cbMulligan.getSelectedItem());
    tOptions.getMatchOptions().setAttackOption(MultiplayerAttackOption.LEFT);
    tOptions.getMatchOptions().setRange(RangeOfInfluence.ALL);
    tOptions.getMatchOptions().setRollbackTurnsAllowed(this.chkRollbackTurnsAllowed.isSelected());
    tOptions.getMatchOptions().setRated(this.chkRated.isSelected());
    return tOptions;
}
Also used : LimitedOptions(mage.game.tournament.LimitedOptions) Deck(mage.cards.decks.Deck) IOException(java.io.IOException) TournamentPlayerPanel(mage.client.table.TournamentPlayerPanel) TournamentTypeView(mage.view.TournamentTypeView) TournamentOptions(mage.game.tournament.TournamentOptions) DraftOptions(mage.game.draft.DraftOptions) IgnoreList(mage.client.util.IgnoreList) ExpansionInfo(mage.cards.repository.ExpansionInfo) GameException(mage.game.GameException)

Example 3 with TournamentTypeView

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

the class NewTournamentDialog method btnOkActionPerformed.

// GEN-LAST:event_cbTournamentTypeActionPerformed
private void btnOkActionPerformed(java.awt.event.ActionEvent evt) {
    // GEN-FIRST:event_btnOkActionPerformed
    // get settings
    TournamentOptions tOptions = getTournamentOptions();
    // CHECKS
    TournamentTypeView tournamentType = (TournamentTypeView) cbTournamentType.getSelectedItem();
    if (tournamentType.isRandom() || tournamentType.isRichMan()) {
        if (tOptions.getLimitedOptions().getSetCodes().isEmpty()) {
            JOptionPane.showMessageDialog(MageFrame.getDesktop(), "Warning, you must select packs for the pool", "Warning", JOptionPane.WARNING_MESSAGE);
            return;
        }
    }
    if (tournamentType.isDraft() && tOptions.getLimitedOptions() instanceof DraftOptions) {
        DraftOptions draftOptions = (DraftOptions) tOptions.getLimitedOptions();
        if (draftOptions.getTiming() == TimingOption.NONE) {
            JOptionPane.showMessageDialog(MageFrame.getDesktop(), "Warning, you must select draft timing option", "Warning", JOptionPane.WARNING_MESSAGE);
            return;
        }
    }
    // save last settings
    onSaveSettings(0, tOptions);
    // run
    table = SessionHandler.createTournamentTable(roomId, tOptions);
    if (table == null) {
        // message must be send by server!
        return;
    }
    // join AI
    for (TournamentPlayerPanel player : players) {
        if (player.getPlayerType().getSelectedItem() != PlayerType.HUMAN) {
            if (!player.joinTournamentTable(roomId, table.getTableId(), DeckImporter.importDeckFromFile(this.player1Panel.getDeckFile(), true))) {
                // error message must be send by sever
                SessionHandler.removeTable(roomId, table.getTableId());
                table = null;
                return;
            }
        }
    }
    // join itself
    if (SessionHandler.joinTournamentTable(roomId, table.getTableId(), this.player1Panel.getPlayerName(), PlayerType.HUMAN, 1, DeckImporter.importDeckFromFile(this.player1Panel.getDeckFile(), true), tOptions.getPassword())) {
        // all fine, can close create dialog (join dialog will be opened after feedback from server)
        this.hideDialog();
        return;
    }
    JOptionPane.showMessageDialog(MageFrame.getDesktop(), "Error joining tournament.", "Error", JOptionPane.ERROR_MESSAGE);
    SessionHandler.removeTable(roomId, table.getTableId());
    table = null;
}
Also used : TournamentPlayerPanel(mage.client.table.TournamentPlayerPanel) TournamentOptions(mage.game.tournament.TournamentOptions) TournamentTypeView(mage.view.TournamentTypeView) DraftOptions(mage.game.draft.DraftOptions)

Example 4 with TournamentTypeView

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

the class NewTournamentDialog method onLoadSettings.

private void onLoadSettings(int version) {
    String versionStr = prepareVersionStr(version, false);
    int numPlayers;
    txtName.setText(PreferencesDialog.getCachedValue(PreferencesDialog.KEY_NEW_TOURNAMENT_NAME + versionStr, "Tournament"));
    txtPassword.setText(PreferencesDialog.getCachedValue(PreferencesDialog.KEY_NEW_TOURNAMENT_PASSWORD + versionStr, ""));
    int timeLimit = Integer.parseInt(PreferencesDialog.getCachedValue(PreferencesDialog.KEY_NEW_TOURNAMENT_TIME_LIMIT + versionStr, "1500"));
    for (MatchTimeLimit mtl : MatchTimeLimit.values()) {
        if (mtl.getTimeLimit() == timeLimit) {
            this.cbTimeLimit.setSelectedItem(mtl);
            break;
        }
    }
    String skillLevelDefault = PreferencesDialog.getCachedValue(PreferencesDialog.KEY_NEW_TABLE_SKILL_LEVEL + versionStr, "Casual");
    for (SkillLevel skillLevel : SkillLevel.values()) {
        if (skillLevel.toString().equals(skillLevelDefault)) {
            this.cbSkillLevel.setSelectedItem(skillLevel);
            break;
        }
    }
    int constructionTime = Integer.parseInt(PreferencesDialog.getCachedValue(PreferencesDialog.KEY_NEW_TOURNAMENT_CONSTR_TIME + versionStr, "600")) / 60;
    if (constructionTime < CONSTRUCTION_TIME_MIN || constructionTime > CONSTRUCTION_TIME_MAX) {
        constructionTime = CONSTRUCTION_TIME_MIN;
    }
    this.spnConstructTime.setValue(constructionTime);
    String tournamentTypeName = PreferencesDialog.getCachedValue(PreferencesDialog.KEY_NEW_TOURNAMENT_TYPE + versionStr, "Sealed Elimination");
    for (TournamentTypeView tournamentTypeView : SessionHandler.getTournamentTypes()) {
        if (tournamentTypeView.getName().equals(tournamentTypeName)) {
            cbTournamentType.setSelectedItem(tournamentTypeView);
            break;
        }
    }
    this.spnFreeMulligans.setValue(Integer.parseInt(PreferencesDialog.getCachedValue(PreferencesDialog.KEY_NEW_TOURNAMENT_NUMBER_OF_FREE_MULLIGANS + versionStr, "0")));
    this.cbMulligan.setSelectedItem(MulliganType.valueByName(PreferencesDialog.getCachedValue(PreferencesDialog.KEY_NEW_TOURNAMENT_MULLIGUN_TYPE + versionStr, MulliganType.GAME_DEFAULT.toString())));
    this.spnNumWins.setValue(Integer.parseInt(PreferencesDialog.getCachedValue(PreferencesDialog.KEY_NEW_TOURNAMENT_NUMBER_OF_WINS + versionStr, "2")));
    this.spnQuitRatio.setValue(Integer.parseInt(PreferencesDialog.getCachedValue(PreferencesDialog.KEY_NEW_TOURNAMENT_QUIT_RATIO + versionStr, "100")));
    this.spnMinimumRating.setValue(Integer.parseInt(PreferencesDialog.getCachedValue(PreferencesDialog.KEY_NEW_TOURNAMENT_MINIMUM_RATING + versionStr, "0")));
    TournamentTypeView tournamentType = (TournamentTypeView) cbTournamentType.getSelectedItem();
    activatePanelElements(tournamentType);
    if (tournamentType.isLimited()) {
        if (tournamentType.isDraft()) {
            numPlayers = Integer.parseInt(PreferencesDialog.getCachedValue(PreferencesDialog.KEY_NEW_TOURNAMENT_PLAYERS_DRAFT + versionStr, "4"));
            prepareTourneyView(numPlayers);
            if (tournamentType.isRandom() || tournamentType.isRichMan()) {
                loadRandomPacks(version);
            } else {
                loadBoosterPacks(PreferencesDialog.getCachedValue(PreferencesDialog.KEY_NEW_TOURNAMENT_PACKS_DRAFT + versionStr, ""));
            }
            String draftTiming = PreferencesDialog.getCachedValue(PreferencesDialog.KEY_NEW_TOURNAMENT_DRAFT_TIMING + versionStr, "REGULAR");
            for (TimingOption timingOption : DraftOptions.TimingOption.values()) {
                if (timingOption.toString().equals(draftTiming)) {
                    cbDraftTiming.setSelectedItem(draftTiming);
                    break;
                }
            }
        } else {
            numPlayers = Integer.parseInt(PreferencesDialog.getCachedValue(PreferencesDialog.KEY_NEW_TOURNAMENT_PLAYERS_SEALED + versionStr, "2"));
            prepareTourneyView(numPlayers);
            loadBoosterPacks(PreferencesDialog.getCachedValue(PreferencesDialog.KEY_NEW_TOURNAMENT_PACKS_SEALED + versionStr, ""));
        }
    }
    this.cbAllowSpectators.setSelected(PreferencesDialog.getCachedValue(PreferencesDialog.KEY_NEW_TOURNAMENT_ALLOW_SPECTATORS + versionStr, "Yes").equals("Yes"));
    this.cbPlaneChase.setSelected(PreferencesDialog.getCachedValue(PreferencesDialog.KEY_NEW_TOURNAMENT_PLANE_CHASE + versionStr, "No").equals("Yes"));
    this.chkRollbackTurnsAllowed.setSelected(PreferencesDialog.getCachedValue(PreferencesDialog.KEY_NEW_TOURNAMENT_ALLOW_ROLLBACKS + versionStr, "Yes").equals("Yes"));
    this.chkRated.setSelected(PreferencesDialog.getCachedValue(PreferencesDialog.KEY_NEW_TOURNAMENT_RATED + versionStr, "No").equals("Yes"));
}
Also used : SkillLevel(mage.constants.SkillLevel) TournamentTypeView(mage.view.TournamentTypeView) MatchTimeLimit(mage.constants.MatchTimeLimit) TimingOption(mage.game.draft.DraftOptions.TimingOption)

Example 5 with TournamentTypeView

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

the class NewTournamentDialog method prepareTourneyView.

private void prepareTourneyView(int numPlayers) {
    TournamentTypeView tournamentType = (TournamentTypeView) cbTournamentType.getSelectedItem();
    activatePanelElements(tournamentType);
    // players
    if (numPlayers < tournamentType.getMinPlayers() || numPlayers > tournamentType.getMaxPlayers()) {
        numPlayers = tournamentType.getMinPlayers();
        // ?
        createPlayers(numPlayers - 1);
    }
    this.spnNumPlayers.setModel(new SpinnerNumberModel(numPlayers, tournamentType.getMinPlayers(), tournamentType.getMaxPlayers(), 1));
    this.spnNumPlayers.setEnabled(tournamentType.getMinPlayers() != tournamentType.getMaxPlayers());
    createPlayers((Integer) spnNumPlayers.getValue() - 1);
    this.spnNumSeats.setModel(new SpinnerNumberModel(2, 2, tournamentType.getMaxPlayers(), 1));
    // packs
    preparePacksView(tournamentType);
}
Also used : TournamentTypeView(mage.view.TournamentTypeView)

Aggregations

TournamentTypeView (mage.view.TournamentTypeView)5 TournamentPlayerPanel (mage.client.table.TournamentPlayerPanel)2 DraftOptions (mage.game.draft.DraftOptions)2 TournamentOptions (mage.game.tournament.TournamentOptions)2 IOException (java.io.IOException)1 Deck (mage.cards.decks.Deck)1 ExpansionInfo (mage.cards.repository.ExpansionInfo)1 IgnoreList (mage.client.util.IgnoreList)1 MatchTimeLimit (mage.constants.MatchTimeLimit)1 SkillLevel (mage.constants.SkillLevel)1 GameException (mage.game.GameException)1 TimingOption (mage.game.draft.DraftOptions.TimingOption)1 LimitedOptions (mage.game.tournament.LimitedOptions)1