use of mage.target.common.TargetCardInLibrary in project mage by magefree.
the class TreasureChestEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player player = game.getPlayer(source.getControllerId());
if (player == null) {
return false;
}
TargetCardInLibrary target = new TargetCardInLibrary();
player.searchLibrary(target, source, game);
Card card = player.getLibrary().getCard(target.getFirstTarget(), game);
if (card == null) {
player.shuffleLibrary(source, game);
return true;
}
if (CardType.ARTIFACT.getPredicate().apply(card, game) && player.chooseUse(Outcome.PlayForFree, "Put it onto the battlefield or your hand?", null, "Battlefield", "Hand", source, game)) {
player.moveCards(card, Zone.BATTLEFIELD, source, game);
} else {
player.moveCards(card, Zone.HAND, source, game);
}
player.shuffleLibrary(source, game);
return true;
}
use of mage.target.common.TargetCardInLibrary in project mage by magefree.
the class BifurcateEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Permanent permanent = game.getPermanent(source.getFirstTarget());
FilterCard filter = new FilterPermanentCard();
filter.add(new NamePredicate(permanent.getName()));
return new SearchLibraryPutInPlayEffect(new TargetCardInLibrary(filter)).apply(game, source);
}
use of mage.target.common.TargetCardInLibrary in project mage by magefree.
the class CleansingWildfireEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Permanent permanent = getTargetPointer().getFirstTargetPermanentOrLKI(game, source);
if (permanent == null) {
return false;
}
Player controller = game.getPlayer(permanent.getControllerId());
if (controller == null) {
return false;
}
if (!controller.chooseUse(Outcome.PutLandInPlay, "Search for a basic land and put it onto the battlefield tapped?", source, game)) {
return true;
}
TargetCardInLibrary target = new TargetCardInLibrary(StaticFilters.FILTER_CARD_BASIC_LAND);
if (controller.searchLibrary(target, source, game)) {
Card card = controller.getLibrary().getCard(target.getFirstTarget(), game);
if (card != null) {
controller.moveCards(card, Zone.BATTLEFIELD, source, game, true, false, true, null);
}
}
controller.shuffleLibrary(source, game);
return true;
}
use of mage.target.common.TargetCardInLibrary in project mage by magefree.
the class CultivateEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
MageObject sourceObject = game.getObject(source.getSourceId());
if (controller == null || sourceObject == null) {
return false;
}
TargetCardInLibrary target = new TargetCardInLibrary(0, 2, StaticFilters.FILTER_CARD_BASIC_LAND);
if (controller.searchLibrary(target, source, game)) {
if (!target.getTargets().isEmpty()) {
Cards revealed = new CardsImpl(target.getTargets());
controller.revealCards(sourceObject.getIdName(), revealed, game);
if (target.getTargets().size() == 2) {
TargetCard target2 = new TargetCard(Zone.LIBRARY, filter);
controller.choose(Outcome.Benefit, revealed, target2, game);
Card card = revealed.get(target2.getFirstTarget(), game);
if (card != null) {
controller.moveCards(card, Zone.BATTLEFIELD, source, game, true, false, false, null);
revealed.remove(card);
}
Set<Card> cards = revealed.getCards(game);
card = cards.isEmpty() ? null : cards.iterator().next();
if (card != null) {
controller.moveCards(card, Zone.HAND, source, game);
}
} else if (target.getTargets().size() == 1) {
Set<Card> cards = revealed.getCards(game);
Card card = cards.isEmpty() ? null : cards.iterator().next();
if (card != null) {
controller.moveCards(card, Zone.BATTLEFIELD, source, game, true, false, false, null);
}
}
}
}
controller.shuffleLibrary(source, game);
return true;
}
use of mage.target.common.TargetCardInLibrary in project mage by magefree.
the class DenyingWindEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player player = game.getPlayer(source.getFirstTarget());
Player controller = game.getPlayer(source.getControllerId());
if (controller != null && player != null) {
TargetCardInLibrary target = new TargetCardInLibrary(0, 7, new FilterCard("cards from player's library to exile"));
if (controller.searchLibrary(target, source, game, player.getId())) {
List<UUID> targets = target.getTargets();
for (UUID targetId : targets) {
Card card = player.getLibrary().remove(targetId, game);
if (card != null) {
controller.moveCardToExileWithInfo(card, null, null, source, game, Zone.LIBRARY, true);
}
}
}
player.shuffleLibrary(source, game);
return true;
}
return false;
}
Aggregations