Esempio n. 1
0
 private static String getPlayerNameUsingStandardPrompt(String playerName) {
   return SOptionPane.showInputDialog(
       "Please enter a new name. (alpha-numeric only)",
       "Personalize Forge Gameplay",
       null,
       playerName);
 }
Esempio n. 2
0
 private static String getPlayerNameUsingFirstTimePrompt() {
   return SOptionPane.showInputDialog(
       "By default, Forge will refer to you as the \"Human\" during gameplay.\n"
           + "If you would prefer a different name please enter it now.",
       "Personalize Forge Gameplay",
       SOptionPane.QUESTION_ICON);
 }
Esempio n. 3
0
 private static void showThankYouPrompt(String playerName) {
   SOptionPane.showMessageDialog(
       "Thank you, "
           + playerName
           + ". "
           + "You will not be prompted again but you can change\n"
           + "your name at any time using the \"Player Name\" setting in Preferences\n"
           + "or via the constructed match setup screen\n");
 }
Esempio n. 4
0
  public boolean setCurrentScreen(final FScreen screen, final boolean previousScreenClosed) {
    // TODO: Uncomment the line below if this function stops being used to refresh
    // the current screen in some places (such as Continue and Restart in the match screen)
    // if (currentScreen == screen) { return; }

    // give previous screen a chance to perform special switch handling and/or cancel switching away
    // from screen
    if (currentScreen != screen && !Singletons.getView().getNavigationBar().canSwitch(screen)) {
      return false;
    }

    if (currentScreen != null
        && currentScreen
            .isMatchScreen()) { // hide targeting overlay and reset image if was on match screen
      // SOverlayUtils.hideTargetingOverlay();
      if (isMatchBackgroundImageVisible()) {
        FView.SINGLETON_INSTANCE.getPnlInsets().setForegroundImage(new ImageIcon());
      }
    }

    clearChildren(JLayeredPane.DEFAULT_LAYER);
    SOverlayUtils.hideOverlay();
    ImageCache.clear(); // reduce memory usage by clearing image cache when switching screens

    currentScreen = screen;

    // load layout for new current screen
    screen.getController().register();
    try {
      SLayoutIO.loadLayout(null);
    } catch (final InvalidLayoutFileException ex) {
      SOptionPane.showMessageDialog(
          String.format(
              "Your %s layout file could not be read. It will be deleted after you press OK.\nThe game will proceed with default layout.",
              screen.getTabCaption()),
          "Warning!");
      if (screen.deleteLayoutFile()) {
        SLayoutIO.loadLayout(null); // try again
      }
    }

    screen.getController().initialize();
    screen.getView().populate();

    if (screen.isMatchScreen()) {
      if (isMatchBackgroundImageVisible()) {
        FView.SINGLETON_INSTANCE
            .getPnlInsets()
            .setForegroundImage(FSkin.getIcon(FSkinProp.BG_MATCH));
      }
      // SOverlayUtils.showTargetingOverlay();
    }

    Singletons.getView().getNavigationBar().updateSelectedTab();
    return true;
  }
  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;
  }
  /**
   * 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;
    }
  }