Search in sources :

Example 66 with TargetCard

use of mage.target.TargetCard in project mage by magefree.

the class StormHeraldAttachableToPredicate method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    if (controller != null) {
        FilterCard filter = new FilterCard("aura cards to attach to creatures you control");
        filter.add(SubType.AURA.getPredicate());
        filter.add(new StormHeraldAttachablePredicate(controller.getId()));
        Set<Card> possibleTargets = controller.getGraveyard().getCards(filter, source.getSourceId(), controller.getId(), game);
        if (!possibleTargets.isEmpty()) {
            TargetCard targetAuras = new TargetCard(0, Integer.MAX_VALUE, Zone.GRAVEYARD, filter);
            targetAuras.setNotTarget(true);
            controller.chooseTarget(outcome, new CardsImpl(possibleTargets), targetAuras, source, game);
            // Move the cards to the battlefield to a creature you control
            List<Permanent> toExile = new ArrayList<>();
            for (UUID auraId : targetAuras.getTargets()) {
                Card auraCard = game.getCard(auraId);
                if (auraCard != null) {
                    FilterPermanent filterAttachTo = new FilterControlledCreaturePermanent("creature you control to attach " + auraCard.getIdName() + " to");
                    filterAttachTo.add(new StormHeraldAttachableToPredicate(auraCard));
                    TargetPermanent targetCreature = new TargetPermanent(filterAttachTo);
                    targetCreature.setNotTarget(true);
                    if (controller.choose(Outcome.PutCardInPlay, targetCreature, source.getSourceId(), game)) {
                        Permanent targetPermanent = game.getPermanent(targetCreature.getFirstTarget());
                        if (!targetPermanent.cantBeAttachedBy(auraCard, source, game, true)) {
                            game.getState().setValue("attachTo:" + auraCard.getId(), targetPermanent);
                            controller.moveCards(auraCard, Zone.BATTLEFIELD, source, game);
                            targetPermanent.addAttachment(auraCard.getId(), source, game);
                            Permanent permanent = game.getPermanent(auraId);
                            if (permanent != null) {
                                toExile.add(permanent);
                            }
                        }
                    }
                }
            }
            ContinuousEffect continuousEffect = new StormHeraldReplacementEffect();
            continuousEffect.setTargetPointer(new FixedTargets(toExile, game));
            game.addEffect(continuousEffect, source);
            Effect exileEffect = new ExileTargetEffect("exile those Auras");
            exileEffect.setTargetPointer(new FixedTargets(toExile, game));
            game.addDelayedTriggeredAbility(new AtTheBeginOfNextEndStepDelayedTriggeredAbility(exileEffect), source);
        }
        return true;
    }
    return false;
}
Also used : Player(mage.players.Player) FilterPermanent(mage.filter.FilterPermanent) FilterPermanent(mage.filter.FilterPermanent) FilterControlledCreaturePermanent(mage.filter.common.FilterControlledCreaturePermanent) Permanent(mage.game.permanent.Permanent) TargetPermanent(mage.target.TargetPermanent) FixedTargets(mage.target.targetpointer.FixedTargets) ArrayList(java.util.ArrayList) FilterControlledCreaturePermanent(mage.filter.common.FilterControlledCreaturePermanent) TargetCard(mage.target.TargetCard) TargetCard(mage.target.TargetCard) Card(mage.cards.Card) FilterCard(mage.filter.FilterCard) FilterCard(mage.filter.FilterCard) AtTheBeginOfNextEndStepDelayedTriggeredAbility(mage.abilities.common.delayed.AtTheBeginOfNextEndStepDelayedTriggeredAbility) ExileTargetEffect(mage.abilities.effects.common.ExileTargetEffect) ContinuousEffect(mage.abilities.effects.ContinuousEffect) OneShotEffect(mage.abilities.effects.OneShotEffect) Effect(mage.abilities.effects.Effect) TargetPermanent(mage.target.TargetPermanent) ContinuousEffect(mage.abilities.effects.ContinuousEffect) UUID(java.util.UUID) CardsImpl(mage.cards.CardsImpl) ExileTargetEffect(mage.abilities.effects.common.ExileTargetEffect)

Example 67 with TargetCard

use of mage.target.TargetCard in project mage by magefree.

the class TayamLuminousEnigmaReplacementEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player player = game.getPlayer(source.getControllerId());
    if (player == null || player.getGraveyard().count(filter, game) == 0) {
        return false;
    }
    TargetCard target = new TargetCardInYourGraveyard(filter);
    target.setNotTarget(true);
    if (!player.choose(outcome, player.getGraveyard(), target, game)) {
        return false;
    }
    return player.moveCards(game.getCard(target.getFirstTarget()), Zone.BATTLEFIELD, source, game);
}
Also used : Player(mage.players.Player) TargetCard(mage.target.TargetCard) TargetCardInYourGraveyard(mage.target.common.TargetCardInYourGraveyard)

Example 68 with TargetCard

use of mage.target.TargetCard in project mage by magefree.

the class FatesealEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    if (controller != null) {
        Target target = new TargetOpponent(true);
        if (controller.choose(outcome, target, source.getSourceId(), game)) {
            Player opponent = game.getPlayer(target.getFirstTarget());
            if (opponent == null) {
                return false;
            }
            // by looking at the cards with fateseal you have not to reveal the next card
            boolean revealed = opponent.isTopCardRevealed();
            opponent.setTopCardRevealed(false);
            Cards cards = new CardsImpl();
            int count = Math.min(fatesealNumber, opponent.getLibrary().size());
            if (count == 0) {
                return true;
            }
            for (int i = 0; i < count; i++) {
                Card card = opponent.getLibrary().removeFromTop(game);
                cards.add(card);
            }
            TargetCard target1 = new TargetCard(Zone.LIBRARY, filter1);
            target1.setRequired(false);
            // move cards to the bottom of the library
            while (!cards.isEmpty() && controller.choose(Outcome.Detriment, cards, target1, game)) {
                if (!controller.canRespond() || !opponent.canRespond()) {
                    return false;
                }
                Card card = cards.get(target1.getFirstTarget(), game);
                if (card != null) {
                    cards.remove(card);
                    controller.moveCardToLibraryWithInfo(card, source, game, Zone.LIBRARY, false, false);
                }
                target1.clearChosen();
            }
            // move cards to the top of the library
            controller.putCardsOnTopOfLibrary(cards, game, source, true);
            game.fireEvent(new GameEvent(GameEvent.EventType.FATESEALED, opponent.getId(), source, source.getControllerId()));
            controller.setTopCardRevealed(revealed);
            return true;
        }
    }
    return false;
}
Also used : Player(mage.players.Player) Target(mage.target.Target) TargetOpponent(mage.target.common.TargetOpponent) GameEvent(mage.game.events.GameEvent) TargetCard(mage.target.TargetCard) Cards(mage.cards.Cards) CardsImpl(mage.cards.CardsImpl) FilterCard(mage.filter.FilterCard) TargetCard(mage.target.TargetCard) Card(mage.cards.Card)

Example 69 with TargetCard

use of mage.target.TargetCard in project mage by magefree.

the class SearchLibraryGraveyardPutInHandEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    MageObject sourceObject = source.getSourceObject(game);
    Card cardFound = null;
    boolean needShuffle = false;
    if (controller != null && sourceObject != null) {
        if (forceToSearchBoth || controller.chooseUse(outcome, "Search your library for a card named " + filter.getMessage() + '?', source, game)) {
            TargetCardInLibrary target = new TargetCardInLibrary(0, 1, filter);
            target.clearChosen();
            if (controller.searchLibrary(target, source, game)) {
                if (!target.getTargets().isEmpty()) {
                    cardFound = game.getCard(target.getFirstTarget());
                }
            }
            needShuffle = true;
        }
        if (cardFound == null && controller.chooseUse(outcome, "Search your graveyard for a card named " + filter.getMessage() + '?', source, game)) {
            TargetCard target = new TargetCardInYourGraveyard(0, 1, filter, true);
            target.clearChosen();
            if (controller.choose(outcome, controller.getGraveyard(), target, game)) {
                if (!target.getTargets().isEmpty()) {
                    cardFound = game.getCard(target.getFirstTarget());
                }
            }
        }
        if (cardFound != null) {
            controller.revealCards(sourceObject.getIdName(), new CardsImpl(cardFound), game);
            controller.moveCards(cardFound, Zone.HAND, source, game);
        }
        if (needShuffle) {
            controller.shuffleLibrary(source, game);
        }
        return true;
    }
    return false;
}
Also used : Player(mage.players.Player) MageObject(mage.MageObject) TargetCard(mage.target.TargetCard) TargetCardInYourGraveyard(mage.target.common.TargetCardInYourGraveyard) TargetCardInLibrary(mage.target.common.TargetCardInLibrary) CardsImpl(mage.cards.CardsImpl) FilterCard(mage.filter.FilterCard) TargetCard(mage.target.TargetCard) Card(mage.cards.Card)

Example 70 with TargetCard

use of mage.target.TargetCard in project mage by magefree.

the class AladdinsLampEffect method replaceEvent.

@Override
public boolean replaceEvent(GameEvent event, Ability source, Game game) {
    Player controller = game.getPlayer(source.getControllerId());
    if (controller == null) {
        return false;
    }
    Cards cards = new CardsImpl(controller.getLibrary().getTopCards(game, source.getManaCostsToPay().getX()));
    controller.lookAtCards(source, null, cards, game);
    TargetCard target = new TargetCard(Zone.LIBRARY, new FilterCard("card to stay at the top of library"));
    if (controller.choose(outcome, cards, target, game)) {
        cards.remove(target.getFirstTarget());
    }
    controller.putCardsOnBottomOfLibrary(cards, game, source, false);
    game.getState().processAction(game);
    controller.drawCards(1, source, game, event);
    discard();
    return true;
}
Also used : FilterCard(mage.filter.FilterCard) Player(mage.players.Player) TargetCard(mage.target.TargetCard)

Aggregations

TargetCard (mage.target.TargetCard)309 Player (mage.players.Player)297 FilterCard (mage.filter.FilterCard)177 Card (mage.cards.Card)130 CardsImpl (mage.cards.CardsImpl)96 UUID (java.util.UUID)83 Cards (mage.cards.Cards)81 MageObject (mage.MageObject)80 TargetCardInLibrary (mage.target.common.TargetCardInLibrary)52 Permanent (mage.game.permanent.Permanent)49 TargetCardInYourGraveyard (mage.target.common.TargetCardInYourGraveyard)30 ApprovingObject (mage.ApprovingObject)26 TargetPlayer (mage.target.TargetPlayer)25 FilterCreatureCard (mage.filter.common.FilterCreatureCard)22 TargetOpponent (mage.target.common.TargetOpponent)22 TargetCardInHand (mage.target.common.TargetCardInHand)21 Target (mage.target.Target)19 FilterNonlandCard (mage.filter.common.FilterNonlandCard)18 FixedTarget (mage.target.targetpointer.FixedTarget)18 ArrayList (java.util.ArrayList)16