예제 #1
0
  protected static Deck buildDeck() {

    String selectedColors = genDialog.getSelectedColors();
    List<ColoredManaSymbol> allowedColors = new ArrayList<>();
    selectedColors = selectedColors != null ? selectedColors.toUpperCase() : getRandomColors("X");
    String format = genDialog.getSelectedFormat();

    List<String> setsToUse = ConstructedFormats.getSetsByFormat(format);
    if (setsToUse.isEmpty()) {
      // Default to using all sets
      setsToUse = ExpansionRepository.instance.getSetCodes();
    }

    int deckSize = genDialog.getDeckSize();

    if (selectedColors.contains("X")) {
      selectedColors = getRandomColors(selectedColors);
    }

    for (int i = 0; i < selectedColors.length(); i++) {
      char c = selectedColors.charAt(i);
      allowedColors.add(ColoredManaSymbol.lookup(c));
    }

    return generateDeck(deckSize, allowedColors, setsToUse);
  }
예제 #2
0
  private static ArrayList<CardDownloadData> getNeededCards(List<CardInfo> allCards) {

    ArrayList<CardDownloadData> cardsToDownload = new ArrayList<>();

    /** read all card names and urls */
    ArrayList<CardDownloadData> allCardsUrls = new ArrayList<>();
    HashSet<String> ignoreUrls = SettingsManager.getIntance().getIgnoreUrls();

    /** get filter for Standard Type 2 cards */
    Set<String> type2SetsFilter = new HashSet<>();
    List<String> constructedFormats =
        ConstructedFormats.getSetsByFormat(ConstructedFormats.STANDARD);
    if (constructedFormats != null && !constructedFormats.isEmpty()) {
      type2SetsFilter.addAll(constructedFormats);
    } else {
      logger.warn("No formats defined. Try connecting to a server first!");
    }

    int numberCardImages = allCards.size();

    try {
      offlineMode = true;

      for (CardInfo card : allCards) {
        if (card.getCardNumber() > 0
            && !card.getSetCode().isEmpty()
            && !ignoreUrls.contains(card.getSetCode())) {
          String cardName = card.getName();
          CardDownloadData url =
              new CardDownloadData(
                  cardName,
                  card.getSetCode(),
                  card.getCardNumber(),
                  card.usesVariousArt(),
                  0,
                  "",
                  false,
                  card.isDoubleFaced(),
                  card.isNightCard());
          if (url.getUsesVariousArt()) {
            url.setDownloadName(createDownloadName(card));
          }

          url.setFlipCard(card.isFlipCard());
          url.setSplitCard(card.isSplitCard());

          if (type2SetsFilter.contains(card.getSetCode())) {
            url.setType2(true);
          }

          allCardsUrls.add(url);
          if (card.isDoubleFaced()) {
            if (card.getSecondSideName() == null || card.getSecondSideName().trim().isEmpty()) {
              throw new IllegalStateException("Second side card can't have empty name.");
            }
            url =
                new CardDownloadData(
                    card.getSecondSideName(),
                    card.getSetCode(),
                    card.getCardNumber(),
                    card.usesVariousArt(),
                    0,
                    "",
                    false,
                    card.isDoubleFaced(),
                    true);
            allCardsUrls.add(url);
          }
          if (card.isFlipCard()) {
            if (card.getFlipCardName() == null || card.getFlipCardName().trim().isEmpty()) {
              throw new IllegalStateException("Flipped card can't have empty name.");
            }
            url =
                new CardDownloadData(
                    card.getFlipCardName(),
                    card.getSetCode(),
                    card.getCardNumber(),
                    card.usesVariousArt(),
                    0,
                    "",
                    false,
                    card.isDoubleFaced(),
                    card.isNightCard());
            url.setFlipCard(true);
            url.setFlippedSide(true);
            allCardsUrls.add(url);
          }
        } else if (card.getCardNumber() < 1) {
          System.err.println("There was a critical error!");
          logger.error("Card has no collector ID and won't be sent to client: " + card);
        } else if (card.getSetCode().isEmpty()) {
          System.err.println("There was a critical error!");
          logger.error("Card has no set name and won't be sent to client:" + card);
        }
      }
      allCardsUrls.addAll(getTokenCardUrls());

    } catch (Exception e) {
      logger.error(e);
    }
    int numberTokenImages = allCardsUrls.size() - numberCardImages;
    TFile file;

    /** check to see which cards we already have */
    for (CardDownloadData card : allCardsUrls) {
      file = new TFile(CardImageUtils.generateImagePath(card));
      if (!file.exists()) {
        cardsToDownload.add(card);
      }
    }

    logger.info(
        "Check download images (total cards: "
            + numberCardImages
            + ", total tokens: "
            + numberTokenImages
            + ") => Missing images: "
            + cardsToDownload.size());
    if (logger.isDebugEnabled()) {
      for (CardDownloadData card : cardsToDownload) {
        if (card.isToken()) {
          logger.debug("Card to download: " + card.getName() + " (Token) ");
        } else {
          try {
            logger.debug("Card to download: " + card.getName() + " (" + card.getSet() + ")");
          } catch (Exception e) {
            logger.error(e);
          }
        }
      }
    }

    return cardsToDownload;
  }