Search in sources :

Example 41 with TargetCardInGraveyard

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

the class GravestormEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player you = game.getPlayer(source.getControllerId());
    Player targetPlayer = game.getPlayer(source.getFirstTarget());
    if (targetPlayer != null && you != null) {
        FilterCard filter = new FilterCard("card from your graveyard");
        filter.add(new OwnerIdPredicate(targetPlayer.getId()));
        TargetCardInGraveyard target = new TargetCardInGraveyard(filter);
        boolean opponentChoosesExile = targetPlayer.chooseUse(Outcome.Exile, "Exile a card from your graveyard?", source, game);
        boolean opponentExilesACard = false;
        if (opponentChoosesExile && targetPlayer.chooseTarget(Outcome.Exile, target, source, game)) {
            Card card = game.getCard(target.getFirstTarget());
            if (card != null) {
                opponentExilesACard = targetPlayer.moveCardToExileWithInfo(card, null, "", source, game, Zone.GRAVEYARD, true);
            }
        }
        if (!opponentExilesACard) {
            if (you.chooseUse(Outcome.DrawCard, "Draw a card?", source, game)) {
                you.drawCards(1, source, game);
            }
        }
        return true;
    }
    return false;
}
Also used : FilterCard(mage.filter.FilterCard) Player(mage.players.Player) OwnerIdPredicate(mage.filter.predicate.card.OwnerIdPredicate) TargetCardInGraveyard(mage.target.common.TargetCardInGraveyard) FilterCard(mage.filter.FilterCard) Card(mage.cards.Card)

Example 42 with TargetCardInGraveyard

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

the class KairiTheSwirlingSkyEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player player = game.getPlayer(source.getControllerId());
    if (player == null) {
        return false;
    }
    player.millCards(6, source, game);
    TargetCard target = new TargetCardInGraveyard(0, 2, StaticFilters.FILTER_CARD_INSTANT_OR_SORCERY);
    target.setNotTarget(true);
    player.choose(outcome, player.getGraveyard(), target, game);
    return player.moveCards(new CardsImpl(target.getTargets()), Zone.HAND, source, game);
}
Also used : Player(mage.players.Player) TargetCardInGraveyard(mage.target.common.TargetCardInGraveyard) TargetCard(mage.target.TargetCard) CardsImpl(mage.cards.CardsImpl)

Example 43 with TargetCardInGraveyard

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

the class MausoleumTurnkeyEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    if (controller != null) {
        UUID opponentId = null;
        if (game.getOpponents(controller.getId()).size() > 1) {
            Target target = new TargetOpponent(true);
            if (controller.chooseTarget(outcome, target, source, game)) {
                opponentId = target.getFirstTarget();
            }
        } else {
            opponentId = game.getOpponents(controller.getId()).iterator().next();
        }
        if (opponentId != null) {
            Player opponent = game.getPlayer(opponentId);
            if (opponent != null) {
                FilterCreatureCard filter = new FilterCreatureCard("creature card from " + controller.getLogName() + " graveyard");
                filter.add(new OwnerIdPredicate(controller.getId()));
                Target target = new TargetCardInGraveyard(filter);
                opponent.chooseTarget(outcome, target, source, game);
                Card card = game.getCard(target.getFirstTarget());
                if (card != null) {
                    controller.moveCards(card, Zone.HAND, source, game);
                }
            }
        }
        return true;
    }
    return false;
}
Also used : Player(mage.players.Player) Target(mage.target.Target) TargetOpponent(mage.target.common.TargetOpponent) FilterCreatureCard(mage.filter.common.FilterCreatureCard) OwnerIdPredicate(mage.filter.predicate.card.OwnerIdPredicate) TargetCardInGraveyard(mage.target.common.TargetCardInGraveyard) UUID(java.util.UUID) FilterCreatureCard(mage.filter.common.FilterCreatureCard) Card(mage.cards.Card)

Example 44 with TargetCardInGraveyard

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

the class ForgottenLoreEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player you = game.getPlayer(source.getControllerId());
    Player opponent = game.getPlayer(targetPointer.getFirst(game, source));
    if (you != null && opponent != null) {
        FilterCard filter = new FilterCard();
        filter.add(new OwnerIdPredicate(you.getId()));
        Cost cost = new ManaCostsImpl("{G}");
        TargetCardInGraveyard chosenCard;
        Card card = null;
        boolean done = false;
        do {
            chosenCard = new TargetCardInGraveyard(filter);
            chosenCard.setNotTarget(true);
            if (chosenCard.canChoose(source.getSourceId(), opponent.getId(), game)) {
                opponent.chooseTarget(Outcome.ReturnToHand, chosenCard, source, game);
                card = game.getCard(chosenCard.getFirstTarget());
                if (card != null) {
                    filter.add(Predicates.not(new CardIdPredicate(card.getId())));
                    game.informPlayers("Forgotten Lore: " + opponent.getLogName() + " has chosen " + card.getLogName());
                }
            } else {
                done = true;
            }
            if (!done) {
                if (cost.canPay(source, source, you.getId(), game) && you.chooseUse(Outcome.Benefit, "Pay {G} to choose a different card ?", source, game)) {
                    cost.clearPaid();
                    if (!cost.pay(source, game, source, you.getId(), false, null)) {
                        done = true;
                    }
                } else {
                    done = true;
                }
            }
        } while (!done);
        if (card != null) {
            Cards cardsToHand = new CardsImpl();
            cardsToHand.add(card);
            you.moveCards(cardsToHand, Zone.HAND, source, game);
        }
        return true;
    }
    return false;
}
Also used : FilterCard(mage.filter.FilterCard) Player(mage.players.Player) OwnerIdPredicate(mage.filter.predicate.card.OwnerIdPredicate) TargetCardInGraveyard(mage.target.common.TargetCardInGraveyard) Cost(mage.abilities.costs.Cost) ManaCostsImpl(mage.abilities.costs.mana.ManaCostsImpl) FilterCard(mage.filter.FilterCard) CardIdPredicate(mage.filter.predicate.mageobject.CardIdPredicate)

Example 45 with TargetCardInGraveyard

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

the class InkEyesServantOfOniTriggeredAbility 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("creature in " + damagedPlayer.getName() + "'s graveyard");
    filter.add(CardType.CREATURE.getPredicate());
    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)

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