Search in sources :

Example 11 with TargetCardInExile

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

the class OlagLudevicsHubrisCopyApplier method getCard.

private Card getCard(Cards cards, Ability source, Game game) {
    if (cards.size() == 1) {
        return cards.getRandom(game);
    }
    Player player = game.getPlayer(source.getControllerId());
    if (player == null) {
        return cards.getRandom(game);
    }
    TargetCard target = new TargetCardInExile(StaticFilters.FILTER_CARD);
    player.choose(outcome, target, source.getSourceId(), game);
    return cards.get(target.getFirstTarget(), game);
}
Also used : Player(mage.players.Player) TargetCardInExile(mage.target.common.TargetCardInExile) TargetCard(mage.target.TargetCard)

Example 12 with TargetCardInExile

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

the class ThievesAuctionEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    if (controller != null) {
        // Exile all nontoken permanents.
        Cards exiledCards = new CardsImpl();
        for (Permanent permanent : game.getBattlefield().getActivePermanents(filter, source.getControllerId(), source.getSourceId(), game)) {
            exiledCards.add(permanent);
            controller.moveCardsToExile(permanent, source, game, true, CardUtil.getCardExileZoneId(game, source.getSourceId()), "Thieves' Auction");
        }
        // Starting with you, each player
        PlayerList playerList = game.getState().getPlayersInRange(controller.getId(), game);
        Player player = playerList.getCurrent(game);
        while (player != null && !exiledCards.isEmpty() && !game.hasEnded()) {
            if (player.canRespond()) {
                // chooses one of the exiled cards
                TargetCard target = new TargetCardInExile(new FilterCard());
                if (player.choose(Outcome.PutCardInPlay, exiledCards, target, game)) {
                    // and puts it onto the battlefield tapped under their control.
                    Card chosenCard = exiledCards.get(target.getFirstTarget(), game);
                    if (chosenCard != null) {
                        player.moveCards(chosenCard, Zone.BATTLEFIELD, source, game, true, false, false, null);
                    }
                    exiledCards.remove(chosenCard);
                } else {
                    break;
                }
            }
            // Repeat this process until all cards exiled this way have been chosen.
            player = playerList.getNext(game, false);
        }
        return true;
    }
    return false;
}
Also used : FilterCard(mage.filter.FilterCard) Player(mage.players.Player) FilterPermanent(mage.filter.FilterPermanent) Permanent(mage.game.permanent.Permanent) PlayerList(mage.players.PlayerList) TargetCardInExile(mage.target.common.TargetCardInExile) TargetCard(mage.target.TargetCard) FilterCard(mage.filter.FilterCard) TargetCard(mage.target.TargetCard)

Example 13 with TargetCardInExile

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

the class VillainousWealthEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    MageObject mageObject = game.getObject(source.getSourceId());
    if (controller != null && mageObject != null) {
        Player player = game.getPlayer(targetPointer.getFirst(game, source));
        FilterCard filter = new FilterNonlandCard();
        filter.add(new ManaValuePredicate(ComparisonType.FEWER_THAN, source.getManaCostsToPay().getX() + 1));
        UUID exileId = CardUtil.getCardExileZoneId(game, source);
        if (player != null) {
            Cards cardsToExile = new CardsImpl();
            cardsToExile.addAll(player.getLibrary().getTopCards(game, source.getManaCostsToPay().getX()));
            controller.moveCards(cardsToExile, Zone.EXILED, source, game);
            if (controller.chooseUse(Outcome.PlayForFree, "Cast cards exiled with " + mageObject.getLogName() + "  without paying its mana cost?", source, game)) {
                OuterLoop: while (cardsToExile.count(filter, game) > 0) {
                    if (!controller.canRespond()) {
                        return false;
                    }
                    TargetCardInExile target = new TargetCardInExile(0, 1, filter, exileId, false);
                    target.setNotTarget(true);
                    while (controller.canRespond() && cardsToExile.count(filter, game) > 0 && controller.choose(Outcome.PlayForFree, cardsToExile, target, game)) {
                        Card card = game.getCard(target.getFirstTarget());
                        if (card != null) {
                            game.getState().setValue("PlayFromNotOwnHandZone" + card.getId(), Boolean.TRUE);
                            Boolean cardWasCast = controller.cast(controller.chooseAbilityForCast(card, game, true), game, true, new ApprovingObject(source, game));
                            game.getState().setValue("PlayFromNotOwnHandZone" + card.getId(), null);
                            if (cardWasCast) {
                                cardsToExile.remove(card);
                            }
                        } else {
                            break OuterLoop;
                        }
                        target.clearChosen();
                    }
                }
            }
        }
        return true;
    }
    return false;
}
Also used : FilterCard(mage.filter.FilterCard) Player(mage.players.Player) ManaValuePredicate(mage.filter.predicate.mageobject.ManaValuePredicate) FilterNonlandCard(mage.filter.common.FilterNonlandCard) ApprovingObject(mage.ApprovingObject) MageObject(mage.MageObject) TargetCardInExile(mage.target.common.TargetCardInExile) UUID(java.util.UUID) FilterCard(mage.filter.FilterCard) FilterNonlandCard(mage.filter.common.FilterNonlandCard)

Example 14 with TargetCardInExile

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

the class CustomTestCard method addCustomEffect_ReturnFromAnyToHand.

/**
 * Return target card to hand that can be called by text "return from ..."
 *
 * @param controller
 */
protected void addCustomEffect_ReturnFromAnyToHand(TestPlayer controller) {
    // graveyard
    Ability ability = new SimpleActivatedAbility(new ReturnFromGraveyardToHandTargetEffect().setText("return from graveyard"), new ManaCostsImpl(""));
    ability.addTarget(new TargetCardInGraveyard(StaticFilters.FILTER_CARD));
    addCustomCardWithAbility("return from graveyard for " + controller.getName(), controller, ability);
    // exile
    ability = new SimpleActivatedAbility(new ReturnFromExileEffect(Zone.HAND).setText("return from exile"), new ManaCostsImpl(""));
    ability.addTarget(new TargetCardInExile(StaticFilters.FILTER_CARD));
    addCustomCardWithAbility("return from exile for " + controller.getName(), controller, ability);
    // library
    ability = new SimpleActivatedAbility(new SearchLibraryPutInHandEffect(new TargetCardInLibrary(StaticFilters.FILTER_CARD)).setText("return from library"), new ManaCostsImpl(""));
    addCustomCardWithAbility("return from library for " + controller.getName(), controller, ability);
}
Also used : SimpleActivatedAbility(mage.abilities.common.SimpleActivatedAbility) SpellAbility(mage.abilities.SpellAbility) SimpleStaticAbility(mage.abilities.common.SimpleStaticAbility) Ability(mage.abilities.Ability) TargetCardInGraveyard(mage.target.common.TargetCardInGraveyard) ReturnFromExileEffect(mage.abilities.effects.common.ReturnFromExileEffect) SimpleActivatedAbility(mage.abilities.common.SimpleActivatedAbility) TargetCardInExile(mage.target.common.TargetCardInExile) SearchLibraryPutInHandEffect(mage.abilities.effects.common.search.SearchLibraryPutInHandEffect) ReturnFromGraveyardToHandTargetEffect(mage.abilities.effects.common.ReturnFromGraveyardToHandTargetEffect) ManaCostsImpl(mage.abilities.costs.mana.ManaCostsImpl) TargetCardInLibrary(mage.target.common.TargetCardInLibrary)

Example 15 with TargetCardInExile

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

the class EtherealForagerEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player player = game.getPlayer(source.getControllerId());
    if (player == null) {
        return false;
    }
    String keyString = CardUtil.getCardZoneString("delvedCards", source.getSourceId(), game, true);
    Cards delvedCards = (Cards) game.getState().getValue(keyString);
    if (delvedCards == null || delvedCards.count(StaticFilters.FILTER_CARD_INSTANT_AND_SORCERY, game) < 1) {
        return false;
    }
    TargetCard targetCard = new TargetCardInExile(0, 1, StaticFilters.FILTER_CARD_INSTANT_OR_SORCERY, null, true);
    ;
    player.choose(Outcome.DrawCard, delvedCards, targetCard, game);
    Card card = game.getCard(targetCard.getFirstTarget());
    if (card == null || !player.moveCards(card, Zone.HAND, source, game)) {
        return false;
    }
    delvedCards.remove(card);
    return true;
}
Also used : Player(mage.players.Player) TargetCardInExile(mage.target.common.TargetCardInExile) TargetCard(mage.target.TargetCard) Cards(mage.cards.Cards) TargetCard(mage.target.TargetCard) Card(mage.cards.Card)

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