use of mage.target.common.TargetCardInLibrary in project mage by magefree.
the class SvellaIceShaperEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
if (controller == null) {
return false;
}
Set<Card> cardsSet = controller.getLibrary().getTopCards(game, 4);
Cards cards = new CardsImpl(cardsSet);
TargetCard target = new TargetCardInLibrary(0, 1, new FilterNonlandCard("card to cast without paying its mana cost"));
controller.choose(Outcome.PlayForFree, cards, target, game);
Card card = controller.getLibrary().getCard(target.getFirstTarget(), game);
if (card == null) {
controller.putCardsOnBottomOfLibrary(cards, game, source, false);
return true;
}
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) {
cards.remove(card);
}
controller.putCardsOnBottomOfLibrary(cards, game, source, false);
return true;
}
use of mage.target.common.TargetCardInLibrary in project mage by magefree.
the class VivienChampionOfTheWildsCastFromExileEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player player = game.getPlayer(source.getControllerId());
if (player == null) {
return false;
}
// select
Cards cardsToLook = new CardsImpl(player.getLibrary().getTopCards(game, 3));
FilterCard filter = new FilterCard("card to exile face down");
TargetCard target = new TargetCardInLibrary(filter);
if (!player.choose(outcome, cardsToLook, target, game)) {
return false;
}
// exile
Card cardToExile = game.getCard(target.getFirstTarget());
if (!player.moveCardsToExile(cardToExile, source, game, false, CardUtil.getCardExileZoneId(game, source), CardUtil.createObjectRealtedWindowTitle(source, game, " (look and cast)"))) {
return false;
}
cardToExile.setFaceDown(true, game);
// look and cast
ContinuousEffect effect = new VivienChampionOfTheWildsLookEffect(player.getId());
effect.setTargetPointer(new FixedTarget(cardToExile, game));
game.addEffect(effect, source);
if (cardToExile.isCreature(game)) {
effect = new VivienChampionOfTheWildsCastFromExileEffect(player.getId());
effect.setTargetPointer(new FixedTarget(cardToExile, game));
game.addEffect(effect, source);
}
// put the rest on the bottom of your library in any order
Cards cardsToBottom = new CardsImpl(cardsToLook);
cardsToBottom.remove(cardToExile);
player.putCardsOnBottomOfLibrary(cardsToBottom, game, source, true);
return true;
}
use of mage.target.common.TargetCardInLibrary in project mage by magefree.
the class WildPairPowerToughnessPredicate method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
Permanent permanent = (Permanent) getValue("permanentEnteringBattlefield");
if (controller == null || permanent == null) {
return false;
}
int totalPT = permanent.getPower().getValue() + permanent.getToughness().getValue();
FilterCreatureCard filter = new FilterCreatureCard("creature card with total power and toughness " + totalPT);
filter.add(new WildPairPowerToughnessPredicate(totalPT));
TargetCardInLibrary target = new TargetCardInLibrary(1, filter);
controller.searchLibrary(target, source, game);
controller.moveCards(new CardsImpl(controller.getLibrary().getCard(target.getFirstTarget(), game)), Zone.BATTLEFIELD, source, game);
controller.shuffleLibrary(source, game);
return true;
}
use of mage.target.common.TargetCardInLibrary in project mage by magefree.
the class CustomTestCard method addCustomEffect_ReturnFromAnyToHand.
/**
* Return target card to hand that can be called by text "return from ..."
*
* @param controller
*/
protected void addCustomEffect_ReturnFromAnyToHand(TestPlayer controller) {
// graveyard
Ability ability = new SimpleActivatedAbility(new ReturnFromGraveyardToHandTargetEffect().setText("return from graveyard"), new ManaCostsImpl(""));
ability.addTarget(new TargetCardInGraveyard(StaticFilters.FILTER_CARD));
addCustomCardWithAbility("return from graveyard for " + controller.getName(), controller, ability);
// exile
ability = new SimpleActivatedAbility(new ReturnFromExileEffect(Zone.HAND).setText("return from exile"), new ManaCostsImpl(""));
ability.addTarget(new TargetCardInExile(StaticFilters.FILTER_CARD));
addCustomCardWithAbility("return from exile for " + controller.getName(), controller, ability);
// library
ability = new SimpleActivatedAbility(new SearchLibraryPutInHandEffect(new TargetCardInLibrary(StaticFilters.FILTER_CARD)).setText("return from library"), new ManaCostsImpl(""));
addCustomCardWithAbility("return from library for " + controller.getName(), controller, ability);
}
use of mage.target.common.TargetCardInLibrary in project mage by magefree.
the class AdventureAwaitsEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player player = game.getPlayer(source.getControllerId());
if (player == null) {
return false;
}
Cards cards = new CardsImpl(player.getLibrary().getTopCards(game, 5));
TargetCard target = new TargetCardInLibrary(0, 1, StaticFilters.FILTER_CARD_CREATURE);
player.choose(outcome, cards, target, game);
Card card = game.getCard(target.getFirstTarget());
if (card != null && player.chooseUse(outcome, "Put " + card.getName() + " into your hand?", "Otherwise draw a card", "Put into hand", "Draw a card", source, game)) {
player.moveCards(card, Zone.HAND, source, game);
cards.remove(card);
player.putCardsOnBottomOfLibrary(cards, game, source, false);
} else {
player.putCardsOnBottomOfLibrary(cards, game, source, false);
player.drawCards(1, source, game);
}
return true;
}
Aggregations