Search in sources :

Example 31 with ApprovingObject

use of mage.ApprovingObject in project mage by magefree.

the class EmergentUltimatumTarget method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player player = game.getPlayer(source.getControllerId());
    if (player == null) {
        return false;
    }
    TargetCardInLibrary targetCardInLibrary = new EmergentUltimatumTarget();
    targetCardInLibrary.setNotTarget(true);
    boolean searched = player.searchLibrary(targetCardInLibrary, source, game);
    Cards cards = new CardsImpl(targetCardInLibrary.getTargets());
    player.moveCards(cards, Zone.EXILED, source, game);
    if (cards.isEmpty()) {
        if (searched) {
            player.shuffleLibrary(source, game);
        }
        return false;
    }
    TargetOpponent targetOpponent = new TargetOpponent();
    targetOpponent.setNotTarget(true);
    player.choose(outcome, targetOpponent, source.getSourceId(), game);
    Player opponent = game.getPlayer(targetOpponent.getFirstTarget());
    if (opponent == null) {
        if (searched) {
            player.shuffleLibrary(source, game);
        }
        return false;
    }
    TargetCardInExile targetCardInExile = new TargetCardInExile(StaticFilters.FILTER_CARD);
    targetCardInExile.setNotTarget(true);
    opponent.choose(outcome, cards, targetCardInExile, game);
    Card toShuffle = game.getCard(targetCardInExile.getFirstTarget());
    if (toShuffle != null) {
        player.putCardsOnBottomOfLibrary(toShuffle, game, source, false);
        player.shuffleLibrary(source, game);
        cards.remove(toShuffle);
    }
    while (!cards.isEmpty()) {
        if (!player.chooseUse(Outcome.PlayForFree, "Cast an exiled card without paying its mana cost?", source, game)) {
            break;
        }
        targetCardInExile.clearChosen();
        if (!player.choose(Outcome.PlayForFree, cards, targetCardInExile, game)) {
            continue;
        }
        Card card = game.getCard(targetCardInExile.getFirstTarget());
        if (card == null) {
            continue;
        }
        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);
        // remove on non cast too (infinite freeze fix)
        cards.remove(card);
        if (cardWasCast) {
            cards.remove(card);
        } else {
            game.informPlayer(player, "You're not able to cast " + card.getIdName() + " or you canceled the casting.");
        }
    }
    return true;
}
Also used : Player(mage.players.Player) TargetOpponent(mage.target.common.TargetOpponent) ApprovingObject(mage.ApprovingObject) TargetCardInExile(mage.target.common.TargetCardInExile) TargetCardInLibrary(mage.target.common.TargetCardInLibrary) FilterCard(mage.filter.FilterCard)

Example 32 with ApprovingObject

use of mage.ApprovingObject in project mage by magefree.

the class MaelstromArchangelCastEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    if (controller != null) {
        Target target = new TargetCardInHand(filter);
        if (target.canChoose(source.getSourceId(), controller.getId(), game) && controller.chooseUse(outcome, "Cast a spell from your hand without paying its mana cost?", source, game)) {
            Card cardToCast = null;
            boolean cancel = false;
            while (controller.canRespond() && !cancel) {
                if (controller.chooseTarget(outcome, target, source, game)) {
                    cardToCast = game.getCard(target.getFirstTarget());
                    if (cardToCast != null && cardToCast.getSpellAbility().canChooseTarget(game, controller.getId())) {
                        cancel = true;
                    }
                } else {
                    cancel = true;
                }
            }
            if (cardToCast != null) {
                game.getState().setValue("PlayFromNotOwnHandZone" + cardToCast.getId(), Boolean.TRUE);
                controller.cast(controller.chooseAbilityForCast(cardToCast, game, true), game, true, new ApprovingObject(source, game));
                game.getState().setValue("PlayFromNotOwnHandZone" + cardToCast.getId(), null);
            }
        }
        return true;
    }
    return false;
}
Also used : Player(mage.players.Player) Target(mage.target.Target) ApprovingObject(mage.ApprovingObject) TargetCardInHand(mage.target.common.TargetCardInHand) FilterCard(mage.filter.FilterCard) FilterNonlandCard(mage.filter.common.FilterNonlandCard) Card(mage.cards.Card)

Example 33 with ApprovingObject

use of mage.ApprovingObject in project mage by magefree.

the class MizzixsMasteryOverloadEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    if (controller != null) {
        Card card = game.getCard(getTargetPointer().getFirst(game, source));
        if (card != null) {
            if (controller.moveCards(card, Zone.EXILED, source, game)) {
                Card cardCopy = game.copyCard(card, source, source.getControllerId());
                if (cardCopy.getSpellAbility().canChooseTarget(game, controller.getId()) && controller.chooseUse(outcome, "Cast copy of " + card.getName() + " without paying its mana cost?", source, game)) {
                    game.getState().setValue("PlayFromNotOwnHandZone" + cardCopy.getId(), Boolean.TRUE);
                    controller.cast(controller.chooseAbilityForCast(cardCopy, game, true), game, true, new ApprovingObject(source, game));
                    game.getState().setValue("PlayFromNotOwnHandZone" + cardCopy.getId(), null);
                }
            }
        }
        return true;
    }
    return false;
}
Also used : Player(mage.players.Player) ApprovingObject(mage.ApprovingObject) FilterCard(mage.filter.FilterCard) TargetCard(mage.target.TargetCard) FilterInstantOrSorceryCard(mage.filter.common.FilterInstantOrSorceryCard)

Example 34 with ApprovingObject

use of mage.ApprovingObject in project mage by magefree.

the class SurtlandElementalistEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player player = game.getPlayer(source.getControllerId());
    if (player != null) {
        TargetCardInHand target = new TargetCardInHand(0, 1, StaticFilters.FILTER_CARD_INSTANT_OR_SORCERY);
        if (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) ApprovingObject(mage.ApprovingObject) TargetCardInHand(mage.target.common.TargetCardInHand) FilterCard(mage.filter.FilterCard) Card(mage.cards.Card)

Example 35 with ApprovingObject

use of mage.ApprovingObject in project mage by magefree.

the class SvellaIceShaperEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    if (controller == null) {
        return false;
    }
    Set<Card> cardsSet = controller.getLibrary().getTopCards(game, 4);
    Cards cards = new CardsImpl(cardsSet);
    TargetCard target = new TargetCardInLibrary(0, 1, new FilterNonlandCard("card to cast without paying its mana cost"));
    controller.choose(Outcome.PlayForFree, cards, target, game);
    Card card = controller.getLibrary().getCard(target.getFirstTarget(), game);
    if (card == null) {
        controller.putCardsOnBottomOfLibrary(cards, game, source, false);
        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);
    if (cardWasCast) {
        cards.remove(card);
    }
    controller.putCardsOnBottomOfLibrary(cards, game, source, false);
    return true;
}
Also used : Player(mage.players.Player) FilterNonlandCard(mage.filter.common.FilterNonlandCard) ApprovingObject(mage.ApprovingObject) TargetCard(mage.target.TargetCard) TargetCardInLibrary(mage.target.common.TargetCardInLibrary) FilterNonlandCard(mage.filter.common.FilterNonlandCard) 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