Esempio n. 1
0
  public static CardPool fromCardList(final Iterable<String> lines) {
    CardPool pool = new CardPool();

    if (lines == null) {
      return pool;
    }

    final Iterator<String> lineIterator = lines.iterator();
    while (lineIterator.hasNext()) {
      final String line = lineIterator.next();
      if (line.startsWith(";") || line.startsWith("#")) {
        continue;
      } // that is a comment or not-yet-supported card

      final Matcher m = p.matcher(line.trim());
      m.matches();
      final String sCnt = m.group(2);
      final String cardName = m.group(3);
      if (StringUtils.isBlank(cardName)) {
        continue;
      }

      final int count = sCnt == null ? 1 : Integer.parseInt(sCnt);
      pool.add(cardName, count);
    }
    return pool;
  }
  /**
   * 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;
  }
  public static DeckGroup generateSealedDeck(final boolean addBasicLands) {
    final String prompt = "Choose Sealed Deck Format";
    final LimitedPoolType poolType = SGuiChoose.oneOrNone(prompt, LimitedPoolType.values());
    if (poolType == null) {
      return null;
    }

    SealedCardPoolGenerator sd = new SealedCardPoolGenerator(poolType);
    if (sd.isEmpty()) {
      return null;
    }

    final CardPool humanPool = sd.getCardPool(true);
    if (humanPool == null) {
      return null;
    }

    // System.out.println(humanPool);

    // This seems to be limited by the MAX_DRAFT_PLAYERS constant
    // in DeckGroupSerializer.java. You could create more AI decks
    // but only the first seven would load. --BBU
    Integer rounds = SGuiChoose.getInteger("How many opponents are you willing to face?", 1, 7);
    if (rounds == null) {
      return null;
    }

    final String sDeckName =
        SOptionPane.showInputDialog(
            "Save this card pool as:", "Save Card Pool", FSkinProp.ICO_QUESTION);

    if (StringUtils.isBlank(sDeckName)) {
      return null;
    }

    final IStorage<DeckGroup> sealedDecks = FModel.getDecks().getSealed();
    if (sealedDecks.contains(sDeckName)) {
      if (!SOptionPane.showConfirmDialog(
          "'" + sDeckName + "' already exists. Do you want to replace it?",
          "Sealed Deck Game Exists")) {
        return null;
      }
      sealedDecks.delete(sDeckName);
    }

    final Deck deck = new Deck(sDeckName);
    deck.getOrCreate(DeckSection.Sideboard).addAll(humanPool);

    if (addBasicLands) {
      final int landsCount = 10;

      final boolean isZendikarSet =
          sd.getLandSetCode()
              .equals("ZEN"); // we want to generate one kind of Zendikar lands at a time only
      final boolean zendikarSetMode = MyRandom.getRandom().nextBoolean();

      for (final String element : MagicColor.Constant.BASIC_LANDS) {
        int numArt = FModel.getMagicDb().getCommonCards().getArtCount(element, sd.getLandSetCode());
        int minArtIndex = isZendikarSet ? (zendikarSetMode ? 1 : 5) : 1;
        int maxArtIndex = isZendikarSet ? minArtIndex + 3 : numArt;

        if (FModel.getPreferences().getPrefBoolean(FPref.UI_RANDOM_ART_IN_POOLS)) {
          for (int i = minArtIndex; i <= maxArtIndex; i++) {
            deck.get(DeckSection.Sideboard)
                .add(element, sd.getLandSetCode(), i, numArt > 1 ? landsCount : 30);
          }
        } else {
          deck.get(DeckSection.Sideboard).add(element, sd.getLandSetCode(), 30);
        }
      }
    }

    final DeckGroup sealed = new DeckGroup(sDeckName);
    sealed.setHumanDeck(deck);
    for (int i = 0; i < rounds; i++) {
      // Generate other decks for next N opponents
      final CardPool aiPool = sd.getCardPool(false);
      if (aiPool == null) {
        return null;
      }

      sealed.addAiDeck(new SealedDeckBuilder(aiPool.toFlatList()).buildDeck());
    }

    // Rank the AI decks
    sealed.rankAiDecks(new SealedDeckComparer());

    FModel.getDecks().getSealed().add(sealed);
    return sealed;
  }