use of mage.cards.repository.CardInfo in project mage by magefree.
the class Constructed method legalSets.
/**
* Checks if the given card is legal in any of the given sets or as single card
*
* @param card - the card to check
* @return Whether the card was printed in any of this format's sets.
*/
protected boolean legalSets(Card card) {
// check if card is legal if taken from other set
boolean legal = false;
List<CardInfo> cardInfos = CardRepository.instance.findCards(card.getName());
for (CardInfo cardInfo : cardInfos) {
if (isSetAllowed(cardInfo.getSetCode())) {
legal = true;
break;
}
}
// check if single card allows
if (singleCards.contains(card.getName())) {
legal = true;
}
if (!legal && !errorsListContainsGroup(card.getName())) {
addError(DeckValidatorErrorType.WRONG_SET, card.getName(), "Invalid set: " + card.getExpansionSetCode(), true);
}
return legal;
}
use of mage.cards.repository.CardInfo in project mage by magefree.
the class Constructed method legalRarity.
/**
* Checks if the given card is legal in any of the given rarities
*
* @param card - the card to check
* @return Whether the card was printed at any of the given rarities.
*/
protected boolean legalRarity(Card card) {
// check if card is legal if taken from other set
boolean legal = false;
List<CardInfo> cardInfos = CardRepository.instance.findCards(card.getName());
for (CardInfo cardInfo : cardInfos) {
if (rarities.contains(cardInfo.getRarity())) {
legal = true;
break;
}
}
if (!legal && !errorsListContainsGroup(card.getName())) {
addError(DeckValidatorErrorType.OTHER, card.getName(), "Invalid rarity: " + card.getRarity(), true);
}
return legal;
}
use of mage.cards.repository.CardInfo in project mage by magefree.
the class CustomTestCard method parseLine.
private void parseLine(String line) {
if (parserState == ParserState.EXPECTED) {
// just remember for future use
expectedResults.add(line);
return;
}
Matcher m = pattern.matcher(line);
if (m.matches()) {
String zone = m.group(1);
String nickname = m.group(2);
if (nickname.startsWith("Computer")) {
List<Card> cards = null;
List<PermanentCard> perms = null;
Zone gameZone;
if ("hand".equalsIgnoreCase(zone)) {
gameZone = Zone.HAND;
cards = getHandCards(getPlayer(nickname));
} else if ("battlefield".equalsIgnoreCase(zone)) {
gameZone = Zone.BATTLEFIELD;
perms = getBattlefieldCards(getPlayer(nickname));
} else if ("graveyard".equalsIgnoreCase(zone)) {
gameZone = Zone.GRAVEYARD;
cards = getGraveCards(getPlayer(nickname));
} else if ("library".equalsIgnoreCase(zone)) {
gameZone = Zone.LIBRARY;
cards = getLibraryCards(getPlayer(nickname));
} else if ("command".equalsIgnoreCase(zone)) {
gameZone = Zone.COMMAND;
cards = getCommandCards(getPlayer(nickname));
} else if ("player".equalsIgnoreCase(zone)) {
String command = m.group(3);
if ("life".equals(command)) {
getCommands(getPlayer(nickname)).put(Zone.OUTSIDE, "life:" + m.group(4));
}
return;
} else {
// go parse next line
return;
}
String cardName = m.group(3);
Integer amount = Integer.parseInt(m.group(4));
boolean tapped = m.group(5) != null && m.group(5).equals(":{tapped}");
if (cardName.equals("clear")) {
getCommands(getPlayer(nickname)).put(gameZone, "clear");
} else {
for (int i = 0; i < amount; i++) {
CardInfo cardInfo = CardRepository.instance.findCard(cardName);
Card newCard = cardInfo != null ? cardInfo.getCard() : null;
if (newCard != null) {
if (gameZone == Zone.BATTLEFIELD) {
Card permCard = CardUtil.getDefaultCardSideForBattlefield(currentGame, newCard);
PermanentCard p = new PermanentCard(permCard, null, currentGame);
p.setTapped(tapped);
perms.add(p);
} else {
cards.add(newCard);
}
} else {
logger.fatal("Couldn't find a card: " + cardName);
logger.fatal("line: " + line);
}
}
}
} else {
logger.warn("Unknown player: " + nickname);
}
} else {
logger.warn("Init string wasn't parsed: " + line);
}
}
use of mage.cards.repository.CardInfo in project mage by magefree.
the class DeckTestUtils method buildRandomDeckAndInitCards.
public static DeckCardLists buildRandomDeckAndInitCards(String colors, boolean onlyBasicLands, String allowedSets) {
Deck deck = buildRandomDeck(colors, onlyBasicLands, allowedSets);
DeckCardLists deckList = new DeckCardLists();
for (Card card : deck.getCards()) {
CardInfo cardInfo = CardRepository.instance.findCard(card.getExpansionSetCode(), card.getCardNumber());
if (cardInfo != null) {
deckList.getCards().add(new DeckCardInfo(cardInfo.getName(), cardInfo.getCardNumber(), cardInfo.getSetCode()));
}
}
return deckList;
}
use of mage.cards.repository.CardInfo in project mage by magefree.
the class SerializationTest method test_PermanentImpl_MarkedDamageInfo.
@Test
public void test_PermanentImpl_MarkedDamageInfo() {
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);
// mark damage from infected ability
permanent.addAbility(InfectAbility.getInstance(), null, currentGame);
permanent.markDamage(1, permanent.getId(), null, currentGame, false, false);
// test compress (it uses default java serialization)
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());
// ensure that it was marked damage
permanent.applyDamage(currentGame);
Assert.assertEquals("Must get infected counter", 1, permanent.getCounters(currentGame).getCount(CounterType.M1M1));
}
Aggregations