Search in sources :

Example 1 with SubType

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;
}
Also used : Player(mage.players.Player) Target(mage.target.Target) SubType(mage.constants.SubType) FilterLandPermanent(mage.filter.common.FilterLandPermanent) TargetLandPermanent(mage.target.common.TargetLandPermanent) FilterLandPermanent(mage.filter.common.FilterLandPermanent) Permanent(mage.game.permanent.Permanent) TargetLandPermanent(mage.target.common.TargetLandPermanent) UUID(java.util.UUID) HashSet(java.util.HashSet)

Example 2 with SubType

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);
    }
}
Also used : SagaAbility(mage.abilities.common.SagaAbility) WerewolfBackTriggeredAbility(mage.abilities.common.WerewolfBackTriggeredAbility) CardScanner(mage.cards.repository.CardScanner) Reflections(org.reflections.Reflections) ScryEffect(mage.abilities.effects.keyword.ScryEffect) java.nio.file(java.nio.file) RateCard(mage.game.draft.RateCard) Logger(org.apache.log4j.Logger) DraftCube(mage.game.draft.DraftCube) TransformAbility(mage.abilities.keyword.TransformAbility) CardType(mage.constants.CardType) ObjectColor(mage.ObjectColor) Method(java.lang.reflect.Method) mage.cards(mage.cards) FightTargetsEffect(mage.abilities.effects.common.FightTargetsEffect) DeckImporter(mage.cards.decks.importer.DeckImporter) Plane(mage.game.command.Plane) CardUtil(mage.util.CardUtil) CardRepository(mage.cards.repository.CardRepository) Collectors(java.util.stream.Collectors) InvocationTargetException(java.lang.reflect.InvocationTargetException) TherosBeyondDeath(mage.sets.TherosBeyondDeath) Dungeon(mage.game.command.Dungeon) Watcher(mage.watchers.Watcher) Token(mage.game.permanent.token.Token) Effect(mage.abilities.effects.Effect) Modifier(java.lang.reflect.Modifier) MultikickerAbility(mage.abilities.keyword.MultikickerAbility) Rarity(mage.constants.Rarity) java.util(java.util) TokenImpl(mage.game.permanent.token.TokenImpl) SubType(mage.constants.SubType) Constructor(java.lang.reflect.Constructor) Mode(mage.abilities.Mode) EnchantAbility(mage.abilities.keyword.EnchantAbility) DownloadPicturesService(org.mage.plugins.card.images.DownloadPicturesService) MenaceAbility(mage.abilities.keyword.MenaceAbility) DeckCardLists(mage.cards.decks.DeckCardLists) ScryfallImageSupportCards(org.mage.plugins.card.dl.sources.ScryfallImageSupportCards) CharMatcher(com.google.common.base.CharMatcher) Test(org.junit.Test) CardDownloadData(org.mage.plugins.card.images.CardDownloadData) IOException(java.io.IOException) MtgJsonCard(mage.verify.mtgjson.MtgJsonCard) BasicFileAttributes(java.nio.file.attribute.BasicFileAttributes) MtgJsonSet(mage.verify.mtgjson.MtgJsonSet) MtgJsonService(mage.verify.mtgjson.MtgJsonService) WerewolfFrontTriggeredAbility(mage.abilities.common.WerewolfFrontTriggeredAbility) Ignore(org.junit.Ignore) CardInfo(mage.cards.repository.CardInfo) Assert(org.junit.Assert) SuperType(mage.constants.SuperType) Ability(mage.abilities.Ability) SubType(mage.constants.SubType) CardType(mage.constants.CardType)

Example 3 with SubType

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;
}
Also used : SubType(mage.constants.SubType) Permanent(mage.game.permanent.Permanent)

Example 4 with SubType

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);
}
Also used : FilterCard(mage.filter.FilterCard) Predicate(mage.filter.predicate.Predicate) SubTypeSet(mage.constants.SubTypeSet) EntersBattlefieldTriggeredAbility(mage.abilities.common.EntersBattlefieldTriggeredAbility) Collection(java.util.Collection) Outcome(mage.constants.Outcome) OneShotEffect(mage.abilities.effects.OneShotEffect) Predicates(mage.filter.predicate.Predicates) UUID(java.util.UUID) MageInt(mage.MageInt) SubType(mage.constants.SubType) Function(java.util.function.Function) Collectors(java.util.stream.Collectors) Player(mage.players.Player) CardSetInfo(mage.cards.CardSetInfo) FilterCreatureCard(mage.filter.common.FilterCreatureCard) Game(mage.game.Game) CardImpl(mage.cards.CardImpl) Map(java.util.Map) ChangelingAbility(mage.abilities.keyword.ChangelingAbility) CardType(mage.constants.CardType) Card(mage.cards.Card) Ability(mage.abilities.Ability) FilterCard(mage.filter.FilterCard) Player(mage.players.Player) FilterCreatureCard(mage.filter.common.FilterCreatureCard) SubType(mage.constants.SubType) Collection(java.util.Collection)

Example 5 with SubType

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;
}
Also used : LinkedHashSet(java.util.LinkedHashSet) Player(mage.players.Player) FilterCreatureCard(mage.filter.common.FilterCreatureCard) SubType(mage.constants.SubType) FilterControlledCreaturePermanent(mage.filter.common.FilterControlledCreaturePermanent) Cards(mage.cards.Cards) CardsImpl(mage.cards.CardsImpl) FilterCreatureCard(mage.filter.common.FilterCreatureCard) Card(mage.cards.Card)

Aggregations

SubType (mage.constants.SubType)24 Player (mage.players.Player)11 MageObject (mage.MageObject)8 CardType (mage.constants.CardType)6 Permanent (mage.game.permanent.Permanent)6 UUID (java.util.UUID)5 SuperType (mage.constants.SuperType)5 Collectors (java.util.stream.Collectors)4 Ability (mage.abilities.Ability)4 Card (mage.cards.Card)4 ObjectColor (mage.ObjectColor)3 Effect (mage.abilities.effects.Effect)3 OneShotEffect (mage.abilities.effects.OneShotEffect)3 FilterCreatureCard (mage.filter.common.FilterCreatureCard)3 HashSet (java.util.HashSet)2 LinkedHashSet (java.util.LinkedHashSet)2 CardImpl (mage.cards.CardImpl)2 CardSetInfo (mage.cards.CardSetInfo)2 Choice (mage.choices.Choice)2 Rarity (mage.constants.Rarity)2