From 9609480109fafbcad748e1200f84fa9b796b3481 Mon Sep 17 00:00:00 2001 From: LevelX2 Date: Sun, 29 Jun 2014 13:35:28 +0200 Subject: [PATCH] * Cruel Ultimatum - Fixed that wrongly creatures in all graveyards could be selected. --- .../src/mage/player/human/HumanPlayer.java | 7 ++-- .../sets/shardsofalara/CruelUltimatum.java | 36 +++++++++++-------- .../common/TargetCardInYourGraveyard.java | 26 ++++++++++++++ 3 files changed, 52 insertions(+), 17 deletions(-) diff --git a/Mage.Server.Plugins/Mage.Player.Human/src/mage/player/human/HumanPlayer.java b/Mage.Server.Plugins/Mage.Player.Human/src/mage/player/human/HumanPlayer.java index f5d24b3ec7..0cd40e18b8 100644 --- a/Mage.Server.Plugins/Mage.Player.Human/src/mage/player/human/HumanPlayer.java +++ b/Mage.Server.Plugins/Mage.Player.Human/src/mage/player/human/HumanPlayer.java @@ -239,6 +239,9 @@ public class HumanPlayer extends PlayerImpl { updateGameStatePriority("choose(5)", game); while (!abort) { Set cards = target.possibleTargets(null, playerId, game); + if (cards == null || cards.isEmpty()) { + return false; + } boolean required = target.isRequired(sourceId, game); if (target.getTargets().size() >= target.getNumberOfTargets()) { required = false; @@ -278,9 +281,7 @@ public class HumanPlayer extends PlayerImpl { if (!target.isRequired(sourceId, game)) { return false; } - if (cards == null || cards.isEmpty()) { - return false; - } + } } return false; diff --git a/Mage.Sets/src/mage/sets/shardsofalara/CruelUltimatum.java b/Mage.Sets/src/mage/sets/shardsofalara/CruelUltimatum.java index aee2fb0b4a..e5f2f46bd1 100644 --- a/Mage.Sets/src/mage/sets/shardsofalara/CruelUltimatum.java +++ b/Mage.Sets/src/mage/sets/shardsofalara/CruelUltimatum.java @@ -27,17 +27,20 @@ */ package mage.sets.shardsofalara; -import mage.abilities.effects.common.discard.DiscardTargetEffect; import java.util.UUID; +import mage.abilities.Ability; +import mage.abilities.effects.OneShotEffect; +import mage.abilities.effects.common.DrawCardSourceControllerEffect; +import mage.abilities.effects.common.GainLifeEffect; +import mage.abilities.effects.common.LoseLifeTargetEffect; +import mage.abilities.effects.common.SacrificeEffect; +import mage.abilities.effects.common.discard.DiscardTargetEffect; +import mage.cards.Card; +import mage.cards.CardImpl; import mage.constants.CardType; import mage.constants.Outcome; import mage.constants.Rarity; import mage.constants.Zone; -import mage.abilities.Ability; -import mage.abilities.effects.OneShotEffect; -import mage.abilities.effects.common.*; -import mage.cards.Card; -import mage.cards.CardImpl; import mage.filter.common.FilterCreatureCard; import mage.filter.common.FilterCreaturePermanent; import mage.game.Game; @@ -59,7 +62,8 @@ public class CruelUltimatum extends CardImpl { this.color.setBlue(true); this.color.setBlack(true); - // Target opponent sacrifices a creature, discards three cards, then loses 5 life. You return a creature card from your graveyard to your hand, draw three cards, then gain 5 life. + // Target opponent sacrifices a creature, discards three cards, then loses 5 life. + // You return a creature card from your graveyard to your hand, draw three cards, then gain 5 life. this.getSpellAbility().addTarget(new TargetOpponent()); this.getSpellAbility().addEffect(new SacrificeEffect(new FilterCreaturePermanent(), 1, "Target opponent")); this.getSpellAbility().addEffect(new DiscardTargetEffect(3)); @@ -99,13 +103,17 @@ class CruelUltimatumEffect extends OneShotEffect { @Override public boolean apply(Game game, Ability source) { Player player = game.getPlayer(source.getControllerId()); - TargetCardInYourGraveyard target = new TargetCardInYourGraveyard(new FilterCreatureCard("creature card from your graveyard")); - if (player != null && player.choose(Outcome.ReturnToHand, target, source.getSourceId(), game)) { - Card card = game.getCard(target.getFirstTarget()); - if (card != null) { - return card.moveToZone(Zone.HAND, source.getId(), game, true); - } + if (player == null) { + return false; } - return false; + TargetCardInYourGraveyard target = new TargetCardInYourGraveyard(new FilterCreatureCard("creature card from your graveyard")); + if (target.canChoose(source.getSourceId(), source.getControllerId(), game) && player.choose(Outcome.ReturnToHand, target, source.getSourceId(), game)) { + Card card = game.getCard(target.getFirstTarget()); + if (card == null) { + return false; + } + return player.moveCardToHandWithInfo(card, source.getSourceId(), game, Zone.GRAVEYARD); + } + return true; } } diff --git a/Mage/src/mage/target/common/TargetCardInYourGraveyard.java b/Mage/src/mage/target/common/TargetCardInYourGraveyard.java index 5553511f69..6767a71eca 100644 --- a/Mage/src/mage/target/common/TargetCardInYourGraveyard.java +++ b/Mage/src/mage/target/common/TargetCardInYourGraveyard.java @@ -28,10 +28,13 @@ package mage.target.common; +import java.util.HashSet; +import java.util.Set; import java.util.UUID; import mage.constants.Zone; import mage.abilities.Ability; import mage.cards.Card; +import mage.cards.Cards; import mage.filter.FilterCard; import mage.game.Game; import mage.game.events.GameEvent; @@ -87,6 +90,29 @@ public class TargetCardInYourGraveyard extends TargetCard { return false; } + @Override + public Set possibleTargets(UUID sourceId, UUID sourceControllerId, Game game) { + Set possibleTargets = new HashSet<>(); + Player player = game.getPlayer(sourceControllerId); + for (Card card : player.getGraveyard().getCards(filter, game)) { + if (sourceId == null || isNotTarget() || !game.replaceEvent(GameEvent.getEvent(GameEvent.EventType.TARGET, card.getId(), sourceId, sourceControllerId))) { + possibleTargets.add(card.getId()); + } + } + return possibleTargets; + } + + @Override + public Set possibleTargets(UUID sourceControllerId, Cards cards, Game game) { + Set possibleTargets = new HashSet<>(); + Player player = game.getPlayer(sourceControllerId); + for (Card card: cards.getCards(filter, game)) { + if (player.getGraveyard().getCards(game).contains(card)) { + possibleTargets.add(card.getId()); + } + } + return possibleTargets; + } /** * Checks if there are enough {@link Card} that can be selected. *