Search in sources :

Example 56 with TargetCardInYourGraveyard

use of mage.target.common.TargetCardInYourGraveyard in project mage by magefree.

the class RunedCrownEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    if (controller == null) {
        return false;
    }
    Card card = null;
    Zone zone = null;
    if (controller.chooseUse(Outcome.Neutral, "Search your graveyard for a Rune card?", source, game)) {
        TargetCardInYourGraveyard target = new TargetCardInYourGraveyard(filter);
        target.setNotTarget(true);
        if (controller.choose(Outcome.PutCardInPlay, controller.getGraveyard(), target, game)) {
            card = game.getCard(target.getFirstTarget());
            if (card != null) {
                zone = Zone.GRAVEYARD;
            }
        }
    }
    if (card == null && controller.chooseUse(Outcome.Neutral, "Search your hand for a Rune card?", source, game)) {
        TargetCardInHand target = new TargetCardInHand(filter);
        if (controller.choose(Outcome.PutCardInPlay, controller.getHand(), target, game)) {
            card = game.getCard(target.getFirstTarget());
            if (card != null) {
                zone = Zone.HAND;
            }
        }
    }
    if (card == null) {
        TargetCardInLibrary target = new TargetCardInLibrary(filter);
        if (controller.searchLibrary(target, source, game)) {
            card = game.getCard(target.getFirstTarget());
            if (card != null) {
                zone = Zone.LIBRARY;
            }
        }
        controller.shuffleLibrary(source, game);
    }
    // aura card found - attach it
    if (card == null) {
        return true;
    }
    Permanent permanent = source.getSourcePermanentIfItStillExists(game);
    if (permanent != null) {
        game.getState().setValue("attachTo:" + card.getId(), permanent);
    }
    controller.moveCards(card, Zone.BATTLEFIELD, source, game);
    if (permanent != null) {
        return permanent.addAttachment(card.getId(), source, game);
    }
    return true;
}
Also used : Player(mage.players.Player) Permanent(mage.game.permanent.Permanent) TargetCardInHand(mage.target.common.TargetCardInHand) Zone(mage.constants.Zone) TargetCardInYourGraveyard(mage.target.common.TargetCardInYourGraveyard) TargetCardInLibrary(mage.target.common.TargetCardInLibrary) FilterCard(mage.filter.FilterCard) Card(mage.cards.Card)

Example 57 with TargetCardInYourGraveyard

use of mage.target.common.TargetCardInYourGraveyard in project mage by magefree.

the class SuturedGhoulEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    Permanent permanent = game.getPermanentEntering(source.getSourceId());
    if (permanent == null || controller == null) {
        return false;
    }
    if (!controller.getGraveyard().isEmpty()) {
        TargetCardInYourGraveyard target = new TargetCardInYourGraveyard(0, Integer.MAX_VALUE, StaticFilters.FILTER_CARD_CREATURES_YOUR_GRAVEYARD);
        if (controller.chooseTarget(Outcome.Benefit, target, source, game)) {
            int count = 0;
            for (UUID uuid : target.getTargets()) {
                Card card = controller.getGraveyard().get(uuid, game);
                if (card != null) {
                    card.moveToExile(getId(), permanent.getIdName(), source, game);
                    permanent.imprint(card.getId(), game);
                    count++;
                }
            }
            Cards cardsToExile = new CardsImpl(target.getTargets());
            controller.moveCards(cardsToExile, Zone.EXILED, source, game);
            String msg = count == 1 ? "1 card" : count + "cards";
            game.informPlayers(permanent.getLogName() + ": " + controller.getLogName() + " exiled " + msg);
        }
    } else {
        game.informPlayers(permanent.getLogName() + ": No cards in graveyard.");
    }
    return true;
}
Also used : Player(mage.players.Player) Permanent(mage.game.permanent.Permanent) TargetCardInYourGraveyard(mage.target.common.TargetCardInYourGraveyard) UUID(java.util.UUID) Cards(mage.cards.Cards) CardsImpl(mage.cards.CardsImpl) Card(mage.cards.Card)

Example 58 with TargetCardInYourGraveyard

use of mage.target.common.TargetCardInYourGraveyard in project mage by magefree.

the class GateToTheAfterlifeEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    if (controller == null) {
        return false;
    }
    FilterCard filter = new FilterCard("card named " + cardName);
    filter.add(new NamePredicate(cardName));
    Card card = null;
    // Graveyard check
    if (controller.chooseUse(Outcome.Benefit, "Search your graveyard for " + cardName + "?", source, game)) {
        TargetCardInYourGraveyard target = new TargetCardInYourGraveyard(1, 1, filter, true);
        if (controller.choose(outcome, controller.getGraveyard(), target, game)) {
            card = game.getCard(target.getFirstTarget());
        }
    }
    // Hand check
    if (card == null && controller.chooseUse(Outcome.Benefit, "Search your hand for " + cardName + "?", source, game)) {
        TargetCardInHand target = new TargetCardInHand(0, 1, filter);
        if (controller.choose(Outcome.PutCardInPlay, controller.getHand(), target, game)) {
            card = game.getCard(target.getFirstTarget());
        }
    }
    // Library check
    boolean librarySearched = false;
    if (card == null && controller.chooseUse(Outcome.Benefit, "Search your library for " + cardName + "?", source, game)) {
        librarySearched = true;
        TargetCardInLibrary target = new TargetCardInLibrary(filter);
        if (controller.searchLibrary(target, source, game)) {
            card = game.getCard(target.getFirstTarget());
        }
        controller.shuffleLibrary(source, game);
    }
    if (card != null) {
        controller.moveCards(card, Zone.BATTLEFIELD, source, game);
    }
    if (librarySearched) {
        controller.shuffleLibrary(source, game);
    }
    return true;
}
Also used : FilterCard(mage.filter.FilterCard) Player(mage.players.Player) NamePredicate(mage.filter.predicate.mageobject.NamePredicate) TargetCardInHand(mage.target.common.TargetCardInHand) TargetCardInYourGraveyard(mage.target.common.TargetCardInYourGraveyard) TargetCardInLibrary(mage.target.common.TargetCardInLibrary) Card(mage.cards.Card) FilterCard(mage.filter.FilterCard)

Example 59 with TargetCardInYourGraveyard

use of mage.target.common.TargetCardInYourGraveyard in project mage by magefree.

the class GruesomeMenagerieEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player player = game.getPlayer(source.getControllerId());
    if (player == null) {
        return false;
    }
    Cards cards = new CardsImpl();
    Target target;
    target = new TargetCardInYourGraveyard(filter1);
    target.setNotTarget(true);
    if (player.choose(outcome, target, source.getSourceId(), game)) {
        Card card = game.getCard(target.getFirstTarget());
        if (card != null) {
            cards.add(card);
        }
    }
    target = new TargetCardInYourGraveyard(filter2);
    target.setNotTarget(true);
    if (player.choose(outcome, target, source.getSourceId(), game)) {
        Card card = game.getCard(target.getFirstTarget());
        if (card != null) {
            cards.add(card);
        }
    }
    target = new TargetCardInYourGraveyard(filter3);
    target.setNotTarget(true);
    if (player.choose(outcome, target, source.getSourceId(), game)) {
        Card card = game.getCard(target.getFirstTarget());
        if (card != null) {
            cards.add(card);
        }
    }
    return player.moveCards(cards, Zone.BATTLEFIELD, source, game);
}
Also used : Player(mage.players.Player) Target(mage.target.Target) TargetCardInYourGraveyard(mage.target.common.TargetCardInYourGraveyard) Cards(mage.cards.Cards) CardsImpl(mage.cards.CardsImpl) FilterCard(mage.filter.FilterCard) FilterCreatureCard(mage.filter.common.FilterCreatureCard) Card(mage.cards.Card)

Example 60 with TargetCardInYourGraveyard

use of mage.target.common.TargetCardInYourGraveyard in project mage by magefree.

the class InventiveIterationEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player player = game.getPlayer(source.getControllerId());
    if (player == null) {
        return false;
    }
    Card card;
    switch(player.getGraveyard().count(StaticFilters.FILTER_CARD_ARTIFACT, game)) {
        case 0:
            player.drawCards(1, source, game);
            return true;
        case 1:
            card = RandomUtil.randomFromCollection(player.getGraveyard().getCards(StaticFilters.FILTER_CARD_ARTIFACT, game));
            break;
        default:
            TargetCard target = new TargetCardInYourGraveyard(StaticFilters.FILTER_CARD_ARTIFACT);
            target.setNotTarget(true);
            player.choose(outcome, player.getGraveyard(), target, game);
            card = game.getCard(target.getFirstTarget());
    }
    player.moveCards(card, Zone.HAND, source, game);
    return true;
}
Also used : Player(mage.players.Player) TargetCard(mage.target.TargetCard) TargetCardInYourGraveyard(mage.target.common.TargetCardInYourGraveyard) TargetCard(mage.target.TargetCard) Card(mage.cards.Card)

Aggregations

TargetCardInYourGraveyard (mage.target.common.TargetCardInYourGraveyard)88 Player (mage.players.Player)78 Card (mage.cards.Card)47 FilterCard (mage.filter.FilterCard)38 TargetCard (mage.target.TargetCard)29 CardsImpl (mage.cards.CardsImpl)18 UUID (java.util.UUID)16 Target (mage.target.Target)16 Permanent (mage.game.permanent.Permanent)14 TargetCardInLibrary (mage.target.common.TargetCardInLibrary)11 FilterCreatureCard (mage.filter.common.FilterCreatureCard)10 TargetCardInHand (mage.target.common.TargetCardInHand)10 Cards (mage.cards.Cards)9 ManaValuePredicate (mage.filter.predicate.mageobject.ManaValuePredicate)7 MageObject (mage.MageObject)6 NamePredicate (mage.filter.predicate.mageobject.NamePredicate)5 HashSet (java.util.HashSet)4 ExileFromGraveCost (mage.abilities.costs.common.ExileFromGraveCost)4 OneShotEffect (mage.abilities.effects.OneShotEffect)4 FixedTarget (mage.target.targetpointer.FixedTarget)4