Search in sources :

Example 36 with TargetCardInGraveyard

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

the class SurgicalExtractionEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    // 6/1/2011 	"Any number of cards" means just that. If you wish, you can choose to
    // leave some or all of the cards with the same name as the targeted card,
    // including that card, in the zone they're in.
    Card chosenCard = game.getCard(source.getFirstTarget());
    Player controller = game.getPlayer(source.getControllerId());
    if (chosenCard != null && controller != null) {
        Player owner = game.getPlayer(chosenCard.getOwnerId());
        if (owner != null) {
            String nameToSearch = CardUtil.getCardNameForSameNameSearch(chosenCard);
            FilterCard filterNamedCard = new FilterCard("card named " + nameToSearch);
            filterNamedCard.add(new NamePredicate(nameToSearch));
            // cards in Graveyard
            int cardsCount = owner.getGraveyard().count(filterNamedCard, game);
            if (cardsCount > 0) {
                filterNamedCard.setMessage("card named " + nameToSearch + " in the graveyard of " + owner.getName());
                TargetCardInGraveyard target = new TargetCardInGraveyard(0, cardsCount, filterNamedCard);
                if (controller.chooseTarget(Outcome.Exile, owner.getGraveyard(), target, source, game)) {
                    List<UUID> targets = target.getTargets();
                    for (UUID targetId : targets) {
                        Card targetCard = owner.getGraveyard().get(targetId, game);
                        if (targetCard != null) {
                            controller.moveCardToExileWithInfo(targetCard, null, "", source, game, Zone.GRAVEYARD, true);
                        }
                    }
                }
            }
            // cards in Hand
            filterNamedCard.setMessage("card named " + nameToSearch + " in the hand of " + owner.getName());
            TargetCard targetCardInHand = new TargetCard(0, Integer.MAX_VALUE, Zone.HAND, filterNamedCard);
            targetCardInHand.setNotTarget(true);
            if (controller.chooseTarget(Outcome.Exile, owner.getHand(), targetCardInHand, source, game)) {
                List<UUID> targets = targetCardInHand.getTargets();
                for (UUID targetId : targets) {
                    Card targetCard = owner.getHand().get(targetId, game);
                    if (targetCard != null) {
                        controller.moveCardToExileWithInfo(targetCard, null, "", source, game, Zone.HAND, true);
                    }
                }
            }
            // cards in Library
            filterNamedCard.setMessage("card named " + nameToSearch + " in the library of " + owner.getName());
            TargetCardInLibrary targetCardInLibrary = new TargetCardInLibrary(0, Integer.MAX_VALUE, filterNamedCard);
            if (controller.searchLibrary(targetCardInLibrary, source, game, owner.getId())) {
                List<UUID> targets = targetCardInLibrary.getTargets();
                for (UUID targetId : targets) {
                    Card targetCard = owner.getLibrary().getCard(targetId, game);
                    if (targetCard != null) {
                        controller.moveCardToExileWithInfo(targetCard, null, "", source, game, Zone.LIBRARY, true);
                    }
                }
            }
            owner.shuffleLibrary(source, game);
            return true;
        }
    }
    return false;
}
Also used : FilterCard(mage.filter.FilterCard) Player(mage.players.Player) NamePredicate(mage.filter.predicate.mageobject.NamePredicate) TargetCardInGraveyard(mage.target.common.TargetCardInGraveyard) TargetCard(mage.target.TargetCard) UUID(java.util.UUID) TargetCardInLibrary(mage.target.common.TargetCardInLibrary) FilterCard(mage.filter.FilterCard) TargetCard(mage.target.TargetCard) Card(mage.cards.Card)

Example 37 with TargetCardInGraveyard

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

the class TakenumaAbandonedMireEffect method apply.

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

Example 38 with TargetCardInGraveyard

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

the class WildfireDevilsEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    if (controller == null) {
        return false;
    }
    PlayerList players = game.getState().getPlayersInRange(controller.getId(), game);
    if (players == null) {
        return false;
    }
    Player randomPlayer = game.getPlayer(players.get(RandomUtil.nextInt(players.size())));
    if (randomPlayer == null) {
        return false;
    }
    game.informPlayers("The chosen random player is " + randomPlayer.getLogName());
    if (randomPlayer.getGraveyard().getCards(game).stream().noneMatch(card1 -> card1.isInstantOrSorcery(game))) {
        return false;
    }
    TargetCardInGraveyard targetCard = new TargetCardInGraveyard(StaticFilters.FILTER_CARD_INSTANT_OR_SORCERY);
    targetCard.setNotTarget(true);
    if (!randomPlayer.choose(Outcome.Discard, randomPlayer.getGraveyard(), targetCard, game)) {
        return false;
    }
    Card card = game.getCard(targetCard.getFirstTarget());
    if (card == null) {
        return false;
    }
    randomPlayer.moveCards(card, Zone.EXILED, source, game);
    if (game.getState().getZone(card.getId()) != Zone.EXILED) {
        return false;
    }
    Card copiedCard = game.copyCard(card, source, controller.getId());
    if (copiedCard == null) {
        return false;
    }
    randomPlayer.moveCards(copiedCard, Zone.EXILED, source, game);
    if (!controller.chooseUse(outcome, "Cast the copy of the exiled card?", source, game)) {
        return false;
    }
    game.getState().setValue("PlayFromNotOwnHandZone" + copiedCard.getId(), Boolean.TRUE);
    Boolean cardWasCast = controller.cast(controller.chooseAbilityForCast(copiedCard, game, true), game, true, new ApprovingObject(source, game));
    game.getState().setValue("PlayFromNotOwnHandZone" + copiedCard.getId(), null);
    return cardWasCast;
}
Also used : Player(mage.players.Player) TargetCardInGraveyard(mage.target.common.TargetCardInGraveyard) ApprovingObject(mage.ApprovingObject) PlayerList(mage.players.PlayerList) Card(mage.cards.Card)

Example 39 with TargetCardInGraveyard

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

the class ZombieCannibalTriggeredAbility method checkTrigger.

@Override
public boolean checkTrigger(GameEvent event, Game game) {
    if (!event.getSourceId().equals(this.sourceId) || !((DamagedPlayerEvent) event).isCombatDamage()) {
        return false;
    }
    Player damagedPlayer = game.getPlayer(event.getTargetId());
    if (damagedPlayer == null) {
        return false;
    }
    FilterCard filter = new FilterCard("card in " + damagedPlayer.getName() + "'s graveyard");
    filter.add(new OwnerIdPredicate(damagedPlayer.getId()));
    TargetCardInGraveyard target = new TargetCardInGraveyard(filter);
    this.getTargets().clear();
    this.addTarget(target);
    return true;
}
Also used : FilterCard(mage.filter.FilterCard) Player(mage.players.Player) OwnerIdPredicate(mage.filter.predicate.card.OwnerIdPredicate) TargetCardInGraveyard(mage.target.common.TargetCardInGraveyard) DamagedPlayerEvent(mage.game.events.DamagedPlayerEvent)

Example 40 with TargetCardInGraveyard

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

the class DranaTheLastBloodchiefCounterEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    Player player = game.getPlayer(targetPointer.getFirst(game, source));
    if (controller == null || player == null || controller.getGraveyard().count(filter, game) < 1) {
        return false;
    }
    TargetCard target = new TargetCardInGraveyard(filter);
    target.setNotTarget(true);
    player.choose(outcome, controller.getGraveyard(), target, game);
    Card card = game.getCard(target.getFirstTarget());
    if (card == null) {
        return false;
    }
    game.addEffect(new DranaTheLastBloodchiefSubtypeEffect(card, game), source);
    game.addEffect(new DranaTheLastBloodchiefCounterEffect(card, game), source);
    return controller.moveCards(card, Zone.BATTLEFIELD, source, game);
}
Also used : Player(mage.players.Player) TargetCardInGraveyard(mage.target.common.TargetCardInGraveyard) TargetCard(mage.target.TargetCard) FilterCard(mage.filter.FilterCard) FilterCreatureCard(mage.filter.common.FilterCreatureCard) TargetCard(mage.target.TargetCard) Card(mage.cards.Card)

Aggregations

TargetCardInGraveyard (mage.target.common.TargetCardInGraveyard)59 Player (mage.players.Player)54 Card (mage.cards.Card)32 FilterCard (mage.filter.FilterCard)24 OwnerIdPredicate (mage.filter.predicate.card.OwnerIdPredicate)23 UUID (java.util.UUID)21 FilterCreatureCard (mage.filter.common.FilterCreatureCard)17 Permanent (mage.game.permanent.Permanent)14 Target (mage.target.Target)14 TargetCard (mage.target.TargetCard)12 MageObject (mage.MageObject)8 Ability (mage.abilities.Ability)6 CardsImpl (mage.cards.CardsImpl)6 CardIdPredicate (mage.filter.predicate.mageobject.CardIdPredicate)5 TargetPlayer (mage.target.TargetPlayer)5 HashSet (java.util.HashSet)4 ManaCostsImpl (mage.abilities.costs.mana.ManaCostsImpl)4 Cards (mage.cards.Cards)4 TargetCardInLibrary (mage.target.common.TargetCardInLibrary)4 TargetOpponent (mage.target.common.TargetOpponent)4