use of org.magic.api.beans.Booster in project MtgDesktopCompanion by nicho92.
the class SealedPanel method open.
protected void open() {
deck = new MagicDeck();
deck.setDateCreation(new Date());
deck.setDescription("Sealed from " + model.getSealedPack());
deck.setName("sealed from " + model.getSealedPack().toList().size() + " boosters");
panelOpenedBooster.clear();
panelDeck.removeAll();
panelDeck.revalidate();
panelDeck.repaint();
ThreadManager.getInstance().execute(() -> {
int column = 0;
list = new ArrayList<>();
lblLoading.setVisible(true);
for (Entry<MagicEdition, Integer> ed : model.getSealedPack().getEntries()) {
try {
for (int i = 0; i < ed.getValue(); i++) {
Booster b = MTGControler.getInstance().getEnabledProviders().generateBooster(ed.getKey());
column++;
for (MagicCard mc : b.getCards()) {
list.add(mc);
DisplayableCard c = createCard(mc);
panelOpenedBooster.addComponent(c, column);
}
}
} catch (IOException e) {
MTGLogger.printStackTrace(e);
lblLoading.setVisible(false);
}
}
panelOpenedBooster.setList(list);
refreshStats();
lblLoading.setVisible(false);
});
}
use of org.magic.api.beans.Booster in project MtgDesktopCompanion by nicho92.
the class MtgjsonProvider method generateBooster.
public Booster generateBooster(MagicEdition me) {
logger.debug("opening booster for " + me);
List<MagicCard> common = new ArrayList<>();
List<MagicCard> uncommon = new ArrayList<>();
List<MagicCard> rare = new ArrayList<>();
List<MagicCard> lands = new ArrayList<>();
Booster b = new Booster();
try {
if (cachedCardEds.get(me.getId()) == null)
cachedCardEds.put(me.getId(), searchCardByCriteria("set", me.getId(), null, true));
for (MagicCard mc : cachedCardEds.get(me.getId())) {
if (mc.getEditions().get(0).getRarity().equalsIgnoreCase("common"))
common.add(mc);
if (mc.getEditions().get(0).getRarity().equalsIgnoreCase("uncommon"))
uncommon.add(mc);
if (mc.getEditions().get(0).getRarity().toLowerCase().contains("rare"))
rare.add(mc);
if (mc.getSupertypes().toString().toLowerCase().contains("basic") && mc.getTypes().toString().toLowerCase().contains("land"))
lands.add(mc);
}
Collections.shuffle(lands);
Collections.shuffle(common);
Collections.shuffle(uncommon);
Collections.shuffle(rare);
} catch (Exception e) {
logger.error("Error opening booster", e);
}
List<MagicCard> resList = new ArrayList<>();
resList.addAll(common.subList(0, 11));
resList.addAll(uncommon.subList(0, 3));
resList.add(rare.get(0));
if (!lands.isEmpty())
resList.addAll(lands.subList(0, 1));
b.setCards(resList);
b.setEdition(me);
return b;
}
use of org.magic.api.beans.Booster in project MtgDesktopCompanion by nicho92.
the class BoosterBoxDashlet method initGUI.
@Override
public void initGUI() {
JSpinner boxSizeSpinner;
JXTable table;
BoostersTableModel boostersModel;
DefaultListModel<MagicCard> cardsModel;
JTextPane txtDetailBox;
JPanel panneauHaut = new JPanel();
getContentPane().add(panneauHaut, BorderLayout.NORTH);
List<MagicEdition> eds = new ArrayList<>();
try {
eds.addAll(MTGControler.getInstance().getEnabledProviders().loadEditions());
Collections.sort(eds);
eds.add(0, null);
} catch (Exception e) {
MTGLogger.printStackTrace(e);
}
JComboBox<MagicEdition> cboEditions = new JComboBox<>(new DefaultComboBoxModel<MagicEdition>(eds.toArray(new MagicEdition[eds.size()])));
cboEditions.setRenderer(new MagicEditionListRenderer());
panneauHaut.add(cboEditions);
JLabel lblBoxSize = new JLabel("Box size: ");
panneauHaut.add(lblBoxSize);
boxSizeSpinner = new JSpinner();
boxSizeSpinner.setModel(new SpinnerNumberModel(36, 0, null, 1));
panneauHaut.add(boxSizeSpinner);
JScrollPane scrollPane = new JScrollPane();
getContentPane().add(scrollPane, BorderLayout.CENTER);
boostersModel = new BoostersTableModel();
cardsModel = new DefaultListModel<>();
table = new JXTable(boostersModel);
scrollPane.setViewportView(table);
JPanel panneauBas = new JPanel();
getContentPane().add(panneauBas, BorderLayout.SOUTH);
JButton btnCalculate = new JButton("Open");
panneauBas.add(btnCalculate);
JTabbedPane tabbedPane = new JTabbedPane(JTabbedPane.TOP);
getContentPane().add(tabbedPane, BorderLayout.EAST);
txtDetailBox = new JTextPane();
txtDetailBox.setEditable(false);
tabbedPane.addTab("Box", null, txtDetailBox, null);
JScrollPane scrollPane1 = new JScrollPane();
tabbedPane.addTab("Booster", null, scrollPane1, null);
JList<MagicCard> list1 = new JList<>();
list1.setModel(cardsModel);
list1.setCellRenderer(new MagicCardListRenderer());
scrollPane1.setViewportView(list1);
btnCalculate.addActionListener(e -> ThreadManager.getInstance().execute(() -> {
try {
List<CardShake> prices = MTGControler.getInstance().getEnabledDashBoard().getShakeForEdition((MagicEdition) cboEditions.getSelectedItem());
boostersModel.clear();
double total = 0;
Map<String, Double> priceRarity = new HashMap<>();
for (int i = 0; i < (int) boxSizeSpinner.getValue(); i++) {
Booster booster = MTGControler.getInstance().getEnabledProviders().generateBooster((MagicEdition) cboEditions.getSelectedItem());
Collections.reverse(booster.getCards());
booster.setBoosterNumber(String.valueOf(i + 1));
double price = 0;
for (MagicCard mc : booster.getCards()) {
for (CardShake cs : prices) if (cs.getName().equalsIgnoreCase(mc.getName())) {
price += cs.getPrice();
booster.setPrice(price);
cs.setCard(mc);
String rarity = mc.getEditions().get(0).getRarity();
if (priceRarity.get(rarity) != null)
priceRarity.put(rarity, priceRarity.get(rarity) + cs.getPrice());
else
priceRarity.put(rarity, cs.getPrice());
}
}
boostersModel.addLine(booster);
total = total + booster.getPrice();
StringBuilder temp = new StringBuilder();
temp.append("TOTAL: ").append(doubleFormat.format(total)).append("\n");
for (Entry<String, Double> s : priceRarity.entrySet()) temp.append(s.getKey()).append(": ").append(doubleFormat.format(priceRarity.get(s.getKey()))).append("\n");
txtDetailBox.setText(temp.toString());
}
} catch (Exception e1) {
logger.error(e1);
}
}, "Open Box"));
table.getSelectionModel().addListSelectionListener(event -> {
if (!event.getValueIsAdjusting()) {
int viewRow = table.getSelectedRow();
if (viewRow > -1) {
int modelRow = table.convertRowIndexToModel(viewRow);
List<MagicCard> list = ((Booster) table.getModel().getValueAt(modelRow, 0)).getCards();
cardsModel.clear();
for (MagicCard mc : list) cardsModel.addElement(mc);
}
}
});
if (getProperties().size() > 0) {
Rectangle r = new Rectangle((int) Double.parseDouble(getProperty("x")), (int) Double.parseDouble(getProperty("y")), (int) Double.parseDouble(getProperty("w")), (int) Double.parseDouble(getProperty("h")));
setBounds(r);
}
setVisible(true);
}
use of org.magic.api.beans.Booster in project MtgDesktopCompanion by nicho92.
the class ScryFallProvider method generateBooster.
@Override
public Booster generateBooster(MagicEdition me) throws IOException {
List<MagicCard> ret = new ArrayList<>();
List<MagicCard> common = new ArrayList<>();
List<MagicCard> uncommon = new ArrayList<>();
List<MagicCard> rare = new ArrayList<>();
if (cachedCardEds.get(me.getId()) == null)
cachedCardEds.put(me.getId(), searchCardByCriteria("set", me.getId(), null, true));
for (MagicCard mc : cachedCardEds.get(me.getId())) {
if (mc.getEditions().get(0).getRarity().equalsIgnoreCase("common"))
common.add(mc);
if (mc.getEditions().get(0).getRarity().equalsIgnoreCase("uncommon"))
uncommon.add(mc);
if (mc.getEditions().get(0).getRarity().toLowerCase().contains("rare"))
rare.add(mc);
}
Collections.shuffle(common);
Collections.shuffle(uncommon);
Collections.shuffle(rare);
ret.addAll(common.subList(0, 11));
ret.addAll(uncommon.subList(0, 3));
ret.add(rare.get(0));
Booster b = new Booster();
b.setEdition(me);
b.setCards(ret);
return b;
}
Aggregations