use of mage.target.common.TargetCardInLibrary in project mage by magefree.
the class CelebrateTheHarvestEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player player = game.getPlayer(source.getControllerId());
if (player == null) {
return false;
}
int powerCount = game.getBattlefield().getActivePermanents(StaticFilters.FILTER_CONTROLLED_CREATURE, source.getControllerId(), source.getSourceId(), game).stream().filter(Objects::nonNull).map(MageObject::getPower).mapToInt(MageInt::getValue).distinct().map(x -> 1).sum();
TargetCardInLibrary target = new TargetCardInLibrary(0, powerCount, StaticFilters.FILTER_CARD_BASIC_LAND);
player.searchLibrary(target, source, game);
Cards cards = new CardsImpl();
target.getTargets().stream().map(cardId -> player.getLibrary().getCard(cardId, game)).forEach(cards::add);
player.moveCards(cards.getCards(game), Zone.BATTLEFIELD, source, game, true, false, true, null);
player.shuffleLibrary(source, game);
return true;
}
use of mage.target.common.TargetCardInLibrary in project mage by magefree.
the class DarkDecisionEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
MageObject sourceObject = source.getSourceObject(game);
if (controller != null && sourceObject != null) {
TargetCardInLibrary target = new TargetCardInLibrary(new FilterNonlandCard());
target.setCardLimit(10);
if (controller.searchLibrary(target, source, game)) {
UUID targetId = target.getFirstTarget();
Card card = game.getCard(targetId);
if (card != null) {
controller.moveCardsToExile(card, source, game, true, source.getSourceId(), sourceObject.getIdName());
ContinuousEffect effect = new PlayFromNotOwnHandZoneTargetEffect(Zone.EXILED, Duration.EndOfTurn);
effect.setTargetPointer(new FixedTarget(card.getId(), game));
game.addEffect(effect, source);
}
controller.shuffleLibrary(source, game);
}
return true;
}
return false;
}
use of mage.target.common.TargetCardInLibrary in project mage by magefree.
the class EnigmaticIncarnationEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player player = game.getPlayer(source.getControllerId());
if (player == null || game.getBattlefield().count(filter, source.getSourceId(), source.getControllerId(), game) == 0 || !player.chooseUse(outcome, "Sacrifice an enchantment?", source, game)) {
return false;
}
TargetPermanent target = new TargetPermanent(0, 1, filter, true);
player.choose(outcome, target, source.getSourceId(), game);
Permanent permanent = game.getPermanent(target.getFirstTarget());
if (permanent == null) {
return false;
}
game.getState().processAction(game);
int cmc = permanent.getManaValue();
if (!permanent.sacrifice(source, game)) {
return false;
}
FilterCard filterCard = new FilterCreatureCard("creature card with mana value " + (cmc + 1));
filterCard.add(new ManaValuePredicate(ComparisonType.EQUAL_TO, cmc + 1));
return new SearchLibraryPutInPlayEffect(new TargetCardInLibrary(filterCard)).apply(game, source);
}
use of mage.target.common.TargetCardInLibrary in project mage by magefree.
the class GigantiformEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
TargetCardInLibrary target = new TargetCardInLibrary(filter);
if (controller != null && controller.searchLibrary(target, source, game)) {
Card card = controller.getLibrary().getCard(target.getFirstTarget(), game);
if (card != null) {
controller.moveCards(card, Zone.BATTLEFIELD, source, game);
}
controller.shuffleLibrary(source, game);
return true;
}
return false;
}
use of mage.target.common.TargetCardInLibrary in project mage by magefree.
the class GrimReminderWatcher method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
MageObject sourceObject = source.getSourceObject(game);
if (controller != null && sourceObject != null) {
TargetCardInLibrary target = new TargetCardInLibrary(StaticFilters.FILTER_CARD_NON_LAND);
if (controller.searchLibrary(target, source, game)) {
Card card = game.getCard(target.getFirstTarget());
if (card != null) {
Cards cardsToReveal = new CardsImpl(card);
controller.revealCards(sourceObject.getIdName(), cardsToReveal, game);
String cardName = card.getName();
GrimReminderWatcher watcher = game.getState().getWatcher(GrimReminderWatcher.class);
if (watcher != null) {
for (UUID playerId : watcher.getPlayersCastSpell(cardName)) {
Player player = game.getPlayer(playerId);
if (player != null) {
player.loseLife(6, game, source, false);
}
}
}
}
}
controller.shuffleLibrary(source, game);
return true;
}
return false;
}
Aggregations