Search in sources :

Example 26 with TargetCardInExile

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

the class IzzetChemisterCastFromExileEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    ExileZone exile = game.getExile().getExileZone(exileId);
    Player controller = game.getPlayer(source.getControllerId());
    FilterCard filter = new FilterCard();
    if (controller != null && exile != null) {
        Cards cardsToExile = new CardsImpl();
        cardsToExile.addAll(exile.getCards(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);
                    controller.cast(controller.chooseAbilityForCast(card, game, true), game, true, new ApprovingObject(source, game));
                    game.getState().setValue("PlayFromNotOwnHandZone" + card.getId(), null);
                    cardsToExile.remove(card);
                } else {
                    break OuterLoop;
                }
                target.clearChosen();
            }
        }
        return true;
    }
    return false;
}
Also used : FilterCard(mage.filter.FilterCard) Player(mage.players.Player) ApprovingObject(mage.ApprovingObject) TargetCardInExile(mage.target.common.TargetCardInExile) ExileZone(mage.game.ExileZone) FilterCard(mage.filter.FilterCard) FilterOwnedCard(mage.filter.common.FilterOwnedCard) TargetCard(mage.target.TargetCard)

Example 27 with TargetCardInExile

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

the class MuseVortexEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    if (controller == null) {
        return false;
    }
    int xValue = source.getManaCostsToPay().getX();
    Cards cards = new CardsImpl(controller.getLibrary().getTopCards(game, xValue));
    controller.moveCards(cards, Zone.EXILED, source, game);
    cards.retainZone(Zone.EXILED, game);
    FilterCard filter = new FilterInstantOrSorceryCard("an instant or sorcery card with mana value " + xValue + " or less");
    filter.add(new ManaValuePredicate(ComparisonType.FEWER_THAN, xValue + 1));
    TargetCardInExile target = new TargetCardInExile(filter);
    target.setNotTarget(true);
    if (controller.choose(Outcome.Benefit, cards, target, game)) {
        Card card = cards.get(target.getFirstTarget(), game);
        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);
            cards.remove(card);
            if (cardWasCast) {
                cards.remove(card);
            } else {
                game.informPlayer(controller, "You're not able to cast " + card.getIdName() + " or you canceled the casting.");
            }
            controller.putCardsOnTopOfLibrary(cards, game, source, true);
            return true;
        }
    }
    return false;
}
Also used : FilterCard(mage.filter.FilterCard) Player(mage.players.Player) ManaValuePredicate(mage.filter.predicate.mageobject.ManaValuePredicate) ApprovingObject(mage.ApprovingObject) FilterInstantOrSorceryCard(mage.filter.common.FilterInstantOrSorceryCard) TargetCardInExile(mage.target.common.TargetCardInExile) FilterCard(mage.filter.FilterCard) FilterInstantOrSorceryCard(mage.filter.common.FilterInstantOrSorceryCard)

Example 28 with TargetCardInExile

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

the class TectonicGiantMayPlayEffect 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(controller.getLibrary().getTopCards(game, 2));
    controller.moveCards(cards, Zone.EXILED, source, game);
    TargetCard targetCard = new TargetCardInExile(StaticFilters.FILTER_CARD);
    controller.choose(outcome, cards, targetCard, game);
    Card card = game.getCard(targetCard.getFirstTarget());
    if (card == null) {
        return true;
    }
    ContinuousEffect effect = new TectonicGiantMayPlayEffect();
    effect.setTargetPointer(new FixedTarget(card.getId()));
    game.addEffect(effect, source);
    return true;
}
Also used : FixedTarget(mage.target.targetpointer.FixedTarget) Player(mage.players.Player) TargetCardInExile(mage.target.common.TargetCardInExile) TargetCard(mage.target.TargetCard) ContinuousEffect(mage.abilities.effects.ContinuousEffect) TargetCard(mage.target.TargetCard)

Example 29 with TargetCardInExile

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

the class KayaTheInexorableEmblemEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player player = game.getPlayer(source.getControllerId());
    if (player != null) {
        Choice zoneChoice = new ChoiceImpl(true);
        zoneChoice.setMessage("Cast a legendary spell from hand, graveyard, or exile");
        zoneChoice.setChoices(choices);
        zoneChoice.clearChoice();
        if (player.choose(Outcome.PlayForFree, zoneChoice, game)) {
            TargetCard target = null;
            switch(zoneChoice.getChoice()) {
                case "Hand":
                    target = new TargetCardInHand(0, 1, filter);
                    target.setTargetName("legendary spell from your hand");
                    break;
                case "Graveyard":
                    target = new TargetCardInYourGraveyard(0, 1, filter, true);
                    target.setTargetName("legendary spell from your graveyard");
                    break;
                case "Exile":
                    target = new TargetCardInExile(0, 1, filter, null, true);
                    target.setNotTarget(true);
                    target.setTargetName("legendary spell you own in exile");
                    break;
            }
            if (target != null && player.chooseTarget(Outcome.PlayForFree, target, source, game)) {
                Card card = game.getCard(target.getFirstTarget());
                if (card != null) {
                    game.getState().setValue("PlayFromNotOwnHandZone" + card.getId(), Boolean.TRUE);
                    boolean cardWasCast = player.cast(player.chooseAbilityForCast(card, game, true), game, true, new ApprovingObject(source, game));
                    game.getState().setValue("PlayFromNotOwnHandZone" + card.getId(), null);
                    return cardWasCast;
                }
            }
        }
    }
    return false;
}
Also used : Player(mage.players.Player) Choice(mage.choices.Choice) ApprovingObject(mage.ApprovingObject) TargetCardInHand(mage.target.common.TargetCardInHand) TargetCardInExile(mage.target.common.TargetCardInExile) ChoiceImpl(mage.choices.ChoiceImpl) TargetCard(mage.target.TargetCard) TargetCardInYourGraveyard(mage.target.common.TargetCardInYourGraveyard) FilterOwnedCard(mage.filter.common.FilterOwnedCard) TargetCard(mage.target.TargetCard) Card(mage.cards.Card)

Example 30 with TargetCardInExile

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

the class DauthiVoidwalkerPlayEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player player = game.getPlayer(source.getControllerId());
    if (player == null) {
        return false;
    }
    TargetCardInExile target = new TargetCardInExile(0, 1, filter, null, true);
    player.choose(outcome, target, source.getSourceId(), game);
    Card card = game.getCard(target.getFirstTarget());
    if (card == null) {
        return false;
    }
    game.addEffect(new PlayFromNotOwnHandZoneTargetEffect(Zone.EXILED, TargetController.YOU, Duration.EndOfTurn, true, false).setTargetPointer(new FixedTarget(card, game)), source);
    return true;
}
Also used : FixedTarget(mage.target.targetpointer.FixedTarget) Player(mage.players.Player) PlayFromNotOwnHandZoneTargetEffect(mage.abilities.effects.common.asthought.PlayFromNotOwnHandZoneTargetEffect) TargetCardInExile(mage.target.common.TargetCardInExile) FilterCard(mage.filter.FilterCard) 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