Search in sources :

Example 1 with ApprovingObject

use of mage.ApprovingObject in project mage by magefree.

the class ChaosWandEffect 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) {
        return false;
    }
    Cards cardsToShuffle = new CardsImpl();
    while (opponent.canRespond() && opponent.getLibrary().hasCards()) {
        Card card = opponent.getLibrary().getFromTop(game);
        if (card == null) {
            break;
        }
        opponent.moveCards(card, Zone.EXILED, source, game);
        controller.revealCards(source, new CardsImpl(card), game);
        if (card.isInstantOrSorcery(game)) {
            boolean cardWasCast = false;
            if (controller.chooseUse(Outcome.PlayForFree, "Cast " + card.getName() + " without paying its mana cost?", source, game)) {
                game.getState().setValue("PlayFromNotOwnHandZone" + card.getId(), Boolean.TRUE);
                cardWasCast = controller.cast(controller.chooseAbilityForCast(card, game, true), game, true, new ApprovingObject(source, game));
                game.getState().setValue("PlayFromNotOwnHandZone" + card.getId(), null);
            }
            if (!cardWasCast) {
                cardsToShuffle.add(card);
            }
            break;
        } else {
            cardsToShuffle.add(card);
        }
    }
    return opponent.putCardsOnBottomOfLibrary(cardsToShuffle, game, source, false);
}
Also used : Player(mage.players.Player) ApprovingObject(mage.ApprovingObject)

Example 2 with ApprovingObject

use of mage.ApprovingObject in project mage by magefree.

the class CounterlashEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    StackObject stackObject = game.getStack().getStackObject(source.getFirstTarget());
    Player controller = game.getPlayer(source.getControllerId());
    if (stackObject != null && controller != null) {
        game.getStack().counter(source.getFirstTarget(), source, game);
        if (controller.chooseUse(Outcome.PlayForFree, "Cast a nonland card in your hand that " + "shares a card type with that spell without paying its mana cost?", source, game)) {
            FilterCard filter = new FilterCard();
            List<Predicate<MageObject>> types = new ArrayList<>();
            for (CardType type : stackObject.getCardType(game)) {
                if (type != CardType.LAND) {
                    types.add(type.getPredicate());
                }
            }
            filter.add(Predicates.or(types));
            TargetCardInHand target = new TargetCardInHand(filter);
            if (controller.choose(Outcome.PutCardInPlay, target, source.getSourceId(), game)) {
                Card card = controller.getHand().get(target.getFirstTarget(), game);
                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);
                }
            }
        }
        return true;
    }
    return false;
}
Also used : FilterCard(mage.filter.FilterCard) Player(mage.players.Player) ApprovingObject(mage.ApprovingObject) TargetCardInHand(mage.target.common.TargetCardInHand) CardType(mage.constants.CardType) StackObject(mage.game.stack.StackObject) ArrayList(java.util.ArrayList) Predicate(mage.filter.predicate.Predicate) FilterCard(mage.filter.FilterCard) Card(mage.cards.Card)

Example 3 with ApprovingObject

use of mage.ApprovingObject in project mage by magefree.

the class DemilichPlayEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    Card card = game.getCard(targetPointer.getFirst(game, source));
    if (controller == null || card == null) {
        return false;
    }
    controller.moveCards(card, Zone.EXILED, source, game);
    if (controller.chooseUse(outcome, "Cast copy of " + card.getName() + '?', source, game)) {
        Card copiedCard = game.copyCard(card, source, controller.getId());
        game.getState().setValue("PlayFromNotOwnHandZone" + copiedCard.getId(), Boolean.TRUE);
        controller.cast(controller.chooseAbilityForCast(copiedCard, game, false), game, false, new ApprovingObject(source, game));
        game.getState().setValue("PlayFromNotOwnHandZone" + copiedCard.getId(), null);
    }
    return true;
}
Also used : Player(mage.players.Player) ApprovingObject(mage.ApprovingObject) Card(mage.cards.Card)

Example 4 with ApprovingObject

use of mage.ApprovingObject in project mage by magefree.

the class DiluvianPrimordialReplacementEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    if (controller != null) {
        for (Target target : source.getTargets()) {
            if (target instanceof TargetCardInOpponentsGraveyard) {
                Card targetCard = game.getCard(target.getFirstTarget());
                if (targetCard != null) {
                    if (controller.chooseUse(Outcome.PlayForFree, "Cast " + targetCard.getLogName() + '?', source, game)) {
                        game.getState().setValue("PlayFromNotOwnHandZone" + targetCard.getId(), Boolean.TRUE);
                        Boolean cardWasCast = controller.cast(controller.chooseAbilityForCast(targetCard, game, true), game, true, new ApprovingObject(source, game));
                        game.getState().setValue("PlayFromNotOwnHandZone" + targetCard.getId(), null);
                        if (cardWasCast) {
                            ContinuousEffect effect = new DiluvianPrimordialReplacementEffect();
                            effect.setTargetPointer(new FixedTarget(targetCard.getId(), game.getState().getZoneChangeCounter(targetCard.getId())));
                            game.addEffect(effect, source);
                        }
                    }
                }
            }
        }
        return true;
    }
    return false;
}
Also used : FixedTarget(mage.target.targetpointer.FixedTarget) Player(mage.players.Player) Target(mage.target.Target) FixedTarget(mage.target.targetpointer.FixedTarget) ApprovingObject(mage.ApprovingObject) TargetCardInOpponentsGraveyard(mage.target.common.TargetCardInOpponentsGraveyard) ContinuousEffect(mage.abilities.effects.ContinuousEffect) FilterCard(mage.filter.FilterCard) Card(mage.cards.Card)

Example 5 with ApprovingObject

use of mage.ApprovingObject in project mage by magefree.

the class ElevenTheMageEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player player = game.getPlayer(source.getControllerId());
    if (player == null) {
        return false;
    }
    player.drawCards(1, source, game);
    player.loseLife(1, game, source, false);
    if (player.getHand().size() < 11) {
        return true;
    }
    // TODO: change this to fit with changes made in https://github.com/magefree/mage/pull/8136 when merged
    Target target = new TargetCardInHand(StaticFilters.FILTER_CARD_INSTANT_OR_SORCERY);
    if (!target.canChoose(source.getSourceId(), player.getId(), game) || !player.chooseUse(Outcome.PlayForFree, "Cast an instant or sorcery spell " + "from your hand without paying its mana cost?", source, game)) {
        return true;
    }
    Card cardToCast = null;
    boolean cancel = false;
    while (player.canRespond() && !cancel) {
        if (player.chooseTarget(Outcome.PlayForFree, target, source, game)) {
            cardToCast = game.getCard(target.getFirstTarget());
            if (cardToCast != null) {
                if (cardToCast.getSpellAbility() == null) {
                    Logger.getLogger(CastWithoutPayingManaCostEffect.class).fatal("Card: " + cardToCast.getName() + " is no land and has no spell ability!");
                    cancel = true;
                }
                if (cardToCast.getSpellAbility().canChooseTarget(game, player.getId())) {
                    cancel = true;
                }
            }
        } else {
            cancel = true;
        }
    }
    if (cardToCast != null) {
        game.getState().setValue("PlayFromNotOwnHandZone" + cardToCast.getId(), Boolean.TRUE);
        player.cast(player.chooseAbilityForCast(cardToCast, game, true), game, true, new ApprovingObject(source, game));
        game.getState().setValue("PlayFromNotOwnHandZone" + cardToCast.getId(), null);
    }
    return true;
}
Also used : Player(mage.players.Player) Target(mage.target.Target) ApprovingObject(mage.ApprovingObject) TargetCardInHand(mage.target.common.TargetCardInHand) CastWithoutPayingManaCostEffect(mage.abilities.effects.common.cost.CastWithoutPayingManaCostEffect) Card(mage.cards.Card)

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