Search in sources :

Example 41 with CardInfo

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

the class Constructed method legalSets.

/**
 * Checks if the given card is legal in any of the given sets or as single card
 *
 * @param card - the card to check
 * @return Whether the card was printed in any of this format's sets.
 */
protected boolean legalSets(Card card) {
    // check if card is legal if taken from other set
    boolean legal = false;
    List<CardInfo> cardInfos = CardRepository.instance.findCards(card.getName());
    for (CardInfo cardInfo : cardInfos) {
        if (isSetAllowed(cardInfo.getSetCode())) {
            legal = true;
            break;
        }
    }
    // check if single card allows
    if (singleCards.contains(card.getName())) {
        legal = true;
    }
    if (!legal && !errorsListContainsGroup(card.getName())) {
        addError(DeckValidatorErrorType.WRONG_SET, card.getName(), "Invalid set: " + card.getExpansionSetCode(), true);
    }
    return legal;
}
Also used : CardInfo(mage.cards.repository.CardInfo)

Example 42 with CardInfo

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

the class Constructed method legalRarity.

/**
 * Checks if the given card is legal in any of the given rarities
 *
 * @param card - the card to check
 * @return Whether the card was printed at any of the given rarities.
 */
protected boolean legalRarity(Card card) {
    // check if card is legal if taken from other set
    boolean legal = false;
    List<CardInfo> cardInfos = CardRepository.instance.findCards(card.getName());
    for (CardInfo cardInfo : cardInfos) {
        if (rarities.contains(cardInfo.getRarity())) {
            legal = true;
            break;
        }
    }
    if (!legal && !errorsListContainsGroup(card.getName())) {
        addError(DeckValidatorErrorType.OTHER, card.getName(), "Invalid rarity: " + card.getRarity(), true);
    }
    return legal;
}
Also used : CardInfo(mage.cards.repository.CardInfo)

Example 43 with CardInfo

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

the class CustomTestCard method parseLine.

private void parseLine(String line) {
    if (parserState == ParserState.EXPECTED) {
        // just remember for future use
        expectedResults.add(line);
        return;
    }
    Matcher m = pattern.matcher(line);
    if (m.matches()) {
        String zone = m.group(1);
        String nickname = m.group(2);
        if (nickname.startsWith("Computer")) {
            List<Card> cards = null;
            List<PermanentCard> perms = null;
            Zone gameZone;
            if ("hand".equalsIgnoreCase(zone)) {
                gameZone = Zone.HAND;
                cards = getHandCards(getPlayer(nickname));
            } else if ("battlefield".equalsIgnoreCase(zone)) {
                gameZone = Zone.BATTLEFIELD;
                perms = getBattlefieldCards(getPlayer(nickname));
            } else if ("graveyard".equalsIgnoreCase(zone)) {
                gameZone = Zone.GRAVEYARD;
                cards = getGraveCards(getPlayer(nickname));
            } else if ("library".equalsIgnoreCase(zone)) {
                gameZone = Zone.LIBRARY;
                cards = getLibraryCards(getPlayer(nickname));
            } else if ("command".equalsIgnoreCase(zone)) {
                gameZone = Zone.COMMAND;
                cards = getCommandCards(getPlayer(nickname));
            } else if ("player".equalsIgnoreCase(zone)) {
                String command = m.group(3);
                if ("life".equals(command)) {
                    getCommands(getPlayer(nickname)).put(Zone.OUTSIDE, "life:" + m.group(4));
                }
                return;
            } else {
                // go parse next line
                return;
            }
            String cardName = m.group(3);
            Integer amount = Integer.parseInt(m.group(4));
            boolean tapped = m.group(5) != null && m.group(5).equals(":{tapped}");
            if (cardName.equals("clear")) {
                getCommands(getPlayer(nickname)).put(gameZone, "clear");
            } else {
                for (int i = 0; i < amount; i++) {
                    CardInfo cardInfo = CardRepository.instance.findCard(cardName);
                    Card newCard = cardInfo != null ? cardInfo.getCard() : null;
                    if (newCard != null) {
                        if (gameZone == Zone.BATTLEFIELD) {
                            Card permCard = CardUtil.getDefaultCardSideForBattlefield(currentGame, newCard);
                            PermanentCard p = new PermanentCard(permCard, null, currentGame);
                            p.setTapped(tapped);
                            perms.add(p);
                        } else {
                            cards.add(newCard);
                        }
                    } else {
                        logger.fatal("Couldn't find a card: " + cardName);
                        logger.fatal("line: " + line);
                    }
                }
            }
        } else {
            logger.warn("Unknown player: " + nickname);
        }
    } else {
        logger.warn("Init string wasn't parsed: " + line);
    }
}
Also used : Matcher(java.util.regex.Matcher) CardInfo(mage.cards.repository.CardInfo) Card(mage.cards.Card) PermanentCard(mage.game.permanent.PermanentCard) PermanentCard(mage.game.permanent.PermanentCard)

Example 44 with CardInfo

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

the class DeckTestUtils method buildRandomDeckAndInitCards.

public static DeckCardLists buildRandomDeckAndInitCards(String colors, boolean onlyBasicLands, String allowedSets) {
    Deck deck = buildRandomDeck(colors, onlyBasicLands, allowedSets);
    DeckCardLists deckList = new DeckCardLists();
    for (Card card : deck.getCards()) {
        CardInfo cardInfo = CardRepository.instance.findCard(card.getExpansionSetCode(), card.getCardNumber());
        if (cardInfo != null) {
            deckList.getCards().add(new DeckCardInfo(cardInfo.getName(), cardInfo.getCardNumber(), cardInfo.getSetCode()));
        }
    }
    return deckList;
}
Also used : DeckCardLists(mage.cards.decks.DeckCardLists) DeckCardInfo(mage.cards.decks.DeckCardInfo) Deck(mage.cards.decks.Deck) DeckCardInfo(mage.cards.decks.DeckCardInfo) CardInfo(mage.cards.repository.CardInfo) Card(mage.cards.Card)

Example 45 with CardInfo

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

the class SerializationTest method test_PermanentImpl_MarkedDamageInfo.

@Test
public void test_PermanentImpl_MarkedDamageInfo() {
    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);
    // mark damage from infected ability
    permanent.addAbility(InfectAbility.getInstance(), null, currentGame);
    permanent.markDamage(1, permanent.getId(), null, currentGame, false, false);
    // test compress (it uses default java serialization)
    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());
    // ensure that it was marked damage
    permanent.applyDamage(currentGame);
    Assert.assertEquals("Must get infected counter", 1, permanent.getCounters(currentGame).getCount(CounterType.M1M1));
}
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)

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