Search in sources :

Example 91 with ApprovingObject

use of mage.ApprovingObject 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 92 with ApprovingObject

use of mage.ApprovingObject in project mage by magefree.

the class KasminaEnigmaSageSearchEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    Permanent permanent = source.getSourcePermanentOrLKI(game);
    if (controller == null || permanent == null) {
        return false;
    }
    FilterCard filter = new FilterInstantOrSorceryCard("an instant, or sorcery card which shares a color with " + permanent.getLogName());
    filter.add(new SharesColorPredicate(permanent.getColor(game)));
    TargetCardInLibrary target = new TargetCardInLibrary(filter);
    controller.searchLibrary(target, source, game);
    Card card = controller.getLibrary().getCard(target.getFirstTarget(), game);
    if (card != null) {
        controller.moveCards(card, Zone.EXILED, source, game);
    }
    controller.shuffleLibrary(source, game);
    if (card == null || !controller.chooseUse(Outcome.PlayForFree, "Cast " + card.getName() + " without paying its mana cost?", source, game)) {
        return true;
    }
    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);
    return true;
}
Also used : FilterCard(mage.filter.FilterCard) Player(mage.players.Player) ApprovingObject(mage.ApprovingObject) Permanent(mage.game.permanent.Permanent) SharesColorPredicate(mage.filter.predicate.mageobject.SharesColorPredicate) FilterInstantOrSorceryCard(mage.filter.common.FilterInstantOrSorceryCard) TargetCardInLibrary(mage.target.common.TargetCardInLibrary) FilterCard(mage.filter.FilterCard) FilterInstantOrSorceryCard(mage.filter.common.FilterInstantOrSorceryCard) Card(mage.cards.Card)

Example 93 with ApprovingObject

use of mage.ApprovingObject 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 94 with ApprovingObject

use of mage.ApprovingObject in project mage by magefree.

the class ReversalOfFortuneEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    Player opponent = game.getPlayer(source.getFirstTarget());
    if (controller != null && opponent != null) {
        // Target opponent reveals their hand
        Cards revealedCards = new CardsImpl();
        revealedCards.addAll(opponent.getHand());
        opponent.revealCards("Reveal", revealedCards, game);
        // You may copy an instant or sorcery card in it
        TargetCard target = new TargetCard(1, Zone.HAND, new FilterInstantOrSorceryCard());
        target.setRequired(false);
        if (controller.choose(Outcome.PlayForFree, revealedCards, target, game)) {
            Card card = revealedCards.get(target.getFirstTarget(), game);
            // If you do, you may cast the copy without paying its mana cost
            if (card != null) {
                Card copiedCard = game.copyCard(card, source, source.getControllerId());
                if (controller.chooseUse(Outcome.PlayForFree, "Cast the copied card without paying mana cost?", source, game)) {
                    game.getState().setValue("PlayFromNotOwnHandZone" + copiedCard.getId(), Boolean.TRUE);
                    controller.cast(controller.chooseAbilityForCast(copiedCard, game, true), game, true, new ApprovingObject(source, game));
                    game.getState().setValue("PlayFromNotOwnHandZone" + copiedCard.getId(), null);
                }
            } else {
                return false;
            }
        }
        return true;
    }
    return false;
}
Also used : Player(mage.players.Player) ApprovingObject(mage.ApprovingObject) FilterInstantOrSorceryCard(mage.filter.common.FilterInstantOrSorceryCard) TargetCard(mage.target.TargetCard) Cards(mage.cards.Cards) CardsImpl(mage.cards.CardsImpl) TargetCard(mage.target.TargetCard) FilterInstantOrSorceryCard(mage.filter.common.FilterInstantOrSorceryCard) Card(mage.cards.Card)

Example 95 with ApprovingObject

use of mage.ApprovingObject in project mage by magefree.

the class SilentBladeOniEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player opponent = game.getPlayer(getTargetPointer().getFirst(game, source));
    Player controller = game.getPlayer(source.getControllerId());
    if (opponent == null || controller == null) {
        return false;
    }
    Cards cardsInHand = new CardsImpl();
    cardsInHand.addAll(opponent.getHand());
    if (cardsInHand.isEmpty()) {
        return true;
    }
    TargetCard target = new TargetCard(0, 1, Zone.HAND, StaticFilters.FILTER_CARD_A_NON_LAND);
    if (!controller.chooseUse(outcome, "Cast a card from " + opponent.getName() + "'s hand?", source, game) || !controller.chooseTarget(outcome, cardsInHand, target, source, game)) {
        return true;
    }
    Card card = game.getCard(target.getFirstTarget());
    if (card == null) {
        return false;
    }
    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);
    return cardWasCast;
}
Also used : Player(mage.players.Player) ApprovingObject(mage.ApprovingObject) TargetCard(mage.target.TargetCard) TargetCard(mage.target.TargetCard)

Aggregations

ApprovingObject (mage.ApprovingObject)111 Player (mage.players.Player)109 Card (mage.cards.Card)77 FilterCard (mage.filter.FilterCard)53 TargetCard (mage.target.TargetCard)30 MageObject (mage.MageObject)20 FilterInstantOrSorceryCard (mage.filter.common.FilterInstantOrSorceryCard)17 CardsImpl (mage.cards.CardsImpl)16 Permanent (mage.game.permanent.Permanent)16 UUID (java.util.UUID)15 TargetCardInHand (mage.target.common.TargetCardInHand)13 ManaValuePredicate (mage.filter.predicate.mageobject.ManaValuePredicate)11 FilterNonlandCard (mage.filter.common.FilterNonlandCard)10 TargetCardInExile (mage.target.common.TargetCardInExile)10 ExileZone (mage.game.ExileZone)9 TargetCardInLibrary (mage.target.common.TargetCardInLibrary)9 Cards (mage.cards.Cards)8 Spell (mage.game.stack.Spell)8 Target (mage.target.Target)7 FixedTarget (mage.target.targetpointer.FixedTarget)7