Search in sources :

Example 11 with ApprovingObject

use of mage.ApprovingObject in project mage by magefree.

the class HellcarverDemonEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    Permanent sourceObject = game.getPermanentOrLKIBattlefield(source.getSourceId());
    if (controller != null && sourceObject != null) {
        for (Permanent permanent : game.getBattlefield().getAllActivePermanents(source.getControllerId())) {
            if (!Objects.equals(permanent, sourceObject)) {
                permanent.sacrifice(source, game);
            }
        }
        if (!controller.getHand().isEmpty()) {
            int cardsInHand = controller.getHand().size();
            controller.discard(cardsInHand, false, false, source, game);
        }
        // move cards from library to exile
        Set<Card> currentExiledCards = new HashSet<>();
        currentExiledCards.addAll(controller.getLibrary().getTopCards(game, 6));
        controller.moveCardsToExile(currentExiledCards, 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, "Cast a" + (alreadyCast ? "another" : "") + " card exiled with " + sourceObject.getLogName() + " without paying its mana cost?", source, game)) {
                break;
            }
            TargetCard targetCard = new TargetCard(1, Zone.EXILED, new FilterNonlandCard("nonland card to cast for free"));
            if (controller.choose(Outcome.PlayForFree, cardsToCast, targetCard, game)) {
                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);
                    cardsToCast.remove(card);
                    if (!cardWasCast) {
                        game.informPlayer(controller, "You're not able to cast " + card.getIdName() + " or you canceled the casting.");
                    }
                }
            }
        }
        return true;
    }
    return false;
}
Also used : Player(mage.players.Player) ApprovingObject(mage.ApprovingObject) Permanent(mage.game.permanent.Permanent) TargetCard(mage.target.TargetCard) FilterNonlandCard(mage.filter.common.FilterNonlandCard) TargetCard(mage.target.TargetCard) FilterNonlandCard(mage.filter.common.FilterNonlandCard) HashSet(java.util.HashSet)

Example 12 with ApprovingObject

use of mage.ApprovingObject in project mage by magefree.

the class JelevaNephaliasWatcher method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    if (controller != null) {
        ExileZone exileZone = game.getExile().getExileZone(CardUtil.getCardExileZoneId(game, source));
        if (exileZone != null && exileZone.count(new FilterInstantOrSorceryCard(), game) > 0) {
            if (controller.chooseUse(outcome, "Cast an instant or sorcery card from " + "exile without paying its mana cost?", source, game)) {
                TargetCardInExile target = new TargetCardInExile(new FilterInstantOrSorceryCard(), CardUtil.getCardExileZoneId(game, source));
                if (controller.choose(Outcome.PlayForFree, exileZone, 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);
                        return cardWasCast;
                    }
                }
            }
        }
        return true;
    }
    return false;
}
Also used : Player(mage.players.Player) ApprovingObject(mage.ApprovingObject) FilterInstantOrSorceryCard(mage.filter.common.FilterInstantOrSorceryCard) TargetCardInExile(mage.target.common.TargetCardInExile) ExileZone(mage.game.ExileZone) FilterInstantOrSorceryCard(mage.filter.common.FilterInstantOrSorceryCard) Card(mage.cards.Card)

Example 13 with ApprovingObject

use of mage.ApprovingObject in project mage by magefree.

the class CipherStoreEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    Card cipherCard = game.getCard(cipherCardId);
    if (cipherCard != null && controller != null) {
        Card copyCard = game.copyCard(cipherCard, source, controller.getId());
        SpellAbility ability = copyCard.getSpellAbility();
        // remove the cipher effect from the copy
        ability.getEffects().removeIf(effect -> effect instanceof CipherEffect);
        controller.cast(ability, game, true, new ApprovingObject(source, game));
    }
    return false;
}
Also used : Player(mage.players.Player) ApprovingObject(mage.ApprovingObject) SpellAbility(mage.abilities.SpellAbility) Card(mage.cards.Card)

Example 14 with ApprovingObject

use of mage.ApprovingObject in project mage by magefree.

the class CastWithoutPayingManaCostEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    if (controller == null) {
        return false;
    }
    int cmc = manaCost.calculate(game, source, this);
    FilterCard filter = this.filter.copy();
    filter.setMessage(filter.getMessage().replace("%mv", "" + cmc));
    filter.add(new ManaValuePredicate(ComparisonType.FEWER_THAN, cmc + 1));
    Target target = new TargetCardInHand(filter);
    if (!target.canChoose(source.getSourceId(), controller.getId(), game) || !controller.chooseUse(Outcome.PlayForFree, "Cast " + CardUtil.addArticle(filter.getMessage()) + " without paying its mana cost?", source, game)) {
        return true;
    }
    Card cardToCast = null;
    boolean cancel = false;
    while (controller.canRespond() && !cancel) {
        if (controller.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, 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;
}
Also used : FilterCard(mage.filter.FilterCard) Player(mage.players.Player) ManaValuePredicate(mage.filter.predicate.mageobject.ManaValuePredicate) 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 15 with ApprovingObject

use of mage.ApprovingObject in project mage by magefree.

the class DescendantsPathEffect 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) {
        if (controller.getLibrary().hasCards()) {
            Card card = controller.getLibrary().getFromTop(game);
            if (card == null) {
                return false;
            }
            controller.revealCards(sourceObject.getIdName(), new CardsImpl(card), game);
            if (card.isCreature(game)) {
                FilterControlledCreaturePermanent filter = new FilterControlledCreaturePermanent();
                boolean found = false;
                for (Permanent permanent : game.getBattlefield().getAllActivePermanents(filter, controller.getId(), game)) {
                    if (card.shareCreatureTypes(game, permanent)) {
                        found = true;
                        break;
                    }
                }
                if (found) {
                    game.informPlayers(sourceObject.getLogName() + ": Found a creature that shares a creature type with the revealed card.");
                    if (controller.chooseUse(Outcome.Benefit, "Cast the card?", source, game)) {
                        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);
                    } else {
                        game.informPlayers(sourceObject.getLogName() + ": " + controller.getLogName() + " canceled casting the card.");
                        controller.getLibrary().putOnBottom(card, game);
                    }
                } else {
                    game.informPlayers(sourceObject.getLogName() + ": No creature that shares a creature type with the revealed card.");
                    controller.getLibrary().putOnBottom(card, game);
                }
            } else {
                game.informPlayers(sourceObject.getLogName() + ": Put " + card.getLogName() + " on the bottom.");
                controller.getLibrary().putOnBottom(card, game);
            }
            return true;
        }
    }
    return false;
}
Also used : Player(mage.players.Player) ApprovingObject(mage.ApprovingObject) Permanent(mage.game.permanent.Permanent) FilterControlledCreaturePermanent(mage.filter.common.FilterControlledCreaturePermanent) MageObject(mage.MageObject) FilterControlledCreaturePermanent(mage.filter.common.FilterControlledCreaturePermanent) CardsImpl(mage.cards.CardsImpl) 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