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;
}
Aggregations