use of mage.target.common.TargetCardInLibrary in project mage by magefree.
the class JungleWayfinderEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
if (controller != null) {
for (UUID playerId : game.getState().getPlayersInRange(controller.getId(), game)) {
Player player = game.getPlayer(playerId);
if (player != null) {
TargetCardInLibrary target = new TargetCardInLibrary(0, 1, StaticFilters.FILTER_CARD_BASIC_LAND);
if (player.chooseUse(Outcome.Benefit, "Search your library for a card to put into your hand?", source, game)) {
player.searchLibrary(target, source, game);
for (UUID cardId : target.getTargets()) {
Card card = player.getLibrary().getCard(cardId, game);
if (card != null) {
player.revealCards(source, new CardsImpl(card), game);
player.moveCards(card, Zone.HAND, source, game);
}
}
player.shuffleLibrary(source, game);
}
}
}
// prevent undo
controller.resetStoredBookmark(game);
return true;
}
return false;
}
use of mage.target.common.TargetCardInLibrary in project mage by magefree.
the class KotoseTheSilentSpiderWatcher method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
Card card = game.getCard(getTargetPointer().getFirst(game, source));
if (controller == null || card == null) {
return false;
}
Player opponent = game.getPlayer(card.getOwnerId());
if (opponent == null) {
return false;
}
UUID exileId = CardUtil.getExileZoneId(game, source);
String exileName = CardUtil.getSourceName(game, source);
controller.moveCardsToExile(card, source, game, true, exileId, exileName);
Cards cards = new CardsImpl();
FilterCard filter = new FilterCard("cards named " + card.getName() + " from " + opponent.getName() + "'s graveyard");
filter.add(new NamePredicate(card.getName()));
TargetCardInGraveyard targetCardInGraveyard = new TargetCardInGraveyard(0, Integer.MAX_VALUE, filter);
controller.choose(outcome, opponent.getGraveyard(), targetCardInGraveyard, game);
cards.addAll(targetCardInGraveyard.getTargets());
filter.setMessage("cards named " + card.getName() + " from " + opponent.getName() + "'s hand");
TargetCardInHand targetCardInHand = new TargetCardInHand(0, Integer.MAX_VALUE, filter);
controller.choose(outcome, opponent.getHand(), targetCardInHand, game);
cards.addAll(targetCardInHand.getTargets());
filter.setMessage("cards named " + card.getName() + " from " + opponent.getName() + "'s library");
TargetCardInLibrary target = new TargetCardInLibrary(0, Integer.MAX_VALUE, filter);
controller.searchLibrary(target, source, game, opponent.getId());
target.getTargets().stream().map(cardId -> opponent.getLibrary().getCard(cardId, game)).forEach(cards::add);
Set<Card> cardSet = cards.getCards(game);
controller.moveCardsToExile(cardSet, source, game, true, exileId, exileName);
opponent.shuffleLibrary(source, game);
cardSet.add(card);
if (cardSet.isEmpty() || source.getSourcePermanentIfItStillExists(game) == null) {
return true;
}
KotoseTheSilentSpiderWatcher.addCards(source, cardSet, game);
for (Card exiledCard : cardSet) {
CardUtil.makeCardPlayable(game, source, exiledCard, Duration.WhileControlled, true, null, new KotoseTheSilentSpiderCondition(exiledCard, game));
}
return true;
}
use of mage.target.common.TargetCardInLibrary in project mage by magefree.
the class LongTermPlansEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player player = game.getPlayer(source.getControllerId());
if (player != null) {
TargetCardInLibrary target = new TargetCardInLibrary();
if (player.searchLibrary(target, source, game)) {
Card card = player.getLibrary().remove(target.getFirstTarget(), game);
if (card != null) {
player.shuffleLibrary(source, game);
// must hides the card name from other players
player.putCardOnTopXOfLibrary(card, game, source, 3, false);
}
}
return true;
}
return false;
}
use of mage.target.common.TargetCardInLibrary in project mage by magefree.
the class MausoleumSecretsEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player player = game.getPlayer(source.getControllerId());
if (player == null) {
return false;
}
int critterCount = player.getGraveyard().count(StaticFilters.FILTER_CARD_CREATURE, game);
FilterCard filter = new FilterCard("a black card with mana value less than or equal to " + critterCount);
filter.add(new ColorPredicate(ObjectColor.BLACK));
filter.add(new ManaValuePredicate(ComparisonType.FEWER_THAN, critterCount + 1));
return new SearchLibraryPutInHandEffect(new TargetCardInLibrary(filter), true).apply(game, source);
}
use of mage.target.common.TargetCardInLibrary in project mage by magefree.
the class NobleBenefactorEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
if (controller != null) {
for (UUID playerId : game.getState().getPlayersInRange(controller.getId(), game)) {
Player player = game.getPlayer(playerId);
if (player != null) {
TargetCardInLibrary target = new TargetCardInLibrary();
if (player.chooseUse(Outcome.Benefit, "Search your library for a card to put into your hand?", source, game)) {
player.searchLibrary(target, source, game);
for (UUID cardId : target.getTargets()) {
Card card = player.getLibrary().getCard(cardId, game);
if (card != null) {
player.moveCards(card, Zone.HAND, source, game);
}
}
player.shuffleLibrary(source, game);
}
}
}
// prevent undo
controller.resetStoredBookmark(game);
return true;
}
return false;
}
Aggregations