Search in sources :

Example 46 with CardInfo

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

the class SerializationTest method processSingleCard.

private void processSingleCard(String cardName) {
    CardInfo cardInfo = CardRepository.instance.findCard(cardName);
    processSingleCard(cardInfo);
}
Also used : CardInfo(mage.cards.repository.CardInfo)

Example 47 with CardInfo

use of mage.cards.repository.CardInfo 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 48 with CardInfo

use of mage.cards.repository.CardInfo 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 49 with CardInfo

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

the class MysteryBooster method createBooster.

@Override
public List<Card> createBooster() {
    if (this.possibleCardsPerBoosterSlot.isEmpty()) {
        // Generate the map only once
        this.populateBoosterSlotMap();
    }
    final List<Card> booster = new ArrayList<>(15);
    for (int slot = 1; slot < 16; ++slot) {
        final List<CardInfo> availableCards = this.possibleCardsPerBoosterSlot.get(slot);
        final int printSheetCardNumber = RandomUtil.nextInt(availableCards.size());
        final Card chosenCard = availableCards.get(printSheetCardNumber).getCard();
        booster.add(chosenCard);
    }
    return booster;
}
Also used : ArrayList(java.util.ArrayList) CardInfo(mage.cards.repository.CardInfo) Card(mage.cards.Card)

Example 50 with CardInfo

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

the class VerifyCardDataTest method test_showCardInfo.

@Test
public void test_showCardInfo() throws Exception {
    // debug only: show direct card info (takes it from class file, not from db repository)
    // can check multiple cards at once, example: name1;name2;name3
    String cardNames = "Spark Double";
    CardScanner.scan();
    Arrays.stream(cardNames.split(";")).forEach(cardName -> {
        cardName = cardName.trim();
        CardSetInfo testSet = new CardSetInfo(cardName, "test", "123", Rarity.COMMON);
        CardInfo cardInfo = CardRepository.instance.findCard(cardName);
        if (cardInfo == null) {
            Assert.fail("Can't find card name: " + cardName);
        }
        Card card = CardImpl.createCard(cardInfo.getClassName(), testSet);
        System.out.println();
        System.out.println(card.getName() + " " + card.getManaCost().getText());
        if (card instanceof SplitCard || card instanceof ModalDoubleFacesCard) {
            card.getAbilities().getRules(card.getName()).forEach(this::printAbilityText);
        } else {
            card.getRules().forEach(this::printAbilityText);
        }
    });
}
Also used : CardInfo(mage.cards.repository.CardInfo) RateCard(mage.game.draft.RateCard) MtgJsonCard(mage.verify.mtgjson.MtgJsonCard) 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