Search in sources :

Example 36 with ApprovingObject

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

use of mage.ApprovingObject in project mage by magefree.

the class ChandraAblazeEffect5 method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player player = game.getPlayer(source.getControllerId());
    if (player != null) {
        FilterCard filter = new FilterCard("red instant or sorcery card from your graveyard to play");
        filter.add(new ColorPredicate(ObjectColor.RED));
        filter.add(Predicates.or(CardType.INSTANT.getPredicate(), CardType.SORCERY.getPredicate()));
        String message = "Play red instant or sorcery card from your graveyard without paying its mana cost?";
        Set<Card> cards = player.getGraveyard().getCards(filter, game);
        TargetCardInGraveyard target = new TargetCardInGraveyard(filter);
        while (!cards.isEmpty() && player.chooseUse(outcome, message, source, game)) {
            target.clearChosen();
            if (player.choose(outcome, target, source.getSourceId(), game)) {
                Card card = game.getCard(target.getFirstTarget());
                if (card != null) {
                    game.getState().setValue("PlayFromNotOwnHandZone" + card.getId(), Boolean.TRUE);
                    player.cast(player.chooseAbilityForCast(card, game, true), game, true, new ApprovingObject(source, game));
                    game.getState().setValue("PlayFromNotOwnHandZone" + card.getId(), null);
                    cards.remove(card);
                }
            }
        }
        return true;
    }
    return false;
}
Also used : FilterCard(mage.filter.FilterCard) ColorPredicate(mage.filter.predicate.mageobject.ColorPredicate) Player(mage.players.Player) TargetCardInGraveyard(mage.target.common.TargetCardInGraveyard) ApprovingObject(mage.ApprovingObject) Card(mage.cards.Card) FilterCard(mage.filter.FilterCard)

Example 38 with ApprovingObject

use of mage.ApprovingObject in project mage by magefree.

the class ChandraTorchOfDefianceEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    MageObject sourceObject = source.getSourceObject(game);
    if (controller != null && sourceObject != null && controller.getLibrary().hasCards()) {
        Library library = controller.getLibrary();
        Card card = library.getFromTop(game);
        if (card != null) {
            boolean cardWasCast = false;
            controller.moveCardsToExile(card, source, game, true, source.getSourceId(), sourceObject.getIdName());
            if (!card.getManaCost().isEmpty() || !card.isLand(game)) {
                if (controller.chooseUse(Outcome.Benefit, "Cast " + card.getName() + "? (You still pay the costs)", source, game) && (game.getState().getZone(card.getId()) == Zone.EXILED)) {
                    // card must be in the exile zone
                    // enable the card to be cast from the exile zone
                    game.getState().setValue("PlayFromNotOwnHandZone" + card.getId(), Boolean.TRUE);
                    cardWasCast = controller.cast(controller.chooseAbilityForCast(card, game, false), game, false, new ApprovingObject(source, game));
                    // reset to null
                    game.getState().setValue("PlayFromNotOwnHandZone" + card.getId(), null);
                }
            }
            if (!cardWasCast) {
                new DamagePlayersEffect(Outcome.Damage, StaticValue.get(2), TargetController.OPPONENT).apply(game, source);
            }
        }
        return true;
    }
    return false;
}
Also used : Player(mage.players.Player) ApprovingObject(mage.ApprovingObject) MageObject(mage.MageObject) Library(mage.players.Library) DamagePlayersEffect(mage.abilities.effects.common.DamagePlayersEffect) Card(mage.cards.Card)

Example 39 with ApprovingObject

use of mage.ApprovingObject in project mage by magefree.

the class EtaliPrimalStormEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    MageObject sourceObject = source.getSourceObject(game);
    if (controller != null && sourceObject != null) {
        // move cards from library to exile
        Set<Card> currentExiledCards = new HashSet<>();
        for (UUID playerId : game.getState().getPlayersInRange(controller.getId(), game)) {
            Player player = game.getPlayer(playerId);
            if (player != null) {
                if (!player.getLibrary().getTopCards(game, 1).isEmpty()) {
                    Card topCard = player.getLibrary().getFromTop(game);
                    if (topCard != null) {
                        if (filter.match(topCard, source.getSourceId(), source.getControllerId(), game)) {
                            currentExiledCards.add(topCard);
                        }
                        controller.moveCardsToExile(topCard, source, game, true, source.getSourceId(), sourceObject.getIdName());
                    }
                }
            }
        }
        // cast the possible cards without paying the mana
        Cards cardsToCast = new CardsImpl();
        cardsToCast.addAll(currentExiledCards);
        boolean alreadyCast = false;
        while (controller.canRespond() && !cardsToCast.isEmpty()) {
            if (!controller.chooseUse(Outcome.PlayForFree, "Cast a" + (alreadyCast ? "nother" : "") + " card exiled with " + sourceObject.getLogName() + " without paying its mana cost?", source, game)) {
                break;
            }
            TargetCard targetCard = new TargetCard(1, Zone.EXILED, new FilterCard("nonland card to cast for free"));
            if (!controller.choose(Outcome.PlayForFree, cardsToCast, targetCard, game)) {
                break;
            }
            alreadyCast = true;
            Card card = game.getCard(targetCard.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) {
                    game.informPlayer(controller, "You're not able to cast " + card.getIdName() + " or you canceled the casting.");
                }
                cardsToCast.remove(card);
            }
        }
        return true;
    }
    return false;
}
Also used : Player(mage.players.Player) ApprovingObject(mage.ApprovingObject) MageObject(mage.MageObject) TargetCard(mage.target.TargetCard) FilterCard(mage.filter.FilterCard) FilterNonlandCard(mage.filter.common.FilterNonlandCard) TargetCard(mage.target.TargetCard) FilterCard(mage.filter.FilterCard) UUID(java.util.UUID) HashSet(java.util.HashSet)

Example 40 with ApprovingObject

use of mage.ApprovingObject in project mage by magefree.

the class GeodeGolemEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    if (controller != null) {
        Card selectedCommander = null;
        Set<Card> commandersInCommandZone = game.getCommanderCardsFromCommandZone(controller, CommanderCardType.COMMANDER_OR_OATHBREAKER);
        if (commandersInCommandZone.isEmpty()) {
            return false;
        }
        // select from commanders
        if (commandersInCommandZone.size() == 1) {
            selectedCommander = commandersInCommandZone.stream().findFirst().get();
        } else {
            TargetCard target = new TargetCard(Zone.COMMAND, new FilterCard("commander to cast without mana cost"));
            target.setNotTarget(true);
            if (controller.canRespond() && controller.choose(Outcome.PlayForFree, new CardsImpl(commandersInCommandZone), target, game)) {
                selectedCommander = commandersInCommandZone.stream().filter(c -> c.getId().equals(target.getFirstTarget())).findFirst().orElse(null);
            }
        }
        if (selectedCommander == null) {
            return false;
        }
        // commander tax applies as additional cost
        if (selectedCommander.getSpellAbility() != null) {
            game.getState().setValue("PlayFromNotOwnHandZone" + selectedCommander.getId(), Boolean.TRUE);
            Boolean commanderWasCast = controller.cast(controller.chooseAbilityForCast(selectedCommander, game, true), game, true, new ApprovingObject(source, game));
            game.getState().setValue("PlayFromNotOwnHandZone" + selectedCommander.getId(), null);
            return commanderWasCast;
        } else {
            // TODO: improve lands support for "cast your commander" (allow land play from mdf cards)?
            return controller.playLand(selectedCommander, game, true);
        }
    }
    return false;
}
Also used : FilterCard(mage.filter.FilterCard) FilterCard(mage.filter.FilterCard) ApprovingObject(mage.ApprovingObject) DealsCombatDamageToAPlayerTriggeredAbility(mage.abilities.common.DealsCombatDamageToAPlayerTriggeredAbility) Set(java.util.Set) OneShotEffect(mage.abilities.effects.OneShotEffect) UUID(java.util.UUID) MageInt(mage.MageInt) CardsImpl(mage.cards.CardsImpl) Player(mage.players.Player) CardSetInfo(mage.cards.CardSetInfo) Game(mage.game.Game) CardImpl(mage.cards.CardImpl) TargetCard(mage.target.TargetCard) TrampleAbility(mage.abilities.keyword.TrampleAbility) Card(mage.cards.Card) mage.constants(mage.constants) Ability(mage.abilities.Ability) Player(mage.players.Player) ApprovingObject(mage.ApprovingObject) TargetCard(mage.target.TargetCard) CardsImpl(mage.cards.CardsImpl) FilterCard(mage.filter.FilterCard) TargetCard(mage.target.TargetCard) 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