Ejemplo n.º 1
0
 private Predicate<PaperCard> buildFilter() {
   final List<String> setCodes = new ArrayList<String>();
   for (final CardEdition set : this.sets) {
     setCodes.add(set.getCode());
   }
   return IPaperCard.Predicates.printedInSets(setCodes, true);
 }
Ejemplo n.º 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);
    }
  }
  /**
   * Constructor for SealedDeck.
   *
   * @param poolType a {@link java.lang.String} object.
   */
  private SealedCardPoolGenerator(final LimitedPoolType poolType) {
    switch (poolType) {
      case Full:
        // Choose number of boosters
        if (!chooseNumberOfBoosters(new UnOpenedProduct(SealedProduct.Template.genericBooster))) {
          return;
        }
        landSetCode =
            CardEdition.Predicates.getRandomSetWithAllBasicLands(FModel.getMagicDb().getEditions())
                .getCode();
        break;

      case Block:
      case FantasyBlock:
        List<CardBlock> blocks = new ArrayList<CardBlock>();
        Iterable<CardBlock> src =
            poolType == LimitedPoolType.Block ? FModel.getBlocks() : FModel.getFantasyBlocks();
        for (CardBlock b : src) {
          blocks.add(b);
        }

        final CardBlock block = SGuiChoose.oneOrNone("Choose Block", blocks);
        if (block == null) {
          return;
        }

        final int nPacks = block.getCntBoostersSealed();
        final Stack<String> sets = new Stack<String>();

        for (CardEdition edition : block.getSets()) {
          sets.add(edition.getCode());
        }

        for (String ms : block.getMetaSetNames()) {
          sets.push(ms);
        }

        if (sets.size() > 1) {
          final List<String> setCombos = getSetCombos(sets, nPacks);
          if (setCombos == null || setCombos.isEmpty()) {
            throw new RuntimeException(
                "Unsupported amount of packs (" + nPacks + ") in a Sealed Deck block!");
          }

          final String p =
              setCombos.size() > 1
                  ? SGuiChoose.oneOrNone("Choose packs to play with", setCombos)
                  : setCombos.get(0);
          if (p == null) {
            return;
          }

          for (String pz : TextUtil.split(p, ',')) {
            String[] pps = TextUtil.splitWithParenthesis(pz.trim(), ' ');
            String setCode = pps[pps.length - 1];
            int nBoosters = pps.length > 1 ? Integer.parseInt(pps[0]) : 1;
            while (nBoosters-- > 0) {
              this.product.add(block.getBooster(setCode));
            }
          }
        } else {
          IUnOpenedProduct prod = block.getBooster(sets.get(0));
          for (int i = 0; i < nPacks; i++) {
            this.product.add(prod);
          }
        }

        landSetCode = block.getLandSet().getCode();
        break;

      case Custom:
        String[] dList;
        final ArrayList<CustomLimited> customs = new ArrayList<CustomLimited>();

        // get list of custom draft files
        final File dFolder = new File(ForgeConstants.SEALED_DIR);
        if (!dFolder.exists()) {
          throw new RuntimeException(
              "GenerateSealed : folder not found -- folder is " + dFolder.getAbsolutePath());
        }

        if (!dFolder.isDirectory()) {
          throw new RuntimeException(
              "GenerateSealed : not a folder -- " + dFolder.getAbsolutePath());
        }

        dList = dFolder.list();

        for (final String element : dList) {
          if (element.endsWith(FILE_EXT)) {
            final List<String> dfData = FileUtil.readFile(ForgeConstants.SEALED_DIR + element);
            final CustomLimited cs = CustomLimited.parse(dfData, FModel.getDecks().getCubes());
            if (cs.getSealedProductTemplate().getNumberOfCardsExpected()
                > 5) { // Do not allow too small cubes to be played as 'stand-alone'!
              customs.add(cs);
            }
          }
        }

        // present list to user
        if (customs.isEmpty()) {
          SOptionPane.showMessageDialog("No custom sealed files found.");
          return;
        }

        final CustomLimited draft = SGuiChoose.oneOrNone("Choose Custom Sealed Pool", customs);
        if (draft == null) {
          return;
        }

        UnOpenedProduct toAdd =
            new UnOpenedProduct(draft.getSealedProductTemplate(), draft.getCardPool());
        toAdd.setLimitedPool(draft.isSingleton());
        if (!chooseNumberOfBoosters(toAdd)) {
          return;
        }

        landSetCode = draft.getLandSetCode();
        break;
    }
  }
Ejemplo n.º 4
0
 public void setFoilIndexOverride(int index0) {
   if (index0 < 0) {
     index0 = CardEdition.getRandomFoil(getSetCode());
   }
   foilIndexOverride = index0;
 }