use of mage.cards.repository.CardCriteria in project mage by magefree.
the class AetherRevoltCollator method generateBoosterMap.
@Override
protected void generateBoosterMap() {
super.generateBoosterMap();
CardRepository.instance.findCards(new CardCriteria().setCodes("MPS").minCardNumber(31)).stream().forEach(cardInfo -> inBoosterMap.put("MPS_" + cardInfo.getCardNumber(), cardInfo));
}
use of mage.cards.repository.CardCriteria in project mage by magefree.
the class DraftLogImporter method readLine.
@Override
protected void readLine(String line, DeckCardLists deckList, FixedInfo fixedInfo) {
Matcher setMatcher = SET_PATTERN.matcher(line);
if (setMatcher.matches()) {
currentSet = setMatcher.group(1);
return;
}
Matcher pickMatcher = PICK_PATTERN.matcher(line);
if (pickMatcher.matches()) {
String name = pickMatcher.group(1);
List<CardInfo> cards = getCardLookup().lookupCardInfo(new CardCriteria().setCodes(currentSet).name(name));
CardInfo card = null;
if (!cards.isEmpty()) {
card = cards.get(0);
} else {
card = getCardLookup().lookupCardInfo(name).orElse(null);
}
if (card != null) {
deckList.getCards().add(new DeckCardInfo(card.getName(), card.getCardNumber(), card.getSetCode()));
} else {
sbMessage.append("couldn't find: \"").append(name).append("\"\n");
}
}
}
use of mage.cards.repository.CardCriteria in project mage by magefree.
the class DraftFromSpellbookEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player player = game.getPlayer(source.getControllerId());
if (player == null) {
return false;
}
Set<String> toSelect = new HashSet<>();
while (toSelect.size() < 3) {
toSelect.add(RandomUtil.randomFromCollection(spellbook));
}
Choice choice = new ChoiceImpl(true, ChoiceHintType.CARD);
choice.setMessage("Choose a card to draft");
choice.setChoices(toSelect);
player.choose(outcome, choice, game);
String cardName = choice.getChoice();
if (cardName == null) {
return false;
}
CardInfo cardInfo = CardRepository.instance.findCards(new CardCriteria().nameExact(cardName)).stream().findFirst().orElse(null);
if (cardInfo == null) {
return false;
}
Set<Card> cards = new HashSet<>();
cards.add(cardInfo.getCard());
game.loadCards(cards, player.getId());
player.moveCards(cards, Zone.HAND, source, game);
return true;
}
use of mage.cards.repository.CardCriteria in project mage by magefree.
the class Sets method generateRandomCardPool.
public static List<Card> generateRandomCardPool(int cardsCount, List<ColoredManaSymbol> allowedColors, boolean onlyBasicLands, List<String> allowedSets) {
CardCriteria criteria = new CardCriteria();
if (onlyBasicLands) {
// only lands
criteria.rarities(Rarity.LAND);
// basic lands is colorless
criteria.colorless(true);
} else {
// any card, but not basic lands
criteria.notTypes(CardType.LAND);
// clear colors
criteria.white(false);
criteria.blue(false);
criteria.black(false);
criteria.red(false);
criteria.green(false);
// colorless is not allowed for gen
criteria.colorless(false);
}
if (allowedSets != null && allowedSets.size() > 0) {
for (String code : allowedSets) {
criteria.setCodes(code);
}
}
FilterMana manaNeed = new FilterMana();
for (ColoredManaSymbol color : allowedColors) {
switch(color) {
case W:
manaNeed.setWhite(true);
criteria.white(true);
break;
case U:
manaNeed.setBlue(true);
criteria.blue(true);
break;
case B:
manaNeed.setBlack(true);
criteria.black(true);
break;
case R:
manaNeed.setRed(true);
criteria.red(true);
break;
case G:
manaNeed.setGreen(true);
criteria.green(true);
break;
}
}
List<CardInfo> cards = CardRepository.instance.findCards(criteria);
if (cards.isEmpty()) {
throw new IllegalStateException("Can't find cards for chosen colors to generate deck: " + allowedColors);
}
int count = 0;
int tries = 0;
List<Card> cardPool = new ArrayList<>();
while (count < cardsCount) {
CardInfo cardInfo = cards.get(RandomUtil.nextInt(cards.size()));
Card card = cardInfo != null ? cardInfo.getCard() : null;
if (card != null) {
FilterMana manaCard = card.getColorIdentity();
boolean cardManaOK = true;
if (onlyBasicLands) {
// Assert.assertEquals("only basic lands allow, but found " + card.getName(), 1, card.getMana().size());
for (Mana manaLand : card.getMana()) {
if (manaLand.getWhite() > 0 && !manaNeed.isWhite()) {
cardManaOK = false;
}
if (manaLand.getBlue() > 0 && !manaNeed.isBlue()) {
cardManaOK = false;
}
if (manaLand.getBlack() > 0 && !manaNeed.isBlack()) {
cardManaOK = false;
}
if (manaLand.getRed() > 0 && !manaNeed.isRed()) {
cardManaOK = false;
}
if (manaLand.getGreen() > 0 && !manaNeed.isGreen()) {
cardManaOK = false;
}
if (manaLand.getColorless() > 0) {
cardManaOK = false;
}
// ignore colorless land (wastes)
}
} else {
// discard any card that have not needed color
if (manaCard.isWhite() && !manaNeed.isWhite()) {
cardManaOK = false;
}
if (manaCard.isBlue() && !manaNeed.isBlue()) {
cardManaOK = false;
}
if (manaCard.isBlack() && !manaNeed.isBlack()) {
cardManaOK = false;
}
if (manaCard.isRed() && !manaNeed.isRed()) {
cardManaOK = false;
}
if (manaCard.isGreen() && !manaNeed.isGreen()) {
cardManaOK = false;
}
}
if (cardManaOK) {
cardPool.add(card);
count++;
}
}
tries++;
if (tries > 4096) {
// to avoid infinite loop
throw new IllegalStateException("Not enough cards for chosen colors to generate deck: " + allowedColors);
}
}
return cardPool;
}
use of mage.cards.repository.CardCriteria in project mage by magefree.
the class MysteryBooster method populateBoosterSpecialSlot.
/**
* Populate the special slot. Defined as protected to allow overwriting this if the playtest cards
* from the convention edition are ever implemented.
*/
protected void populateBoosterSpecialSlot() {
CardCriteria criteria = new CardCriteria();
criteria.setCodes("FMB1");
this.possibleCardsPerBoosterSlot.get(15).addAll(CardRepository.instance.findCards(criteria));
}
Aggregations