Search in sources :

Example 1 with CardType

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

the class CounterlashEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    StackObject stackObject = game.getStack().getStackObject(source.getFirstTarget());
    Player controller = game.getPlayer(source.getControllerId());
    if (stackObject != null && controller != null) {
        game.getStack().counter(source.getFirstTarget(), source, game);
        if (controller.chooseUse(Outcome.PlayForFree, "Cast a nonland card in your hand that " + "shares a card type with that spell without paying its mana cost?", source, game)) {
            FilterCard filter = new FilterCard();
            List<Predicate<MageObject>> types = new ArrayList<>();
            for (CardType type : stackObject.getCardType(game)) {
                if (type != CardType.LAND) {
                    types.add(type.getPredicate());
                }
            }
            filter.add(Predicates.or(types));
            TargetCardInHand target = new TargetCardInHand(filter);
            if (controller.choose(Outcome.PutCardInPlay, target, source.getSourceId(), game)) {
                Card card = controller.getHand().get(target.getFirstTarget(), game);
                if (card != null) {
                    game.getState().setValue("PlayFromNotOwnHandZone" + card.getId(), Boolean.TRUE);
                    controller.cast(controller.chooseAbilityForCast(card, game, true), game, true, new ApprovingObject(source, game));
                    game.getState().setValue("PlayFromNotOwnHandZone" + card.getId(), null);
                }
            }
        }
        return true;
    }
    return false;
}
Also used : FilterCard(mage.filter.FilterCard) Player(mage.players.Player) ApprovingObject(mage.ApprovingObject) TargetCardInHand(mage.target.common.TargetCardInHand) CardType(mage.constants.CardType) StackObject(mage.game.stack.StackObject) ArrayList(java.util.ArrayList) Predicate(mage.filter.predicate.Predicate) FilterCard(mage.filter.FilterCard) Card(mage.cards.Card)

Example 2 with CardType

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

the class FertileImaginationEffect 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();
                SaprolingToken saprolingToken = new SaprolingToken();
                opponent.revealCards(sourceObject.getIdName(), hand, game);
                Set<Card> cards = hand.getCards(game);
                int tokensToMake = 0;
                for (Card card : cards) {
                    if (card != null && card.getCardType(game).contains(type)) {
                        tokensToMake += 2;
                    }
                }
                game.informPlayers(sourceObject.getLogName() + " creates " + (tokensToMake == 0 ? "no" : "" + tokensToMake) + " 1/1 green Saproling creature tokens.");
                saprolingToken.putOntoBattlefield(tokensToMake, game, source, source.getControllerId());
                return true;
            }
        }
    }
    return false;
}
Also used : SaprolingToken(mage.game.permanent.token.SaprolingToken) 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 3 with CardType

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

the class AminatousAuguryCastFromExileEffect method applies.

@Override
public boolean applies(UUID objectId, Ability source, UUID affectedControllerId, Game game) {
    Player player = game.getPlayer(affectedControllerId);
    EnumSet<CardType> usedCardTypes = EnumSet.noneOf(CardType.class);
    if (game.getState().getValue(source.getSourceId().toString() + "cardTypes") != null) {
        usedCardTypes = (EnumSet<CardType>) game.getState().getValue(source.getSourceId().toString() + "cardTypes");
    }
    if (player != null && objectId != null && objectId.equals(getTargetPointer().getFirst(game, source)) && affectedControllerId.equals(source.getControllerId())) {
        Card card = game.getCard(objectId);
        if (card != null && game.getState().getZone(objectId) == Zone.EXILED) {
            EnumSet<CardType> unusedCardTypes = EnumSet.noneOf(CardType.class);
            for (CardType cardT : card.getCardType(game)) {
                if (!usedCardTypes.contains(cardT)) {
                    unusedCardTypes.add(cardT);
                }
            }
            if (!unusedCardTypes.isEmpty()) {
                if (!game.inCheckPlayableState()) {
                    // Select the card type to consume and remove all not seleczted card types
                    if (unusedCardTypes.size() > 1) {
                        Choice choice = new ChoiceImpl(true);
                        choice.setMessage("Which card type do you want to consume?");
                        Set<String> choices = choice.getChoices();
                        for (CardType cardType : unusedCardTypes) {
                            choices.add(cardType.toString());
                        }
                        player.choose(Outcome.Detriment, choice, game);
                        for (Iterator<CardType> iterator = unusedCardTypes.iterator(); iterator.hasNext(); ) {
                            CardType next = iterator.next();
                            if (!next.toString().equals(choice.getChoice())) {
                                iterator.remove();
                            }
                        }
                        usedCardTypes.add(CardType.fromString(choice.getChoice()));
                    }
                    usedCardTypes.addAll(unusedCardTypes);
                    game.getState().setValue(source.getSourceId().toString() + "cardTypes", usedCardTypes);
                }
                player.setCastSourceIdWithAlternateMana(objectId, null, card.getSpellAbility().getCosts());
                return true;
            }
        }
    }
    return false;
}
Also used : Player(mage.players.Player) Choice(mage.choices.Choice) CardType(mage.constants.CardType) ChoiceImpl(mage.choices.ChoiceImpl) TargetCard(mage.target.TargetCard) Card(mage.cards.Card)

Example 4 with CardType

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

the class MuldrothaTheGravetideWatcher method addPermanentTypes.

private void addPermanentTypes(GameEvent event, Card mageObject, Game game) {
    if (mageObject != null && event.getAdditionalReference() != null && MageIdentifier.MuldrothaTheGravetideWatcher.equals(event.getAdditionalReference().getApprovingAbility().getIdentifier())) {
        UUID playerId = null;
        if (mageObject instanceof Spell) {
            playerId = ((Spell) mageObject).getControllerId();
        } else if (mageObject instanceof Permanent) {
            playerId = ((Permanent) mageObject).getControllerId();
        }
        if (playerId != null) {
            Set<CardType> permanentTypes = sourcePlayedPermanentTypes.get(event.getAdditionalReference().getApprovingMageObjectReference());
            if (permanentTypes == null) {
                permanentTypes = EnumSet.noneOf(CardType.class);
                sourcePlayedPermanentTypes.put(event.getAdditionalReference().getApprovingMageObjectReference(), permanentTypes);
            }
            Set<CardType> typesNotCast = EnumSet.noneOf(CardType.class);
            for (CardType cardType : mageObject.getCardType(game)) {
                if (cardType.isPermanentType()) {
                    if (!permanentTypes.contains(cardType)) {
                        typesNotCast.add(cardType);
                    }
                }
            }
            if (typesNotCast.size() <= 1) {
                permanentTypes.addAll(typesNotCast);
            } else {
                Player player = game.getPlayer(playerId);
                if (player != null) {
                    Choice typeChoice = new ChoiceImpl(true);
                    typeChoice.setMessage("Choose permanent type you consume for casting from graveyard.");
                    for (CardType cardType : typesNotCast) {
                        typeChoice.getChoices().add(cardType.toString());
                    }
                    if (player.choose(Outcome.Detriment, typeChoice, game)) {
                        String typeName = typeChoice.getChoice();
                        CardType chosenType = null;
                        for (CardType cardType : CardType.values()) {
                            if (cardType.toString().equals(typeName)) {
                                chosenType = cardType;
                                break;
                            }
                        }
                        if (chosenType != null) {
                            permanentTypes.add(chosenType);
                        }
                    }
                }
            }
        }
    }
}
Also used : Player(mage.players.Player) Choice(mage.choices.Choice) Permanent(mage.game.permanent.Permanent) CardType(mage.constants.CardType) ChoiceImpl(mage.choices.ChoiceImpl) UUID(java.util.UUID) Spell(mage.game.stack.Spell)

Example 5 with CardType

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

the class ReweaveEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Permanent permanent = game.getPermanent(getTargetPointer().getFirst(game, source));
    MageObject sourceObject = source.getSourceObject(game);
    if (permanent != null && sourceObject != null) {
        if (permanent.sacrifice(source, game)) {
            Player permanentController = game.getPlayer(permanent.getControllerId());
            if (permanentController != null) {
                Library library = permanentController.getLibrary();
                if (library.hasCards()) {
                    Cards cards = new CardsImpl();
                    Card permanentCard = null;
                    for (Card card : permanentController.getLibrary().getCards(game)) {
                        cards.add(card);
                        if (card.isPermanent(game)) {
                            for (CardType cardType : permanent.getCardType(game)) {
                                if (card.getCardType(game).contains(cardType)) {
                                    permanentCard = card;
                                    break;
                                }
                            }
                        }
                    }
                    permanentController.revealCards(source, cards, game);
                    if (permanentCard != null) {
                        permanentController.moveCards(permanentCard, Zone.BATTLEFIELD, source, game);
                    }
                    permanentController.shuffleLibrary(source, game);
                }
                return true;
            }
            return false;
        }
    }
    return true;
}
Also used : Player(mage.players.Player) Permanent(mage.game.permanent.Permanent) TargetPermanent(mage.target.TargetPermanent) CardType(mage.constants.CardType) MageObject(mage.MageObject) Library(mage.players.Library) FilterPermanentCard(mage.filter.common.FilterPermanentCard)

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