use of mage.filter.predicate.mageobject.ManaValuePredicate in project mage by magefree.
the class NeoformReplacementEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Permanent sacrificedPermanent = null;
for (Cost cost : source.getCosts()) {
if (cost instanceof SacrificeTargetCost) {
SacrificeTargetCost sacrificeCost = (SacrificeTargetCost) cost;
if (!sacrificeCost.getPermanents().isEmpty()) {
sacrificedPermanent = sacrificeCost.getPermanents().get(0);
}
break;
}
}
Player controller = game.getPlayer(source.getControllerId());
if (sacrificedPermanent == null || controller == null) {
return false;
}
int newConvertedCost = sacrificedPermanent.getManaValue() + 1;
FilterCard filter = new FilterCard("creature card with mana value " + newConvertedCost);
filter.add(new ManaValuePredicate(ComparisonType.EQUAL_TO, newConvertedCost));
filter.add(CardType.CREATURE.getPredicate());
TargetCardInLibrary target = new TargetCardInLibrary(filter);
if (controller.searchLibrary(target, source, game)) {
Card card = controller.getLibrary().getCard(target.getFirstTarget(), game);
if (card != null) {
ContinuousEffectImpl effect = new NeoformReplacementEffect();
effect.setTargetPointer(new FixedTarget(card, game));
game.addEffect(effect, source);
if (!controller.moveCards(card, Zone.BATTLEFIELD, source, game)) {
effect.discard();
}
}
}
controller.shuffleLibrary(source, game);
return true;
}
use of mage.filter.predicate.mageobject.ManaValuePredicate in project mage by magefree.
the class PyreOfHeroesEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Permanent sacrificedPermanent = null;
for (Cost cost : source.getCosts()) {
if (cost instanceof SacrificeTargetCost) {
SacrificeTargetCost sacrificeCost = (SacrificeTargetCost) cost;
if (!sacrificeCost.getPermanents().isEmpty()) {
sacrificedPermanent = sacrificeCost.getPermanents().get(0);
}
break;
}
}
Player controller = game.getPlayer(source.getControllerId());
if (sacrificedPermanent == null || controller == null) {
return false;
}
int newConvertedCost = sacrificedPermanent.getManaValue() + 1;
FilterCard filter = new FilterCard("creature card with mana value " + newConvertedCost);
filter.add(new ManaValuePredicate(ComparisonType.EQUAL_TO, newConvertedCost));
filter.add(CardType.CREATURE.getPredicate());
filter.add(new SharesCreatureTypePredicate(sacrificedPermanent));
TargetCardInLibrary target = new TargetCardInLibrary(filter);
if (controller.searchLibrary(target, source, game)) {
Card card = controller.getLibrary().getCard(target.getFirstTarget(), game);
controller.moveCards(card, Zone.BATTLEFIELD, source, game);
}
controller.shuffleLibrary(source, game);
return true;
}
use of mage.filter.predicate.mageobject.ManaValuePredicate in project mage by magefree.
the class SaheelisDirectiveEffect 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 FilterArtifactCard("artifact 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 DroningBureaucratsEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
int xValue = source.getManaCostsToPay().getX();
FilterCreaturePermanent filter = new FilterCreaturePermanent("creature with mana value X");
filter.add(new ManaValuePredicate(ComparisonType.EQUAL_TO, xValue));
game.addEffect(new CantAttackBlockAllEffect(Duration.EndOfTurn, filter), source);
return true;
}
use of mage.filter.predicate.mageobject.ManaValuePredicate in project mage by magefree.
the class FavorOfTheMightyEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
int maxCMC = Integer.MIN_VALUE;
for (Permanent permanent : game.getBattlefield().getActivePermanents(StaticFilters.FILTER_PERMANENT_CREATURE, source.getControllerId(), game)) {
if (permanent != null && permanent.getManaValue() > maxCMC) {
maxCMC = permanent.getManaValue();
}
}
FilterPermanent filterMaxCMC = new FilterCreaturePermanent();
filterMaxCMC.add(new ManaValuePredicate(ComparisonType.EQUAL_TO, maxCMC));
for (Permanent permanent : game.getBattlefield().getActivePermanents(filterMaxCMC, source.getControllerId(), game)) {
if (permanent != null) {
permanent.addAbility(new ProtectionAbility(filter), source.getSourceId(), game);
}
}
return true;
}
Aggregations