Search in sources :

Example 16 with CardInfo

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

the class DragonsMazeCollator method findSpecialCardsByRarity.

@Override
protected List<CardInfo> findSpecialCardsByRarity(Rarity rarity) {
    CardCriteria criteria = new CardCriteria();
    criteria.rarities(rarity).types(CardType.LAND);
    if (rarity == Rarity.RARE) {
        // shocklands
        criteria.setCodes("RTR", "GTC");
    } else {
        // Guildgates and Maze's End
        criteria.setCodes(this.code);
    }
    List<CardInfo> cardInfos = CardRepository.instance.findCards(criteria);
    cardInfos.removeIf(cardInfo -> (cardInfo.getName().equals("Grove of the Guardian") || cardInfo.getName().equals("Thespian's Stage")));
    return cardInfos;
}
Also used : CardCriteria(mage.cards.repository.CardCriteria) CardInfo(mage.cards.repository.CardInfo)

Example 17 with CardInfo

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

the class MysteryBooster method populateSlot.

/**
 * Populate the given booster slot.
 *
 * @param slotNumber booster slot number. 1-indexed, valid range is 1-14, as 15 is the special slot
 * @param cardNames  List of English card names found on the given slot
 */
private void populateSlot(int slotNumber, List<String> cardNames) {
    final List<CardInfo> cardInfoList = this.possibleCardsPerBoosterSlot.get(slotNumber);
    for (String name : cardNames) {
        final CardInfo cardWithGivenName = CardRepository.instance.findCardWPreferredSet(name, this.code, false);
        cardInfoList.add(cardWithGivenName);
    }
}
Also used : CardInfo(mage.cards.repository.CardInfo)

Example 18 with CardInfo

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

the class CardTestPlayerAPIImpl method addCard.

/**
 * Add any amount of cards to specified zone of specified player.
 *
 * @param gameZone {@link mage.constants.Zone} to add cards to.
 * @param player   {@link Player} to add cards for. Use either playerA or
 *                 playerB.
 * @param cardName Card name in string format.
 * @param count    Amount of cards to be added.
 * @param tapped   In case gameZone is Battlefield, determines whether
 *                 permanent should be tapped. In case gameZone is other
 *                 than Battlefield, {@link IllegalArgumentException} is
 *                 thrown
 */
@Override
public void addCard(Zone gameZone, TestPlayer player, String cardName, int count, boolean tapped) {
    // aliases for mage objects
    String aliasName = "";
    boolean useAliasMultiNames = (count != 1);
    if (cardName.contains(ALIAS_PREFIX)) {
        aliasName = cardName.substring(cardName.indexOf(ALIAS_PREFIX) + ALIAS_PREFIX.length());
        cardName = cardName.substring(0, cardName.indexOf(ALIAS_PREFIX));
    }
    // one card = one aliase, massive adds can use auto-name
    if (!useAliasMultiNames && !aliasName.isEmpty() && player.getAliasByName(aliasName) != null) {
        Assert.fail("Can't add card " + cardName + " - alias " + aliasName + " already exists for " + player.getName());
    }
    // game tests don't need cards from a specific set, so it can be from any set
    CardInfo cardInfo = CardRepository.instance.findCard(cardName, true);
    if (cardInfo == null) {
        throw new IllegalArgumentException("[TEST] Couldn't find a card: " + cardName);
    }
    if (gameZone == Zone.BATTLEFIELD) {
        for (int i = 0; i < count; i++) {
            Card newCard = cardInfo.getCard();
            Card permCard = CardUtil.getDefaultCardSideForBattlefield(currentGame, newCard);
            PermanentCard p = new PermanentCard(permCard, player.getId(), currentGame);
            p.setTapped(tapped);
            getBattlefieldCards(player).add(p);
            if (!aliasName.isEmpty()) {
                player.addAlias(player.generateAliasName(aliasName, useAliasMultiNames, i + 1), p.getId());
            }
        }
    } else {
        if (tapped) {
            throw new IllegalArgumentException("Parameter tapped=true can be used only for Zone.BATTLEFIELD.");
        }
        List<Card> cards = getCardList(gameZone, player);
        for (int i = 0; i < count; i++) {
            Card newCard = cardInfo.getCard();
            cards.add(newCard);
            if (!aliasName.isEmpty()) {
                player.addAlias(player.generateAliasName(aliasName, useAliasMultiNames, i + 1), newCard.getId());
            }
        }
    }
}
Also used : CardInfo(mage.cards.repository.CardInfo) Card(mage.cards.Card) FilterCard(mage.filter.FilterCard) PermanentCard(mage.game.permanent.PermanentCard) PermanentCard(mage.game.permanent.PermanentCard)

Example 19 with CardInfo

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

the class SerializationTest method test_PermanentImpl_Simple.

@Test
public void test_PermanentImpl_Simple() {
    CardInfo cardInfo = CardRepository.instance.findCard("Balduvian Bears");
    Card newCard = cardInfo.getCard();
    Card permCard = CardUtil.getDefaultCardSideForBattlefield(currentGame, newCard);
    PermanentImpl permanent = new PermanentCard(permCard, playerA.getId(), currentGame);
    currentGame.addPermanent(permanent, 0);
    Object compressed = CompressUtil.compress(permanent);
    Assert.assertTrue("Must be zip", compressed instanceof ZippedObjectImpl);
    PermanentImpl uncompressed = (PermanentImpl) CompressUtil.decompress(compressed);
    Assert.assertEquals("Must be same", permanent.getName(), uncompressed.getName());
}
Also used : CardInfo(mage.cards.repository.CardInfo) PermanentImpl(mage.game.permanent.PermanentImpl) ZippedObjectImpl(mage.remote.traffic.ZippedObjectImpl) PermanentCard(mage.game.permanent.PermanentCard) Card(mage.cards.Card) PermanentCard(mage.game.permanent.PermanentCard) Test(org.junit.Test)

Example 20 with CardInfo

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

the class SerializationTest method test_Single_AllCards.

// WARNING, debug only, needs few minutes to execute, so run it manually
@Ignore
@Test
public void test_Single_AllCards() {
    // checking FULL cards list for serialization errors
    String filterSet = "";
    String filterCard = "";
    List<String> errorsList = new ArrayList<>();
    int checkedCount = 0;
    for (ExpansionSet set : Sets.getInstance().values()) {
        if (!filterSet.isEmpty() && !set.getCode().equals(filterSet)) {
            continue;
        }
        checkedCount++;
        System.out.printf("Checking set %d of %d (%s)%n", checkedCount, Sets.getInstance().size(), set.getName());
        for (ExpansionSet.SetCardInfo info : set.getSetCardInfo()) {
            if (!filterCard.isEmpty() && !info.getName().equals(filterCard)) {
                continue;
            }
            CardInfo cardInfo = CardRepository.instance.findCardsByClass(info.getCardClass().getCanonicalName()).stream().findFirst().orElse(null);
            try {
                processSingleCard(cardInfo);
            } catch (Throwable e) {
                System.out.println("Broken card: " + info.getName());
                // e.printStackTrace(); // search exception errors in the logs
                errorsList.add(info.getName());
            }
        }
    }
    if (!errorsList.isEmpty()) {
        Assert.fail("Found broken cards: " + errorsList.size() + "\n" + errorsList.stream().sorted().collect(Collectors.joining("\n")));
    }
}
Also used : ArrayList(java.util.ArrayList) CardInfo(mage.cards.repository.CardInfo) ExpansionSet(mage.cards.ExpansionSet) Ignore(org.junit.Ignore) Test(org.junit.Test)

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