/** * 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; }
public static List<Card> getLands(String landName, int number, Set<String> landSets) { Random random = new Random(); CardCriteria criteria = new CardCriteria(); if (!landSets.isEmpty()) { criteria.setCodes(landSets.toArray(new String[landSets.size()])); } criteria.rarities(Rarity.LAND).name(landName); List<CardInfo> lands = CardRepository.instance.findCards(criteria); List<Card> cards = new ArrayList<>(); if (!lands.isEmpty()) { for (int i = 0; i < number; i++) { Card land = lands.get(random.nextInt(lands.size())).getCard(); cards.add(land); } } return cards; }
public List<Card> createBooster() { List<Card> booster = new ArrayList<Card>(); if (!hasBoosters) { return booster; } CardCriteria criteria = new CardCriteria(); criteria .setCodes(!hasBasicLands && parentSet != null ? parentSet.code : this.code) .rarities(Rarity.LAND) .doubleFaced(false); List<CardInfo> basicLand = CardRepository.instance.findCards(criteria); criteria = new CardCriteria(); criteria.setCodes(this.code).rarities(Rarity.COMMON).doubleFaced(false); List<CardInfo> common = CardRepository.instance.findCards(criteria); criteria = new CardCriteria(); criteria.setCodes(this.code).rarities(Rarity.UNCOMMON).doubleFaced(false); List<CardInfo> uncommon = CardRepository.instance.findCards(criteria); criteria = new CardCriteria(); criteria.setCodes(this.code).rarities(Rarity.RARE).doubleFaced(false); List<CardInfo> rare = CardRepository.instance.findCards(criteria); criteria = new CardCriteria(); criteria.setCodes(this.code).rarities(Rarity.MYTHIC).doubleFaced(false); List<CardInfo> mythic = CardRepository.instance.findCards(criteria); criteria = new CardCriteria(); criteria.setCodes(this.code).doubleFaced(true); List<CardInfo> doubleFaced = CardRepository.instance.findCards(criteria); for (int i = 0; i < numBoosterLands; i++) { addToBooster(booster, basicLand); } for (int i = 0; i < numBoosterCommon; i++) { addToBooster(booster, common); } for (int i = 0; i < numBoosterUncommon; i++) { addToBooster(booster, uncommon); } for (int i = 0; i < numBoosterRare; i++) { if (ratioBoosterMythic > 0 && rnd.nextInt(ratioBoosterMythic) == 1) { addToBooster(booster, mythic); } else { addToBooster(booster, rare); } } for (int i = 0; i < numBoosterDoubleFaced; i++) { addToBooster(booster, doubleFaced); } return booster; }
/** * Generates all the cards to use in the deck. Adds creatures, non-creatures, lands (including * non-basic). Fixes the deck, adjusting for size and color of the cards retrieved. * * @param deckSize how big the deck is to generate. * @param allowedColors which colors are allowed in the deck. * @param setsToUse which sets to use to retrieve cards for this deck. * @return the final deck to use. */ private static Deck generateDeck( int deckSize, List<ColoredManaSymbol> allowedColors, List<String> setsToUse) { genPool = new DeckGeneratorPool(deckSize, allowedColors, genDialog.isSingleton()); final String[] sets = setsToUse.toArray(new String[setsToUse.size()]); // Creatures final CardCriteria creatureCriteria = new CardCriteria(); creatureCriteria.setCodes(sets); creatureCriteria.notTypes(CardType.LAND); creatureCriteria.types(CardType.CREATURE); if (!(genDialog.useArtifacts())) creatureCriteria.notTypes(CardType.ARTIFACT); // Non-creatures (sorcery, instant, enchantment, artifact etc.) final CardCriteria nonCreatureCriteria = new CardCriteria(); nonCreatureCriteria.setCodes(sets); nonCreatureCriteria.notTypes(CardType.LAND); nonCreatureCriteria.notTypes(CardType.CREATURE); if (!(genDialog.useArtifacts())) nonCreatureCriteria.notTypes(CardType.ARTIFACT); // Non-basic land final CardCriteria nonBasicLandCriteria = new CardCriteria(); nonBasicLandCriteria.setCodes(sets); nonBasicLandCriteria.types(CardType.LAND); nonBasicLandCriteria.notSupertypes("Basic"); // Generate basic land cards Map<String, List<CardInfo>> basicLands = generateBasicLands(setsToUse); generateSpells(creatureCriteria, genPool.getCreatureCount()); generateSpells(nonCreatureCriteria, genPool.getNonCreatureCount()); generateLands(nonBasicLandCriteria, genPool.getLandCount(), basicLands); // Reconstructs the final deck and adjusts for Math rounding and/or missing cards return genPool.getDeck(); }