use of mage.filter.common.FilterPermanentCard in project mage by magefree.
the class KamahlsDruidicVowEffect 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));
controller.lookAtCards(source, null, cards, game);
if (!cards.isEmpty()) {
FilterCard filter = new FilterPermanentCard("land and/or legendary permanent cards with mana value " + xValue + " or less to put onto the battlefield");
filter.add(new ManaValuePredicate(ComparisonType.FEWER_THAN, xValue + 1));
filter.add(Predicates.or(CardType.LAND.getPredicate(), SuperType.LEGENDARY.getPredicate()));
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.common.FilterPermanentCard in project mage by magefree.
the class ZirilanOfTheClawEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
if (controller != null) {
FilterPermanentCard filter = new FilterPermanentCard("a Dragon permanent card");
filter.add(SubType.DRAGON.getPredicate());
TargetCardInLibrary target = new TargetCardInLibrary(filter);
if (controller.searchLibrary(target, source, game)) {
Card card = controller.getLibrary().getCard(target.getFirstTarget(), game);
if (card != null) {
controller.moveCards(card, Zone.BATTLEFIELD, source, game);
Permanent permanent = game.getPermanent(card.getId());
if (permanent != null) {
// gains haste
ContinuousEffect effect = new GainAbilityTargetEffect(HasteAbility.getInstance(), Duration.EndOfTurn);
effect.setTargetPointer(new FixedTarget(permanent, game));
game.addEffect(effect, source);
// Exile at begin of next end step
ExileTargetEffect exileEffect = new ExileTargetEffect(null, null, Zone.BATTLEFIELD);
exileEffect.setTargetPointer(new FixedTarget(permanent, game));
DelayedTriggeredAbility delayedAbility = new AtTheBeginOfNextEndStepDelayedTriggeredAbility(exileEffect);
game.addDelayedTriggeredAbility(delayedAbility, source);
}
}
return true;
}
}
return false;
}
use of mage.filter.common.FilterPermanentCard 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;
}
use of mage.filter.common.FilterPermanentCard in project mage by magefree.
the class GenesisWaveEffect 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 FilterPermanentCard("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.common.FilterPermanentCard in project mage by magefree.
the class KodamaOfTheEastTreeWatcher method apply.
@Override
public boolean apply(Game game, Ability source) {
Object obj = this.getValue("permanentEnteringBattlefield");
if (!(obj instanceof Permanent)) {
return false;
}
Permanent permanent = (Permanent) obj;
Player player = game.getPlayer(source.getControllerId());
if (player == null) {
return false;
}
FilterCard filter = new FilterPermanentCard("a permanent card with mana value " + permanent.getManaValue() + " or less");
filter.add(new ManaValuePredicate(ComparisonType.FEWER_THAN, permanent.getManaValue() + 1));
TargetCardInHand target = new TargetCardInHand(filter);
if (!target.canChoose(source.getSourceId(), source.getControllerId(), game) || !player.chooseUse(outcome, "Put a permanent card onto the battlefield?", source, game)) {
return false;
}
player.choose(outcome, target, source.getSourceId(), game);
Card card = game.getCard(target.getFirstTarget());
if (card == null) {
return false;
}
player.moveCards(card, Zone.BATTLEFIELD, source, game);
Permanent otherPermanent = game.getPermanent(card.getId());
if (otherPermanent == null) {
return false;
}
KodamaOfTheEastTreeWatcher watcher = game.getState().getWatcher(KodamaOfTheEastTreeWatcher.class);
if (watcher != null) {
watcher.addPermanent(otherPermanent, source, game);
}
return true;
}
Aggregations