use of mage.filter.predicate.mageobject.ManaValuePredicate in project mage by magefree.
the class VivienMonstersAdvocateTriggeredAbility method checkTrigger.
@Override
public boolean checkTrigger(GameEvent event, Game game) {
Spell spell = game.getSpell(event.getTargetId());
if (spell != null && spell.isCreature(game)) {
int cmc = spell.getManaValue();
FilterCard filter = new FilterCreatureCard("creature card with mana value less than " + cmc);
filter.add(new ManaValuePredicate(ComparisonType.FEWER_THAN, cmc));
this.getEffects().clear();
this.getEffects().add(new SearchLibraryPutInPlayEffect(new TargetCardInLibrary(filter)));
return true;
}
return false;
}
use of mage.filter.predicate.mageobject.ManaValuePredicate in project mage by magefree.
the class ViviensArkbowEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player player = game.getPlayer(source.getControllerId());
if (player == null) {
return false;
}
int xValue = source.getManaCostsToPay().getX();
Cards cards = new CardsImpl(player.getLibrary().getTopCards(game, xValue));
player.lookAtCards(source, null, cards, game);
FilterCard filter = new FilterCreatureCard("creature card with mana value " + xValue + " or less");
filter.add(new ManaValuePredicate(ComparisonType.FEWER_THAN, xValue + 1));
TargetCard target = new TargetCardInLibrary(0, 1, filter);
if (player.choose(outcome, cards, target, game)) {
Card card = game.getCard(target.getFirstTarget());
if (player.moveCards(card, Zone.BATTLEFIELD, source, game)) {
cards.remove(card);
}
}
return player.putCardsOnBottomOfLibrary(cards, game, source, false);
}
use of mage.filter.predicate.mageobject.ManaValuePredicate in project mage by magefree.
the class SearchLibraryGraveyardWithLessMVPutIntoPlay method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
MageObject sourceObject = source.getSourceObject(game);
Card cardFound = null;
if (controller != null && sourceObject != null) {
// create x cost filter
// never change static objects so copy the object here before
FilterCard advancedFilter = filter.copy();
advancedFilter.add(new ManaValuePredicate(ComparisonType.FEWER_THAN, source.getManaCostsToPay().getX() + 1));
if (controller.chooseUse(outcome, "Search your library for a " + filter.getMessage() + " with mana value X or less" + '?', source, game)) {
TargetCardInLibrary target = new TargetCardInLibrary(advancedFilter);
target.clearChosen();
if (controller.searchLibrary(target, source, game)) {
if (!target.getTargets().isEmpty()) {
cardFound = game.getCard(target.getFirstTarget());
}
}
controller.shuffleLibrary(source, game);
}
if (cardFound == null && controller.chooseUse(outcome, "Search your graveyard for a " + filter.getMessage() + " with mana value X or less" + '?', source, game)) {
TargetCard target = new TargetCard(0, 1, Zone.GRAVEYARD, advancedFilter);
target.clearChosen();
if (controller.choose(outcome, controller.getGraveyard(), target, game)) {
if (!target.getTargets().isEmpty()) {
cardFound = game.getCard(target.getFirstTarget());
}
}
}
if (cardFound != null) {
controller.revealCards(sourceObject.getIdName(), new CardsImpl(cardFound), game);
controller.moveCards(cardFound, Zone.BATTLEFIELD, source, game);
}
return true;
}
return false;
}
use of mage.filter.predicate.mageobject.ManaValuePredicate in project mage by magefree.
the class LinSivviDefiantHeroEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
if (controller == null) {
return false;
}
int xCost = source.getManaCostsToPay().getX();
FilterPermanentCard filter = new FilterPermanentCard("Rebel permanent card with mana value " + xCost + " or less");
filter.add(new ManaValuePredicate(ComparisonType.FEWER_THAN, xCost + 1));
filter.add(SubType.REBEL.getPredicate());
TargetCardInLibrary target = new TargetCardInLibrary(filter);
if (controller.searchLibrary(target, source, game)) {
Card card = controller.getLibrary().getCard(target.getFirstTarget(), game);
if (card != null) {
controller.moveCards(card, Zone.BATTLEFIELD, source, game);
}
controller.shuffleLibrary(source, game);
return true;
}
controller.shuffleLibrary(source, game);
return false;
}
use of mage.filter.predicate.mageobject.ManaValuePredicate in project mage by magefree.
the class MuseVortexEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
if (controller == null) {
return false;
}
int xValue = source.getManaCostsToPay().getX();
Cards cards = new CardsImpl(controller.getLibrary().getTopCards(game, xValue));
controller.moveCards(cards, Zone.EXILED, source, game);
cards.retainZone(Zone.EXILED, game);
FilterCard filter = new FilterInstantOrSorceryCard("an instant or sorcery card with mana value " + xValue + " or less");
filter.add(new ManaValuePredicate(ComparisonType.FEWER_THAN, xValue + 1));
TargetCardInExile target = new TargetCardInExile(filter);
target.setNotTarget(true);
if (controller.choose(Outcome.Benefit, cards, target, game)) {
Card card = cards.get(target.getFirstTarget(), game);
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);
cards.remove(card);
if (cardWasCast) {
cards.remove(card);
} else {
game.informPlayer(controller, "You're not able to cast " + card.getIdName() + " or you canceled the casting.");
}
controller.putCardsOnTopOfLibrary(cards, game, source, true);
return true;
}
}
return false;
}
Aggregations