Search in sources :

Example 1 with LimitedOptions

use of mage.game.tournament.LimitedOptions 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)

Aggregations

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