Search in sources :

Example 36 with CardInfo

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

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

the class MtgjsonDeckImporter method addBoardToList.

private void addBoardToList(JsonArray board, List<mage.cards.decks.DeckCardInfo> list, String deckSet) {
    if (board == null || board.isEmpty()) {
        return;
    }
    board.forEach(arrayCard -> {
        JsonObject card = (JsonObject) arrayCard;
        String name = JsonUtil.getAsString(card, "name");
        String setCode = JsonUtil.getAsString(card, "setCode");
        if (setCode.isEmpty()) {
            setCode = deckSet;
        }
        int num = JsonUtil.getAsInt(card, "count");
        Optional<CardInfo> cardLookup = getCardLookup().lookupCardInfo(name, setCode);
        if (!cardLookup.isPresent()) {
            sbMessage.append("Could not find card: '").append(name).append("'\n");
        } else {
            CardInfo cardInfo = cardLookup.get();
            for (int i = 0; i < num; i++) {
                list.add(new DeckCardInfo(cardInfo.getName(), cardInfo.getCardNumber(), cardInfo.getSetCode()));
            }
        }
    });
}
Also used : DeckCardInfo(mage.cards.decks.DeckCardInfo) JsonObject(com.google.gson.JsonObject) DeckCardInfo(mage.cards.decks.DeckCardInfo) CardInfo(mage.cards.repository.CardInfo)

Example 38 with CardInfo

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

the class DekDeckImporter method readLine.

@Override
protected void readLine(String line, DeckCardLists deckList, FixedInfo fixedInfo) {
    if (line.isEmpty() || line.startsWith("#") || !line.contains("<Cards CatID")) {
        return;
    }
    try {
        // e.g. <Cards CatID="61202" Quantity="1" Sideboard="false" Name="Vildin-Pack Outcast" />
        Integer cardCount = Integer.parseInt(extractAttribute(line, "Quantity"));
        String cardName = extractAttribute(line, "Name");
        boolean isSideboard = "true".equals(extractAttribute(line, "Sideboard"));
        CardInfo cardInfo = CardRepository.instance.findPreferredCoreExpansionCard(cardName, true);
        if (cardInfo == null) {
            sbMessage.append("Could not find card: '").append(cardName).append("' at line ").append(lineCount).append('\n');
        } else {
            for (int i = 0; i < cardCount; i++) {
                DeckCardInfo deckCardInfo = new DeckCardInfo(cardInfo.getName(), cardInfo.getCardNumber(), cardInfo.getSetCode());
                if (isSideboard) {
                    deckList.getSideboard().add(deckCardInfo);
                } else {
                    deckList.getCards().add(deckCardInfo);
                }
            }
        }
    } catch (NumberFormatException nfe) {
        sbMessage.append("Invalid number: ").append(extractAttribute(line, "Quantity")).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 39 with CardInfo

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

the class Deck method createCard.

private static Card createCard(DeckCardInfo deckCardInfo, boolean mockCards, Map<String, CardInfo> cardInfoCache) {
    CardInfo cardInfo;
    if (cardInfoCache != null) {
        // from cache
        String key = String.format("%s_%s", deckCardInfo.getSetCode(), deckCardInfo.getCardNum());
        cardInfo = cardInfoCache.getOrDefault(key, null);
        if (cardInfo == null) {
            cardInfo = CardRepository.instance.findCard(deckCardInfo.getSetCode(), deckCardInfo.getCardNum());
            cardInfoCache.put(key, cardInfo);
        }
    } else {
        // from db
        cardInfo = CardRepository.instance.findCard(deckCardInfo.getSetCode(), deckCardInfo.getCardNum());
    }
    if (cardInfo == null) {
        return null;
    }
    if (mockCards) {
        return cardInfo.getMockCard();
    } else {
        return cardInfo.getCard();
    }
}
Also used : CardInfo(mage.cards.repository.CardInfo)

Example 40 with CardInfo

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

the class TxtDeckImporter method readLine.

@Override
protected void readLine(String line, DeckCardLists deckList, FixedInfo fixedInfo) {
    line = line.trim();
    // process comment:
    // skip or force to sideboard
    String commentString = line.toLowerCase(Locale.ENGLISH);
    if (commentString.startsWith("//")) {
        if (commentString.startsWith("//sideboard")) {
            sideboard = true;
        }
        // skip comment line
        return;
    }
    // remove inner card comments from text line: 2 Blinding Fog #some text (like deckstats format)
    int commentDelim = line.indexOf('#');
    if (commentDelim >= 0) {
        line = line.substring(0, commentDelim).trim();
    }
    // ignore all empty lines until real cards starts
    if (line.isEmpty() && !wasCardLines) {
        return;
    }
    // switch sideboard by empty line
    if (switchSideboardByEmptyLine && line.isEmpty()) {
        if (!sideboard) {
            sideboard = true;
        } else {
            sbMessage.append("Found empty line at ").append(lineCount).append(", but sideboard already used. Use //sideboard switcher OR use only one empty line to devide your cards.").append('\n');
        }
        // skip empty line
        return;
    }
    // single line sideboard card from deckstats.net
    // SB: 3 Carnage Tyrant
    boolean singleLineSideBoard = false;
    if (line.startsWith("SB:")) {
        line = line.replace("SB:", "").trim();
        singleLineSideBoard = true;
    }
    // changing tabs to blanks as delimiter
    line = line.replace("\t", " ");
    int delim = line.indexOf(' ');
    String lineNum = "";
    if (delim > 0) {
        lineNum = line.substring(0, delim).trim();
        if (IGNORE_NAMES.contains(lineNum)) {
            return;
        }
    }
    // amount
    int cardAmount = 0;
    boolean haveCardAmout = false;
    if (!lineNum.isEmpty()) {
        try {
            cardAmount = Integer.parseInt(lineNum.replaceAll("\\D+", ""));
            if ((cardAmount <= 0) || (cardAmount >= 100)) {
                sbMessage.append("Invalid number (too small or too big): ").append(lineNum).append(" at line ").append(lineCount).append('\n');
                return;
            }
            haveCardAmout = true;
        } catch (NumberFormatException nfe) {
        // card without amount
        }
    }
    String lineName;
    if (haveCardAmout) {
        lineName = line.substring(delim).trim();
    } else {
        lineName = line.trim();
        cardAmount = 1;
    }
    lineName = CardNameUtil.normalizeCardName(lineName);
    if (lineName.contains("//") && !lineName.contains(" // ")) {
        lineName = lineName.replace("//", " // ");
    }
    lineName = lineName.replaceFirst("(?<=[^/])\\s*/\\s*(?=[^/])", " // ");
    if (IGNORE_NAMES.contains(lineName)) {
        return;
    }
    wasCardLines = true;
    CardInfo cardInfo = CardRepository.instance.findPreferredCoreExpansionCard(lineName, true);
    if (cardInfo == null) {
        sbMessage.append("Could not find card: '").append(lineName).append("' at line ").append(lineCount).append('\n');
    } else {
        for (int i = 0; i < cardAmount; i++) {
            if (!sideboard && !singleLineSideBoard) {
                deckList.getCards().add(new DeckCardInfo(cardInfo.getName(), cardInfo.getCardNumber(), cardInfo.getSetCode()));
            } else {
                deckList.getSideboard().add(new DeckCardInfo(cardInfo.getName(), cardInfo.getCardNumber(), cardInfo.getSetCode()));
            }
        }
    }
}
Also used : DeckCardInfo(mage.cards.decks.DeckCardInfo) DeckCardInfo(mage.cards.decks.DeckCardInfo) 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