use of mage.filter.predicate.mageobject.ManaValuePredicate in project mage by magefree.
the class SarulfRealmEaterEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player player = game.getPlayer(source.getControllerId());
Permanent permanent = source.getSourcePermanentIfItStillExists(game);
if (player == null || permanent == null) {
return false;
}
int counterCount = permanent.getCounters(game).getCount(CounterType.P1P1);
permanent.removeCounters(CounterType.P1P1.createInstance(counterCount), source, game);
FilterPermanent filter = new FilterNonlandPermanent();
filter.add(new ManaValuePredicate(ComparisonType.FEWER_THAN, counterCount + 1));
filter.add(AnotherPredicate.instance);
Cards cards = new CardsImpl();
game.getBattlefield().getActivePermanents(filter, source.getControllerId(), source.getSourceId(), game).stream().filter(Objects::nonNull).map(MageItem::getId).forEach(cards::add);
return player.moveCards(cards, Zone.EXILED, source, game);
}
use of mage.filter.predicate.mageobject.ManaValuePredicate in project mage by magefree.
the class VenerableWarsingerTriggeredAbility method checkTrigger.
@Override
public boolean checkTrigger(GameEvent event, Game game) {
Player player = game.getPlayer(event.getPlayerId());
if (player == null || !event.getSourceId().equals(getSourceId()) || !((DamagedEvent) event).isCombatDamage()) {
return false;
}
FilterCard filter = new FilterCreatureCard("creature card with mana value " + event.getAmount() + " less from your graveyard");
filter.add(new ManaValuePredicate(ComparisonType.FEWER_THAN, event.getAmount() + 1));
this.getTargets().clear();
this.addTarget(new TargetCardInYourGraveyard(filter));
return true;
}
use of mage.filter.predicate.mageobject.ManaValuePredicate in project mage by magefree.
the class CovertTechnicianEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
int damage = (Integer) getValue("damage");
FilterCard filter = new FilterArtifactCard("artifact card with mana value " + damage + " or less");
filter.add(new ManaValuePredicate(ComparisonType.FEWER_THAN, damage + 1));
return new PutCardFromHandOntoBattlefieldEffect(filter).apply(game, source);
}
use of mage.filter.predicate.mageobject.ManaValuePredicate in project mage by magefree.
the class AetherVialEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Permanent permanent = game.getBattlefield().getPermanent(source.getSourceId());
if (permanent == null) {
permanent = (Permanent) game.getLastKnownInformation(source.getSourceId(), Zone.BATTLEFIELD);
if (permanent == null) {
return false;
}
}
int count = permanent.getCounters(game).getCount(CounterType.CHARGE);
FilterCreatureCard filter = new FilterCreatureCard("creature card with mana value equal to " + count);
filter.add(new ManaValuePredicate(ComparisonType.EQUAL_TO, count));
String choiceText = "Put a " + filter.getMessage() + " from your hand onto the battlefield?";
Player controller = game.getPlayer(source.getControllerId());
if (controller == null) {
return false;
}
if (controller.getHand().count(filter, game) == 0 || !controller.chooseUse(this.outcome, choiceText, source, game)) {
return true;
}
TargetCardInHand target = new TargetCardInHand(filter);
if (controller.choose(this.outcome, target, source.getSourceId(), game)) {
Card card = game.getCard(target.getFirstTarget());
if (card != null) {
return controller.moveCards(card, Zone.BATTLEFIELD, source, game);
}
}
return false;
}
use of mage.filter.predicate.mageobject.ManaValuePredicate in project mage by magefree.
the class BrainInAJarScryEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
Permanent sourceObject = game.getPermanentOrLKIBattlefield(source.getSourceId());
if (controller != null && sourceObject != null) {
int counters = sourceObject.getCounters(game).getCount(CounterType.CHARGE);
FilterCard filter = new FilterInstantOrSorceryCard();
filter.add(new ManaValuePredicate(ComparisonType.EQUAL_TO, counters));
int cardsToCast = controller.getHand().count(filter, source.getControllerId(), source.getSourceId(), game);
if (cardsToCast > 0 && controller.chooseUse(Outcome.PlayForFree, "Cast an instant or sorcery card with mana values of " + counters + " from your hand without paying its mana cost?", source, game)) {
TargetCardInHand target = new TargetCardInHand(filter);
controller.chooseTarget(outcome, target, source, 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;
}
Aggregations