use of mage.filter.predicate.mageobject.ManaValuePredicate in project mage by magefree.
the class GenesisWaveEffect 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));
if (!cards.isEmpty()) {
controller.revealCards(source, cards, game);
FilterCard filter = new FilterPermanentCard("cards with mana value " + xValue + " or less to put onto the battlefield");
filter.add(new ManaValuePredicate(ComparisonType.FEWER_THAN, xValue + 1));
TargetCard target1 = new TargetCard(0, Integer.MAX_VALUE, Zone.LIBRARY, filter);
target1.setNotTarget(true);
controller.choose(Outcome.PutCardInPlay, cards, target1, game);
Cards toBattlefield = new CardsImpl(target1.getTargets());
cards.removeAll(toBattlefield);
controller.moveCards(toBattlefield.getCards(game), Zone.BATTLEFIELD, source, game, false, false, false, null);
controller.moveCards(cards, Zone.GRAVEYARD, source, game);
}
return true;
}
use of mage.filter.predicate.mageobject.ManaValuePredicate in project mage by magefree.
the class KodamaOfTheEastTreeWatcher method apply.
@Override
public boolean apply(Game game, Ability source) {
Object obj = this.getValue("permanentEnteringBattlefield");
if (!(obj instanceof Permanent)) {
return false;
}
Permanent permanent = (Permanent) obj;
Player player = game.getPlayer(source.getControllerId());
if (player == null) {
return false;
}
FilterCard filter = new FilterPermanentCard("a permanent card with mana value " + permanent.getManaValue() + " or less");
filter.add(new ManaValuePredicate(ComparisonType.FEWER_THAN, permanent.getManaValue() + 1));
TargetCardInHand target = new TargetCardInHand(filter);
if (!target.canChoose(source.getSourceId(), source.getControllerId(), game) || !player.chooseUse(outcome, "Put a permanent card onto the battlefield?", source, game)) {
return false;
}
player.choose(outcome, target, source.getSourceId(), game);
Card card = game.getCard(target.getFirstTarget());
if (card == null) {
return false;
}
player.moveCards(card, Zone.BATTLEFIELD, source, game);
Permanent otherPermanent = game.getPermanent(card.getId());
if (otherPermanent == null) {
return false;
}
KodamaOfTheEastTreeWatcher watcher = game.getState().getWatcher(KodamaOfTheEastTreeWatcher.class);
if (watcher != null) {
watcher.addPermanent(otherPermanent, source, game);
}
return true;
}
use of mage.filter.predicate.mageobject.ManaValuePredicate in project mage by magefree.
the class RelentlessDeadEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
if (controller != null) {
if (controller.chooseUse(Outcome.Benefit, "Do you want to pay {X} to return zombie?", source, game)) {
int payCount = ManaUtil.playerPaysXGenericMana(true, "Relentless Dead", controller, source, game);
// can be 0
FilterCard filter = new FilterCard("Another target Zombie card with mana value {" + payCount + "}");
filter.add(SubType.ZOMBIE.getPredicate());
filter.add(new ManaValuePredicate(ComparisonType.EQUAL_TO, payCount));
filter.add(new AnotherCardPredicate());
TargetCardInYourGraveyard target = new TargetCardInYourGraveyard(filter);
if (controller.chooseTarget(outcome, target, source, game)) {
Card card = game.getCard(target.getFirstTarget());
if (card != null) {
controller.moveCards(card, Zone.BATTLEFIELD, source, game);
}
}
}
return true;
}
return false;
}
use of mage.filter.predicate.mageobject.ManaValuePredicate in project mage by magefree.
the class ScrapTrawlerTriggeredAbility method checkTrigger.
@Override
public boolean checkTrigger(GameEvent event, Game game) {
if (((ZoneChangeEvent) event).getToZone() == Zone.GRAVEYARD && ((ZoneChangeEvent) event).getFromZone() == Zone.BATTLEFIELD) {
Permanent permanent = ((ZoneChangeEvent) event).getTarget();
if (permanent != null && permanent.isControlledBy(this.getControllerId()) && permanent.isArtifact(game)) {
FilterCard filter = new FilterArtifactCard("artifact card in your graveyard with mana value less than " + permanent.getManaCost().manaValue());
filter.add(new ManaValuePredicate(ComparisonType.FEWER_THAN, permanent.getManaCost().manaValue()));
TargetCardInYourGraveyard target = new TargetCardInYourGraveyard(filter);
getTargets().clear();
addTarget(target);
return true;
}
}
return false;
}
use of mage.filter.predicate.mageobject.ManaValuePredicate in project mage by magefree.
the class SunbirdsInvocationEffect 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) {
return false;
}
Spell spell = game.getSpellOrLKIStack(this.getTargetPointer().getFirst(game, source));
if (spell == null) {
return false;
}
int xValue = spell.getManaValue();
Cards cards = new CardsImpl(controller.getLibrary().getTopCards(game, xValue));
if (!cards.isEmpty()) {
controller.revealCards(sourceObject.getIdName(), cards, game);
FilterCard filter = new FilterNonlandCard("card revealed this way with mana value " + xValue + " or less");
filter.add(new ManaValuePredicate(ComparisonType.FEWER_THAN, xValue + 1));
TargetCard target = new TargetCard(1, Zone.LIBRARY, filter);
if (controller.chooseTarget(Outcome.PlayForFree, cards, target, source, game)) {
Card card = cards.get(target.getFirstTarget(), game);
if (card != null) {
if (controller.chooseUse(Outcome.Benefit, "Cast " + card.getLogName() + " without paying its mana cost?", source, game)) {
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;
}
Aggregations