Esempio n. 1
0
  /**
   * Returns a map of colored mana symbol to basic land cards of that color.
   *
   * @param setsToUse which sets to retrieve basic lands from.
   * @return a map of color to basic lands.
   */
  private static Map<String, List<CardInfo>> generateBasicLands(List<String> setsToUse) {

    List<String> landSets = new LinkedList<>();

    // decide from which sets basic lands are taken from
    for (String setCode : setsToUse) {
      ExpansionInfo expansionInfo = ExpansionRepository.instance.getSetByCode(setCode);
      if (expansionInfo.hasBasicLands()) {
        landSets.add(expansionInfo.getCode());
      }
    }

    // if sets have no basic land, take land from block
    if (landSets.isEmpty()) {
      for (String setCode : setsToUse) {
        ExpansionInfo expansionInfo = ExpansionRepository.instance.getSetByCode(setCode);
        List<ExpansionInfo> blockSets =
            ExpansionRepository.instance.getSetsFromBlock(expansionInfo.getBlockName());
        for (ExpansionInfo blockSet : blockSets) {
          if (blockSet.hasBasicLands()) {
            landSets.add(blockSet.getCode());
          }
        }
      }
    }
    // if still no set with lands found, take one by random
    if (landSets.isEmpty()) {
      // if sets have no basic lands and also it has no parent or parent has no lands get last set
      // with lands
      // select a set with basic lands by random
      Random generator = new Random();
      List<ExpansionInfo> basicLandSets =
          ExpansionRepository.instance.getSetsWithBasicLandsByReleaseDate();
      if (basicLandSets.size() > 0) {
        landSets.add(basicLandSets.get(generator.nextInt(basicLandSets.size())).getCode());
      }
    }

    if (landSets.isEmpty()) {
      throw new IllegalArgumentException("No set with basic land was found");
    }

    CardCriteria criteria = new CardCriteria();
    if (!landSets.isEmpty()) {
      criteria.setCodes(landSets.toArray(new String[landSets.size()]));
    }

    Map<String, List<CardInfo>> basicLandMap = new HashMap<>();

    for (ColoredManaSymbol c : ColoredManaSymbol.values()) {
      String landName = DeckGeneratorPool.getBasicLandName(c.toString());
      criteria.rarities(Rarity.LAND).name(landName);
      List<CardInfo> cards = CardRepository.instance.findCards(criteria);
      basicLandMap.put(landName, cards);
    }
    return basicLandMap;
  }
Esempio n. 2
0
  /**
   * Tries to calculate the most appropiate sets to add basic lands for cards of a deck
   *
   * @param setCodesDeck
   * @return setCode for lands
   */
  public static Set<String> getLandSetCodeForDeckSets(Collection<String> setCodesDeck) {

    Set<String> landSetCodes = new HashSet<>();
    // decide from which sets basic lands are taken from
    for (String setCode : setCodesDeck) {
      ExpansionInfo expansionInfo = ExpansionRepository.instance.getSetByCode(setCode);
      if (expansionInfo.hasBasicLands()) {
        landSetCodes.add(expansionInfo.getCode());
      }
    }

    // if sets have no basic land, take land from block
    if (landSetCodes.isEmpty()) {
      for (String setCode : setCodesDeck) {
        ExpansionInfo expansionInfo = ExpansionRepository.instance.getSetByCode(setCode);
        List<ExpansionInfo> blockSets =
            ExpansionRepository.instance.getSetsFromBlock(expansionInfo.getBlockName());
        for (ExpansionInfo blockSet : blockSets) {
          if (blockSet.hasBasicLands()) {
            landSetCodes.add(blockSet.getCode());
          }
        }
      }
    }
    // if still no set with lands found, take one by random
    if (landSetCodes.isEmpty()) {
      // if sets have no basic lands and also it has no parent or parent has no lands get last set
      // with lands
      // select a set with basic lands by random
      Random generator = new Random();
      List<ExpansionInfo> basicLandSets =
          ExpansionRepository.instance.getSetsWithBasicLandsByReleaseDate();
      if (basicLandSets.size() > 0) {
        landSetCodes.add(basicLandSets.get(generator.nextInt(basicLandSets.size())).getCode());
      }
    }

    if (landSetCodes.isEmpty()) {
      throw new IllegalArgumentException("No set with basic land was found");
    }
    return landSetCodes;
  }