Search in sources :

Example 51 with CardInfo

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

the class VerifyCardDataTest method test_checkCardsInCubes.

@Test
public void test_checkCardsInCubes() {
    Reflections reflections = new Reflections("mage.tournament.cubes.");
    Set<Class<? extends DraftCube>> cubesList = reflections.getSubTypesOf(DraftCube.class);
    Assert.assertFalse("Can't find any cubes", cubesList.isEmpty());
    CardScanner.scan();
    Collection<String> errorsList = new ArrayList<>();
    for (Class<? extends DraftCube> cubeClass : cubesList) {
        // need drafts with fixed cards list (constructor with zero params)
        if (Arrays.stream(cubeClass.getConstructors()).noneMatch(c -> c.getParameterCount() == 0)) {
            continue;
        }
        DraftCube cube = (DraftCube) createNewObject(cubeClass);
        if (cube.getCubeCards().isEmpty()) {
            errorsList.add("Error: broken cube, empty cards list: " + cube.getClass().getCanonicalName());
        }
        for (DraftCube.CardIdentity cardId : cube.getCubeCards()) {
            // same find code as original cube
            CardInfo cardInfo;
            if (!cardId.getExtension().isEmpty()) {
                cardInfo = CardRepository.instance.findCardWPreferredSet(cardId.getName(), cardId.getExtension(), false);
            } else {
                cardInfo = CardRepository.instance.findPreferredCoreExpansionCard(cardId.getName(), false);
            }
            if (cardInfo == null) {
                errorsList.add("Error: broken cube, can't find card: " + cube.getClass().getCanonicalName() + " - " + cardId.getName());
            }
        }
    }
    if (!errorsList.isEmpty()) {
        printMessages(errorsList);
        Assert.fail("Found " + errorsList.size() + " errors in the cubes, look at logs above for more details");
    }
}
Also used : DraftCube(mage.game.draft.DraftCube) CardInfo(mage.cards.repository.CardInfo) Reflections(org.reflections.Reflections) Test(org.junit.Test)

Example 52 with CardInfo

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

the class VerifyCardDataTest method test_checkMissingSecondSideCardsInSets.

@Test
public void test_checkMissingSecondSideCardsInSets() {
    Collection<String> errorsList = new ArrayList<>();
    // CHECK: if card have second side (flip, transform) then it must have all sides in that set
    for (ExpansionSet set : Sets.getInstance().values()) {
        for (ExpansionSet.SetCardInfo info : set.getSetCardInfo()) {
            CardInfo cardInfo = CardRepository.instance.findCardsByClass(info.getCardClass().getCanonicalName()).stream().findFirst().orElse(null);
            Assert.assertNotNull(cardInfo);
            Card card = cardInfo.getCard();
            Card secondCard = card.getSecondCardFace();
            if (secondCard != null) {
                if (set.findCardInfoByClass(secondCard.getClass()).isEmpty()) {
                    errorsList.add("Error: missing second face card from set: " + set.getCode() + " - " + set.getName() + " - main: " + card.getName() + "; second: " + secondCard.getName());
                }
            }
        }
    }
    printMessages(errorsList);
    if (errorsList.size() > 0) {
        Assert.fail("Found missing second side cards in sets, errors: " + errorsList.size());
    }
}
Also used : CardInfo(mage.cards.repository.CardInfo) RateCard(mage.game.draft.RateCard) MtgJsonCard(mage.verify.mtgjson.MtgJsonCard) Test(org.junit.Test)

Example 53 with CardInfo

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

the class DraftCube method createBooster.

public List<Card> createBooster() {
    List<Card> booster = new ArrayList<>();
    if (leftCubeCards.isEmpty()) {
        leftCubeCards.addAll(cubeCards);
    }
    for (int i = 0; i < boosterSize; i++) {
        boolean done = false;
        int notValid = 0;
        while (!done) {
            int index = RandomUtil.nextInt(leftCubeCards.size());
            CardIdentity cardId = leftCubeCards.get(index);
            leftCubeCards.remove(index);
            if (!cardId.getName().isEmpty()) {
                CardInfo cardInfo = null;
                if (!cardId.getExtension().isEmpty()) {
                    cardInfo = CardRepository.instance.findCardWPreferredSet(cardId.getName(), cardId.getExtension(), false);
                } else {
                    cardInfo = CardRepository.instance.findPreferredCoreExpansionCard(cardId.getName(), false);
                }
                if (cardInfo != null) {
                    booster.add(cardInfo.getCard());
                    done = true;
                } else {
                    logger.warn(new StringBuilder(this.getName()).append(" - Card not found: ").append(cardId.getName()).append(':').append(cardId.extension));
                    notValid++;
                }
            } else {
                logger.error(new StringBuilder(this.getName()).append(" - Empty card name: ").append(cardId.getName()).append(':').append(cardId.extension));
                notValid++;
            }
            if (leftCubeCards.isEmpty()) {
                leftCubeCards.addAll(cubeCards);
            }
            if (notValid > cubeCards.size()) {
                logger.error(new StringBuilder(this.getName()).append(" - Booster could not be created, no valid cards found "));
                done = true;
            }
        }
    }
    return booster;
}
Also used : ArrayList(java.util.ArrayList) CardInfo(mage.cards.repository.CardInfo) Card(mage.cards.Card)

Example 54 with CardInfo

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

the class SelectionBox method oldVersionDeck.

private void oldVersionDeck() {
    if (this.mode != Constants.DeckEditorMode.FREE_BUILDING) {
        return;
    }
    if (JOptionPane.showConfirmDialog(null, "Are you sure you want to switch your card versions to the oldest ones?", "WARNING", JOptionPane.YES_NO_OPTION) != JOptionPane.YES_OPTION) {
        return;
    }
    List<List<List<CardView>>> newCardGrid = new ArrayList<>();
    for (List<List<CardView>> gridRow : cardGrid) {
        List<List<CardView>> newGridRow = new ArrayList<>();
        for (List<CardView> stack : gridRow) {
            List<CardView> newStack = new ArrayList<>();
            for (CardView card : stack) {
                CardInfo oldestCardInfo = CardRepository.instance.findOldestNonPromoVersionCard(card.getName());
                if (oldestCardInfo != null) {
                    CardView oldestCardView = new CardView(oldestCardInfo.getMockCard());
                    this.removeCardView(card);
                    eventSource.fireEvent(card, ClientEventType.DECK_REMOVE_SPECIFIC_CARD);
                    this.addCardView(oldestCardView, false);
                    eventSource.fireEvent(oldestCardView, ClientEventType.DECK_ADD_SPECIFIC_CARD);
                    newStack.add(oldestCardView);
                } else {
                    newStack.add(card);
                }
            }
            newGridRow.add(newStack);
        }
        newCardGrid.add(newGridRow);
    }
    cardGrid = newCardGrid;
    layoutGrid();
    repaintGrid();
}
Also used : CardView(mage.view.CardView) DeckCardInfo(mage.cards.decks.DeckCardInfo) CardInfo(mage.cards.repository.CardInfo) List(java.util.List)

Example 55 with CardInfo

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

the class SelectionBox method blingDeck.

public void blingDeck() {
    if (this.mode != Constants.DeckEditorMode.FREE_BUILDING) {
        return;
    }
    if (JOptionPane.showConfirmDialog(null, "Are you sure you want to bling your deck?  This process will add cards!", "WARNING", JOptionPane.YES_NO_OPTION) == JOptionPane.NO_OPTION) {
        return;
    }
    // TODO: Why are these a HashMap? It can be a HashSet<String> instead, as the value is never used in the code.
    Map<String, Integer> pimpedSets = new HashMap<>();
    Map<CardView, Integer> pimpedCards = new HashMap<>();
    pimpedSets.put("PCMP", 1);
    pimpedSets.put("MPS", 1);
    pimpedSets.put("MP2", 1);
    pimpedSets.put("EXP", 1);
    pimpedSets.put("CP1", 1);
    pimpedSets.put("CP2", 1);
    pimpedSets.put("CP3", 1);
    // Judge Reward Gifts
    pimpedSets.put("JGP", 1);
    pimpedSets.put("G99", 1);
    pimpedSets.put("G00", 1);
    pimpedSets.put("G01", 1);
    pimpedSets.put("G02", 1);
    pimpedSets.put("G03", 1);
    pimpedSets.put("G04", 1);
    pimpedSets.put("G05", 1);
    pimpedSets.put("G06", 1);
    pimpedSets.put("G07", 1);
    pimpedSets.put("G08", 1);
    pimpedSets.put("G09", 1);
    pimpedSets.put("G10", 1);
    pimpedSets.put("G11", 1);
    pimpedSets.put("J12", 1);
    pimpedSets.put("J13", 1);
    pimpedSets.put("J14", 1);
    pimpedSets.put("J15", 1);
    pimpedSets.put("J16", 1);
    pimpedSets.put("J17", 1);
    pimpedSets.put("J18", 1);
    pimpedSets.put("J19", 1);
    pimpedSets.put("J20", 1);
    // Arena League
    pimpedSets.put("PARL", 1);
    pimpedSets.put("PAL99", 1);
    pimpedSets.put("PAL00", 1);
    pimpedSets.put("PAL01", 1);
    pimpedSets.put("PAL02", 1);
    pimpedSets.put("PAL03", 1);
    pimpedSets.put("PAL04", 1);
    pimpedSets.put("PAL05", 1);
    pimpedSets.put("PAL06", 1);
    pimpedSets.put("UGIN", 1);
    pimpedSets.put("PALP", 1);
    pimpedSets.put("PELP", 1);
    // Friday Night Magic
    pimpedSets.put("FNM", 1);
    pimpedSets.put("F01", 1);
    pimpedSets.put("F02", 1);
    pimpedSets.put("F03", 1);
    pimpedSets.put("F04", 1);
    pimpedSets.put("F05", 1);
    pimpedSets.put("F06", 1);
    pimpedSets.put("F07", 1);
    pimpedSets.put("F08", 1);
    pimpedSets.put("F09", 1);
    pimpedSets.put("F10", 1);
    pimpedSets.put("F11", 1);
    pimpedSets.put("F12", 1);
    pimpedSets.put("F13", 1);
    pimpedSets.put("F14", 1);
    pimpedSets.put("F15", 1);
    pimpedSets.put("F16", 1);
    pimpedSets.put("F17", 1);
    pimpedSets.put("F18", 1);
    // Magic Player Rewards 2001-2011, except for 2002 (P02), which only contains tokens
    pimpedSets.put("MPR", 1);
    pimpedSets.put("P03", 1);
    pimpedSets.put("P04", 1);
    pimpedSets.put("P05", 1);
    pimpedSets.put("P06", 1);
    pimpedSets.put("P07", 1);
    pimpedSets.put("P08", 1);
    pimpedSets.put("P09", 1);
    pimpedSets.put("P10", 1);
    pimpedSets.put("P11", 1);
    // Vintage Championship
    pimpedSets.put("OVNT", 1);
    // Junior Series Europe
    pimpedSets.put("PJSE", 1);
    // Two-Headed Giant Tournament
    pimpedSets.put("P2HG", 1);
    // Gateway 2006
    pimpedSets.put("PGTW", 1);
    // Junior APAC Series
    pimpedSets.put("PJAS", 1);
    pimpedSets.put("EXP", 1);
    pimpedSets.put("PGPX", 1);
    pimpedSets.put("PMEI", 1);
    pimpedSets.put("PLS", 1);
    String[] sets = pimpedSets.keySet().toArray(new String[pimpedSets.keySet().size()]);
    Boolean didModify = false;
    for (List<List<CardView>> gridRow : cardGrid) {
        for (List<CardView> stack : gridRow) {
            for (CardView card : stack) {
                if (card.getSuperTypes().contains(SuperType.BASIC)) {
                    continue;
                }
                if (!pimpedSets.containsKey(card.getExpansionSetCode())) {
                    final CardCriteria cardCriteria = new CardCriteria();
                    cardCriteria.setCodes(sets);
                    cardCriteria.name(card.getName());
                    java.util.List<CardInfo> cardPool = CardRepository.instance.findCards(cardCriteria);
                    if (!cardPool.isEmpty()) {
                        Card acard = cardPool.get(RandomUtil.nextInt(cardPool.size())).getMockCard();
                        if (acard.getName().equals(card.getName())) {
                            CardView pimpedCard = new CardView(acard);
                            addCardView(pimpedCard, false);
                            eventSource.fireEvent(pimpedCard, ClientEventType.DECK_ADD_SPECIFIC_CARD);
                            pimpedCards.put(pimpedCard, 1);
                            didModify = true;
                        }
                    }
                }
            }
        }
        if (didModify) {
            for (CardView c : pimpedCards.keySet()) {
                sortIntoGrid(c);
            }
            trimGrid();
            layoutGrid();
            repaintGrid();
            JOptionPane.showMessageDialog(null, "Added " + pimpedCards.size() + " cards.  You can select them and the originals by choosing 'Multiples'");
        }
    }
}
Also used : CardCriteria(mage.cards.repository.CardCriteria) CardView(mage.view.CardView) DeckCardInfo(mage.cards.decks.DeckCardInfo) CardInfo(mage.cards.repository.CardInfo) MageCard(mage.cards.MageCard) Card(mage.cards.Card) java.util(java.util) List(java.util.List)

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