Search in sources :

Example 6 with CardType

use of mage.constants.CardType in project mage by magefree.

the class WorldQuellerEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    List<Card> chosen = new ArrayList<>();
    Player player = game.getPlayer(source.getControllerId());
    Permanent sourceCreature = game.getPermanent(source.getSourceId());
    if (player != null && sourceCreature != null) {
        Choice choiceImpl = new ChoiceImpl();
        choiceImpl.setChoices(choice);
        if (!player.choose(Outcome.Neutral, choiceImpl, game)) {
            return false;
        }
        CardType type = null;
        String choosenType = choiceImpl.getChoice();
        if (choosenType.equals(CardType.ARTIFACT.toString())) {
            type = CardType.ARTIFACT;
        } else if (choosenType.equals(CardType.LAND.toString())) {
            type = CardType.LAND;
        } else if (choosenType.equals(CardType.CREATURE.toString())) {
            type = CardType.CREATURE;
        } else if (choosenType.equals(CardType.ENCHANTMENT.toString())) {
            type = CardType.ENCHANTMENT;
        } else if (choosenType.equals(CardType.INSTANT.toString())) {
            type = CardType.INSTANT;
        } else if (choosenType.equals(CardType.SORCERY.toString())) {
            type = CardType.SORCERY;
        } else if (choosenType.equals(CardType.PLANESWALKER.toString())) {
            type = CardType.PLANESWALKER;
        } else if (choosenType.equals(CardType.TRIBAL.toString())) {
            type = CardType.TRIBAL;
        }
        if (type != null) {
            FilterControlledPermanent filter = new FilterControlledPermanent("permanent you control of type " + type.toString());
            filter.add(type.getPredicate());
            TargetPermanent target = new TargetControlledPermanent(1, 1, filter, false);
            target.setNotTarget(true);
            for (UUID playerId : game.getState().getPlayersInRange(source.getControllerId(), game)) {
                Player player2 = game.getPlayer(playerId);
                if (player2 != null && target.canChoose(source.getSourceId(), playerId, game)) {
                    while (player2.canRespond() && !target.isChosen() && target.canChoose(source.getSourceId(), playerId, game)) {
                        player2.chooseTarget(Outcome.Sacrifice, target, source, game);
                    }
                    Permanent permanent = game.getPermanent(target.getFirstTarget());
                    if (permanent != null) {
                        chosen.add(permanent);
                    }
                    target.clearChosen();
                }
            }
            // all chosen permanents are sacrificed together
            for (Permanent permanent : game.getBattlefield().getAllActivePermanents()) {
                if (chosen.contains(permanent)) {
                    permanent.sacrifice(source, game);
                }
            }
            return true;
        }
    }
    return false;
}
Also used : Player(mage.players.Player) Choice(mage.choices.Choice) FilterControlledPermanent(mage.filter.common.FilterControlledPermanent) Permanent(mage.game.permanent.Permanent) TargetControlledPermanent(mage.target.common.TargetControlledPermanent) TargetPermanent(mage.target.TargetPermanent) FilterControlledPermanent(mage.filter.common.FilterControlledPermanent) Card(mage.cards.Card) TargetControlledPermanent(mage.target.common.TargetControlledPermanent) CardType(mage.constants.CardType) ChoiceImpl(mage.choices.ChoiceImpl) TargetPermanent(mage.target.TargetPermanent)

Example 7 with CardType

use of mage.constants.CardType 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 8 with CardType

use of mage.constants.CardType in project mage by magefree.

the class BloodOathEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    MageObject sourceObject = game.getObject(source.getSourceId());
    Player player = game.getPlayer(source.getControllerId());
    Player opponent = game.getPlayer(source.getFirstTarget());
    if (player != null && opponent != null && sourceObject != null) {
        Choice choiceImpl = new ChoiceImpl();
        choiceImpl.setChoices(choice);
        if (player.choose(Outcome.Neutral, choiceImpl, game)) {
            CardType type = null;
            String choosenType = choiceImpl.getChoice();
            if (choosenType.equals(CardType.ARTIFACT.toString())) {
                type = CardType.ARTIFACT;
            } else if (choosenType.equals(CardType.LAND.toString())) {
                type = CardType.LAND;
            } else if (choosenType.equals(CardType.CREATURE.toString())) {
                type = CardType.CREATURE;
            } else if (choosenType.equals(CardType.ENCHANTMENT.toString())) {
                type = CardType.ENCHANTMENT;
            } else if (choosenType.equals(CardType.INSTANT.toString())) {
                type = CardType.INSTANT;
            } else if (choosenType.equals(CardType.SORCERY.toString())) {
                type = CardType.SORCERY;
            } else if (choosenType.equals(CardType.PLANESWALKER.toString())) {
                type = CardType.PLANESWALKER;
            } else if (choosenType.equals(CardType.TRIBAL.toString())) {
                type = CardType.TRIBAL;
            }
            if (type != null) {
                Cards hand = opponent.getHand();
                opponent.revealCards(sourceObject.getIdName(), hand, game);
                Set<Card> cards = hand.getCards(game);
                int damageToDeal = 0;
                for (Card card : cards) {
                    if (card != null && card.getCardType(game).contains(type)) {
                        damageToDeal += 3;
                    }
                }
                game.informPlayers(sourceObject.getLogName() + " deals " + (damageToDeal == 0 ? "no" : "" + damageToDeal) + " damage to " + opponent.getLogName());
                opponent.damage(damageToDeal, source.getSourceId(), source, game);
                return true;
            }
        }
    }
    return false;
}
Also used : Player(mage.players.Player) Choice(mage.choices.Choice) CardType(mage.constants.CardType) MageObject(mage.MageObject) ChoiceImpl(mage.choices.ChoiceImpl) Cards(mage.cards.Cards) Card(mage.cards.Card)

Example 9 with CardType

use of mage.constants.CardType in project mage by magefree.

the class CreepingRenaissanceEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    if (controller == null) {
        return false;
    }
    Choice typeChoice = new ChoiceCardType(true, Arrays.stream(CardType.values()).filter(CardType::isPermanentType).collect(Collectors.toList()));
    typeChoice.setMessage("Choose a permanent type");
    if (!controller.choose(Outcome.ReturnToHand, typeChoice, game)) {
        return false;
    }
    String typeName = typeChoice.getChoice();
    CardType chosenType = CardType.fromString(typeChoice.getChoice());
    if (chosenType == null) {
        return false;
    }
    FilterCard filter = new FilterCard(chosenType.toString().toLowerCase(Locale.ENGLISH) + " card");
    filter.add(chosenType.getPredicate());
    return controller.moveCards(controller.getGraveyard().getCards(filter, source.getSourceId(), controller.getId(), game), Zone.HAND, source, game);
}
Also used : FilterCard(mage.filter.FilterCard) Player(mage.players.Player) Choice(mage.choices.Choice) ChoiceCardType(mage.choices.ChoiceCardType) CardType(mage.constants.CardType) ChoiceCardType(mage.choices.ChoiceCardType)

Example 10 with CardType

use of mage.constants.CardType in project mage by magefree.

the class MythosOfSnapdaxEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    if (controller == null) {
        return false;
    }
    boolean conditionMet = condition.apply(game, source);
    List<Player> playerList = game.getState().getPlayersInRange(source.getControllerId(), game).stream().map(game::getPlayer).filter(Objects::nonNull).collect(Collectors.toList());
    Set<UUID> toKeep = new HashSet();
    for (Player player : playerList) {
        for (CardType cardType : cardTypes) {
            String message = cardType.toString().equals("Artifact") ? "an " : "a ";
            message += cardType.toString().toLowerCase(Locale.ENGLISH);
            message += (conditionMet && player != controller) ? " controlled by " + player.getName() : " you control";
            FilterPermanent filter = new FilterNonlandPermanent(message);
            filter.add(cardType.getPredicate());
            filter.add(new ControllerIdPredicate(player.getId()));
            if (game.getBattlefield().count(filter, source.getSourceId(), source.getControllerId(), game) == 0) {
                continue;
            }
            TargetPermanent target = new TargetPermanent(filter);
            target.setNotTarget(true);
            if (conditionMet) {
                controller.choose(outcome, target, source.getSourceId(), game);
            } else {
                player.choose(outcome, target, source.getSourceId(), game);
            }
            toKeep.add(target.getFirstTarget());
        }
    }
    for (Permanent permanent : game.getBattlefield().getActivePermanents(StaticFilters.FILTER_PERMANENT_NON_LAND, source.getControllerId(), game)) {
        if (permanent == null || toKeep.contains(permanent.getId())) {
            continue;
        }
        permanent.sacrifice(source, game);
    }
    return true;
}
Also used : Player(mage.players.Player) FilterPermanent(mage.filter.FilterPermanent) FilterNonlandPermanent(mage.filter.common.FilterNonlandPermanent) FilterPermanent(mage.filter.FilterPermanent) Permanent(mage.game.permanent.Permanent) TargetPermanent(mage.target.TargetPermanent) CardType(mage.constants.CardType) ControllerIdPredicate(mage.filter.predicate.permanent.ControllerIdPredicate) TargetPermanent(mage.target.TargetPermanent) FilterNonlandPermanent(mage.filter.common.FilterNonlandPermanent)

Aggregations

CardType (mage.constants.CardType)29 Player (mage.players.Player)16 Permanent (mage.game.permanent.Permanent)11 MageObject (mage.MageObject)9 Card (mage.cards.Card)9 TargetPermanent (mage.target.TargetPermanent)8 Choice (mage.choices.Choice)7 ChoiceImpl (mage.choices.ChoiceImpl)7 UUID (java.util.UUID)4 Cards (mage.cards.Cards)4 SuperType (mage.constants.SuperType)4 FilterCard (mage.filter.FilterCard)4 ArrayList (java.util.ArrayList)3 HashSet (java.util.HashSet)3 FilterControlledPermanent (mage.filter.common.FilterControlledPermanent)3 TargetControlledPermanent (mage.target.common.TargetControlledPermanent)3 Ability (mage.abilities.Ability)2 Effect (mage.abilities.effects.Effect)2 Rarity (mage.constants.Rarity)2 SubType (mage.constants.SubType)2