Search in sources :

Example 21 with TargetCardInGraveyard

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

the class DawnbreakReclaimerEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    /**
     * 04.11.2015 If any opponent has a creature card in their graveyard as
     * Dawnbreak Reclaimer's ability resolves, then you must choose one of
     * those cards. You can't choose a different opponent with no creature
     * cards in their graveyard to avoid returning one of those cards.
     *
     * 04.11.2015 If there are no creature cards in any opponent's graveyard
     * as Dawnbreak Reclaimer's ability resolves, you'll still have the
     * option to return a creature card from your graveyard to the
     * battlefield. You choose which opponent will choose a creature card in
     * your graveyard.
     */
    Player controller = game.getPlayer(source.getControllerId());
    MageObject sourceObject = source.getSourceObject(game);
    if (controller != null && sourceObject != null) {
        FilterCreatureCard filter = new FilterCreatureCard("a creature card in an opponent's graveyard");
        filter.add(TargetController.OPPONENT.getOwnerPredicate());
        TargetCard chosenCreatureOpponentGraveyard = new TargetCard(Zone.GRAVEYARD, filter);
        Player opponent = null;
        Card cardOpponentGraveyard = null;
        chosenCreatureOpponentGraveyard.setNotTarget(true);
        if (chosenCreatureOpponentGraveyard.canChoose(source.getSourceId(), source.getControllerId(), game)) {
            controller.choose(Outcome.Detriment, chosenCreatureOpponentGraveyard, source.getSourceId(), game);
            cardOpponentGraveyard = game.getCard(chosenCreatureOpponentGraveyard.getFirstTarget());
            if (cardOpponentGraveyard != null) {
                opponent = game.getPlayer(cardOpponentGraveyard.getOwnerId());
                game.informPlayers(sourceObject.getLogName() + ": " + controller.getLogName() + " has chosen " + cardOpponentGraveyard.getIdName() + " of " + opponent.getLogName());
            }
        }
        if (opponent == null) {
            // if no card from opponent was available controller has to chose an opponent to select a creature card in controllers graveyard
            TargetOpponent targetOpponent = new TargetOpponent(true);
            controller.choose(outcome, targetOpponent, source.getSourceId(), game);
            opponent = game.getPlayer(targetOpponent.getFirstTarget());
            if (opponent != null) {
                game.informPlayers(sourceObject.getLogName() + ": " + controller.getLogName() + " has chosen " + opponent.getLogName() + " to select a creature card from their graveyard");
            }
        }
        if (opponent != null) {
            FilterCreatureCard filterCreatureCard = new FilterCreatureCard("a creature card in " + controller.getName() + "'s the graveyard");
            filterCreatureCard.add(new OwnerIdPredicate(controller.getId()));
            TargetCardInGraveyard targetControllerGaveyard = new TargetCardInGraveyard(filterCreatureCard);
            targetControllerGaveyard.setNotTarget(true);
            Card controllerCreatureCard = null;
            if (targetControllerGaveyard.canChoose(source.getSourceId(), opponent.getId(), game) && opponent.choose(outcome, targetControllerGaveyard, source.getSourceId(), game)) {
                controllerCreatureCard = game.getCard(targetControllerGaveyard.getFirstTarget());
                if (controllerCreatureCard != null) {
                    game.informPlayers(sourceObject.getLogName() + ": " + opponent.getLogName() + " has chosen " + controllerCreatureCard.getIdName() + " of " + controller.getLogName());
                }
            }
            Set<Card> cards = new HashSet<>();
            if (cardOpponentGraveyard != null) {
                cards.add(cardOpponentGraveyard);
            }
            if (controllerCreatureCard != null) {
                cards.add(controllerCreatureCard);
            }
            if (!cards.isEmpty()) {
                if (controller.chooseUse(outcome, "Return those cards to the battlefield under their owners' control?", "Opponent's creature card: " + (cardOpponentGraveyard == null ? "none" : cardOpponentGraveyard.getLogName()) + ", your creature card: " + (controllerCreatureCard == null ? "none" : controllerCreatureCard.getLogName()), null, null, source, game)) {
                    controller.moveCards(cards, Zone.BATTLEFIELD, source, game, false, false, true, null);
                }
            }
        }
        return true;
    }
    return false;
}
Also used : Player(mage.players.Player) FilterCreatureCard(mage.filter.common.FilterCreatureCard) TargetOpponent(mage.target.common.TargetOpponent) OwnerIdPredicate(mage.filter.predicate.card.OwnerIdPredicate) TargetCardInGraveyard(mage.target.common.TargetCardInGraveyard) MageObject(mage.MageObject) TargetCard(mage.target.TargetCard) FilterCreatureCard(mage.filter.common.FilterCreatureCard) TargetCard(mage.target.TargetCard) Card(mage.cards.Card) HashSet(java.util.HashSet)

Example 22 with TargetCardInGraveyard

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

the class DredgeTheMireEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    if (controller == null) {
        return false;
    }
    Cards cards = new CardsImpl();
    for (UUID opponentId : game.getOpponents(source.getControllerId())) {
        Player player = game.getPlayer(opponentId);
        if (player == null || player.getGraveyard().count(StaticFilters.FILTER_CARD_CREATURE, game) == 0) {
            continue;
        }
        TargetCard target = new TargetCardInGraveyard(StaticFilters.FILTER_CARD_CREATURE_YOUR_GRAVEYARD);
        target.setNotTarget(true);
        if (!player.choose(outcome, player.getGraveyard(), target, game)) {
            continue;
        }
        cards.add(target.getFirstTarget());
    }
    return controller.moveCards(cards, Zone.BATTLEFIELD, source, game);
}
Also used : Player(mage.players.Player) TargetCardInGraveyard(mage.target.common.TargetCardInGraveyard) TargetCard(mage.target.TargetCard) UUID(java.util.UUID) Cards(mage.cards.Cards) CardsImpl(mage.cards.CardsImpl)

Example 23 with TargetCardInGraveyard

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

the class LilianaTheNecromancerEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player player = game.getPlayer(source.getControllerId());
    if (player == null) {
        return false;
    }
    Target target = new TargetCardInGraveyard(0, 2, filter);
    target.setNotTarget(true);
    if (!player.choose(outcome, target, source.getSourceId(), game)) {
        return false;
    }
    Cards cardsToMove = new CardsImpl();
    for (UUID targetId : target.getTargets()) {
        Card card = game.getCard(targetId);
        if (card != null) {
            cardsToMove.add(card);
        }
    }
    return player.moveCards(cardsToMove, Zone.BATTLEFIELD, source, game);
}
Also used : Player(mage.players.Player) TargetPlayer(mage.target.TargetPlayer) Target(mage.target.Target) TargetCardInGraveyard(mage.target.common.TargetCardInGraveyard) UUID(java.util.UUID) Cards(mage.cards.Cards) CardsImpl(mage.cards.CardsImpl) FilterCreatureCard(mage.filter.common.FilterCreatureCard) Card(mage.cards.Card)

Example 24 with TargetCardInGraveyard

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

the class ScroungeEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    Player opponent = game.getPlayer(targetPointer.getFirst(game, source));
    if (controller != null && opponent != null) {
        FilterArtifactCard filter = new FilterArtifactCard();
        filter.add(new OwnerIdPredicate(opponent.getId()));
        TargetCardInGraveyard chosenCard = new TargetCardInGraveyard(filter);
        chosenCard.setNotTarget(true);
        if (chosenCard.canChoose(source.getSourceId(), opponent.getId(), game)) {
            opponent.chooseTarget(Outcome.ReturnToHand, chosenCard, source, game);
            Card card = game.getCard(chosenCard.getFirstTarget());
            if (card != null) {
                game.informPlayers("Scrounge: " + opponent.getLogName() + " has chosen " + card.getLogName());
                Cards cardsToMove = new CardsImpl();
                cardsToMove.add(card);
                controller.moveCards(cardsToMove, Zone.BATTLEFIELD, source, game);
            }
        }
        return true;
    }
    return false;
}
Also used : Player(mage.players.Player) OwnerIdPredicate(mage.filter.predicate.card.OwnerIdPredicate) TargetCardInGraveyard(mage.target.common.TargetCardInGraveyard) FilterArtifactCard(mage.filter.common.FilterArtifactCard) FilterArtifactCard(mage.filter.common.FilterArtifactCard)

Example 25 with TargetCardInGraveyard

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

the class ScrabblingClawsEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player targetPlayer = game.getPlayer(source.getFirstTarget());
    if (targetPlayer == null) {
        return false;
    }
    FilterCard filter = new FilterCard("card from your graveyard");
    filter.add(new OwnerIdPredicate(targetPlayer.getId()));
    TargetCardInGraveyard target = new TargetCardInGraveyard(filter);
    if (!targetPlayer.chooseTarget(Outcome.Exile, target, source, game)) {
        return false;
    }
    Card card = game.getCard(target.getFirstTarget());
    return card != null && targetPlayer.moveCards(card, Zone.EXILED, source, game);
}
Also used : FilterCard(mage.filter.FilterCard) TargetPlayer(mage.target.TargetPlayer) Player(mage.players.Player) OwnerIdPredicate(mage.filter.predicate.card.OwnerIdPredicate) TargetCardInGraveyard(mage.target.common.TargetCardInGraveyard) FilterCard(mage.filter.FilterCard) 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