Search in sources :

Example 61 with CardInfo

use of mage.cards.repository.CardInfo in project mage by magefree.

the class UpdateDeckTask method moveSelectorCardToSideboard.

private void moveSelectorCardToSideboard(Event event) {
    boolean gameMode = mode != DeckEditorMode.FREE_BUILDING;
    if (gameMode) {
        throw new IllegalArgumentException("ERROR, you can move card to sideboard from selector in game mode.");
    }
    SimpleCardView cardView = (SimpleCardView) event.getSource();
    CardInfo cardInfo = CardRepository.instance.findCard(cardView.getExpansionSetCode(), cardView.getCardNumber());
    Card card = cardInfo != null ? cardInfo.getMockCard() : null;
    if (card != null) {
        deck.getSideboard().add(card);
    }
    // card hint update
    if (cardInfoPane instanceof CardInfoPane) {
        ((CardInfoPane) cardInfoPane).setCard(new CardView(card), null);
    }
    hidePopup();
}
Also used : SimpleCardView(mage.view.SimpleCardView) SimpleCardView(mage.view.SimpleCardView) CardView(mage.view.CardView) CardInfo(mage.cards.repository.CardInfo) Card(mage.cards.Card) BigCard(mage.client.cards.BigCard) CardInfoPane(mage.components.CardInfoPane)

Example 62 with CardInfo

use of mage.cards.repository.CardInfo in project mage by magefree.

the class LoadMissingCardDataNew method prepareMissingCards.

private static List<CardDownloadData> prepareMissingCards(List<CardInfo> allCards, boolean redownloadMode) {
    // get filter for Standard Type 2 cards
    Set<String> type2SetsFilter = new HashSet<>();
    List<String> constructedFormats = ConstructedFormats.getSetsByFormat(ConstructedFormats.STANDARD);
    if (constructedFormats != null && !constructedFormats.isEmpty()) {
        type2SetsFilter.addAll(constructedFormats);
    } else {
        logger.warn("No formats defined. Try connecting to a server first!");
    }
    // prepare checking list
    List<CardDownloadData> allCardsUrls = Collections.synchronizedList(new ArrayList<>());
    try {
        allCards.parallelStream().forEach(card -> {
            if (!card.getCardNumber().isEmpty() && !"0".equals(card.getCardNumber()) && !card.getSetCode().isEmpty()) {
                String cardName = card.getName();
                boolean isType2 = type2SetsFilter.contains(card.getSetCode());
                CardDownloadData url = new CardDownloadData(cardName, card.getSetCode(), card.getCardNumber(), card.usesVariousArt(), 0, "", "", false, card.isDoubleFaced(), card.isNightCard());
                // variations must have diff file names with additional postfix
                if (url.getUsesVariousArt()) {
                    url.setDownloadName(createDownloadName(card));
                }
                url.setFlipCard(card.isFlipCard());
                url.setSplitCard(card.isSplitCard());
                url.setType2(isType2);
                // main side
                allCardsUrls.add(url);
                // second side (xmage's set doesn't have info about it, so generate it here)
                if (card.isDoubleFaced()) {
                    if (card.getSecondSideName() == null || card.getSecondSideName().trim().isEmpty()) {
                        throw new IllegalStateException("Second side card can't have empty name.");
                    }
                    CardInfo secondSideCard = CardRepository.instance.findCardWPreferredSet(card.getSecondSideName(), card.getSetCode(), false);
                    if (secondSideCard == null) {
                        throw new IllegalStateException("Can''t find second side card in database: " + card.getSecondSideName());
                    }
                    url = new CardDownloadData(card.getSecondSideName(), card.getSetCode(), secondSideCard.getCardNumber(), card.usesVariousArt(), 0, "", "", false, card.isDoubleFaced(), true);
                    url.setType2(isType2);
                    allCardsUrls.add(url);
                }
                if (card.isFlipCard()) {
                    if (card.getFlipCardName() == null || card.getFlipCardName().trim().isEmpty()) {
                        throw new IllegalStateException("Flipped card can't have empty name.");
                    }
                    CardDownloadData cardDownloadData = new CardDownloadData(card.getFlipCardName(), card.getSetCode(), card.getCardNumber(), card.usesVariousArt(), 0, "", "", false, card.isDoubleFaced(), card.isNightCard());
                    cardDownloadData.setFlipCard(true);
                    cardDownloadData.setFlippedSide(true);
                    cardDownloadData.setType2(isType2);
                    allCardsUrls.add(cardDownloadData);
                }
                if (card.isModalDoubleFacesCard()) {
                    if (card.getModalDoubleFacesSecondSideName() == null || card.getModalDoubleFacesSecondSideName().trim().isEmpty()) {
                        throw new IllegalStateException("MDF card can't have empty name.");
                    }
                    CardDownloadData cardDownloadData = new CardDownloadData(card.getModalDoubleFacesSecondSideName(), card.getSetCode(), card.getCardNumber(), card.usesVariousArt(), 0, "", "", false, true, true);
                    cardDownloadData.setType2(isType2);
                    allCardsUrls.add(cardDownloadData);
                }
            } else if (card.getCardNumber().isEmpty() || "0".equals(card.getCardNumber())) {
                logger.error("Card has no collector ID and won't be sent to client: " + card.getName());
            } else if (card.getSetCode().isEmpty()) {
                logger.error("Card has no set name and won't be sent to client:" + card.getName());
            } else {
                logger.info("Card was not selected: " + card.getName());
            }
        });
        allCardsUrls.addAll(getTokenCardUrls());
    } catch (Exception e) {
        logger.error(e);
    }
    // find missing files
    List<CardDownloadData> cardsToDownload = Collections.synchronizedList(new ArrayList<>());
    allCardsUrls.parallelStream().forEach(card -> {
        if (redownloadMode) {
            // need all cards
            cardsToDownload.add(card);
        } else {
            // need missing cards
            File file = new TFile(CardImageUtils.buildImagePathToCard(card));
            if (!file.exists()) {
                cardsToDownload.add(card);
            }
        }
    });
    return Collections.synchronizedList(new ArrayList<>(cardsToDownload));
}
Also used : CardInfo(mage.cards.repository.CardInfo) FsSyncException(net.java.truevfs.kernel.spec.FsSyncException) AccessDeniedException(java.nio.file.AccessDeniedException) TFile(net.java.truevfs.access.TFile) TFile(net.java.truevfs.access.TFile)

Example 63 with CardInfo

use of mage.cards.repository.CardInfo in project mage by magefree.

the class TestGameType method createHandCard.

private CardView createHandCard(Game game, UUID controllerId, String code, String cardNumber) {
    CardInfo cardInfo = CardRepository.instance.findCard(code, cardNumber);
    ExpansionInfo setInfo = ExpansionRepository.instance.getSetByCode(code);
    CardSetInfo testSet = new CardSetInfo(cardInfo.getName(), setInfo.getCode(), cardNumber, cardInfo.getRarity(), new CardGraphicInfo(cardInfo.getFrameStyle(), cardInfo.usesVariousArt()));
    Card card = CardImpl.createCard(cardInfo.getClassName(), testSet);
    Set<Card> cardsList = new HashSet<>();
    cardsList.add(card);
    game.loadCards(cardsList, controllerId);
    CardView cardView = new CardView(card);
    return cardView;
}
Also used : CardInfo(mage.cards.repository.CardInfo) ExpansionInfo(mage.cards.repository.ExpansionInfo) BigCard(mage.client.cards.BigCard) PermanentCard(mage.game.permanent.PermanentCard)

Example 64 with CardInfo

use of mage.cards.repository.CardInfo in project mage by magefree.

the class CardsViewUtil method convertSimple.

public static CardsView convertSimple(SimpleCardsView view) {
    CardsView cards = new CardsView();
    for (SimpleCardView simple : view.values()) {
        CardInfo cardInfo = CardRepository.instance.findCard(simple.getExpansionSetCode(), simple.getCardNumber());
        Card card = cardInfo != null ? cardInfo.getMockCard() : null;
        if (card != null) {
            cards.put(simple.getId(), new CardView(card, simple));
        }
    }
    return cards;
}
Also used : CardInfo(mage.cards.repository.CardInfo) Card(mage.cards.Card)

Example 65 with CardInfo

use of mage.cards.repository.CardInfo in project mage by magefree.

the class DeckUtil method construct.

public static Deck construct(DeckView view) {
    Deck deck = new Deck();
    for (SimpleCardView cardView : view.getCards().values()) {
        CardInfo cardInfo = CardRepository.instance.findCard(cardView.getExpansionSetCode(), cardView.getCardNumber());
        Card card = cardInfo != null ? cardInfo.getMockCard() : null;
        if (card != null) {
            deck.getCards().add(card);
        } else {
            log.fatal("(Deck constructing) Couldn't find card: set=" + cardView.getExpansionSetCode() + ", cid=" + Integer.valueOf(cardView.getCardNumber()));
        }
    }
    for (SimpleCardView cardView : view.getSideboard().values()) {
        CardInfo cardInfo = CardRepository.instance.findCard(cardView.getExpansionSetCode(), cardView.getCardNumber());
        Card card = cardInfo != null ? cardInfo.getMockCard() : null;
        if (card != null) {
            deck.getSideboard().add(card);
        } else {
            log.fatal("(Deck constructing) Couldn't find card: set=" + cardView.getExpansionSetCode() + ", cid=" + Integer.valueOf(cardView.getCardNumber()));
        }
    }
    return deck;
}
Also used : SimpleCardView(mage.view.SimpleCardView) Deck(mage.cards.decks.Deck) CardInfo(mage.cards.repository.CardInfo) Card(mage.cards.Card)

Aggregations

CardInfo (mage.cards.repository.CardInfo)67 Card (mage.cards.Card)25 CardCriteria (mage.cards.repository.CardCriteria)14 DeckCardInfo (mage.cards.decks.DeckCardInfo)13 PermanentCard (mage.game.permanent.PermanentCard)10 Matcher (java.util.regex.Matcher)8 Test (org.junit.Test)8 CardView (mage.view.CardView)7 ArrayList (java.util.ArrayList)6 BigCard (mage.client.cards.BigCard)6 Player (mage.players.Player)5 java.util (java.util)3 List (java.util.List)3 Ability (mage.abilities.Ability)3 SimpleStaticAbility (mage.abilities.common.SimpleStaticAbility)3 InfoEffect (mage.abilities.effects.common.InfoEffect)3 ExpansionInfo (mage.cards.repository.ExpansionInfo)3 Rarity (mage.constants.Rarity)3 PermanentImpl (mage.game.permanent.PermanentImpl)3 SimpleCardView (mage.view.SimpleCardView)3