Пример #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;
  }
Пример #2
0
 /**
  * Return a random basic land of the chosen color.
  *
  * @param color the color the basic land should produce.
  * @param basicLands list of information about basic lands from the database.
  * @return a single basic land that produces the color needed.
  */
 private static Card getBasicLand(
     ColoredManaSymbol color, Map<String, List<CardInfo>> basicLands) {
   Random random = new Random();
   String landName = DeckGeneratorPool.getBasicLandName(color.toString());
   return basicLands.get(landName).get(random.nextInt(basicLands.size() - 1)).getMockCard().copy();
 }