use of mage.target.common.TargetCardInYourGraveyard in project mage by magefree.
the class RunedCrownEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
if (controller == null) {
return false;
}
Card card = null;
Zone zone = null;
if (controller.chooseUse(Outcome.Neutral, "Search your graveyard for a Rune card?", source, game)) {
TargetCardInYourGraveyard target = new TargetCardInYourGraveyard(filter);
target.setNotTarget(true);
if (controller.choose(Outcome.PutCardInPlay, controller.getGraveyard(), target, game)) {
card = game.getCard(target.getFirstTarget());
if (card != null) {
zone = Zone.GRAVEYARD;
}
}
}
if (card == null && controller.chooseUse(Outcome.Neutral, "Search your hand for a Rune card?", source, game)) {
TargetCardInHand target = new TargetCardInHand(filter);
if (controller.choose(Outcome.PutCardInPlay, controller.getHand(), target, game)) {
card = game.getCard(target.getFirstTarget());
if (card != null) {
zone = Zone.HAND;
}
}
}
if (card == null) {
TargetCardInLibrary target = new TargetCardInLibrary(filter);
if (controller.searchLibrary(target, source, game)) {
card = game.getCard(target.getFirstTarget());
if (card != null) {
zone = Zone.LIBRARY;
}
}
controller.shuffleLibrary(source, game);
}
// aura card found - attach it
if (card == null) {
return true;
}
Permanent permanent = source.getSourcePermanentIfItStillExists(game);
if (permanent != null) {
game.getState().setValue("attachTo:" + card.getId(), permanent);
}
controller.moveCards(card, Zone.BATTLEFIELD, source, game);
if (permanent != null) {
return permanent.addAttachment(card.getId(), source, game);
}
return true;
}
use of mage.target.common.TargetCardInYourGraveyard in project mage by magefree.
the class SuturedGhoulEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
Permanent permanent = game.getPermanentEntering(source.getSourceId());
if (permanent == null || controller == null) {
return false;
}
if (!controller.getGraveyard().isEmpty()) {
TargetCardInYourGraveyard target = new TargetCardInYourGraveyard(0, Integer.MAX_VALUE, StaticFilters.FILTER_CARD_CREATURES_YOUR_GRAVEYARD);
if (controller.chooseTarget(Outcome.Benefit, target, source, game)) {
int count = 0;
for (UUID uuid : target.getTargets()) {
Card card = controller.getGraveyard().get(uuid, game);
if (card != null) {
card.moveToExile(getId(), permanent.getIdName(), source, game);
permanent.imprint(card.getId(), game);
count++;
}
}
Cards cardsToExile = new CardsImpl(target.getTargets());
controller.moveCards(cardsToExile, Zone.EXILED, source, game);
String msg = count == 1 ? "1 card" : count + "cards";
game.informPlayers(permanent.getLogName() + ": " + controller.getLogName() + " exiled " + msg);
}
} else {
game.informPlayers(permanent.getLogName() + ": No cards in graveyard.");
}
return true;
}
use of mage.target.common.TargetCardInYourGraveyard in project mage by magefree.
the class GateToTheAfterlifeEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
if (controller == null) {
return false;
}
FilterCard filter = new FilterCard("card named " + cardName);
filter.add(new NamePredicate(cardName));
Card card = null;
// Graveyard check
if (controller.chooseUse(Outcome.Benefit, "Search your graveyard for " + cardName + "?", source, game)) {
TargetCardInYourGraveyard target = new TargetCardInYourGraveyard(1, 1, filter, true);
if (controller.choose(outcome, controller.getGraveyard(), target, game)) {
card = game.getCard(target.getFirstTarget());
}
}
// Hand check
if (card == null && controller.chooseUse(Outcome.Benefit, "Search your hand for " + cardName + "?", source, game)) {
TargetCardInHand target = new TargetCardInHand(0, 1, filter);
if (controller.choose(Outcome.PutCardInPlay, controller.getHand(), target, game)) {
card = game.getCard(target.getFirstTarget());
}
}
// Library check
boolean librarySearched = false;
if (card == null && controller.chooseUse(Outcome.Benefit, "Search your library for " + cardName + "?", source, game)) {
librarySearched = true;
TargetCardInLibrary target = new TargetCardInLibrary(filter);
if (controller.searchLibrary(target, source, game)) {
card = game.getCard(target.getFirstTarget());
}
controller.shuffleLibrary(source, game);
}
if (card != null) {
controller.moveCards(card, Zone.BATTLEFIELD, source, game);
}
if (librarySearched) {
controller.shuffleLibrary(source, game);
}
return true;
}
use of mage.target.common.TargetCardInYourGraveyard in project mage by magefree.
the class GruesomeMenagerieEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player player = game.getPlayer(source.getControllerId());
if (player == null) {
return false;
}
Cards cards = new CardsImpl();
Target target;
target = new TargetCardInYourGraveyard(filter1);
target.setNotTarget(true);
if (player.choose(outcome, target, source.getSourceId(), game)) {
Card card = game.getCard(target.getFirstTarget());
if (card != null) {
cards.add(card);
}
}
target = new TargetCardInYourGraveyard(filter2);
target.setNotTarget(true);
if (player.choose(outcome, target, source.getSourceId(), game)) {
Card card = game.getCard(target.getFirstTarget());
if (card != null) {
cards.add(card);
}
}
target = new TargetCardInYourGraveyard(filter3);
target.setNotTarget(true);
if (player.choose(outcome, target, source.getSourceId(), game)) {
Card card = game.getCard(target.getFirstTarget());
if (card != null) {
cards.add(card);
}
}
return player.moveCards(cards, Zone.BATTLEFIELD, source, game);
}
use of mage.target.common.TargetCardInYourGraveyard in project mage by magefree.
the class InventiveIterationEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player player = game.getPlayer(source.getControllerId());
if (player == null) {
return false;
}
Card card;
switch(player.getGraveyard().count(StaticFilters.FILTER_CARD_ARTIFACT, game)) {
case 0:
player.drawCards(1, source, game);
return true;
case 1:
card = RandomUtil.randomFromCollection(player.getGraveyard().getCards(StaticFilters.FILTER_CARD_ARTIFACT, game));
break;
default:
TargetCard target = new TargetCardInYourGraveyard(StaticFilters.FILTER_CARD_ARTIFACT);
target.setNotTarget(true);
player.choose(outcome, player.getGraveyard(), target, game);
card = game.getCard(target.getFirstTarget());
}
player.moveCards(card, Zone.HAND, source, game);
return true;
}
Aggregations