Exemplo n.º 1
0
  private void startGame(final GameType gameType) {
    final DeckProxy humanDeck = VSubmenuWinston.SINGLETON_INSTANCE.getLstDecks().getSelectedItem();
    final int aiIndex = 0;

    if (humanDeck == null) {
      FOptionPane.showErrorDialog(
          "No deck selected for human.\n(You may need to build a new deck)", "No Deck");
      return;
    }

    if (FModel.getPreferences().getPrefBoolean(FPref.ENFORCE_DECK_LEGALITY)) {
      final String errorMessage =
          gameType.getDeckFormat().getDeckConformanceProblem(humanDeck.getDeck());
      if (null != errorMessage) {
        FOptionPane.showErrorDialog(
            "Your deck " + errorMessage + " Please edit or choose a different deck.",
            "Invalid Deck");
        return;
      }
    }

    SwingUtilities.invokeLater(
        new Runnable() {
          @Override
          public void run() {
            SOverlayUtils.startGameOverlay();
            SOverlayUtils.showOverlay();
          }
        });

    final DeckGroup opponentDecks = FModel.getDecks().getWinston().get(humanDeck.getName());
    final Deck aiDeck = opponentDecks.getAiDecks().get(aiIndex);
    if (aiDeck == null) {
      throw new IllegalStateException("Draft: Computer deck is null!");
    }

    final List<RegisteredPlayer> starter = new ArrayList<RegisteredPlayer>();
    final RegisteredPlayer human =
        new RegisteredPlayer(humanDeck.getDeck()).setPlayer(GamePlayerUtil.getGuiPlayer());
    starter.add(human);
    starter.add(new RegisteredPlayer(aiDeck).setPlayer(GamePlayerUtil.createAiPlayer()));

    final HostedMatch hostedMatch = GuiBase.getInterface().hostMatch();
    hostedMatch.startMatch(
        GameType.Winston, null, starter, human, GuiBase.getInterface().getNewGuiGame());

    SwingUtilities.invokeLater(
        new Runnable() {
          @Override
          public void run() {
            SOverlayUtils.hideOverlay();
          }
        });
  }
  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;
  }