Search in sources :

Example 66 with MagicCard

use of org.magic.api.beans.MagicCard in project MtgDesktopCompanion by nicho92.

the class EternalizeActions method actionPerformed.

@Override
public void actionPerformed(ActionEvent e) {
    try {
        MagicCard tok = GamePanelGUI.getInstance().getTokenGenerator().generateTokenFor(card.getMagicCard());
        DisplayableCard dc = new DisplayableCard(tok, MTGControler.getInstance().getCardsDimension(), true);
        dc.setMagicCard(tok);
        GamePanelGUI.getInstance().getPlayer().exileCardFromGraveyard(card.getMagicCard());
        GamePanelGUI.getInstance().getPanelGrave().remove(card);
        GamePanelGUI.getInstance().getPanelBattleField().addComponent(dc);
        GamePanelGUI.getInstance().getPanelBattleField().revalidate();
        GamePanelGUI.getInstance().getPanelBattleField().repaint();
        GamePanelGUI.getInstance().getPanelGrave().postTreatment(card);
        GamePanelGUI.getInstance().getPlayer().playToken(tok);
        GamePanelGUI.getInstance().getPlayer().logAction("Embalm " + card);
    } catch (Exception ex) {
        logger.error(ex);
    }
}
Also used : MagicCard(org.magic.api.beans.MagicCard) DisplayableCard(org.magic.game.gui.components.DisplayableCard)

Example 67 with MagicCard

use of org.magic.api.beans.MagicCard in project MtgDesktopCompanion by nicho92.

the class Player method discardCardFromLibrary.

public List<MagicCard> discardCardFromLibrary(int parseInt) {
    List<MagicCard> ret = new ArrayList<>();
    for (int i = 0; i < parseInt; i++) {
        MagicCard mc = library.getCards().get(i);
        ret.add(mc);
        graveyard.add(mc);
        library.getCards().remove(i);
    }
    logAction("Discard " + parseInt + " cards from library");
    return ret;
}
Also used : MagicCard(org.magic.api.beans.MagicCard) ArrayList(java.util.ArrayList)

Example 68 with MagicCard

use of org.magic.api.beans.MagicCard in project MtgDesktopCompanion by nicho92.

the class JSONHttpServer method start.

@Override
public void start() throws IOException {
    port(getInt("SERVER-PORT"));
    exception(Exception.class, new ExceptionHandler<Exception>() {

        @Override
        public void handle(Exception exception, Request req, Response res) {
            res.status(500);
            res.body("{\"error\":\"" + exception + "\"}");
        }
    });
    notFound((req, res) -> {
        res.status(404);
        return "{\"error\":\"not found\"}";
    });
    before("/*", (request, response) -> {
        response.type(getString("MIME"));
        logger.info("Received api call from " + request.ip());
    });
    get("/cards/search/:att/:val", getString("MIME"), (request, response) -> {
        return MTGControler.getInstance().getEnabledProviders().searchCardByCriteria(request.params(":att"), request.params(":val"), null, false);
    }, transformer);
    post("/cards/move/:from/:to/:id", getString("MIME"), (request, response) -> {
        MagicCollection from = new MagicCollection(request.params(":from"));
        MagicCollection to = new MagicCollection(request.params(":to"));
        MagicCard mc = MTGControler.getInstance().getEnabledProviders().getCardById(request.params(":id"));
        MTGControler.getInstance().getEnabledDAO().removeCard(mc, from);
        MTGControler.getInstance().getEnabledDAO().saveCard(mc, to);
        return "OK";
    }, transformer);
    get("/cards/list/:col/:idEd", getString("MIME"), (request, response) -> {
        MagicCollection col = new MagicCollection(request.params(":col"));
        MagicEdition ed = new MagicEdition();
        ed.setId(request.params(":idEd"));
        ed.setSet(request.params(":idEd"));
        return MTGControler.getInstance().getEnabledDAO().listCardsFromCollection(col, ed);
    }, transformer);
    get("/cards/:id", getString("MIME"), (request, response) -> {
        return MTGControler.getInstance().getEnabledProviders().getCardById(request.params(":id"));
    }, transformer);
    get("/collections/list", getString("MIME"), (request, response) -> {
        return MTGControler.getInstance().getEnabledDAO().getCollections();
    }, transformer);
    get("/collections/:name", getString("MIME"), (request, response) -> {
        return MTGControler.getInstance().getEnabledDAO().getCollection(request.params(":name"));
    }, transformer);
    get("/editions/list", getString("MIME"), (request, response) -> {
        return MTGControler.getInstance().getEnabledProviders().loadEditions();
    }, transformer);
    get("/editions/:idSet", getString("MIME"), (request, response) -> {
        return MTGControler.getInstance().getEnabledProviders().getSetById(request.params(":idSet"));
    }, transformer);
    get("/editions/list/:colName", getString("MIME"), (request, response) -> {
        List<MagicEdition> eds = new ArrayList<>();
        List<String> list = MTGControler.getInstance().getEnabledDAO().getEditionsIDFromCollection(new MagicCollection(request.params(":colName")));
        for (String s : list) eds.add(MTGControler.getInstance().getEnabledProviders().getSetById(s));
        Collections.sort(eds);
        return eds;
    }, transformer);
    get("/prices/:idSet/:name", getString("MIME"), (request, response) -> {
        MagicCard mc = MTGControler.getInstance().getEnabledProviders().searchCardByCriteria("name", request.params(":name"), null, false).get(0);
        MagicEdition ed = MTGControler.getInstance().getEnabledProviders().getSetById(request.params(":idSet"));
        List<MagicPrice> pricesret = new ArrayList<>();
        for (MTGPricesProvider prices : MTGControler.getInstance().getEnabledPricers()) pricesret.addAll(prices.getPrice(ed, mc));
        return pricesret;
    }, transformer);
    if (getBoolean("ENABLE_GZIP")) {
        after((request, response) -> {
            response.header("Content-Encoding", "gzip");
        });
    }
    Spark.init();
    logger.info("Server start on port " + getString("SERVER-PORT"));
    running = true;
}
Also used : MTGPricesProvider(org.magic.api.interfaces.MTGPricesProvider) MagicPrice(org.magic.api.beans.MagicPrice) Request(spark.Request) MagicEdition(org.magic.api.beans.MagicEdition) ArrayList(java.util.ArrayList) IOException(java.io.IOException) Response(spark.Response) MagicCard(org.magic.api.beans.MagicCard) MagicCollection(org.magic.api.beans.MagicCollection)

Example 69 with MagicCard

use of org.magic.api.beans.MagicCard in project MtgDesktopCompanion by nicho92.

the class CardsProviderTests method createCards.

@Before
public void createCards() {
    mc = new MagicCard();
    mc.setName("Black Lotus");
    mc.setLayout("normal");
    mc.setCost("{0}");
    mc.setCmc(0);
    mc.getTypes().add("Artifact");
    mc.setReserved(true);
    mc.setText("{T}, Sacrifice Black Lotus: Add three mana of any one color to your mana pool.");
    mc.setRarity("Rare");
    mc.setArtist("Christopher Rush");
    mc.setNumber("232");
    mc.setMciNumber("232");
    ed = new MagicEdition();
    ed.setId("lea");
    ed.setSet("Limited Edition Alpha");
    ed.setBorder("Black");
    ed.setRarity("Rare");
    ed.setArtist("Christopher Rush");
    ed.setMultiverse_id("3");
    ed.setNumber(mc.getNumber());
    mc.getEditions().add(ed);
}
Also used : MagicCard(org.magic.api.beans.MagicCard) MagicEdition(org.magic.api.beans.MagicEdition) Before(org.junit.Before)

Example 70 with MagicCard

use of org.magic.api.beans.MagicCard in project MtgDesktopCompanion by nicho92.

the class DashboardsProviderTests method createCards.

@Before
public void createCards() {
    mc = new MagicCard();
    mc.setName("Black Lotus");
    mc.setLayout("normal");
    mc.setCost("{0}");
    mc.setCmc(0);
    mc.getTypes().add("Artifact");
    mc.setReserved(true);
    mc.setText("{T}, Sacrifice Black Lotus: Add three mana of any one color to your mana pool.");
    mc.setRarity("Rare");
    mc.setArtist("Christopher Rush");
    mc.setId("c944c7dc960c4832604973844edee2a1fdc82d98");
    mc.setMciNumber("232");
    ed = new MagicEdition();
    ed.setId("LEA");
    ed.setSet("Limited Edition Alpha");
    ed.setBorder("Black");
    ed.setRarity("Rare");
    ed.setArtist("Christopher Rush");
    ed.setMultiverse_id("3");
    ed.setNumber("232");
    ed.setMkm_id(1);
    ed.setMkm_name("Alpha");
    mc.getEditions().add(ed);
}
Also used : MagicCard(org.magic.api.beans.MagicCard) MagicEdition(org.magic.api.beans.MagicEdition) Before(org.junit.Before)

Aggregations

MagicCard (org.magic.api.beans.MagicCard)106 MagicEdition (org.magic.api.beans.MagicEdition)40 ArrayList (java.util.ArrayList)31 IOException (java.io.IOException)28 MagicDeck (org.magic.api.beans.MagicDeck)21 MagicCollection (org.magic.api.beans.MagicCollection)14 SQLException (java.sql.SQLException)12 Date (java.util.Date)11 MagicCardStock (org.magic.api.beans.MagicCardStock)10 DisplayableCard (org.magic.game.gui.components.DisplayableCard)10 JsonArray (com.google.gson.JsonArray)8 List (java.util.List)8 FileReader (java.io.FileReader)7 Before (org.junit.Before)7 BufferedReader (java.io.BufferedReader)6 File (java.io.File)6 FileWriter (java.io.FileWriter)6 MalformedURLException (java.net.MalformedURLException)6 PreparedStatement (java.sql.PreparedStatement)6 ResultSet (java.sql.ResultSet)6