Search in sources :

Example 16 with TargetCardInExile

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

the class YouFindSomePrisonersEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player player = game.getPlayer(source.getControllerId());
    Player opponent = game.getPlayer(source.getFirstTarget());
    if (player == null || opponent == null) {
        return false;
    }
    Cards cards = new CardsImpl(opponent.getLibrary().getTopCards(game, 3));
    player.moveCards(cards, Zone.EXILED, source, game);
    TargetCardInExile target = new TargetCardInExile(StaticFilters.FILTER_CARD);
    target.setNotTarget(true);
    player.choose(Outcome.PlayForFree, cards, target, game);
    Card card = cards.get(target.getFirstTarget(), game);
    if (card != null) {
        CardUtil.makeCardPlayable(game, source, card, Duration.UntilEndOfYourNextTurn, true);
    }
    return true;
}
Also used : Player(mage.players.Player) TargetCardInExile(mage.target.common.TargetCardInExile)

Example 17 with TargetCardInExile

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

the class ImbrahamDeanOfTheoryEffect 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(player.getLibrary().getTopCards(game, source.getManaCostsToPay().getX()));
    player.moveCards(cards, Zone.EXILED, source, game);
    for (Card card : cards.getCards(game)) {
        if (card == null) {
            continue;
        }
        card.addCounters(CounterType.STUDY.createInstance(), source.getControllerId(), source, game);
    }
    TargetCard targetCard = new TargetCardInExile(0, 1, filter, null);
    targetCard.setNotTarget(true);
    player.choose(outcome, targetCard, source.getSourceId(), game);
    Card card = game.getCard(targetCard.getFirstTarget());
    if (card != null) {
        player.moveCards(card, Zone.HAND, source, game);
    }
    return true;
}
Also used : Player(mage.players.Player) TargetCardInExile(mage.target.common.TargetCardInExile) TargetCard(mage.target.TargetCard) FilterCard(mage.filter.FilterCard) FilterOwnedCard(mage.filter.common.FilterOwnedCard) TargetCard(mage.target.TargetCard)

Example 18 with TargetCardInExile

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

the class MemoryTheftEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    new DiscardCardYouChooseTargetEffect(StaticFilters.FILTER_CARD_NON_LAND, TargetController.ANY).apply(game, source);
    Player controller = game.getPlayer(source.getControllerId());
    Player player = game.getPlayer(source.getFirstTarget());
    if (controller == null || player == null) {
        return false;
    }
    FilterCard filter = new FilterCard("card owned by " + player.getName() + " that has an Adventure");
    filter.add(AdventurePredicate.instance);
    filter.add(new OwnerIdPredicate(player.getId()));
    TargetCard target = new TargetCardInExile(0, 1, filter, null, true);
    if (!target.canChoose(source.getSourceId(), source.getControllerId(), game) || !controller.choose(outcome, target, source.getSourceId(), game)) {
        return false;
    }
    Card card = game.getCard(target.getFirstTarget());
    return controller.moveCards(card, Zone.GRAVEYARD, source, game);
}
Also used : FilterCard(mage.filter.FilterCard) Player(mage.players.Player) OwnerIdPredicate(mage.filter.predicate.card.OwnerIdPredicate) TargetCardInExile(mage.target.common.TargetCardInExile) DiscardCardYouChooseTargetEffect(mage.abilities.effects.common.discard.DiscardCardYouChooseTargetEffect) TargetCard(mage.target.TargetCard) FilterCard(mage.filter.FilterCard) TargetCard(mage.target.TargetCard) Card(mage.cards.Card)

Example 19 with TargetCardInExile

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

the class ExileOpponentsCardFromExileToGraveyardCost method pay.

@Override
public boolean pay(Ability ability, Game game, Ability source, UUID controllerId, boolean noMana, Cost costToPay) {
    Player controller = game.getPlayer(controllerId);
    if (controller != null) {
        FilterCard filter = new FilterCard();
        filter.add(TargetController.OPPONENT.getOwnerPredicate());
        Target target = new TargetCardInExile(filter);
        if (controller.chooseTarget(Outcome.Damage, target, ability, game)) {
            Card card = game.getCard(target.getFirstTarget());
            if (card != null) {
                paid = true;
                controller.moveCards(card, Zone.GRAVEYARD, ability, game);
            }
        }
    }
    return paid;
}
Also used : FilterCard(mage.filter.FilterCard) Player(mage.players.Player) Target(mage.target.Target) TargetCardInExile(mage.target.common.TargetCardInExile) FilterCard(mage.filter.FilterCard) Card(mage.cards.Card)

Example 20 with TargetCardInExile

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

the class CascadeEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    if (controller == null) {
        return false;
    }
    Card sourceCard = game.getCard(source.getSourceId());
    if (sourceCard == null) {
        return false;
    }
    // exile cards from the top of your library until you exile a nonland card whose converted mana cost is less than this spell's converted mana cost
    Cards cardsToExile = new CardsImpl();
    int sourceCost = sourceCard.getManaValue();
    Card cardToCast = null;
    for (Card card : controller.getLibrary().getCards(game)) {
        cardsToExile.add(card);
        // the card move is sequential, not all at once.
        controller.moveCards(card, Zone.EXILED, source, game);
        // Laelia, the Blade Reforged
        game.getState().processAction(game);
        if (!card.isLand(game) && card.getManaValue() < sourceCost) {
            cardToCast = card;
            break;
        }
    }
    // set back empty draw state if that caused an empty draw
    controller.getLibrary().reset();
    // additional replacement effect: As you cascade, you may put a land card from among the exiled cards onto the battlefield tapped
    GameEvent event = GameEvent.getEvent(GameEvent.EventType.CASCADE_LAND, source.getSourceId(), source, source.getControllerId(), 0);
    game.replaceEvent(event);
    if (event.getAmount() > 0) {
        TargetCardInExile target = new TargetCardInExile(0, event.getAmount(), StaticFilters.FILTER_CARD_LAND, null, true);
        target.withChooseHint("land to put onto battlefield tapped");
        controller.choose(Outcome.PutCardInPlay, cardsToExile, target, game);
        controller.moveCards(new CardsImpl(target.getTargets()).getCards(game), Zone.BATTLEFIELD, source, game, true, false, false, null);
    }
    // You may cast that spell without paying its mana cost if its converted mana cost is less than this spell's converted mana cost.
    List<Card> partsToCast = new ArrayList<>();
    if (cardToCast != null) {
        if (cardToCast instanceof SplitCard) {
            partsToCast.add(((SplitCard) cardToCast).getLeftHalfCard());
            partsToCast.add(((SplitCard) cardToCast).getRightHalfCard());
            partsToCast.add(cardToCast);
        } else if (cardToCast instanceof AdventureCard) {
            partsToCast.add(((AdventureCard) cardToCast).getSpellCard());
            partsToCast.add(cardToCast);
        } else if (cardToCast instanceof ModalDoubleFacesCard) {
            partsToCast.add(((ModalDoubleFacesCard) cardToCast).getLeftHalfCard());
            partsToCast.add(((ModalDoubleFacesCard) cardToCast).getRightHalfCard());
        } else {
            partsToCast.add(cardToCast);
        }
        // remove too big cmc
        partsToCast.removeIf(card -> card.getManaValue() >= sourceCost);
        // remove non spells
        partsToCast.removeIf(card -> card.getSpellAbility() == null);
    }
    String partsInfo = partsToCast.stream().map(MageObject::getIdName).collect(Collectors.joining(" or "));
    if (cardToCast != null && partsToCast.size() > 0 && controller.chooseUse(outcome, "Cast spell without paying its mana cost (" + partsInfo + ")?", source, game)) {
        try {
            // enable free cast for all compatible parts
            partsToCast.forEach(card -> game.getState().setValue("PlayFromNotOwnHandZone" + card.getId(), Boolean.TRUE));
            controller.cast(controller.chooseAbilityForCast(cardToCast, game, true), game, true, new ApprovingObject(source, game));
        } finally {
            partsToCast.forEach(card -> game.getState().setValue("PlayFromNotOwnHandZone" + card.getId(), null));
        }
    }
    // Then put all cards exiled this way that weren't cast on the bottom of your library in a random order.
    cardsToExile.removeIf(uuid -> game.getState().getZone(uuid) != Zone.EXILED);
    return controller.putCardsOnBottomOfLibrary(cardsToExile, game, source, false);
}
Also used : Player(mage.players.Player) ApprovingObject(mage.ApprovingObject) TargetCardInExile(mage.target.common.TargetCardInExile) ArrayList(java.util.ArrayList) GameEvent(mage.game.events.GameEvent)

Aggregations

TargetCardInExile (mage.target.common.TargetCardInExile)32 Player (mage.players.Player)31 FilterCard (mage.filter.FilterCard)17 TargetCard (mage.target.TargetCard)13 Card (mage.cards.Card)11 ApprovingObject (mage.ApprovingObject)10 Cards (mage.cards.Cards)6 Target (mage.target.Target)6 CardsImpl (mage.cards.CardsImpl)5 UUID (java.util.UUID)3 FilterOwnedCard (mage.filter.common.FilterOwnedCard)3 ManaValuePredicate (mage.filter.predicate.mageobject.ManaValuePredicate)3 ExileZone (mage.game.ExileZone)3 FilterInstantOrSorceryCard (mage.filter.common.FilterInstantOrSorceryCard)2 Permanent (mage.game.permanent.Permanent)2 TargetCardInLibrary (mage.target.common.TargetCardInLibrary)2 FixedTarget (mage.target.targetpointer.FixedTarget)2 ArrayList (java.util.ArrayList)1 Objects (java.util.Objects)1 MageObject (mage.MageObject)1