use of mage.filter.predicate.mageobject.ManaValuePredicate in project mage by magefree.
the class TransmuteEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
MageObject sourceObject = game.getObject(source.getSourceId());
if (sourceObject != null && controller != null) {
FilterCard filter = new FilterCard("card with mana value " + sourceObject.getManaValue());
filter.add(new ManaValuePredicate(ComparisonType.EQUAL_TO, sourceObject.getManaValue()));
TargetCardInLibrary target = new TargetCardInLibrary(1, filter);
if (controller.searchLibrary(target, source, game)) {
if (!target.getTargets().isEmpty()) {
Cards revealed = new CardsImpl(target.getTargets());
controller.revealCards(sourceObject.getIdName(), revealed, game);
controller.moveCards(revealed, Zone.HAND, source, game);
}
}
controller.shuffleLibrary(source, game);
return true;
}
return false;
}
use of mage.filter.predicate.mageobject.ManaValuePredicate in project mage by magefree.
the class SoulshiftAbility method trigger.
@Override
public void trigger(Game game, UUID controllerId, GameEvent triggeringEvent) {
this.getTargets().clear();
int intValue = amount.calculate(game, this, null);
FilterCard filter = new FilterCard("Spirit card with mana value " + intValue + " or less from your graveyard");
filter.add(new ManaValuePredicate(ComparisonType.FEWER_THAN, intValue + 1));
filter.add(SubType.SPIRIT.getPredicate());
this.addTarget(new TargetCardInYourGraveyard(filter));
// To change body of generated methods, choose Tools | Templates.
super.trigger(game, controllerId, triggeringEvent);
}
use of mage.filter.predicate.mageobject.ManaValuePredicate in project mage by magefree.
the class InSearchOfGreatnessEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
if (controller == null) {
return false;
}
int cmc = 0;
UUID permId = source.getSourceId();
for (Permanent permanent : game.getBattlefield().getAllActivePermanents(controller.getId())) {
if (permanent != null && !permanent.getId().equals(permId)) {
int permCmc = permanent.getManaValue();
if (permCmc > cmc) {
cmc = permCmc;
}
}
}
if (controller.chooseUse(outcome, "Cast a permanent spell from your hand with CMC equal to " + ++cmc + "?", source, game)) {
FilterPermanentCard filter = new FilterPermanentCard("permanent spell from your hand");
filter.add(Predicates.not(CardType.LAND.getPredicate()));
filter.add(new ManaValuePredicate(ComparisonType.EQUAL_TO, cmc));
TargetCardInHand target = new TargetCardInHand(filter);
if (controller.chooseTarget(outcome, target, source, game)) {
Card card = game.getCard(target.getFirstTarget());
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);
if (cardWasCast) {
return true;
}
}
}
}
return controller.scry(1, source, game);
}
use of mage.filter.predicate.mageobject.ManaValuePredicate in project mage by magefree.
the class LonisCryptozoologistEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
Player opponent = game.getPlayer(getTargetPointer().getFirst(game, source));
if (controller != null && opponent != null) {
int xValue = GetXValue.instance.calculate(game, source, this);
Cards cards = new CardsImpl(opponent.getLibrary().getTopCards(game, xValue));
opponent.revealCards(source, cards, game);
if (controller.chooseUse(outcome, "Put a nonland permanent card with mana value " + xValue + " or less from among revealed cards onto the battlefield under your control?", source, game)) {
FilterPermanentCard filter = new FilterPermanentCard("nonland permanent card with mana value " + xValue + " or less");
filter.add(Predicates.not(CardType.LAND.getPredicate()));
filter.add(new ManaValuePredicate(ComparisonType.FEWER_THAN, xValue + 1));
TargetCard target = new TargetCard(Zone.LIBRARY, filter);
if (controller.choose(outcome, cards, target, game)) {
Card selectedCard = game.getCard(target.getFirstTarget());
if (selectedCard != null) {
cards.remove(selectedCard);
controller.moveCards(selectedCard, Zone.BATTLEFIELD, source, game);
}
}
}
opponent.putCardsOnBottomOfLibrary(cards, game, source, false);
return true;
}
return false;
}
use of mage.filter.predicate.mageobject.ManaValuePredicate in project mage by magefree.
the class MercadianLiftEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
if (controller != null) {
int numberOfCounters = 0;
for (Cost cost : source.getCosts()) {
if (cost instanceof RemoveVariableCountersSourceCost) {
numberOfCounters = ((RemoveVariableCountersSourceCost) cost).getAmount();
}
}
System.out.println("The number is " + numberOfCounters);
FilterCreatureCard filter = new FilterCreatureCard();
filter.add(new ManaValuePredicate(ComparisonType.EQUAL_TO, numberOfCounters));
filter.setMessage("creature card with mana value " + numberOfCounters);
TargetCardInHand target = new TargetCardInHand(filter);
if (target.canChoose(source.getSourceId(), controller.getId(), game) && controller.chooseUse(Outcome.PutCardInPlay, "Put " + filter.getMessage() + " from your hand onto the battlefield?", source, game) && controller.choose(Outcome.PutCardInPlay, target, source.getSourceId(), game)) {
target.setRequired(false);
Card card = game.getCard(target.getFirstTarget());
if (card != null) {
return controller.moveCards(card, Zone.BATTLEFIELD, source, game);
}
}
}
return false;
}
Aggregations