use of mage.filter.predicate.mageobject.ManaValuePredicate in project mage by magefree.
the class EcologicalAppreciationEffect 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();
FilterCard filter = new FilterCreatureCard();
filter.add(new ManaValuePredicate(ComparisonType.FEWER_THAN, xValue + 1));
TargetCard targetCardsInLibrary = new TargetCardInLibrary(0, 4, filter) {
@Override
public boolean canTarget(UUID playerId, UUID id, Ability source, Game game) {
if (!super.canTarget(playerId, id, source, game)) {
return false;
}
Card card = game.getCard(id);
Set<Card> disallowedCards = this.getTargets().stream().map(game::getCard).collect(Collectors.toSet());
return isValidTarget(card, disallowedCards);
}
};
targetCardsInLibrary.setNotTarget(true);
targetCardsInLibrary.withChooseHint("Step 1 of 2: Search library");
player.choose(Outcome.PutCreatureInPlay, new CardsImpl(player.getLibrary().getCards(game)), targetCardsInLibrary, game);
Cards cards = new CardsImpl(targetCardsInLibrary.getTargets());
boolean status = !cards.isEmpty();
if (status) {
int remainingCards = 4 - cards.size();
if (remainingCards > 0) {
TargetCard targetCardsInGY = new TargetCardInYourGraveyard(0, remainingCards, filter) {
@Override
public boolean canTarget(UUID playerId, UUID id, Ability source, Game game) {
if (!super.canTarget(playerId, id, source, game)) {
return false;
}
Card card = game.getCard(id);
Set<Card> disallowedCards = this.getTargets().stream().map(game::getCard).collect(Collectors.toSet());
Set<Card> checkList = new HashSet<>();
checkList.addAll(disallowedCards);
checkList.addAll(cards.getCards(game));
return isValidTarget(card, checkList);
}
};
targetCardsInGY.setNotTarget(true);
targetCardsInGY.withChooseHint("Step 2 of 2: Search graveyard");
player.choose(Outcome.PutCreatureInPlay, new CardsImpl(player.getGraveyard().getCards(game)), targetCardsInGY, game);
cards.addAll(targetCardsInGY.getTargets());
}
TargetOpponent targetOpponent = new TargetOpponent();
targetOpponent.setNotTarget(true);
player.choose(outcome, targetOpponent, source.getSourceId(), game);
Player opponent = game.getPlayer(targetOpponent.getFirstTarget());
if (opponent == null) {
status = false;
}
if (status) {
TargetCard chosenCards = new TargetCard(2, Zone.ALL, StaticFilters.FILTER_CARD);
chosenCards.setNotTarget(true);
opponent.choose(outcome, cards, chosenCards, game);
Cards toShuffle = new CardsImpl(chosenCards.getTargets().stream().map(game::getCard).collect(Collectors.toList()));
player.putCardsOnTopOfLibrary(toShuffle, game, source, false);
cards.removeAll(toShuffle);
player.moveCards(cards, Zone.BATTLEFIELD, source, game);
}
}
player.shuffleLibrary(source, game);
return status;
}
use of mage.filter.predicate.mageobject.ManaValuePredicate in project mage by magefree.
the class EldritchEvolutionEffect 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) {
int newConvertedCost = sacrificedPermanent.getManaValue() + 2;
FilterCard filter = new FilterCard("creature card with mana value " + newConvertedCost + " or less");
filter.add(new ManaValuePredicate(ComparisonType.FEWER_THAN, newConvertedCost + 1));
filter.add(CardType.CREATURE.getPredicate());
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;
}
return false;
}
use of mage.filter.predicate.mageobject.ManaValuePredicate in project mage by magefree.
the class InstrumentOfTheBardsEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
Permanent permanent = game.getPermanentOrLKIBattlefield(source.getSourceId());
if (controller == null || permanent == null) {
return false;
}
int counters = permanent.getCounters(game).getCount(CounterType.HARMONY);
FilterCreatureCard filter = new FilterCreatureCard("creature card with mana value " + counters);
filter.add(new ManaValuePredicate(ComparisonType.EQUAL_TO, counters));
TargetCardInLibrary target = new TargetCardInLibrary(filter);
if (controller.searchLibrary(target, source, game)) {
Card card = game.getCard(target.getFirstTarget());
if (card != null) {
controller.revealCards(permanent.getIdName(), new CardsImpl(card), game);
controller.moveCards(card, Zone.HAND, source, game);
if (card.isLegendary()) {
new TreasureToken().putOntoBattlefield(1, game, source, source.getControllerId());
}
}
}
controller.shuffleLibrary(source, game);
return true;
}
use of mage.filter.predicate.mageobject.ManaValuePredicate in project mage by magefree.
the class KindredDenialEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player player = game.getPlayer(source.getControllerId());
Spell spell = game.getSpell(source.getFirstTarget());
if (player == null || spell == null) {
return false;
}
int manaValue = spell.getManaValue();
spell.counter(source, game);
FilterCard filter = new FilterCard();
filter.add(new ManaValuePredicate(ComparisonType.EQUAL_TO, manaValue));
player.seekCard(filter, source, game);
return true;
}
use of mage.filter.predicate.mageobject.ManaValuePredicate in project mage by magefree.
the class MinnWilyIllusionistEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player player = game.getPlayer(source.getControllerId());
Permanent permanent = (Permanent) getValue("creatureDied");
if (player == null || permanent == null) {
return false;
}
FilterCard filterCard = new FilterPermanentCard("permanent card with mana value " + permanent.getPower().getValue() + " or less");
filterCard.add(new ManaValuePredicate(ComparisonType.FEWER_THAN, permanent.getPower().getValue() + 1));
TargetCardInHand target = new TargetCardInHand(0, 1, filterCard);
player.choose(Outcome.PutCardInPlay, player.getHand(), target, game);
Card card = game.getCard(target.getFirstTarget());
if (card == null) {
return false;
}
return player.moveCards(card, Zone.BATTLEFIELD, source, game);
}
Aggregations