/**
   * getCardpool.
   *
   * @param isHuman boolean, get pool for human (possible choices)
   * @return a {@link forge.CardList} object.
   */
  public CardPool getCardPool(final boolean isHuman) {
    final CardPool pool = new CardPool();

    for (IUnOpenedProduct prod : product) {
      if (prod instanceof UnOpenedMeta) {
        List<PaperCard> cards = ((UnOpenedMeta) prod).open(isHuman, true);
        if (cards == null) {
          return null; // return null if user canceled
        }
        pool.addAllFlat(cards);
      } else {
        pool.addAllFlat(prod.get());
      }
    }
    return pool;
  }
예제 #2
0
  /** awardBooster. Generates and displays booster pack win case. */
  private void awardBooster() {
    List<PaperCard> cardsWon;

    String title;
    if (qData.getFormat() == null) {

      final List<GameFormat> formats = new ArrayList<>();
      final String preferredFormat = FModel.getQuestPreferences().getPref(QPref.BOOSTER_FORMAT);

      GameFormat pref = null;
      for (final GameFormat f : FModel.getFormats().getOrderedList()) {
        formats.add(f);
        if (f.toString().equals(preferredFormat)) {
          pref = f;
        }
      }

      Collections.sort(formats);

      final GameFormat selected =
          SGuiChoose.getChoices("Choose bonus booster format", 1, 1, formats, pref, null).get(0);
      FModel.getQuestPreferences().setPref(QPref.BOOSTER_FORMAT, selected.toString());

      cardsWon = qData.getCards().generateQuestBooster(selected.getFilterPrinted());
      qData.getCards().addAllCards(cardsWon);

      title = "Bonus booster pack from the \"" + selected.getName() + "\" format!";

    } else {

      final List<String> sets = new ArrayList<>();

      for (final SealedProduct.Template bd : FModel.getMagicDb().getBoosters()) {
        if (bd != null && qData.getFormat().isSetLegal(bd.getEdition())) {
          sets.add(bd.getEdition());
        }
      }

      boolean customBooster = false;

      // No boosters found for current quest settings
      if (sets.isEmpty()) {
        customBooster = true;
        CardEdition.Collection editions = FModel.getMagicDb().getEditions();
        for (CardEdition edition : editions) {
          if (qData.getFormat().isSetLegal(edition.getCode())) {
            sets.add(edition.getCode());
          }
        }
      }

      int maxChoices = 1;
      if (wonMatch) {
        maxChoices++;
        final int wins = qData.getAchievements().getWin();
        if ((wins + 1) % 5 == 0) {
          maxChoices++;
        }
        if ((wins + 1) % 20 == 0) {
          maxChoices++;
        }
        if ((wins + 1) % 50 == 0) {
          maxChoices++;
        }
        maxChoices += qData.getAssets().getItemLevel(QuestItemType.MEMBERSHIP_TOKEN);
      }

      final List<CardEdition> options = new ArrayList<>();

      while (!sets.isEmpty() && maxChoices > 0) {
        final int ix = MyRandom.getRandom().nextInt(sets.size());
        final String set = sets.get(ix);
        sets.remove(ix);
        options.add(FModel.getMagicDb().getEditions().get(set));
        maxChoices--;
      }

      final CardEdition chooseEd = SGuiChoose.one("Choose bonus booster set", options);

      if (customBooster) {
        List<PaperCard> cards =
            FModel.getMagicDb()
                .getCommonCards()
                .getAllCards(Predicates.printedInSet(chooseEd.getCode()));
        final IUnOpenedProduct product = new UnOpenedProduct(getBoosterTemplate(), cards);
        cardsWon = product.get();
      } else {
        final IUnOpenedProduct product =
            new UnOpenedProduct(FModel.getMagicDb().getBoosters().get(chooseEd.getCode()));
        cardsWon = product.get();
      }

      qData.getCards().addAllCards(cardsWon);
      title = "Bonus " + chooseEd.getName() + " Booster Pack!";
    }

    if (cardsWon != null) {
      BoosterUtils.sort(cardsWon);
      view.showCards(title, cardsWon);
    }
  }