Search in sources :

Example 11 with CardCriteria

use of mage.cards.repository.CardCriteria 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 12 with CardCriteria

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

the class FateReforgedCollator method findSpecialCardsByRarity.

@Override
protected List<CardInfo> findSpecialCardsByRarity(Rarity rarity) {
    CardCriteria criteria = new CardCriteria();
    criteria.rarities(rarity).types(CardType.LAND);
    if (rarity == Rarity.RARE) {
        // fetchlands
        criteria.setCodes("KTK");
    } else {
        // gainlands
        criteria.setCodes(this.code);
    }
    return CardRepository.instance.findCards(criteria);
}
Also used : CardCriteria(mage.cards.repository.CardCriteria)

Example 13 with CardCriteria

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

the class MWSDeckImporter method readLine.

@Override
protected void readLine(String line, DeckCardLists deckList, FixedInfo fixedInfo) {
    if (line.isEmpty() || line.startsWith("//")) {
        return;
    }
    boolean sideboard = false;
    if (line.startsWith("SB:")) {
        line = line.substring(3).trim();
        sideboard = true;
    }
    int delim = line.indexOf(' ');
    String lineNum = line.substring(0, delim).trim();
    String setCode = "";
    if (line.indexOf('[') != -1) {
        int setStart = line.indexOf('[') + 1;
        int setEnd = line.indexOf(']');
        setCode = line.substring(setStart, setEnd).trim();
        delim = setEnd;
    }
    String lineName = line.substring(delim + 1).trim();
    try {
        int num = Integer.parseInt(lineNum);
        CardInfo cardInfo = null;
        if (!setCode.isEmpty()) {
            CardCriteria criteria = new CardCriteria();
            criteria.name(lineName);
            criteria.setCodes(setCode);
            List<CardInfo> cards = getCardLookup().lookupCardInfo(criteria);
            if (!cards.isEmpty()) {
                cardInfo = cards.get(RandomUtil.nextInt(cards.size()));
            }
        }
        if (cardInfo == null) {
            cardInfo = getCardLookup().lookupCardInfo(lineName).orElse(null);
        }
        if (cardInfo == null) {
            sbMessage.append("Could not find card: '").append(lineName).append("' at line ").append(lineCount).append('\n');
        } else {
            for (int i = 0; i < num; i++) {
                if (!sideboard) {
                    deckList.getCards().add(new DeckCardInfo(cardInfo.getName(), cardInfo.getCardNumber(), cardInfo.getSetCode()));
                } else {
                    deckList.getSideboard().add(new DeckCardInfo(cardInfo.getName(), cardInfo.getCardNumber(), cardInfo.getSetCode()));
                }
            }
        }
    } catch (NumberFormatException nfe) {
        sbMessage.append("Invalid number: ").append(lineNum).append(" at line ").append(lineCount).append('\n');
    }
}
Also used : DeckCardInfo(mage.cards.decks.DeckCardInfo) CardCriteria(mage.cards.repository.CardCriteria) DeckCardInfo(mage.cards.decks.DeckCardInfo) CardInfo(mage.cards.repository.CardInfo)

Example 14 with CardCriteria

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

the class MomirEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    int value = source.getManaCostsToPay().getX();
    if (game.isSimulation()) {
        // Create dummy token to prevent multiple DB find cards what causes H2 java.lang.IllegalStateException if AI cancels calculation because of time out
        Token token = new CreatureToken(value, value + 1);
        token.putOntoBattlefield(1, game, source, source.getControllerId(), false, false);
        return true;
    }
    // should this be random across card names
    CardCriteria criteria = new CardCriteria().types(CardType.CREATURE).manaValue(value);
    List<CardInfo> options = CardRepository.instance.findCards(criteria);
    if (options == null || options.isEmpty()) {
        game.informPlayers("No random creature card with mana value of " + value + " was found.");
        return false;
    }
    // search for a random non custom set creature
    EmptyToken token = null;
    while (!options.isEmpty()) {
        int index = RandomUtil.nextInt(options.size());
        ExpansionSet expansionSet = Sets.findSet(options.get(index).getSetCode());
        if (expansionSet == null || !expansionSet.getSetType().isEternalLegal()) {
            options.remove(index);
        } else {
            Card card = options.get(index).getCard();
            if (card != null) {
                token = new EmptyToken();
                CardUtil.copyTo(token).from(card, game);
                break;
            } else {
                options.remove(index);
            }
        }
    }
    if (token != null) {
        token.putOntoBattlefield(1, game, source, source.getControllerId(), false, false);
        return true;
    }
    return false;
}
Also used : CardCriteria(mage.cards.repository.CardCriteria) CardInfo(mage.cards.repository.CardInfo) EmptyToken(mage.game.permanent.token.EmptyToken) CreatureToken(mage.game.permanent.token.custom.CreatureToken) Token(mage.game.permanent.token.Token) ExpansionSet(mage.cards.ExpansionSet) CreatureToken(mage.game.permanent.token.custom.CreatureToken) EmptyToken(mage.game.permanent.token.EmptyToken) Card(mage.cards.Card)

Example 15 with CardCriteria

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

the class ExpansionSet method generateBoosterMap.

protected void generateBoosterMap() {
    CardRepository.instance.findCards(new CardCriteria().setCodes(code)).stream().forEach(cardInfo -> inBoosterMap.put(cardInfo.getCardNumber(), cardInfo));
    // get basic lands from parent set if this set doesn't have them
    if (!hasBasicLands && parentSet != null) {
        String parentCode = parentSet.code;
        CardRepository.instance.findCards(new CardCriteria().setCodes(parentCode).rarities(Rarity.LAND)).stream().forEach(cardInfo -> inBoosterMap.put(parentCode + "_" + cardInfo.getCardNumber(), cardInfo));
    }
}
Also used : CardCriteria(mage.cards.repository.CardCriteria)

Aggregations

CardCriteria (mage.cards.repository.CardCriteria)25 CardInfo (mage.cards.repository.CardInfo)14 Card (mage.cards.Card)6 DeckCardInfo (mage.cards.decks.DeckCardInfo)3 Player (mage.players.Player)3 java.util (java.util)2 HashSet (java.util.HashSet)2 Matcher (java.util.regex.Matcher)2 Choice (mage.choices.Choice)2 ChoiceImpl (mage.choices.ChoiceImpl)2 NaturalOrderCardNumberComparator (mage.client.util.NaturalOrderCardNumberComparator)2 ColoredManaSymbol (mage.constants.ColoredManaSymbol)2 Token (mage.game.permanent.token.Token)2 File (java.io.File)1 Constructor (java.lang.reflect.Constructor)1 DateFormat (java.text.DateFormat)1 SimpleDateFormat (java.text.SimpleDateFormat)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 TimeUnit (java.util.concurrent.TimeUnit)1