use of mage.filter.predicate.mageobject.ManaValuePredicate in project mage by magefree.
the class KahoMinamoHistorianCastEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
if (controller != null) {
FilterCard filter = new FilterCard();
filter.add(new ManaValuePredicate(ComparisonType.EQUAL_TO, source.getManaCostsToPay().getX()));
TargetCardInExile target = new TargetCardInExile(filter, CardUtil.getCardExileZoneId(game, source));
Cards cards = game.getExile().getExileZone(CardUtil.getCardExileZoneId(game, source));
if (cards != null && !cards.isEmpty() && controller.choose(Outcome.PlayForFree, cards, target, 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;
}
use of mage.filter.predicate.mageobject.ManaValuePredicate in project mage by magefree.
the class TajNarSwordsmithEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player player = game.getPlayer(source.getControllerId());
if (player != null && player.chooseUse(Outcome.Benefit, "Do you want to pay {X} to search and put Equipment?", source, game)) {
// can be zero
int payCount = ManaUtil.playerPaysXGenericMana(true, "Taj-Nar Swordsmith", player, source, game);
FilterCard filter = new FilterCard("Equipment card with mana value {" + payCount + "} or less");
filter.add(SubType.EQUIPMENT.getPredicate());
filter.add(new ManaValuePredicate(ComparisonType.FEWER_THAN, payCount + 1));
new SearchLibraryPutInPlayEffect(new TargetCardInLibrary(0, 1, filter), false, true).apply(game, source);
return true;
}
return false;
}
use of mage.filter.predicate.mageobject.ManaValuePredicate in project mage by magefree.
the class UginTheSpiritDragonEffect3 method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
if (controller == null) {
return false;
}
int cmc = 0;
for (Cost cost : source.getCosts()) {
if (cost instanceof PayVariableLoyaltyCost) {
cmc = ((PayVariableLoyaltyCost) cost).getAmount();
}
}
FilterPermanent filter = new FilterPermanent("permanent with mana value X or less that's one or more colors");
filter.add(new ManaValuePredicate(ComparisonType.FEWER_THAN, cmc + 1));
filter.add(Predicates.not(ColorlessPredicate.instance));
Set<Card> permanentsToExile = new HashSet<>();
permanentsToExile.addAll(game.getBattlefield().getActivePermanents(filter, source.getControllerId(), source.getSourceId(), game));
controller.moveCards(permanentsToExile, Zone.EXILED, source, game);
return true;
}
use of mage.filter.predicate.mageobject.ManaValuePredicate in project mage by magefree.
the class EvershrikeEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Card evershrikeCard = game.getCard(source.getSourceId());
Player controller = game.getPlayer(source.getControllerId());
if (controller == null || evershrikeCard == null) {
return false;
}
int xAmount = source.getManaCostsToPay().getX();
controller.moveCards(evershrikeCard, Zone.BATTLEFIELD, source, game);
Permanent evershrikePermanent = game.getPermanent(evershrikeCard.getId());
if (evershrikePermanent == null) {
if (game.getState().getZone(evershrikeCard.getId()) != Zone.EXILED) {
controller.moveCards(evershrikeCard, Zone.EXILED, source, game);
}
return false;
}
boolean exileSource = true;
FilterCard filterAuraCard = new FilterCard("Aura card with mana value X or less from your hand");
filterAuraCard.add(CardType.ENCHANTMENT.getPredicate());
filterAuraCard.add(SubType.AURA.getPredicate());
filterAuraCard.add(new AuraCardCanAttachToPermanentId(evershrikePermanent.getId()));
filterAuraCard.add(new ManaValuePredicate(ComparisonType.FEWER_THAN, xAmount + 1));
int count = controller.getHand().count(filterAuraCard, game);
if (count > 0 && controller.chooseUse(Outcome.Benefit, "Put an Aura card from your hand onto the battlefield attached to " + evershrikeCard.getIdName() + "?", source, game)) {
TargetCard targetAura = new TargetCard(Zone.HAND, filterAuraCard);
if (controller.choose(Outcome.Benefit, controller.getHand(), targetAura, game)) {
Card aura = game.getCard(targetAura.getFirstTarget());
if (aura != null) {
game.getState().setValue("attachTo:" + aura.getId(), evershrikePermanent);
if (controller.moveCards(aura, Zone.BATTLEFIELD, source, game)) {
evershrikePermanent.addAttachment(aura.getId(), source, game);
}
exileSource = false;
}
}
}
if (exileSource) {
controller.moveCards(evershrikeCard, Zone.EXILED, source, game);
}
return true;
}
use of mage.filter.predicate.mageobject.ManaValuePredicate in project mage by magefree.
the class GenesisHydraPutOntoBattlefieldEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
Object obj = getValue(CastSourceTriggeredAbility.SOURCE_CAST_SPELL_ABILITY);
if (controller != null && obj instanceof SpellAbility) {
int count = ((SpellAbility) obj).getManaCostsToPay().getX();
if (count > 0) {
Cards cards = new CardsImpl(controller.getLibrary().getTopCards(game, count));
controller.revealCards(source, cards, game);
FilterCard filter = new FilterPermanentCard("a nonland permanent card with mana value " + count + " or less to put onto the battlefield");
filter.add(Predicates.not(CardType.LAND.getPredicate()));
filter.add(new ManaValuePredicate(ComparisonType.FEWER_THAN, count + 1));
TargetCard target1 = new TargetCard(Zone.LIBRARY, filter);
target1.setRequired(false);
if (cards.count(filter, controller.getId(), source.getSourceId(), game) > 0) {
if (controller.choose(Outcome.PutCardInPlay, cards, target1, game)) {
Card card = cards.get(target1.getFirstTarget(), game);
if (card != null) {
cards.remove(card);
controller.moveCards(card, Zone.BATTLEFIELD, source, game);
}
target1.clearChosen();
} else {
game.informPlayers(controller.getLogName() + " didn't choose anything");
}
} else {
game.informPlayers("No nonland permanent card with mana value " + count + " or less to choose.");
}
if (!cards.isEmpty()) {
controller.moveCards(cards, Zone.LIBRARY, source, game);
controller.shuffleLibrary(source, game);
}
}
return true;
}
return false;
}
Aggregations