Search in sources :

Example 31 with CardInfo

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

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

the class Deck method createCardNotFoundGameException.

private static GameException createCardNotFoundGameException(DeckCardInfo deckCardInfo, String deckName) {
    // Try WORKAROUND for Card DB error: Try to read a card that does exist
    CardInfo cardInfo = CardRepository.instance.findCard("Silvercoat Lion");
    if (cardInfo == null) {
        // DB seems to have a problem - try to restart the DB
        CardRepository.instance.closeDB();
        CardRepository.instance.openDB();
        cardInfo = CardRepository.instance.findCard("Silvercoat Lion");
        Logger.getLogger(Deck.class).error("Tried to restart the DB: " + (cardInfo == null ? "not successful" : "successful"));
    }
    return new GameException("Card not found - " + deckCardInfo.getCardName() + " - " + deckCardInfo.getSetCode() + "/" + deckCardInfo.getCardNum() + " for deck - " + deckName + '\n' + "Possible reason is, that you use cards in your deck, that are only supported in newer versions of the server.\n" + "So it can help to use the same card from another set, that's already supported from this server.");
}
Also used : CardInfo(mage.cards.repository.CardInfo) GameException(mage.game.GameException)

Example 33 with CardInfo

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

the class XmageInfoDeckExporter method writeDeck.

@Override
public void writeDeck(PrintWriter out, DeckCardLists deck) {
    List<DeckCardInfo> deckMain = new ArrayList<>();
    List<DeckCardInfo> deckSideboard = new ArrayList<>();
    Map<String, Integer> amount = new HashMap<>();
    // Info
    if (deck.getName() != null && !deck.getName().isEmpty()) {
        out.println("NAME:" + deck.getName());
    }
    // Author
    if (deck.getAuthor() != null && !deck.getAuthor().isEmpty()) {
        out.println("AUTHOR:" + deck.getAuthor());
    }
    // Main
    for (DeckCardInfo card : deck.getCards()) {
        String code = "M@" + card.getCardKey();
        int curAmount = amount.getOrDefault(code, 0);
        if (curAmount == 0) {
            deckMain.add(card);
        }
        amount.put(code, curAmount + card.getQuantity());
    }
    // Sideboard
    for (DeckCardInfo card : deck.getSideboard()) {
        String code = "S@" + card.getCardKey();
        int curAmount = amount.getOrDefault(code, 0);
        if (curAmount == 0) {
            deckSideboard.add(card);
        }
        amount.put(code, curAmount + card.getQuantity());
    }
    // Cards print
    for (DeckCardInfo card : deckMain) {
        CardInfo cardInfo = CardRepository.instance.findCard(card.getCardName());
        if (cardInfo == null) {
            out.printf("%d [%s:%s] %s%n\n", amount.get("M@" + card.getCardKey()), card.getSetCode(), card.getCardNum(), card.getCardName());
        } else {
            out.printf("%d [%s:%s] %s ;; %s ;; %s ;; %d %n", amount.get("M@" + card.getCardKey()), card.getSetCode(), card.getCardNum(), card.getCardName(), cardInfo.getColor().getDescription(), cardInfo.getTypes().toString(), cardInfo.getManaValue());
        }
    }
    for (DeckCardInfo card : deckSideboard) {
        CardInfo cardInfo = CardRepository.instance.findCard(card.getCardName());
        if (cardInfo == null) {
            out.printf("SB: %d [%s:%s] %s%n\n", amount.get("S@" + card.getCardKey()), card.getSetCode(), card.getCardNum(), card.getCardName());
        } else {
            out.printf("SB: %d [%s:%s] %s ;; %s ;; %s ;; %d %n", amount.get("S@" + card.getCardKey()), card.getSetCode(), card.getCardNum(), card.getCardName(), cardInfo.getColor().getDescription(), cardInfo.getTypes().toString(), cardInfo.getManaValue());
        }
    }
    // layout print
    if (deck.getCardLayout() != null) {
        out.print("LAYOUT MAIN:");
        writeCardLayout(out, deck.getCardLayout());
        out.println("");
        out.print("LAYOUT SIDEBOARD:");
        writeCardLayout(out, deck.getSideboardLayout());
        out.println("");
    }
}
Also used : DeckCardInfo(mage.cards.decks.DeckCardInfo) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) DeckCardInfo(mage.cards.decks.DeckCardInfo) CardInfo(mage.cards.repository.CardInfo)

Example 34 with CardInfo

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

the class DecDeckImporter 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 lineName = line.substring(delim).trim();
    try {
        int num = Integer.parseInt(lineNum);
        Optional<CardInfo> cardLookup = getCardLookup().lookupCardInfo(lineName);
        if (!cardLookup.isPresent()) {
            sbMessage.append("Could not find card: '").append(lineName).append("' at line ").append(lineCount).append('\n');
        } else {
            CardInfo cardInfo = cardLookup.get();
            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) DeckCardInfo(mage.cards.decks.DeckCardInfo) CardInfo(mage.cards.repository.CardInfo)

Example 35 with CardInfo

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

the class ExpansionSet method tryBooster.

public List<Card> tryBooster() {
    List<Card> booster = new ArrayList<>();
    if (!hasBoosters) {
        return booster;
    }
    if (numBoosterLands > 0) {
        List<CardInfo> specialLands = getSpecialCardsByRarity(Rarity.LAND);
        List<CardInfo> basicLands = getCardsByRarity(Rarity.LAND);
        for (int i = 0; i < numBoosterLands; i++) {
            if (ratioBoosterSpecialLand > 0 && RandomUtil.nextInt(ratioBoosterSpecialLand) < ratioBoosterSpecialLandNumerator) {
                addToBooster(booster, specialLands);
            } else {
                addToBooster(booster, basicLands);
            }
        }
    }
    int numCommonsToGenerate = numBoosterCommon;
    int numSpecialToGenerate = numBoosterSpecial;
    if (ratioBoosterSpecialCommon > 0 && RandomUtil.nextInt(ratioBoosterSpecialCommon) < 1) {
        --numCommonsToGenerate;
        ++numSpecialToGenerate;
    }
    List<CardInfo> commons = getCardsByRarity(Rarity.COMMON);
    for (int i = 0; i < numCommonsToGenerate; i++) {
        addToBooster(booster, commons);
    }
    int numUncommonsToGenerate = numBoosterUncommon;
    int numRaresToGenerate = numBoosterRare;
    if (ratioBoosterSpecialRare > 0) {
        Rarity specialRarity = Rarity.UNCOMMON;
        if (ratioBoosterSpecialRare * RandomUtil.nextDouble() <= 1) {
            specialRarity = (checkSpecialMythic() ? Rarity.MYTHIC : Rarity.RARE);
            --numRaresToGenerate;
        } else {
            --numUncommonsToGenerate;
        }
        addToBooster(booster, getSpecialCardsByRarity(specialRarity));
    }
    List<CardInfo> uncommons = getCardsByRarity(Rarity.UNCOMMON);
    for (int i = 0; i < numUncommonsToGenerate; i++) {
        addToBooster(booster, uncommons);
    }
    if (numRaresToGenerate > 0) {
        List<CardInfo> rares = getCardsByRarity(Rarity.RARE);
        List<CardInfo> mythics = getCardsByRarity(Rarity.MYTHIC);
        for (int i = 0; i < numRaresToGenerate; i++) {
            addToBooster(booster, checkMythic() ? mythics : rares);
        }
    }
    if (numBoosterDoubleFaced > 0) {
        addDoubleFace(booster);
    }
    if (numSpecialToGenerate > 0) {
        addSpecialCards(booster, numSpecialToGenerate);
    }
    return booster;
}
Also used : Rarity(mage.constants.Rarity) CardInfo(mage.cards.repository.CardInfo)

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