use of mage.filter.common.FilterInstantOrSorceryCard 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;
}
use of mage.filter.common.FilterInstantOrSorceryCard in project mage by magefree.
the class GoblinTutorEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
if (controller != null) {
int amount = controller.rollDice(outcome, source, game, 6);
Effect effect = null;
// 6 - An instant or sorcery card
if (amount == 2) {
effect = new SearchLibraryPutInHandEffect(new TargetCardInLibrary(0, 1, filter), true);
} else if (amount == 3) {
effect = new SearchLibraryPutInHandEffect(new TargetCardInLibrary(0, 1, StaticFilters.FILTER_CARD_ENTCHANTMENT), true);
} else if (amount == 4) {
effect = new SearchLibraryPutInHandEffect(new TargetCardInLibrary(0, 1, StaticFilters.FILTER_CARD_ARTIFACT), true);
} else if (amount == 5) {
effect = new SearchLibraryPutInHandEffect(new TargetCardInLibrary(0, 1, StaticFilters.FILTER_CARD_CREATURE), true);
} else if (amount == 6) {
effect = new SearchLibraryPutInHandEffect(new TargetCardInLibrary(0, 1, new FilterInstantOrSorceryCard()), true);
}
if (effect != null) {
effect.apply(game, source);
return true;
}
}
return false;
}
use of mage.filter.common.FilterInstantOrSorceryCard in project mage by magefree.
the class AugurOfBolasEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
MageObject sourceObject = game.getObject(source.getSourceId());
if (controller != null && sourceObject != null) {
Cards topCards = new CardsImpl();
topCards.addAll(controller.getLibrary().getTopCards(game, 3));
if (!topCards.isEmpty()) {
controller.lookAtCards(sourceObject.getIdName(), topCards, game);
int number = topCards.count(new FilterInstantOrSorceryCard(), source.getSourceId(), source.getControllerId(), game);
if (number > 0) {
if (controller.chooseUse(outcome, "Reveal an instant or sorcery card from the looked at cards and put it into your hand?", source, game)) {
Card card = null;
if (number == 1) {
Set<Card> cards = topCards.getCards(new FilterInstantOrSorceryCard(), source.getSourceId(), source.getControllerId(), game);
if (!cards.isEmpty()) {
card = cards.iterator().next();
}
} else {
TargetCard target = new TargetCard(Zone.LIBRARY, new FilterInstantOrSorceryCard());
controller.chooseTarget(outcome, topCards, target, source, game);
card = topCards.get(target.getFirstTarget(), game);
}
if (card != null) {
controller.moveCards(card, Zone.HAND, source, game);
controller.revealCards(sourceObject.getIdName(), new CardsImpl(card), game);
topCards.remove(card);
}
}
}
controller.putCardsOnBottomOfLibrary(topCards, game, source, true);
}
return true;
}
return false;
}
use of mage.filter.common.FilterInstantOrSorceryCard in project mage by magefree.
the class VelomachusLoreholdEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
Permanent permanent = source.getSourcePermanentOrLKI(game);
if (controller == null || permanent == null) {
return false;
}
Set<Card> cardsSet = controller.getLibrary().getTopCards(game, 7);
Cards cards = new CardsImpl(cardsSet);
FilterCard filter = new FilterInstantOrSorceryCard("instant or sorcery card with mana value " + permanent.getPower().getValue() + " or less");
filter.add(new ManaValuePredicate(ComparisonType.FEWER_THAN, permanent.getPower().getValue() + 1));
TargetCard target = new TargetCardInLibrary(0, 1, filter);
controller.choose(Outcome.PlayForFree, cards, target, game);
Card card = controller.getLibrary().getCard(target.getFirstTarget(), game);
if (card == null) {
controller.putCardsOnBottomOfLibrary(cards, game, source, false);
return true;
}
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) {
cards.remove(card);
}
controller.putCardsOnBottomOfLibrary(cards, game, source, false);
return true;
}
use of mage.filter.common.FilterInstantOrSorceryCard in project mage by magefree.
the class WildfireEternalCastEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
if (controller != null) {
FilterCard filter = new FilterInstantOrSorceryCard();
int cardsToCast = controller.getHand().count(filter, source.getControllerId(), source.getSourceId(), game);
if (cardsToCast > 0 && controller.chooseUse(outcome, "Cast an instant or sorcery card 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