use of mage.cards.repository.CardCriteria in project mage by magefree.
the class DragonsMazeCollator method findSpecialCardsByRarity.
@Override
protected List<CardInfo> findSpecialCardsByRarity(Rarity rarity) {
CardCriteria criteria = new CardCriteria();
criteria.rarities(rarity).types(CardType.LAND);
if (rarity == Rarity.RARE) {
// shocklands
criteria.setCodes("RTR", "GTC");
} else {
// Guildgates and Maze's End
criteria.setCodes(this.code);
}
List<CardInfo> cardInfos = CardRepository.instance.findCards(criteria);
cardInfos.removeIf(cardInfo -> (cardInfo.getName().equals("Grove of the Guardian") || cardInfo.getName().equals("Thespian's Stage")));
return cardInfos;
}
use of mage.cards.repository.CardCriteria in project mage by magefree.
the class FateReforgedCollator method findSpecialCardsByRarity.
@Override
protected List<CardInfo> findSpecialCardsByRarity(Rarity rarity) {
CardCriteria criteria = new CardCriteria();
criteria.rarities(rarity).types(CardType.LAND);
if (rarity == Rarity.RARE) {
// fetchlands
criteria.setCodes("KTK");
} else {
// gainlands
criteria.setCodes(this.code);
}
return CardRepository.instance.findCards(criteria);
}
use of mage.cards.repository.CardCriteria in project mage by magefree.
the class MWSDeckImporter method readLine.
@Override
protected void readLine(String line, DeckCardLists deckList, FixedInfo fixedInfo) {
if (line.isEmpty() || line.startsWith("//")) {
return;
}
boolean sideboard = false;
if (line.startsWith("SB:")) {
line = line.substring(3).trim();
sideboard = true;
}
int delim = line.indexOf(' ');
String lineNum = line.substring(0, delim).trim();
String setCode = "";
if (line.indexOf('[') != -1) {
int setStart = line.indexOf('[') + 1;
int setEnd = line.indexOf(']');
setCode = line.substring(setStart, setEnd).trim();
delim = setEnd;
}
String lineName = line.substring(delim + 1).trim();
try {
int num = Integer.parseInt(lineNum);
CardInfo cardInfo = null;
if (!setCode.isEmpty()) {
CardCriteria criteria = new CardCriteria();
criteria.name(lineName);
criteria.setCodes(setCode);
List<CardInfo> cards = getCardLookup().lookupCardInfo(criteria);
if (!cards.isEmpty()) {
cardInfo = cards.get(RandomUtil.nextInt(cards.size()));
}
}
if (cardInfo == null) {
cardInfo = getCardLookup().lookupCardInfo(lineName).orElse(null);
}
if (cardInfo == null) {
sbMessage.append("Could not find card: '").append(lineName).append("' at line ").append(lineCount).append('\n');
} else {
for (int i = 0; i < num; i++) {
if (!sideboard) {
deckList.getCards().add(new DeckCardInfo(cardInfo.getName(), cardInfo.getCardNumber(), cardInfo.getSetCode()));
} else {
deckList.getSideboard().add(new DeckCardInfo(cardInfo.getName(), cardInfo.getCardNumber(), cardInfo.getSetCode()));
}
}
}
} catch (NumberFormatException nfe) {
sbMessage.append("Invalid number: ").append(lineNum).append(" at line ").append(lineCount).append('\n');
}
}
use of mage.cards.repository.CardCriteria in project mage by magefree.
the class MomirEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
int value = source.getManaCostsToPay().getX();
if (game.isSimulation()) {
// Create dummy token to prevent multiple DB find cards what causes H2 java.lang.IllegalStateException if AI cancels calculation because of time out
Token token = new CreatureToken(value, value + 1);
token.putOntoBattlefield(1, game, source, source.getControllerId(), false, false);
return true;
}
// should this be random across card names
CardCriteria criteria = new CardCriteria().types(CardType.CREATURE).manaValue(value);
List<CardInfo> options = CardRepository.instance.findCards(criteria);
if (options == null || options.isEmpty()) {
game.informPlayers("No random creature card with mana value of " + value + " was found.");
return false;
}
// search for a random non custom set creature
EmptyToken token = null;
while (!options.isEmpty()) {
int index = RandomUtil.nextInt(options.size());
ExpansionSet expansionSet = Sets.findSet(options.get(index).getSetCode());
if (expansionSet == null || !expansionSet.getSetType().isEternalLegal()) {
options.remove(index);
} else {
Card card = options.get(index).getCard();
if (card != null) {
token = new EmptyToken();
CardUtil.copyTo(token).from(card, game);
break;
} else {
options.remove(index);
}
}
}
if (token != null) {
token.putOntoBattlefield(1, game, source, source.getControllerId(), false, false);
return true;
}
return false;
}
use of mage.cards.repository.CardCriteria in project mage by magefree.
the class ExpansionSet method generateBoosterMap.
protected void generateBoosterMap() {
CardRepository.instance.findCards(new CardCriteria().setCodes(code)).stream().forEach(cardInfo -> inBoosterMap.put(cardInfo.getCardNumber(), cardInfo));
// get basic lands from parent set if this set doesn't have them
if (!hasBasicLands && parentSet != null) {
String parentCode = parentSet.code;
CardRepository.instance.findCards(new CardCriteria().setCodes(parentCode).rarities(Rarity.LAND)).stream().forEach(cardInfo -> inBoosterMap.put(parentCode + "_" + cardInfo.getCardNumber(), cardInfo));
}
}
Aggregations