Search in sources :

Example 16 with CardCriteria

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

the class AetherRevoltCollator method generateBoosterMap.

@Override
protected void generateBoosterMap() {
    super.generateBoosterMap();
    CardRepository.instance.findCards(new CardCriteria().setCodes("MPS").minCardNumber(31)).stream().forEach(cardInfo -> inBoosterMap.put("MPS_" + cardInfo.getCardNumber(), cardInfo));
}
Also used : CardCriteria(mage.cards.repository.CardCriteria)

Example 17 with CardCriteria

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

the class DraftLogImporter method readLine.

@Override
protected void readLine(String line, DeckCardLists deckList, FixedInfo fixedInfo) {
    Matcher setMatcher = SET_PATTERN.matcher(line);
    if (setMatcher.matches()) {
        currentSet = setMatcher.group(1);
        return;
    }
    Matcher pickMatcher = PICK_PATTERN.matcher(line);
    if (pickMatcher.matches()) {
        String name = pickMatcher.group(1);
        List<CardInfo> cards = getCardLookup().lookupCardInfo(new CardCriteria().setCodes(currentSet).name(name));
        CardInfo card = null;
        if (!cards.isEmpty()) {
            card = cards.get(0);
        } else {
            card = getCardLookup().lookupCardInfo(name).orElse(null);
        }
        if (card != null) {
            deckList.getCards().add(new DeckCardInfo(card.getName(), card.getCardNumber(), card.getSetCode()));
        } else {
            sbMessage.append("couldn't find: \"").append(name).append("\"\n");
        }
    }
}
Also used : DeckCardInfo(mage.cards.decks.DeckCardInfo) Matcher(java.util.regex.Matcher) CardCriteria(mage.cards.repository.CardCriteria) DeckCardInfo(mage.cards.decks.DeckCardInfo) CardInfo(mage.cards.repository.CardInfo)

Example 18 with CardCriteria

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

the class DraftFromSpellbookEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player player = game.getPlayer(source.getControllerId());
    if (player == null) {
        return false;
    }
    Set<String> toSelect = new HashSet<>();
    while (toSelect.size() < 3) {
        toSelect.add(RandomUtil.randomFromCollection(spellbook));
    }
    Choice choice = new ChoiceImpl(true, ChoiceHintType.CARD);
    choice.setMessage("Choose a card to draft");
    choice.setChoices(toSelect);
    player.choose(outcome, choice, game);
    String cardName = choice.getChoice();
    if (cardName == null) {
        return false;
    }
    CardInfo cardInfo = CardRepository.instance.findCards(new CardCriteria().nameExact(cardName)).stream().findFirst().orElse(null);
    if (cardInfo == null) {
        return false;
    }
    Set<Card> cards = new HashSet<>();
    cards.add(cardInfo.getCard());
    game.loadCards(cards, player.getId());
    player.moveCards(cards, Zone.HAND, source, game);
    return true;
}
Also used : Player(mage.players.Player) Choice(mage.choices.Choice) CardCriteria(mage.cards.repository.CardCriteria) ChoiceImpl(mage.choices.ChoiceImpl) CardInfo(mage.cards.repository.CardInfo) HashSet(java.util.HashSet) Card(mage.cards.Card)

Example 19 with CardCriteria

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

the class Sets method generateRandomCardPool.

public static List<Card> generateRandomCardPool(int cardsCount, List<ColoredManaSymbol> allowedColors, boolean onlyBasicLands, List<String> allowedSets) {
    CardCriteria criteria = new CardCriteria();
    if (onlyBasicLands) {
        // only lands
        criteria.rarities(Rarity.LAND);
        // basic lands is colorless
        criteria.colorless(true);
    } else {
        // any card, but not basic lands
        criteria.notTypes(CardType.LAND);
        // clear colors
        criteria.white(false);
        criteria.blue(false);
        criteria.black(false);
        criteria.red(false);
        criteria.green(false);
        // colorless is not allowed for gen
        criteria.colorless(false);
    }
    if (allowedSets != null && allowedSets.size() > 0) {
        for (String code : allowedSets) {
            criteria.setCodes(code);
        }
    }
    FilterMana manaNeed = new FilterMana();
    for (ColoredManaSymbol color : allowedColors) {
        switch(color) {
            case W:
                manaNeed.setWhite(true);
                criteria.white(true);
                break;
            case U:
                manaNeed.setBlue(true);
                criteria.blue(true);
                break;
            case B:
                manaNeed.setBlack(true);
                criteria.black(true);
                break;
            case R:
                manaNeed.setRed(true);
                criteria.red(true);
                break;
            case G:
                manaNeed.setGreen(true);
                criteria.green(true);
                break;
        }
    }
    List<CardInfo> cards = CardRepository.instance.findCards(criteria);
    if (cards.isEmpty()) {
        throw new IllegalStateException("Can't find cards for chosen colors to generate deck: " + allowedColors);
    }
    int count = 0;
    int tries = 0;
    List<Card> cardPool = new ArrayList<>();
    while (count < cardsCount) {
        CardInfo cardInfo = cards.get(RandomUtil.nextInt(cards.size()));
        Card card = cardInfo != null ? cardInfo.getCard() : null;
        if (card != null) {
            FilterMana manaCard = card.getColorIdentity();
            boolean cardManaOK = true;
            if (onlyBasicLands) {
                // Assert.assertEquals("only basic lands allow, but found " + card.getName(), 1, card.getMana().size());
                for (Mana manaLand : card.getMana()) {
                    if (manaLand.getWhite() > 0 && !manaNeed.isWhite()) {
                        cardManaOK = false;
                    }
                    if (manaLand.getBlue() > 0 && !manaNeed.isBlue()) {
                        cardManaOK = false;
                    }
                    if (manaLand.getBlack() > 0 && !manaNeed.isBlack()) {
                        cardManaOK = false;
                    }
                    if (manaLand.getRed() > 0 && !manaNeed.isRed()) {
                        cardManaOK = false;
                    }
                    if (manaLand.getGreen() > 0 && !manaNeed.isGreen()) {
                        cardManaOK = false;
                    }
                    if (manaLand.getColorless() > 0) {
                        cardManaOK = false;
                    }
                // ignore colorless land (wastes)
                }
            } else {
                // discard any card that have not needed color
                if (manaCard.isWhite() && !manaNeed.isWhite()) {
                    cardManaOK = false;
                }
                if (manaCard.isBlue() && !manaNeed.isBlue()) {
                    cardManaOK = false;
                }
                if (manaCard.isBlack() && !manaNeed.isBlack()) {
                    cardManaOK = false;
                }
                if (manaCard.isRed() && !manaNeed.isRed()) {
                    cardManaOK = false;
                }
                if (manaCard.isGreen() && !manaNeed.isGreen()) {
                    cardManaOK = false;
                }
            }
            if (cardManaOK) {
                cardPool.add(card);
                count++;
            }
        }
        tries++;
        if (tries > 4096) {
            // to avoid infinite loop
            throw new IllegalStateException("Not enough cards for chosen colors to generate deck: " + allowedColors);
        }
    }
    return cardPool;
}
Also used : FilterMana(mage.filter.FilterMana) Mana(mage.Mana) FilterMana(mage.filter.FilterMana) CardCriteria(mage.cards.repository.CardCriteria) CardInfo(mage.cards.repository.CardInfo) ColoredManaSymbol(mage.constants.ColoredManaSymbol)

Example 20 with CardCriteria

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

the class MysteryBooster method populateBoosterSpecialSlot.

/**
 * Populate the special slot. Defined as protected to allow overwriting this if the playtest cards
 * from the convention edition are ever implemented.
 */
protected void populateBoosterSpecialSlot() {
    CardCriteria criteria = new CardCriteria();
    criteria.setCodes("FMB1");
    this.possibleCardsPerBoosterSlot.get(15).addAll(CardRepository.instance.findCards(criteria));
}
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