Search in sources :

Example 11 with FilterInstantOrSorceryCard

use of mage.filter.common.FilterInstantOrSorceryCard in project mage by magefree.

the class BrainInAJarScryEffect 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) {
        int counters = sourceObject.getCounters(game).getCount(CounterType.CHARGE);
        FilterCard filter = new FilterInstantOrSorceryCard();
        filter.add(new ManaValuePredicate(ComparisonType.EQUAL_TO, counters));
        int cardsToCast = controller.getHand().count(filter, source.getControllerId(), source.getSourceId(), game);
        if (cardsToCast > 0 && controller.chooseUse(Outcome.PlayForFree, "Cast an instant or sorcery card with mana values of " + counters + " from your hand without paying its mana cost?", source, game)) {
            TargetCardInHand target = new TargetCardInHand(filter);
            controller.chooseTarget(outcome, target, source, 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) Permanent(mage.game.permanent.Permanent) TargetCardInHand(mage.target.common.TargetCardInHand) FilterInstantOrSorceryCard(mage.filter.common.FilterInstantOrSorceryCard) FilterInstantOrSorceryCard(mage.filter.common.FilterInstantOrSorceryCard) Card(mage.cards.Card) FilterCard(mage.filter.FilterCard)

Aggregations

FilterInstantOrSorceryCard (mage.filter.common.FilterInstantOrSorceryCard)11 Player (mage.players.Player)11 ApprovingObject (mage.ApprovingObject)8 FilterCard (mage.filter.FilterCard)7 Card (mage.cards.Card)6 ManaValuePredicate (mage.filter.predicate.mageobject.ManaValuePredicate)4 TargetCard (mage.target.TargetCard)4 Permanent (mage.game.permanent.Permanent)3 TargetCardInLibrary (mage.target.common.TargetCardInLibrary)3 MageObject (mage.MageObject)2 ExileZone (mage.game.ExileZone)2 TargetCardInExile (mage.target.common.TargetCardInExile)2 TargetCardInHand (mage.target.common.TargetCardInHand)2 ContinuousEffect (mage.abilities.effects.ContinuousEffect)1 Effect (mage.abilities.effects.Effect)1 OneShotEffect (mage.abilities.effects.OneShotEffect)1 PlayFromNotOwnHandZoneTargetEffect (mage.abilities.effects.common.asthought.PlayFromNotOwnHandZoneTargetEffect)1 SearchLibraryPutInHandEffect (mage.abilities.effects.common.search.SearchLibraryPutInHandEffect)1 Cards (mage.cards.Cards)1 CardsImpl (mage.cards.CardsImpl)1