use of mage.target.common.TargetCardInGraveyard in project mage by magefree.
the class DawnbreakReclaimerEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
/**
* 04.11.2015 If any opponent has a creature card in their graveyard as
* Dawnbreak Reclaimer's ability resolves, then you must choose one of
* those cards. You can't choose a different opponent with no creature
* cards in their graveyard to avoid returning one of those cards.
*
* 04.11.2015 If there are no creature cards in any opponent's graveyard
* as Dawnbreak Reclaimer's ability resolves, you'll still have the
* option to return a creature card from your graveyard to the
* battlefield. You choose which opponent will choose a creature card in
* your graveyard.
*/
Player controller = game.getPlayer(source.getControllerId());
MageObject sourceObject = source.getSourceObject(game);
if (controller != null && sourceObject != null) {
FilterCreatureCard filter = new FilterCreatureCard("a creature card in an opponent's graveyard");
filter.add(TargetController.OPPONENT.getOwnerPredicate());
TargetCard chosenCreatureOpponentGraveyard = new TargetCard(Zone.GRAVEYARD, filter);
Player opponent = null;
Card cardOpponentGraveyard = null;
chosenCreatureOpponentGraveyard.setNotTarget(true);
if (chosenCreatureOpponentGraveyard.canChoose(source.getSourceId(), source.getControllerId(), game)) {
controller.choose(Outcome.Detriment, chosenCreatureOpponentGraveyard, source.getSourceId(), game);
cardOpponentGraveyard = game.getCard(chosenCreatureOpponentGraveyard.getFirstTarget());
if (cardOpponentGraveyard != null) {
opponent = game.getPlayer(cardOpponentGraveyard.getOwnerId());
game.informPlayers(sourceObject.getLogName() + ": " + controller.getLogName() + " has chosen " + cardOpponentGraveyard.getIdName() + " of " + opponent.getLogName());
}
}
if (opponent == null) {
// if no card from opponent was available controller has to chose an opponent to select a creature card in controllers graveyard
TargetOpponent targetOpponent = new TargetOpponent(true);
controller.choose(outcome, targetOpponent, source.getSourceId(), game);
opponent = game.getPlayer(targetOpponent.getFirstTarget());
if (opponent != null) {
game.informPlayers(sourceObject.getLogName() + ": " + controller.getLogName() + " has chosen " + opponent.getLogName() + " to select a creature card from their graveyard");
}
}
if (opponent != null) {
FilterCreatureCard filterCreatureCard = new FilterCreatureCard("a creature card in " + controller.getName() + "'s the graveyard");
filterCreatureCard.add(new OwnerIdPredicate(controller.getId()));
TargetCardInGraveyard targetControllerGaveyard = new TargetCardInGraveyard(filterCreatureCard);
targetControllerGaveyard.setNotTarget(true);
Card controllerCreatureCard = null;
if (targetControllerGaveyard.canChoose(source.getSourceId(), opponent.getId(), game) && opponent.choose(outcome, targetControllerGaveyard, source.getSourceId(), game)) {
controllerCreatureCard = game.getCard(targetControllerGaveyard.getFirstTarget());
if (controllerCreatureCard != null) {
game.informPlayers(sourceObject.getLogName() + ": " + opponent.getLogName() + " has chosen " + controllerCreatureCard.getIdName() + " of " + controller.getLogName());
}
}
Set<Card> cards = new HashSet<>();
if (cardOpponentGraveyard != null) {
cards.add(cardOpponentGraveyard);
}
if (controllerCreatureCard != null) {
cards.add(controllerCreatureCard);
}
if (!cards.isEmpty()) {
if (controller.chooseUse(outcome, "Return those cards to the battlefield under their owners' control?", "Opponent's creature card: " + (cardOpponentGraveyard == null ? "none" : cardOpponentGraveyard.getLogName()) + ", your creature card: " + (controllerCreatureCard == null ? "none" : controllerCreatureCard.getLogName()), null, null, source, game)) {
controller.moveCards(cards, Zone.BATTLEFIELD, source, game, false, false, true, null);
}
}
}
return true;
}
return false;
}
use of mage.target.common.TargetCardInGraveyard in project mage by magefree.
the class DredgeTheMireEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
if (controller == null) {
return false;
}
Cards cards = new CardsImpl();
for (UUID opponentId : game.getOpponents(source.getControllerId())) {
Player player = game.getPlayer(opponentId);
if (player == null || player.getGraveyard().count(StaticFilters.FILTER_CARD_CREATURE, game) == 0) {
continue;
}
TargetCard target = new TargetCardInGraveyard(StaticFilters.FILTER_CARD_CREATURE_YOUR_GRAVEYARD);
target.setNotTarget(true);
if (!player.choose(outcome, player.getGraveyard(), target, game)) {
continue;
}
cards.add(target.getFirstTarget());
}
return controller.moveCards(cards, Zone.BATTLEFIELD, source, game);
}
use of mage.target.common.TargetCardInGraveyard in project mage by magefree.
the class LilianaTheNecromancerEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player player = game.getPlayer(source.getControllerId());
if (player == null) {
return false;
}
Target target = new TargetCardInGraveyard(0, 2, filter);
target.setNotTarget(true);
if (!player.choose(outcome, target, source.getSourceId(), game)) {
return false;
}
Cards cardsToMove = new CardsImpl();
for (UUID targetId : target.getTargets()) {
Card card = game.getCard(targetId);
if (card != null) {
cardsToMove.add(card);
}
}
return player.moveCards(cardsToMove, Zone.BATTLEFIELD, source, game);
}
use of mage.target.common.TargetCardInGraveyard in project mage by magefree.
the class ScroungeEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
Player opponent = game.getPlayer(targetPointer.getFirst(game, source));
if (controller != null && opponent != null) {
FilterArtifactCard filter = new FilterArtifactCard();
filter.add(new OwnerIdPredicate(opponent.getId()));
TargetCardInGraveyard chosenCard = new TargetCardInGraveyard(filter);
chosenCard.setNotTarget(true);
if (chosenCard.canChoose(source.getSourceId(), opponent.getId(), game)) {
opponent.chooseTarget(Outcome.ReturnToHand, chosenCard, source, game);
Card card = game.getCard(chosenCard.getFirstTarget());
if (card != null) {
game.informPlayers("Scrounge: " + opponent.getLogName() + " has chosen " + card.getLogName());
Cards cardsToMove = new CardsImpl();
cardsToMove.add(card);
controller.moveCards(cardsToMove, Zone.BATTLEFIELD, source, game);
}
}
return true;
}
return false;
}
use of mage.target.common.TargetCardInGraveyard in project mage by magefree.
the class ScrabblingClawsEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player targetPlayer = game.getPlayer(source.getFirstTarget());
if (targetPlayer == null) {
return false;
}
FilterCard filter = new FilterCard("card from your graveyard");
filter.add(new OwnerIdPredicate(targetPlayer.getId()));
TargetCardInGraveyard target = new TargetCardInGraveyard(filter);
if (!targetPlayer.chooseTarget(Outcome.Exile, target, source, game)) {
return false;
}
Card card = game.getCard(target.getFirstTarget());
return card != null && targetPlayer.moveCards(card, Zone.EXILED, source, game);
}
Aggregations