Search in sources :

Example 61 with ApprovingObject

use of mage.ApprovingObject in project mage by magefree.

the class EpicExperimentEffect 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
        controller.moveCardsToExile(controller.getLibrary().getTopCards(game, source.getManaCostsToPay().getX()), source, game, true, source.getSourceId(), sourceObject.getIdName());
        // cast the possible cards without paying the mana
        ExileZone epicExperimentExileZone = game.getExile().getExileZone(source.getSourceId());
        FilterCard filter = new FilterInstantOrSorceryCard();
        filter.add(new ManaValuePredicate(ComparisonType.FEWER_THAN, source.getManaCostsToPay().getX() + 1));
        filter.setMessage("instant and sorcery cards with mana value " + source.getManaCostsToPay().getX() + " or less");
        Cards cardsToCast = new CardsImpl();
        if (epicExperimentExileZone == null) {
            return true;
        }
        cardsToCast.addAll(epicExperimentExileZone.getCards(filter, source.getSourceId(), source.getControllerId(), game));
        while (controller.canRespond() && !cardsToCast.isEmpty()) {
            if (!controller.chooseUse(Outcome.PlayForFree, "Cast (another) a card exiled with " + sourceObject.getLogName() + " without paying its mana cost?", source, game)) {
                break;
            }
            TargetCard targetCard = new TargetCard(1, Zone.EXILED, new FilterCard("instant or sorcery card to cast for free"));
            if (controller.choose(Outcome.PlayForFree, cardsToCast, targetCard, game)) {
                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);
                } else {
                    break;
                }
            } else {
                break;
            }
        }
        // move cards not cast to graveyard
        ExileZone exileZone = game.getExile().getExileZone(source.getSourceId());
        if (exileZone != null) {
            controller.moveCards(exileZone.getCards(game), Zone.GRAVEYARD, source, game);
        }
        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) MageObject(mage.MageObject) ExileZone(mage.game.ExileZone) TargetCard(mage.target.TargetCard) FilterCard(mage.filter.FilterCard) TargetCard(mage.target.TargetCard) FilterInstantOrSorceryCard(mage.filter.common.FilterInstantOrSorceryCard)

Example 62 with ApprovingObject

use of mage.ApprovingObject in project mage by magefree.

the class GalvanothEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    if (controller != null) {
        Card card = controller.getLibrary().getFromTop(game);
        if (card != null) {
            controller.lookAtCards(source, null, new CardsImpl(card), game);
            if (card.isInstantOrSorcery(game)) {
                if (controller.chooseUse(Outcome.PlayForFree, "Cast " + card.getName() + " without paying its mana cost?", 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);
                }
            }
        }
        return true;
    }
    return false;
}
Also used : Player(mage.players.Player) ApprovingObject(mage.ApprovingObject)

Example 63 with ApprovingObject

use of mage.ApprovingObject in project mage by magefree.

the class GuileReplacementEffect method replaceEvent.

@Override
public boolean replaceEvent(GameEvent event, Ability source, Game game) {
    Spell spell = game.getStack().getSpell(event.getTargetId());
    Player controller = game.getPlayer(source.getControllerId());
    if (spell != null && controller != null) {
        controller.moveCards(spell, Zone.EXILED, source, game);
        if (!spell.isCopy()) {
            // copies doesn't exists in exile zone
            Card spellCard = spell.getCard();
            if (spellCard != null && controller.chooseUse(Outcome.PlayForFree, "Play " + spellCard.getIdName() + " for free?", source, game)) {
                controller.playCard(spellCard, game, true, new ApprovingObject(source, game));
            }
            return true;
        }
    }
    return false;
}
Also used : Player(mage.players.Player) ApprovingObject(mage.ApprovingObject) Spell(mage.game.stack.Spell) Card(mage.cards.Card)

Example 64 with ApprovingObject

use of mage.ApprovingObject in project mage by magefree.

the class KahoMinamoHistorianCastEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    if (controller != null) {
        FilterCard filter = new FilterCard();
        filter.add(new ManaValuePredicate(ComparisonType.EQUAL_TO, source.getManaCostsToPay().getX()));
        TargetCardInExile target = new TargetCardInExile(filter, CardUtil.getCardExileZoneId(game, source));
        Cards cards = game.getExile().getExileZone(CardUtil.getCardExileZoneId(game, source));
        if (cards != null && !cards.isEmpty() && controller.choose(Outcome.PlayForFree, cards, 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);
            }
        }
        return true;
    }
    return false;
}
Also used : FilterCard(mage.filter.FilterCard) Player(mage.players.Player) ManaValuePredicate(mage.filter.predicate.mageobject.ManaValuePredicate) ApprovingObject(mage.ApprovingObject) TargetCardInExile(mage.target.common.TargetCardInExile) FilterCard(mage.filter.FilterCard)

Example 65 with ApprovingObject

use of mage.ApprovingObject in project mage by magefree.

the class MindsDilationEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    MageObject sourceObject = source.getSourceObject(game);
    Player opponent = game.getPlayer(getTargetPointer().getFirst(game, source));
    if (controller != null && sourceObject != null && opponent != null) {
        if (opponent.getLibrary().hasCards()) {
            Card card = opponent.getLibrary().getFromTop(game);
            if (card != null && opponent.moveCards(card, Zone.EXILED, source, game)) {
                if (!card.isLand(game)) {
                    if (controller.chooseUse(outcome, "Cast " + card.getLogName() + " without paying its mana cost from exile?", 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);
                    }
                }
            }
        }
        return true;
    }
    return false;
}
Also used : Player(mage.players.Player) ApprovingObject(mage.ApprovingObject) MageObject(mage.MageObject) 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