use of mage.cards.repository.CardCriteria in project mage by magefree.
the class ComputerPlayer method addBasicLands.
private static void addBasicLands(Deck deck, String landName, int number) {
Set<String> landSets = TournamentUtil.getLandSetCodeForDeckSets(deck.getExpansionSetCodes());
CardCriteria criteria = new CardCriteria();
if (!landSets.isEmpty()) {
criteria.setCodes(landSets.toArray(new String[landSets.size()]));
}
criteria.rarities(Rarity.LAND).name(landName);
List<CardInfo> cards = CardRepository.instance.findCards(criteria);
if (cards.isEmpty()) {
criteria = new CardCriteria();
criteria.rarities(Rarity.LAND).name(landName);
criteria.setCodes("M15");
cards = CardRepository.instance.findCards(criteria);
}
for (int i = 0; i < number; i++) {
Card land = cards.get(RandomUtil.nextInt(cards.size())).getCard();
deck.getCards().add(land);
}
}
use of mage.cards.repository.CardCriteria in project mage by magefree.
the class AmonkhetCollator method generateBoosterMap.
@Override
protected void generateBoosterMap() {
super.generateBoosterMap();
CardRepository.instance.findCards(new CardCriteria().setCodes("MP2").maxCardNumber(30)).stream().forEach(cardInfo -> inBoosterMap.put("MP2_" + cardInfo.getCardNumber(), cardInfo));
}
use of mage.cards.repository.CardCriteria in project mage by magefree.
the class BattleForZendikarCollator method generateBoosterMap.
@Override
protected void generateBoosterMap() {
super.generateBoosterMap();
CardRepository.instance.findCards(new CardCriteria().setCodes("EXP").maxCardNumber(25)).stream().forEach(cardInfo -> inBoosterMap.put("EXP_" + cardInfo.getCardNumber(), cardInfo));
}
use of mage.cards.repository.CardCriteria in project mage by magefree.
the class DeckGenerator method generateDeck.
/**
* 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, genDialog.getCreaturePercentage(), genDialog.getNonCreaturePercentage(), genDialog.getLandPercentage(), allowedColors, genDialog.isSingleton(), genDialog.isColorless(), genDialog.isAdvanced(), genDialog.getDeckGeneratorCMC());
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(SuperType.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();
}
use of mage.cards.repository.CardCriteria in project mage by magefree.
the class DeckGenerator method generateBasicLands.
/**
* 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) {
Set<String> landSets = TournamentUtil.getLandSetCodeForDeckSets(setsToUse);
CardCriteria criteria = new CardCriteria();
if (!landSets.isEmpty()) {
criteria.setCodes(landSets.toArray(new String[landSets.size()]));
}
criteria.ignoreSetsWithSnowLands();
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);
if (cards.isEmpty()) {
// Workaround to get basic lands if lands are not available for the given sets
criteria.setCodes("M15");
cards = CardRepository.instance.findCards(criteria);
}
basicLandMap.put(landName, cards);
}
return basicLandMap;
}
Aggregations