use of mage.cards.repository.CardInfo 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.CardInfo in project mage by magefree.
the class MysteryBooster method populateSlot.
/**
* Populate the given booster slot.
*
* @param slotNumber booster slot number. 1-indexed, valid range is 1-14, as 15 is the special slot
* @param cardNames List of English card names found on the given slot
*/
private void populateSlot(int slotNumber, List<String> cardNames) {
final List<CardInfo> cardInfoList = this.possibleCardsPerBoosterSlot.get(slotNumber);
for (String name : cardNames) {
final CardInfo cardWithGivenName = CardRepository.instance.findCardWPreferredSet(name, this.code, false);
cardInfoList.add(cardWithGivenName);
}
}
use of mage.cards.repository.CardInfo in project mage by magefree.
the class CardTestPlayerAPIImpl method addCard.
/**
* Add any amount of cards to specified zone of specified player.
*
* @param gameZone {@link mage.constants.Zone} to add cards to.
* @param player {@link Player} to add cards for. Use either playerA or
* playerB.
* @param cardName Card name in string format.
* @param count Amount of cards to be added.
* @param tapped In case gameZone is Battlefield, determines whether
* permanent should be tapped. In case gameZone is other
* than Battlefield, {@link IllegalArgumentException} is
* thrown
*/
@Override
public void addCard(Zone gameZone, TestPlayer player, String cardName, int count, boolean tapped) {
// aliases for mage objects
String aliasName = "";
boolean useAliasMultiNames = (count != 1);
if (cardName.contains(ALIAS_PREFIX)) {
aliasName = cardName.substring(cardName.indexOf(ALIAS_PREFIX) + ALIAS_PREFIX.length());
cardName = cardName.substring(0, cardName.indexOf(ALIAS_PREFIX));
}
// one card = one aliase, massive adds can use auto-name
if (!useAliasMultiNames && !aliasName.isEmpty() && player.getAliasByName(aliasName) != null) {
Assert.fail("Can't add card " + cardName + " - alias " + aliasName + " already exists for " + player.getName());
}
// game tests don't need cards from a specific set, so it can be from any set
CardInfo cardInfo = CardRepository.instance.findCard(cardName, true);
if (cardInfo == null) {
throw new IllegalArgumentException("[TEST] Couldn't find a card: " + cardName);
}
if (gameZone == Zone.BATTLEFIELD) {
for (int i = 0; i < count; i++) {
Card newCard = cardInfo.getCard();
Card permCard = CardUtil.getDefaultCardSideForBattlefield(currentGame, newCard);
PermanentCard p = new PermanentCard(permCard, player.getId(), currentGame);
p.setTapped(tapped);
getBattlefieldCards(player).add(p);
if (!aliasName.isEmpty()) {
player.addAlias(player.generateAliasName(aliasName, useAliasMultiNames, i + 1), p.getId());
}
}
} else {
if (tapped) {
throw new IllegalArgumentException("Parameter tapped=true can be used only for Zone.BATTLEFIELD.");
}
List<Card> cards = getCardList(gameZone, player);
for (int i = 0; i < count; i++) {
Card newCard = cardInfo.getCard();
cards.add(newCard);
if (!aliasName.isEmpty()) {
player.addAlias(player.generateAliasName(aliasName, useAliasMultiNames, i + 1), newCard.getId());
}
}
}
}
use of mage.cards.repository.CardInfo in project mage by magefree.
the class SerializationTest method test_PermanentImpl_Simple.
@Test
public void test_PermanentImpl_Simple() {
CardInfo cardInfo = CardRepository.instance.findCard("Balduvian Bears");
Card newCard = cardInfo.getCard();
Card permCard = CardUtil.getDefaultCardSideForBattlefield(currentGame, newCard);
PermanentImpl permanent = new PermanentCard(permCard, playerA.getId(), currentGame);
currentGame.addPermanent(permanent, 0);
Object compressed = CompressUtil.compress(permanent);
Assert.assertTrue("Must be zip", compressed instanceof ZippedObjectImpl);
PermanentImpl uncompressed = (PermanentImpl) CompressUtil.decompress(compressed);
Assert.assertEquals("Must be same", permanent.getName(), uncompressed.getName());
}
use of mage.cards.repository.CardInfo in project mage by magefree.
the class SerializationTest method test_Single_AllCards.
// WARNING, debug only, needs few minutes to execute, so run it manually
@Ignore
@Test
public void test_Single_AllCards() {
// checking FULL cards list for serialization errors
String filterSet = "";
String filterCard = "";
List<String> errorsList = new ArrayList<>();
int checkedCount = 0;
for (ExpansionSet set : Sets.getInstance().values()) {
if (!filterSet.isEmpty() && !set.getCode().equals(filterSet)) {
continue;
}
checkedCount++;
System.out.printf("Checking set %d of %d (%s)%n", checkedCount, Sets.getInstance().size(), set.getName());
for (ExpansionSet.SetCardInfo info : set.getSetCardInfo()) {
if (!filterCard.isEmpty() && !info.getName().equals(filterCard)) {
continue;
}
CardInfo cardInfo = CardRepository.instance.findCardsByClass(info.getCardClass().getCanonicalName()).stream().findFirst().orElse(null);
try {
processSingleCard(cardInfo);
} catch (Throwable e) {
System.out.println("Broken card: " + info.getName());
// e.printStackTrace(); // search exception errors in the logs
errorsList.add(info.getName());
}
}
}
if (!errorsList.isEmpty()) {
Assert.fail("Found broken cards: " + errorsList.size() + "\n" + errorsList.stream().sorted().collect(Collectors.joining("\n")));
}
}
Aggregations