use of mage.target.common.TargetCardInLibrary in project mage by magefree.
the class EldritchEvolutionEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Permanent sacrificedPermanent = null;
for (Cost cost : source.getCosts()) {
if (cost instanceof SacrificeTargetCost) {
SacrificeTargetCost sacrificeCost = (SacrificeTargetCost) cost;
if (!sacrificeCost.getPermanents().isEmpty()) {
sacrificedPermanent = sacrificeCost.getPermanents().get(0);
}
break;
}
}
Player controller = game.getPlayer(source.getControllerId());
if (sacrificedPermanent != null && controller != null) {
int newConvertedCost = sacrificedPermanent.getManaValue() + 2;
FilterCard filter = new FilterCard("creature card with mana value " + newConvertedCost + " or less");
filter.add(new ManaValuePredicate(ComparisonType.FEWER_THAN, newConvertedCost + 1));
filter.add(CardType.CREATURE.getPredicate());
TargetCardInLibrary target = new TargetCardInLibrary(filter);
if (controller.searchLibrary(target, source, game)) {
Card card = controller.getLibrary().getCard(target.getFirstTarget(), game);
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 EarwigSquadEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player opponent = game.getPlayer(source.getFirstTarget());
Player player = game.getPlayer(source.getControllerId());
if (player != null && opponent != null) {
TargetCardInLibrary target = new TargetCardInLibrary(0, 3, new FilterCard("cards from opponents library to exile"));
if (player.searchLibrary(target, source, game, opponent.getId())) {
List<UUID> targets = target.getTargets();
for (UUID targetId : targets) {
Card card = opponent.getLibrary().remove(targetId, game);
if (card != null) {
player.moveCardToExileWithInfo(card, null, null, source, game, Zone.LIBRARY, true);
}
}
}
opponent.shuffleLibrary(source, game);
return true;
}
return false;
}
use of mage.target.common.TargetCardInLibrary in project mage by magefree.
the class ExtractEffect 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(1, 1, filter);
if (player.searchLibrary(target, source, game, targetPlayer.getId())) {
Card card = targetPlayer.getLibrary().remove(target.getFirstTarget(), game);
if (card != null) {
player.moveCardToExileWithInfo(card, null, null, source, game, Zone.LIBRARY, true);
}
}
targetPlayer.shuffleLibrary(source, game);
return true;
}
return false;
}
use of mage.target.common.TargetCardInLibrary in project mage by magefree.
the class InstrumentOfTheBardsEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
Permanent permanent = game.getPermanentOrLKIBattlefield(source.getSourceId());
if (controller == null || permanent == null) {
return false;
}
int counters = permanent.getCounters(game).getCount(CounterType.HARMONY);
FilterCreatureCard filter = new FilterCreatureCard("creature card with mana value " + counters);
filter.add(new ManaValuePredicate(ComparisonType.EQUAL_TO, counters));
TargetCardInLibrary target = new TargetCardInLibrary(filter);
if (controller.searchLibrary(target, source, game)) {
Card card = game.getCard(target.getFirstTarget());
if (card != null) {
controller.revealCards(permanent.getIdName(), new CardsImpl(card), game);
controller.moveCards(card, Zone.HAND, source, game);
if (card.isLegendary()) {
new TreasureToken().putOntoBattlefield(1, game, source, source.getControllerId());
}
}
}
controller.shuffleLibrary(source, game);
return true;
}
use of mage.target.common.TargetCardInLibrary in project mage by magefree.
the class InsidiousDreamsEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
MageObject sourceObject = game.getObject(source.getSourceId());
int amount = GetXValue.instance.calculate(game, source, this);
if (controller != null && sourceObject != null) {
TargetCardInLibrary target = new TargetCardInLibrary(0, amount, new FilterCard());
if (controller.searchLibrary(target, source, game)) {
Cards chosen = new CardsImpl();
for (UUID cardId : target.getTargets()) {
Card card = controller.getLibrary().remove(cardId, game);
chosen.add(card);
}
controller.shuffleLibrary(source, game);
TargetCard targetToLib = new TargetCard(Zone.LIBRARY, new FilterCard(textTop));
while (chosen.size() > 1 && controller.canRespond()) {
controller.choose(Outcome.Neutral, chosen, targetToLib, game);
Card card = chosen.get(targetToLib.getFirstTarget(), game);
if (card != null) {
chosen.remove(card);
controller.moveCardToLibraryWithInfo(card, source, game, Zone.LIBRARY, true, false);
}
targetToLib.clearChosen();
}
if (chosen.size() == 1) {
Card card = chosen.get(chosen.iterator().next(), game);
controller.moveCardToLibraryWithInfo(card, source, game, Zone.LIBRARY, true, false);
}
}
return true;
}
return false;
}
Aggregations