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);
}
}
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;
}
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;
}
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);
}
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);
}
Aggregations