use of mage.target.common.TargetCardInLibrary in project mage by magefree.
the class PeregrinationEffect 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();
for (UUID cardId : target.getTargets()) {
Card card = controller.getLibrary().getCard(cardId, game);
revealed.add(card);
}
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);
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();
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();
controller.moveCards(card, Zone.BATTLEFIELD, source, game, true, false, false, null);
}
}
controller.shuffleLibrary(source, game);
return true;
}
controller.shuffleLibrary(source, game);
return false;
}
use of mage.target.common.TargetCardInLibrary in project mage by magefree.
the class RemembranceTriggeredAbility method checkTrigger.
@Override
public boolean checkTrigger(GameEvent event, Game game) {
if (!((ZoneChangeEvent) event).isDiesEvent()) {
return false;
}
Permanent permanent = game.getPermanentOrLKIBattlefield(event.getTargetId());
if (permanent != null && filter.match(permanent, game)) {
FilterCard filterCard = new FilterCard("card named " + permanent.getName());
filterCard.add(new NamePredicate(permanent.getName()));
this.getEffects().clear();
this.addEffect(new SearchLibraryPutInHandEffect(new TargetCardInLibrary(filterCard), true, true));
return true;
}
return false;
}
use of mage.target.common.TargetCardInLibrary in project mage by magefree.
the class RenownedWeaponsmithEffect 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) {
TargetCardInLibrary target = new TargetCardInLibrary(filter);
if (controller.searchLibrary(target, source, game)) {
if (!target.getTargets().isEmpty()) {
Cards revealed = new CardsImpl();
Card card = game.getCard(target.getFirstTarget());
if (card != null) {
revealed.add(card);
controller.revealCards(sourceObject.getIdName(), revealed, game);
controller.moveCards(revealed, Zone.HAND, source, game);
}
}
}
controller.shuffleLibrary(source, game);
return true;
}
return false;
}
use of mage.target.common.TargetCardInLibrary in project mage by magefree.
the class SadisticSacramentEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player targetPlayer = game.getPlayer(source.getFirstTarget());
Player player = game.getPlayer(source.getControllerId());
if (player != null && targetPlayer != null) {
TargetCardInLibrary target = new TargetCardInLibrary(0, amount, new FilterCard("cards to exile"));
if (player.searchLibrary(target, source, game, targetPlayer.getId())) {
List<UUID> targets = target.getTargets();
for (UUID targetId : targets) {
Card card = targetPlayer.getLibrary().remove(targetId, game);
if (card != null) {
card.moveToExile(null, "", source, game);
}
}
}
targetPlayer.shuffleLibrary(source, game);
return true;
}
return false;
}
use of mage.target.common.TargetCardInLibrary in project mage by magefree.
the class RushedRebirthDelayedTriggeredAbility method makeEffect.
private static Effect makeEffect(Permanent permanent) {
FilterCard filter = new FilterCreatureCard("creature card with lesser mana value than " + permanent.getIdName());
filter.add(new RushedRebirthPredicate(permanent));
return new SearchLibraryPutInPlayEffect(new TargetCardInLibrary(filter), true);
}
Aggregations