use of mage.cards.repository.CardInfo in project mage by magefree.
the class SerializationTest method processSingleCard.
private void processSingleCard(String cardName) {
CardInfo cardInfo = CardRepository.instance.findCard(cardName);
processSingleCard(cardInfo);
}
use of mage.cards.repository.CardInfo 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.CardInfo 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.CardInfo in project mage by magefree.
the class MysteryBooster method createBooster.
@Override
public List<Card> createBooster() {
if (this.possibleCardsPerBoosterSlot.isEmpty()) {
// Generate the map only once
this.populateBoosterSlotMap();
}
final List<Card> booster = new ArrayList<>(15);
for (int slot = 1; slot < 16; ++slot) {
final List<CardInfo> availableCards = this.possibleCardsPerBoosterSlot.get(slot);
final int printSheetCardNumber = RandomUtil.nextInt(availableCards.size());
final Card chosenCard = availableCards.get(printSheetCardNumber).getCard();
booster.add(chosenCard);
}
return booster;
}
use of mage.cards.repository.CardInfo in project mage by magefree.
the class VerifyCardDataTest method test_showCardInfo.
@Test
public void test_showCardInfo() throws Exception {
// debug only: show direct card info (takes it from class file, not from db repository)
// can check multiple cards at once, example: name1;name2;name3
String cardNames = "Spark Double";
CardScanner.scan();
Arrays.stream(cardNames.split(";")).forEach(cardName -> {
cardName = cardName.trim();
CardSetInfo testSet = new CardSetInfo(cardName, "test", "123", Rarity.COMMON);
CardInfo cardInfo = CardRepository.instance.findCard(cardName);
if (cardInfo == null) {
Assert.fail("Can't find card name: " + cardName);
}
Card card = CardImpl.createCard(cardInfo.getClassName(), testSet);
System.out.println();
System.out.println(card.getName() + " " + card.getManaCost().getText());
if (card instanceof SplitCard || card instanceof ModalDoubleFacesCard) {
card.getAbilities().getRules(card.getName()).forEach(this::printAbilityText);
} else {
card.getRules().forEach(this::printAbilityText);
}
});
}
Aggregations