Search in sources :

Example 6 with DeckCardLists

use of mage.cards.decks.DeckCardLists in project mage by magefree.

the class JsonDeckImporter method importDeck.

/**
 * @param fileName              file to import
 * @param errorMessages     you can setup output messages to showup to user
 * @param saveAutoFixedFile do not supported for that format
 * @return decks list
 */
public DeckCardLists importDeck(String fileName, StringBuilder errorMessages, boolean saveAutoFixedFile) {
    File f = new File(fileName);
    DeckCardLists deckList = new DeckCardLists();
    if (!f.exists()) {
        logger.warn("Deckfile " + fileName + " not found.");
        return deckList;
    }
    sbMessage.setLength(0);
    try {
        try (FileReader reader = new FileReader(f)) {
            try {
                JsonObject json = JsonParser.parseReader(reader).getAsJsonObject();
                readJson(json, deckList);
                if (sbMessage.length() > 0) {
                    if (errorMessages != null) {
                        // normal output for user
                        errorMessages.append(sbMessage);
                    } else {
                        // fatal error
                        logger.fatal(sbMessage);
                    }
                }
            } catch (JsonParseException ex) {
                logger.fatal("Can't parse json-deck: " + fileName, ex);
            }
        } catch (Exception ex) {
            logger.fatal(null, ex);
        }
    } catch (Exception ex) {
        logger.fatal(null, ex);
    }
    return deckList;
}
Also used : DeckCardLists(mage.cards.decks.DeckCardLists) FileReader(java.io.FileReader) File(java.io.File)

Example 7 with DeckCardLists

use of mage.cards.decks.DeckCardLists in project mage by magefree.

the class JumpstartPoolGenerator method doGeneratePool.

private static Set<Card> doGeneratePool(List<JumpstartPack> packs) {
    try {
        DeckCardLists list = new DeckCardLists();
        SecureRandom random = new SecureRandom();
        for (int i = 0; i < 2; i++) {
            int index = random.nextInt(packs.size());
            list.getCards().addAll(packs.get(index).getCards());
        }
        return Deck.load(list, false, false).getCards();
    } catch (GameException e) {
        throw new RuntimeException(e);
    }
}
Also used : DeckCardLists(mage.cards.decks.DeckCardLists) SecureRandom(java.security.SecureRandom) GameException(mage.game.GameException)

Example 8 with DeckCardLists

use of mage.cards.decks.DeckCardLists in project mage by magefree.

the class MtgaImporterTest method testImport.

@Test
public void testImport() {
    MtgaImporter importer = new MtgaImporter() {

        @Override
        public CardLookup getCardLookup() {
            return LOOKUP;
        }
    };
    StringBuilder errors = new StringBuilder();
    DeckCardLists deck = importer.importDeck(Paths.get("src", "test", "data", "importer", "testdeck.mtga").toString(), errors, false);
    TestDeckChecker.checker().addMain("Niv-Mizzet Reborn", 1).addMain("Teferi, Time Raveler", 1).addMain("Dovin's Veto", 1).addMain("Knight of Autumn", 1).addMain("Expansion // Explosion", 1).addMain("Forest", 1).addMain("Teferi, Hero of Dominaria", 1).addSide("Unmoored Ego", 1).addSide("Beacon Bolt", 1).verify(deck, 7, 2);
    assertEquals("", errors.toString());
}
Also used : DeckCardLists(mage.cards.decks.DeckCardLists) Test(org.junit.Test)

Example 9 with DeckCardLists

use of mage.cards.decks.DeckCardLists in project mage by magefree.

the class MwsDeckImportTest method testImport.

@Test
public void testImport() {
    MWSDeckImporter importer = new MWSDeckImporter() {

        @Override
        public CardLookup getCardLookup() {
            return LOOKUP;
        }
    };
    StringBuilder errors = new StringBuilder();
    DeckCardLists deck = importer.importDeck(Paths.get("src", "test", "data", "importer", "testdeck.mwDeck").toString(), errors, false);
    TestDeckChecker.checker().addMain("Mutavault", 4).addMain("Plains", 18).addMain("Daring Skyjek", 2).addMain("Azorius Arrester", 4).addMain("Banisher Priest", 4).addMain("Boros Elite", 4).addMain("Dryad Militant", 4).addMain("Imposing Sovereign", 4).addMain("Precinct Captain", 4).addMain("Soldier of the Pantheon", 4).addMain("Spear of Heliod", 3).addMain("Rootborn Defenses", 1).addMain("Brave the Elements", 4).addSide("Wear/Tear", 1).addSide("Glare of Heresy", 2).addSide("Fiendslayer Paladin", 3).addSide("Riot Control", 3).addSide("Ajani, Caller of the Pride", 3).addSide("Rootborn Defenses", 3).verify(deck, 60, 15);
    assertEquals("", errors.toString());
}
Also used : DeckCardLists(mage.cards.decks.DeckCardLists) Test(org.junit.Test)

Example 10 with DeckCardLists

use of mage.cards.decks.DeckCardLists in project mage by magefree.

the class MtgOnlineDeckExporterTest method writeDeck.

@Test
public void writeDeck() throws IOException {
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    DeckCardLists deck = new DeckCardLists();
    deck.getCards().add(new DeckCardInfo("Forest", "1", "RNA", 2));
    deck.getCards().add(new DeckCardInfo("Plains", "2", "RNA", 3));
    // must combine
    deck.getCards().add(new DeckCardInfo("Plains", "2", "RNA", 5));
    deck.getCards().add(new DeckCardInfo("Mountain", "3", "RNA", 1));
    deck.getSideboard().add(new DeckCardInfo("Island", "1", "RNA", 2));
    // must combine
    deck.getSideboard().add(new DeckCardInfo("Island", "1", "RNA", 5));
    deck.getSideboard().add(new DeckCardInfo("Mountain", "2", "RNA", 3));
    DeckExporter exporter = new MtgOnlineDeckExporter();
    exporter.writeDeck(baos, deck);
    assertEquals("2 Forest" + System.lineSeparator() + "8 Plains" + System.lineSeparator() + "1 Mountain" + System.lineSeparator() + System.lineSeparator() + "7 Island" + System.lineSeparator() + "3 Mountain" + System.lineSeparator(), baos.toString());
}
Also used : DeckCardLists(mage.cards.decks.DeckCardLists) DeckCardInfo(mage.cards.decks.DeckCardInfo) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Test(org.junit.Test)

Aggregations

DeckCardLists (mage.cards.decks.DeckCardLists)23 Test (org.junit.Test)14 DeckCardInfo (mage.cards.decks.DeckCardInfo)5 File (java.io.File)4 ByteArrayOutputStream (java.io.ByteArrayOutputStream)3 Deck (mage.cards.decks.Deck)3 MatchOptions (mage.game.match.MatchOptions)3 IOException (java.io.IOException)2 ArrayList (java.util.ArrayList)2 CardInfo (mage.cards.repository.CardInfo)2 Ignore (org.junit.Ignore)2 Document (org.w3c.dom.Document)2 Node (org.w3c.dom.Node)2 java.awt (java.awt)1 BufferedImage (java.awt.image.BufferedImage)1 FileReader (java.io.FileReader)1 BasicFileAttributes (java.nio.file.attribute.BasicFileAttributes)1 SecureRandom (java.security.SecureRandom)1 List (java.util.List)1 Scanner (java.util.Scanner)1