use of mage.target.common.TargetCardInLibrary in project mage by magefree.
the class FinalPartingEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
if (controller != null) {
// Unlike Jarad's Orders, which this mostly copies, you can't fail to find
TargetCardInLibrary target = new TargetCardInLibrary(2, 2, new FilterCard());
if (controller.searchLibrary(target, source, game)) {
if (!target.getTargets().isEmpty()) {
Cards searched = new CardsImpl();
for (UUID cardId : target.getTargets()) {
Card card = controller.getLibrary().getCard(cardId, game);
searched.add(card);
}
if (target.getTargets().size() == 2) {
TargetCard target2 = new TargetCard(Zone.LIBRARY, filter);
controller.choose(Outcome.Benefit, searched, target2, game);
Card card = searched.get(target2.getFirstTarget(), game);
controller.moveCards(card, Zone.HAND, source, game);
searched.remove(card);
Set<Card> cards = searched.getCards(game);
card = cards.isEmpty() ? null : cards.iterator().next();
controller.moveCards(card, Zone.GRAVEYARD, source, game);
} else if (target.getTargets().size() == 1) {
Set<Card> cards = searched.getCards(game);
Card card = cards.isEmpty() ? null : cards.iterator().next();
controller.moveCards(card, Zone.HAND, source, game);
}
}
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 GoblinTutorEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
if (controller != null) {
int amount = controller.rollDice(outcome, source, game, 6);
Effect effect = null;
// 6 - An instant or sorcery card
if (amount == 2) {
effect = new SearchLibraryPutInHandEffect(new TargetCardInLibrary(0, 1, filter), true);
} else if (amount == 3) {
effect = new SearchLibraryPutInHandEffect(new TargetCardInLibrary(0, 1, StaticFilters.FILTER_CARD_ENTCHANTMENT), true);
} else if (amount == 4) {
effect = new SearchLibraryPutInHandEffect(new TargetCardInLibrary(0, 1, StaticFilters.FILTER_CARD_ARTIFACT), true);
} else if (amount == 5) {
effect = new SearchLibraryPutInHandEffect(new TargetCardInLibrary(0, 1, StaticFilters.FILTER_CARD_CREATURE), true);
} else if (amount == 6) {
effect = new SearchLibraryPutInHandEffect(new TargetCardInLibrary(0, 1, new FilterInstantOrSorceryCard()), true);
}
if (effect != null) {
effect.apply(game, source);
return true;
}
}
return false;
}
use of mage.target.common.TargetCardInLibrary in project mage by magefree.
the class LifesFinaleEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
List<Permanent> permanents = game.getBattlefield().getActivePermanents(StaticFilters.FILTER_PERMANENT_CREATURES, source.getControllerId(), game);
for (Permanent permanent : permanents) {
permanent.destroy(source, game, false);
}
Player opponent = game.getPlayer(source.getFirstTarget());
Player player = game.getPlayer(source.getControllerId());
if (player != null && opponent != null) {
TargetCardInLibrary target = new TargetCardInLibrary(0, 3, new FilterCreatureCard("creature cards from their library to put in their graveyard"));
if (player.searchLibrary(target, source, game, opponent.getId())) {
player.moveCards(new CardsImpl(target.getTargets()), Zone.GRAVEYARD, source, game);
}
opponent.shuffleLibrary(source, game);
return true;
}
return false;
}
use of mage.target.common.TargetCardInLibrary in project mage by magefree.
the class NecromentiaEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
String cardName = (String) game.getState().getValue(source.getSourceId().toString() + ChooseACardNameEffect.INFO_KEY);
Player controller = game.getPlayer(source.getControllerId());
if (cardName != null && controller != null) {
FilterCard filter = new FilterCard("card named " + cardName);
filter.add(new NamePredicate(cardName));
Player targetPlayer = game.getPlayer(getTargetPointer().getFirst(game, source));
// cards in Graveyard
int cardsCount = (cardName.isEmpty() ? 0 : targetPlayer.getGraveyard().count(filter, game));
if (cardsCount > 0) {
filter.setMessage("card named " + cardName + " in the graveyard of " + targetPlayer.getName());
TargetCard target = new TargetCard(0, cardsCount, Zone.GRAVEYARD, filter);
if (controller.choose(Outcome.Exile, targetPlayer.getGraveyard(), target, game)) {
controller.moveCards(new CardsImpl(target.getTargets()), Zone.EXILED, source, game);
}
}
// cards in Hand
int numberOfCardsExiledFromHand = 0;
cardsCount = (cardName.isEmpty() ? 0 : targetPlayer.getHand().count(filter, game));
if (cardsCount > 0) {
filter.setMessage("card named " + cardName + " in the hand of " + targetPlayer.getName());
TargetCard target = new TargetCard(0, cardsCount, Zone.HAND, filter);
if (controller.choose(Outcome.Exile, targetPlayer.getHand(), target, game)) {
numberOfCardsExiledFromHand = target.getTargets().size();
controller.moveCards(new CardsImpl(target.getTargets()), Zone.EXILED, source, game);
}
} else {
targetPlayer.revealCards(targetPlayer.getName() + "'s Hand", targetPlayer.getHand(), game);
}
// cards in Library
Cards cardsInLibrary = new CardsImpl();
cardsInLibrary.addAll(targetPlayer.getLibrary().getCards(game));
cardsCount = (cardName.isEmpty() ? 0 : cardsInLibrary.count(filter, game));
if (cardsCount > 0) {
filter.setMessage("card named " + cardName + " in the library of " + targetPlayer.getLogName());
TargetCardInLibrary targetLib = new TargetCardInLibrary(0, cardsCount, filter);
if (controller.choose(Outcome.Exile, cardsInLibrary, targetLib, game)) {
controller.moveCards(new CardsImpl(targetLib.getTargets()), Zone.EXILED, source, game);
}
} else {
targetPlayer.revealCards(targetPlayer.getName() + "'s Library", new CardsImpl(new HashSet<>(targetPlayer.getLibrary().getCards(game))), game);
}
targetPlayer.shuffleLibrary(source, game);
if (numberOfCardsExiledFromHand > 0) {
game.getState().applyEffects(game);
Token zombieToken = new ZombieToken();
zombieToken.putOntoBattlefield(numberOfCardsExiledFromHand, game, source, targetPlayer.getId());
}
return true;
}
return false;
}
use of mage.target.common.TargetCardInLibrary in project mage by magefree.
the class SettleTheWreckageEffect 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) {
return false;
}
int attackers = 0;
Set<Card> toExile = new HashSet<>();
Iterator<UUID> creatureIds = game.getCombat().getAttackers().iterator();
while (creatureIds.hasNext()) {
Permanent creature = game.getPermanent(creatureIds.next());
if (creature != null && creature.isControlledBy(player.getId())) {
toExile.add(creature);
attackers++;
}
}
controller.moveCards(toExile, Zone.EXILED, source, game);
TargetCardInLibrary target = new TargetCardInLibrary(0, attackers, StaticFilters.FILTER_CARD_BASIC_LAND);
if (player.chooseUse(Outcome.Benefit, "Search for up to " + attackers + " basic land" + ((attackers == 1) ? "" : "s") + "?", source, game) && player.searchLibrary(target, source, game)) {
player.moveCards(new CardsImpl(target.getTargets()).getCards(game), Zone.BATTLEFIELD, source, game, true, false, false, null);
player.shuffleLibrary(source, game);
}
return true;
}
Aggregations