Search in sources :

Example 16 with TargetCard

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

the class MuzzioVisionaryArchitectEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    if (controller == null) {
        return false;
    }
    int highCMC = 0;
    List<Permanent> controlledArtifacts = game.getBattlefield().getAllActivePermanents(new FilterArtifactPermanent(), controller.getId(), game);
    for (Permanent permanent : controlledArtifacts) {
        if (permanent.getSpellAbility() != null) {
            int cmc = permanent.getSpellAbility().getManaCosts().manaValue();
            if (cmc > highCMC) {
                highCMC = cmc;
            }
        }
    }
    Cards cards = new CardsImpl(controller.getLibrary().getTopCards(game, highCMC));
    controller.lookAtCards(source, null, cards, game);
    if (!cards.isEmpty()) {
        TargetCard target = new TargetCard(Zone.LIBRARY, new FilterArtifactCard("artifact card to put onto the battlefield"));
        if (target.canChoose(source.getSourceId(), controller.getId(), game) && controller.choose(Outcome.Benefit, cards, target, game)) {
            Card card = cards.get(target.getFirstTarget(), game);
            if (card != null) {
                controller.revealCards(source, new CardsImpl(card), game);
                cards.remove(card);
                controller.moveCards(card, Zone.BATTLEFIELD, source, game);
            }
        }
    }
    controller.putCardsOnBottomOfLibrary(cards, game, source, true);
    return true;
}
Also used : Player(mage.players.Player) FilterArtifactPermanent(mage.filter.common.FilterArtifactPermanent) Permanent(mage.game.permanent.Permanent) FilterArtifactPermanent(mage.filter.common.FilterArtifactPermanent) TargetCard(mage.target.TargetCard) FilterArtifactCard(mage.filter.common.FilterArtifactCard) TargetCard(mage.target.TargetCard) FilterArtifactCard(mage.filter.common.FilterArtifactCard)

Example 17 with TargetCard

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

the class NissasEncouragementTarget method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player player = game.getPlayer(source.getControllerId());
    Card sourceCard = game.getCard(source.getSourceId());
    if (player == null || sourceCard == null) {
        return false;
    }
    NissasEncouragementTarget target = new NissasEncouragementTarget(filter);
    if (player.searchLibrary(target, source, game)) {
        boolean searchGY = false;
        if (target.getTargets().size() < 3) {
            searchGY = true;
        }
        Map<String, Integer> foundCards = new HashMap<>();
        foundCards.put("Forest", 0);
        foundCards.put("Brambleweft Behemoth", 0);
        foundCards.put("Nissa, Genesis Mage", 0);
        Cards cards = new CardsImpl();
        if (!target.getTargets().isEmpty()) {
            for (UUID cardId : target.getTargets()) {
                Card card = player.getLibrary().remove(cardId, game);
                if (card != null) {
                    cards.add(card);
                    foundCards.put(card.getName(), 1);
                }
            }
        }
        if (searchGY) {
            for (String name : foundCards.keySet()) {
                if (foundCards.get(name) == 1) {
                    continue;
                }
                // Look in graveyard for any with this name
                // never change static objects so copy the object here before
                FilterCard namedFilterGY = filterGY.copy();
                namedFilterGY.add(new NamePredicate(name));
                if (player.getGraveyard().count(namedFilterGY, game) > 0) {
                    TargetCard targetGY = new TargetCard(0, 1, Zone.GRAVEYARD, namedFilterGY);
                    if (player.choose(Outcome.ReturnToHand, player.getGraveyard(), targetGY, game)) {
                        for (UUID cardIdGY : targetGY.getTargets()) {
                            Card cardGY = player.getGraveyard().get(cardIdGY, game);
                            cards.add(cardGY);
                        }
                    }
                }
            }
        }
        if (!cards.isEmpty()) {
            player.revealCards(sourceCard.getIdName(), cards, game);
            player.moveCards(cards, Zone.HAND, source, game);
            player.shuffleLibrary(source, game);
            return true;
        }
    }
    player.shuffleLibrary(source, game);
    return false;
}
Also used : Player(mage.players.Player) NamePredicate(mage.filter.predicate.mageobject.NamePredicate) HashMap(java.util.HashMap) TargetCard(mage.target.TargetCard) FilterCard(mage.filter.FilterCard) TargetCard(mage.target.TargetCard) FilterCard(mage.filter.FilterCard) UUID(java.util.UUID)

Example 18 with TargetCard

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

the class PeregrinationEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    MageObject sourceObject = game.getObject(source.getSourceId());
    if (controller == null || sourceObject == null) {
        return false;
    }
    TargetCardInLibrary target = new TargetCardInLibrary(0, 2, StaticFilters.FILTER_CARD_BASIC_LAND);
    if (controller.searchLibrary(target, source, game)) {
        if (!target.getTargets().isEmpty()) {
            Cards revealed = new CardsImpl();
            for (UUID cardId : target.getTargets()) {
                Card card = controller.getLibrary().getCard(cardId, game);
                revealed.add(card);
            }
            controller.revealCards(sourceObject.getIdName(), revealed, game);
            if (target.getTargets().size() == 2) {
                TargetCard target2 = new TargetCard(Zone.LIBRARY, filter);
                controller.choose(Outcome.Benefit, revealed, target2, game);
                Card card = revealed.get(target2.getFirstTarget(), game);
                controller.moveCards(card, Zone.BATTLEFIELD, source, game, true, false, false, null);
                revealed.remove(card);
                Set<Card> cards = revealed.getCards(game);
                card = cards.isEmpty() ? null : cards.iterator().next();
                controller.moveCards(card, Zone.HAND, source, game);
            } else if (target.getTargets().size() == 1) {
                Set<Card> cards = revealed.getCards(game);
                Card card = cards.isEmpty() ? null : cards.iterator().next();
                controller.moveCards(card, Zone.BATTLEFIELD, source, game, true, false, false, null);
            }
        }
        controller.shuffleLibrary(source, game);
        return true;
    }
    controller.shuffleLibrary(source, game);
    return false;
}
Also used : Player(mage.players.Player) Set(java.util.Set) MageObject(mage.MageObject) TargetCard(mage.target.TargetCard) UUID(java.util.UUID) TargetCardInLibrary(mage.target.common.TargetCardInLibrary) FilterCard(mage.filter.FilterCard) TargetCard(mage.target.TargetCard)

Example 19 with TargetCard

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

the class PsychicIntrusionSpendAnyManaEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player opponent = game.getPlayer(targetPointer.getFirst(game, source));
    MageObject sourceObject = game.getObject(source.getSourceId());
    if (opponent != null && sourceObject != null) {
        opponent.revealCards(sourceObject.getName(), opponent.getHand(), game);
        Player controller = game.getPlayer(source.getControllerId());
        if (controller != null) {
            int cardsGraveyard = opponent.getGraveyard().count(filter, game);
            int cardsHand = opponent.getHand().count(filter, game);
            boolean fromHand = false;
            if (cardsGraveyard > 0 && cardsHand > 0) {
                if (controller.chooseUse(Outcome.Detriment, "Exile card from opponents Hand?", source, game)) {
                    fromHand = true;
                }
            } else {
                if (cardsHand > 0) {
                    fromHand = true;
                }
            }
            Card card = null;
            if (cardsHand > 0 && fromHand) {
                TargetCard target = new TargetCard(Zone.HAND, filter);
                if (controller.choose(Outcome.Benefit, opponent.getHand(), target, game)) {
                    card = opponent.getHand().get(target.getFirstTarget(), game);
                }
            }
            if (cardsGraveyard > 0 && !fromHand) {
                TargetCard target = new TargetCard(Zone.GRAVEYARD, filter);
                if (controller.choose(Outcome.Benefit, opponent.getGraveyard(), target, game)) {
                    card = opponent.getGraveyard().get(target.getFirstTarget(), game);
                }
            }
            if (card != null) {
                // move card to exile
                UUID exileId = CardUtil.getCardExileZoneId(game, source);
                controller.moveCardToExileWithInfo(card, exileId, sourceObject.getIdName(), source, game, fromHand ? Zone.HAND : Zone.GRAVEYARD, true);
                // allow to cast the card
                ContinuousEffect effect = new PsychicIntrusionCastFromExileEffect();
                effect.setTargetPointer(new FixedTarget(card.getId()));
                game.addEffect(effect, source);
                // and you may spend mana as though it were mana of any color to cast it
                effect = new PsychicIntrusionSpendAnyManaEffect();
                effect.setTargetPointer(new FixedTarget(card.getId()));
                game.addEffect(effect, source);
            }
            return true;
        }
    }
    return false;
}
Also used : FixedTarget(mage.target.targetpointer.FixedTarget) Player(mage.players.Player) MageObject(mage.MageObject) TargetCard(mage.target.TargetCard) ContinuousEffect(mage.abilities.effects.ContinuousEffect) UUID(java.util.UUID) FilterNonlandCard(mage.filter.common.FilterNonlandCard) TargetCard(mage.target.TargetCard) Card(mage.cards.Card)

Example 20 with TargetCard

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

the class PsychicTheftWatcher method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player opponent = game.getPlayer(targetPointer.getFirst(game, source));
    if (opponent == null) {
        return false;
    }
    opponent.revealCards(CardUtil.getSourceName(game, source), opponent.getHand(), game);
    Player controller = game.getPlayer(source.getControllerId());
    if (controller == null) {
        return false;
    }
    int cardsHand = opponent.getHand().count(filter, game);
    Card chosenCard = null;
    if (cardsHand > 0) {
        TargetCard target = new TargetCard(Zone.HAND, filter);
        if (controller.choose(Outcome.Exile, opponent.getHand(), target, game)) {
            chosenCard = opponent.getHand().get(target.getFirstTarget(), game);
        }
    }
    if (chosenCard == null) {
        return false;
    }
    controller.moveCardToExileWithInfo(chosenCard, CardUtil.getExileZoneId(game, source), CardUtil.getSourceName(game, source), source, game, Zone.HAND, true);
    CardUtil.makeCardPlayable(game, source, chosenCard, Duration.Custom, false);
    game.addDelayedTriggeredAbility(new AtTheBeginOfNextEndStepDelayedTriggeredAbility(new ConditionalOneShotEffect(new ReturnFromExileEffect(Zone.HAND), new PsychicTheftCondition(chosenCard, game), "if you haven't cast it, return it to its owner's hand.")), source);
    return true;
}
Also used : TargetPlayer(mage.target.TargetPlayer) Player(mage.players.Player) AtTheBeginOfNextEndStepDelayedTriggeredAbility(mage.abilities.common.delayed.AtTheBeginOfNextEndStepDelayedTriggeredAbility) ReturnFromExileEffect(mage.abilities.effects.common.ReturnFromExileEffect) TargetCard(mage.target.TargetCard) ConditionalOneShotEffect(mage.abilities.decorator.ConditionalOneShotEffect) TargetCard(mage.target.TargetCard) FilterInstantOrSorceryCard(mage.filter.common.FilterInstantOrSorceryCard) Card(mage.cards.Card)

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