use of mage.constants.SubType in project mage by magefree.
the class SunderingTitanDestroyLandEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
Permanent sourcePermanent = game.getPermanentOrLKIBattlefield(source.getSourceId());
Set<UUID> lands = new HashSet<>();
if (controller != null && sourcePermanent != null) {
for (SubType landName : SubType.getBasicLands()) {
FilterLandPermanent filter = new FilterLandPermanent(landName + " to destroy");
filter.add(landName.getPredicate());
Target target = new TargetLandPermanent(1, 1, filter, true);
if (target.canChoose(source.getSourceId(), source.getControllerId(), game)) {
controller.chooseTarget(outcome, target, source, game);
lands.add(target.getFirstTarget());
}
}
if (!lands.isEmpty()) {
int destroyedLands = 0;
for (UUID landId : lands) {
Permanent land = game.getPermanent(landId);
if (land != null) {
if (land.destroy(source, game, false)) {
destroyedLands++;
}
}
}
game.informPlayers(sourcePermanent.getLogName() + ": " + destroyedLands + (destroyedLands > 1 ? " lands were" : "land was") + " destroyed");
}
return true;
}
return false;
}
use of mage.constants.SubType in project mage by magefree.
the class VerifyCardDataTest method checkSubtypes.
private void checkSubtypes(Card card, MtgJsonCard ref) {
if (skipListHaveName(SKIP_LIST_SUBTYPE, card.getExpansionSetCode(), card.getName())) {
return;
}
Collection<String> expected = ref.subtypes;
// fix names (e.g. Urza’s to Urza's)
if (expected != null && expected.contains("Urza’s")) {
expected = new ArrayList<>(expected);
for (ListIterator<String> it = ((List<String>) expected).listIterator(); it.hasNext(); ) {
if (it.next().equals("Urza’s")) {
it.set("Urza's");
}
}
}
// Remove subtypes that need to be ignored
Collection<String> actual = card.getSubtype().stream().map(SubType::toString).collect(Collectors.toSet());
actual.removeIf(subtypesToIgnore::contains);
if (expected != null) {
expected.removeIf(subtypesToIgnore::contains);
}
for (SubType subType : card.getSubtype()) {
if (!subType.isCustomSet() && !subType.canGain(card)) {
String cardTypeString = card.getCardType().stream().map(CardType::toString).reduce((a, b) -> a + " " + b).orElse("");
fail(card, "subtypes", "card has subtype " + subType.getDescription() + " (" + subType.getSubTypeSet() + ')' + " that doesn't match its card type(s) (" + cardTypeString + ')');
}
}
if (!eqSet(actual, expected)) {
fail(card, "subtypes", actual + " != " + expected);
}
}
use of mage.constants.SubType in project mage by magefree.
the class EnterAttributeAddChosenSubtypeEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Permanent permanent = game.getPermanentEntering(source.getSourceId());
SubType subtype = (SubType) game.getState().getValue(source.getSourceId() + "_type");
if (permanent != null && subtype != null) {
permanent.addSubType(game, subtype);
return true;
}
return false;
}
use of mage.constants.SubType in project mage by magefree.
the class FacelessAgentEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player player = game.getPlayer(source.getControllerId());
if (player == null || player.getLibrary().count(filterAnyType, game) < 1) {
return false;
}
Map<SubType, Integer> typeMap = player.getLibrary().getCards(game).stream().filter(card -> !card.isAllCreatureTypes(game)).map(card -> card.getSubtype(game)).flatMap(Collection::stream).filter(subType -> subType.getSubTypeSet() == SubTypeSet.CreatureType).collect(Collectors.toMap(Function.identity(), x -> 1, Integer::sum));
if (typeMap.isEmpty()) {
return player.seekCard(filterAnyType, source, game);
}
int max = typeMap.values().stream().mapToInt(x -> x).max().orElse(0);
FilterCard filter = new FilterCreatureCard();
filter.add(Predicates.or(typeMap.entrySet().stream().filter(entry -> entry.getValue() == max).map(Map.Entry::getKey).map(SubType::getPredicate).collect(Collectors.toSet())));
return player.seekCard(filter, source, game);
}
use of mage.constants.SubType in project mage by magefree.
the class KindredSummonsEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
if (controller != null) {
SubType subType = ChooseCreatureTypeEffect.getChosenCreatureType(source.getSourceId(), game);
if (subType == null) {
return false;
}
FilterControlledCreaturePermanent filterPermanent = new FilterControlledCreaturePermanent("creature you control of the chosen type");
filterPermanent.add(subType.getPredicate());
int numberOfCards = game.getBattlefield().countAll(filterPermanent, source.getControllerId(), game);
Cards revealed = new CardsImpl();
Set<Card> chosenSubtypeCreatureCards = new LinkedHashSet<>();
Cards otherCards = new CardsImpl();
FilterCreatureCard filterCard = new FilterCreatureCard("creature card of the chosen type");
filterCard.add(subType.getPredicate());
if (numberOfCards == 0) {
// no matches so nothing is revealed
game.informPlayers("There are 0 creature cards of the chosen type in " + controller.getName() + "'s library.");
return true;
}
for (Card card : controller.getLibrary().getCards(game)) {
revealed.add(card);
if (card != null && filterCard.match(card, game)) {
chosenSubtypeCreatureCards.add(card);
if (chosenSubtypeCreatureCards.size() == numberOfCards) {
break;
}
} else {
otherCards.add(card);
}
}
controller.revealCards(source, revealed, game);
controller.moveCards(chosenSubtypeCreatureCards, Zone.BATTLEFIELD, source, game);
if (!otherCards.isEmpty()) {
controller.putCardsOnTopOfLibrary(otherCards, game, source, false);
controller.shuffleLibrary(source, game);
}
return true;
}
return false;
}
Aggregations