use of mage.target.common.TargetCardInGraveyard in project mage by magefree.
the class SurgicalExtractionEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
// 6/1/2011 "Any number of cards" means just that. If you wish, you can choose to
// leave some or all of the cards with the same name as the targeted card,
// including that card, in the zone they're in.
Card chosenCard = game.getCard(source.getFirstTarget());
Player controller = game.getPlayer(source.getControllerId());
if (chosenCard != null && controller != null) {
Player owner = game.getPlayer(chosenCard.getOwnerId());
if (owner != null) {
String nameToSearch = CardUtil.getCardNameForSameNameSearch(chosenCard);
FilterCard filterNamedCard = new FilterCard("card named " + nameToSearch);
filterNamedCard.add(new NamePredicate(nameToSearch));
// cards in Graveyard
int cardsCount = owner.getGraveyard().count(filterNamedCard, game);
if (cardsCount > 0) {
filterNamedCard.setMessage("card named " + nameToSearch + " in the graveyard of " + owner.getName());
TargetCardInGraveyard target = new TargetCardInGraveyard(0, cardsCount, filterNamedCard);
if (controller.chooseTarget(Outcome.Exile, owner.getGraveyard(), target, source, game)) {
List<UUID> targets = target.getTargets();
for (UUID targetId : targets) {
Card targetCard = owner.getGraveyard().get(targetId, game);
if (targetCard != null) {
controller.moveCardToExileWithInfo(targetCard, null, "", source, game, Zone.GRAVEYARD, true);
}
}
}
}
// cards in Hand
filterNamedCard.setMessage("card named " + nameToSearch + " in the hand of " + owner.getName());
TargetCard targetCardInHand = new TargetCard(0, Integer.MAX_VALUE, Zone.HAND, filterNamedCard);
targetCardInHand.setNotTarget(true);
if (controller.chooseTarget(Outcome.Exile, owner.getHand(), targetCardInHand, source, game)) {
List<UUID> targets = targetCardInHand.getTargets();
for (UUID targetId : targets) {
Card targetCard = owner.getHand().get(targetId, game);
if (targetCard != null) {
controller.moveCardToExileWithInfo(targetCard, null, "", source, game, Zone.HAND, true);
}
}
}
// cards in Library
filterNamedCard.setMessage("card named " + nameToSearch + " in the library of " + owner.getName());
TargetCardInLibrary targetCardInLibrary = new TargetCardInLibrary(0, Integer.MAX_VALUE, filterNamedCard);
if (controller.searchLibrary(targetCardInLibrary, source, game, owner.getId())) {
List<UUID> targets = targetCardInLibrary.getTargets();
for (UUID targetId : targets) {
Card targetCard = owner.getLibrary().getCard(targetId, game);
if (targetCard != null) {
controller.moveCardToExileWithInfo(targetCard, null, "", source, game, Zone.LIBRARY, true);
}
}
}
owner.shuffleLibrary(source, game);
return true;
}
}
return false;
}
use of mage.target.common.TargetCardInGraveyard in project mage by magefree.
the class TakenumaAbandonedMireEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player player = game.getPlayer(source.getControllerId());
if (player == null) {
return false;
}
player.millCards(3, source, game);
if (player.getGraveyard().count(filter, game) < 1) {
return true;
}
TargetCard target = new TargetCardInGraveyard(filter);
target.setNotTarget(true);
player.choose(outcome, player.getGraveyard(), target, game);
return player.moveCards(game.getCard(target.getFirstTarget()), Zone.HAND, source, game);
}
use of mage.target.common.TargetCardInGraveyard in project mage by magefree.
the class WildfireDevilsEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
if (controller == null) {
return false;
}
PlayerList players = game.getState().getPlayersInRange(controller.getId(), game);
if (players == null) {
return false;
}
Player randomPlayer = game.getPlayer(players.get(RandomUtil.nextInt(players.size())));
if (randomPlayer == null) {
return false;
}
game.informPlayers("The chosen random player is " + randomPlayer.getLogName());
if (randomPlayer.getGraveyard().getCards(game).stream().noneMatch(card1 -> card1.isInstantOrSorcery(game))) {
return false;
}
TargetCardInGraveyard targetCard = new TargetCardInGraveyard(StaticFilters.FILTER_CARD_INSTANT_OR_SORCERY);
targetCard.setNotTarget(true);
if (!randomPlayer.choose(Outcome.Discard, randomPlayer.getGraveyard(), targetCard, game)) {
return false;
}
Card card = game.getCard(targetCard.getFirstTarget());
if (card == null) {
return false;
}
randomPlayer.moveCards(card, Zone.EXILED, source, game);
if (game.getState().getZone(card.getId()) != Zone.EXILED) {
return false;
}
Card copiedCard = game.copyCard(card, source, controller.getId());
if (copiedCard == null) {
return false;
}
randomPlayer.moveCards(copiedCard, Zone.EXILED, source, game);
if (!controller.chooseUse(outcome, "Cast the copy of the exiled card?", source, game)) {
return false;
}
game.getState().setValue("PlayFromNotOwnHandZone" + copiedCard.getId(), Boolean.TRUE);
Boolean cardWasCast = controller.cast(controller.chooseAbilityForCast(copiedCard, game, true), game, true, new ApprovingObject(source, game));
game.getState().setValue("PlayFromNotOwnHandZone" + copiedCard.getId(), null);
return cardWasCast;
}
use of mage.target.common.TargetCardInGraveyard in project mage by magefree.
the class ZombieCannibalTriggeredAbility method checkTrigger.
@Override
public boolean checkTrigger(GameEvent event, Game game) {
if (!event.getSourceId().equals(this.sourceId) || !((DamagedPlayerEvent) event).isCombatDamage()) {
return false;
}
Player damagedPlayer = game.getPlayer(event.getTargetId());
if (damagedPlayer == null) {
return false;
}
FilterCard filter = new FilterCard("card in " + damagedPlayer.getName() + "'s graveyard");
filter.add(new OwnerIdPredicate(damagedPlayer.getId()));
TargetCardInGraveyard target = new TargetCardInGraveyard(filter);
this.getTargets().clear();
this.addTarget(target);
return true;
}
use of mage.target.common.TargetCardInGraveyard in project mage by magefree.
the class DranaTheLastBloodchiefCounterEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
Player player = game.getPlayer(targetPointer.getFirst(game, source));
if (controller == null || player == null || controller.getGraveyard().count(filter, game) < 1) {
return false;
}
TargetCard target = new TargetCardInGraveyard(filter);
target.setNotTarget(true);
player.choose(outcome, controller.getGraveyard(), target, game);
Card card = game.getCard(target.getFirstTarget());
if (card == null) {
return false;
}
game.addEffect(new DranaTheLastBloodchiefSubtypeEffect(card, game), source);
game.addEffect(new DranaTheLastBloodchiefCounterEffect(card, game), source);
return controller.moveCards(card, Zone.BATTLEFIELD, source, game);
}
Aggregations