Search in sources :

Example 1 with GameException

use of mage.game.GameException 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 GameException

use of mage.game.GameException 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 3 with GameException

use of mage.game.GameException in project mage by magefree.

the class Deck method createCardNotFoundGameException.

private static GameException createCardNotFoundGameException(DeckCardInfo deckCardInfo, String deckName) {
    // Try WORKAROUND for Card DB error: Try to read a card that does exist
    CardInfo cardInfo = CardRepository.instance.findCard("Silvercoat Lion");
    if (cardInfo == null) {
        // DB seems to have a problem - try to restart the DB
        CardRepository.instance.closeDB();
        CardRepository.instance.openDB();
        cardInfo = CardRepository.instance.findCard("Silvercoat Lion");
        Logger.getLogger(Deck.class).error("Tried to restart the DB: " + (cardInfo == null ? "not successful" : "successful"));
    }
    return new GameException("Card not found - " + deckCardInfo.getCardName() + " - " + deckCardInfo.getSetCode() + "/" + deckCardInfo.getCardNum() + " for deck - " + deckName + '\n' + "Possible reason is, that you use cards in your deck, that are only supported in newer versions of the server.\n" + "So it can help to use the same card from another set, that's already supported from this server.");
}
Also used : CardInfo(mage.cards.repository.CardInfo) GameException(mage.game.GameException)

Example 4 with GameException

use of mage.game.GameException in project mage by magefree.

the class JumpstartPoolGenerator method doGeneratePool.

private static Set<Card> doGeneratePool(List<JumpstartPack> packs) {
    try {
        DeckCardLists list = new DeckCardLists();
        SecureRandom random = new SecureRandom();
        for (int i = 0; i < 2; i++) {
            int index = random.nextInt(packs.size());
            list.getCards().addAll(packs.get(index).getCards());
        }
        return Deck.load(list, false, false).getCards();
    } catch (GameException e) {
        throw new RuntimeException(e);
    }
}
Also used : DeckCardLists(mage.cards.decks.DeckCardLists) SecureRandom(java.security.SecureRandom) GameException(mage.game.GameException)

Example 5 with GameException

use of mage.game.GameException 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

GameException (mage.game.GameException)6 IOException (java.io.IOException)2 Table (mage.game.Table)2 TournamentPlayer (mage.game.tournament.TournamentPlayer)2 TableManager (mage.server.managers.TableManager)2 File (java.io.File)1 SecureRandom (java.security.SecureRandom)1 UUID (java.util.UUID)1 Deck (mage.cards.decks.Deck)1 DeckCardLists (mage.cards.decks.DeckCardLists)1 CardInfo (mage.cards.repository.CardInfo)1 ExpansionInfo (mage.cards.repository.ExpansionInfo)1 TournamentPlayerPanel (mage.client.table.TournamentPlayerPanel)1 IgnoreList (mage.client.util.IgnoreList)1 DraftOptions (mage.game.draft.DraftOptions)1 LimitedOptions (mage.game.tournament.LimitedOptions)1 TournamentOptions (mage.game.tournament.TournamentOptions)1 TournamentTypeView (mage.view.TournamentTypeView)1