* Dawnbreak Reclaimer - Fixed effect handling that could lead to blocked games.

This commit is contained in:
LevelX2 2016-03-21 15:08:35 +01:00
parent 285cff0b33
commit 7cd7f392a8

View file

@ -49,6 +49,7 @@ import mage.game.Game;
import mage.players.Player; import mage.players.Player;
import mage.target.common.TargetCardInGraveyard; import mage.target.common.TargetCardInGraveyard;
import mage.target.common.TargetCardInOpponentsGraveyard; import mage.target.common.TargetCardInOpponentsGraveyard;
import mage.target.common.TargetOpponent;
import mage.util.MessageToClient; import mage.util.MessageToClient;
/** /**
@ -99,34 +100,72 @@ class DawnbreakReclaimerEffect extends OneShotEffect {
@Override @Override
public boolean apply(Game game, Ability source) { public boolean apply(Game game, Ability source) {
/**
* 04.11.2015 If any opponent has a creature card in his or her
* graveyard as Dawnbreak Reclaimers ability resolves, then you must
* choose one of those cards. You cant choose a different opponent with
* no creature cards in his or her graveyard to avoid returning one of
* those cards.
*
* 04.11.2015 If there are no creature cards in any opponents graveyard
* as Dawnbreak Reclaimers ability resolves, youll 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()); Player controller = game.getPlayer(source.getControllerId());
MageObject sourceObject = source.getSourceObject(game); MageObject sourceObject = source.getSourceObject(game);
if (controller != null && sourceObject != null) { if (controller != null && sourceObject != null) {
TargetCardInOpponentsGraveyard targetCreature = new TargetCardInOpponentsGraveyard(new FilterCreatureCard("a creature card in an opponent's graveyard")); TargetCardInOpponentsGraveyard targetOpponentGraveyard = new TargetCardInOpponentsGraveyard(new FilterCreatureCard("a creature card in an opponent's graveyard"));
if (controller.choose(Outcome.Detriment, targetCreature, source.getSourceId(), game)) { Player opponent = null;
Card creatureCard = game.getCard(targetCreature.getFirstTarget()); Card cardOpponentGraveyard = null;
Player opponent = game.getPlayer(creatureCard.getOwnerId()); if (targetOpponentGraveyard.canChoose(source.getSourceId(), source.getControllerId(), game)) {
controller.choose(Outcome.Detriment, targetOpponentGraveyard, source.getSourceId(), game);
cardOpponentGraveyard = game.getCard(targetOpponentGraveyard.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) { if (opponent != null) {
game.informPlayers(sourceObject.getLogName() + ": " + controller.getLogName() + " has chosen " + creatureCard.getIdName() + " of " + opponent.getLogName()); game.informPlayers(sourceObject.getLogName() + ": " + controller.getLogName() + " has chosen " + opponent.getLogName() + " to select a creature card from his or her graveyard");
FilterCreatureCard filter = new FilterCreatureCard("a creature card in " + controller.getName() + "'s the graveyard"); }
filter.add(new OwnerIdPredicate(controller.getId())); }
TargetCardInGraveyard targetCard = new TargetCardInGraveyard(filter); if (opponent != null) {
targetCard.setNotTarget(true); FilterCreatureCard filter = new FilterCreatureCard("a creature card in " + controller.getName() + "'s the graveyard");
if (opponent.choose(outcome, targetCard, source.getSourceId(), game)) { filter.add(new OwnerIdPredicate(controller.getId()));
Card controllerCreatureCard = game.getCard(targetCard.getFirstTarget()); TargetCardInGraveyard targetControllerGaveyard = new TargetCardInGraveyard(filter);
if (controllerCreatureCard != null) { targetControllerGaveyard.setNotTarget(true);
MessageToClient message = new MessageToClient("Return those cards to the battlefield under their owners' control?", Card controllerCreatureCard = null;
"Opponent's creature card: " + creatureCard.getLogName() + " - Your creature: " + controllerCreatureCard.getLogName()); if (targetControllerGaveyard.canChoose(source.getSourceId(), opponent.getId(), game)
if (controller.chooseUse(outcome, message, source, game)) { && opponent.choose(outcome, targetControllerGaveyard, source.getSourceId(), game)) {
Set<Card> cards = new HashSet<>(); controllerCreatureCard = game.getCard(targetControllerGaveyard.getFirstTarget());
cards.add(creatureCard); if (controllerCreatureCard != null) {
cards.add(controllerCreatureCard); game.informPlayers(sourceObject.getLogName() + ": " + opponent.getLogName() + " has chosen " + controllerCreatureCard.getIdName() + " of " + controller.getLogName());
opponent.moveCards(cards, Zone.BATTLEFIELD, source, game, false, false, true, null); }
} }
} Set<Card> cards = new HashSet<>();
if (cardOpponentGraveyard != null) {
cards.add(cardOpponentGraveyard);
}
if (controllerCreatureCard != null) {
cards.add(controllerCreatureCard);
}
if (!cards.isEmpty()) {
MessageToClient message = new MessageToClient("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()));
if (controller.chooseUse(outcome, message, source, game)) {
controller.moveCards(cards, Zone.BATTLEFIELD, source, game, false, false, true, null);
} }
} }
} }
return true; return true;
} }
return false; return false;