diff --git a/Mage.Sets/src/mage/cards/d/DanithaBenaliasHope.java b/Mage.Sets/src/mage/cards/d/DanithaBenaliasHope.java index 2957f5a5c86..9193a5c64f1 100644 --- a/Mage.Sets/src/mage/cards/d/DanithaBenaliasHope.java +++ b/Mage.Sets/src/mage/cards/d/DanithaBenaliasHope.java @@ -1,17 +1,14 @@ package mage.cards.d; -import java.util.UUID; import mage.MageInt; import mage.abilities.Ability; import mage.abilities.common.EntersBattlefieldTriggeredAbility; import mage.abilities.effects.OneShotEffect; -import mage.cards.Card; -import mage.constants.*; import mage.abilities.keyword.FirstStrikeAbility; -import mage.abilities.keyword.VigilanceAbility; import mage.abilities.keyword.LifelinkAbility; -import mage.cards.CardImpl; -import mage.cards.CardSetInfo; +import mage.abilities.keyword.VigilanceAbility; +import mage.cards.*; +import mage.constants.*; import mage.filter.FilterCard; import mage.filter.predicate.Predicates; import mage.filter.predicate.card.AuraCardCanAttachToPermanentId; @@ -19,8 +16,8 @@ import mage.game.Game; import mage.game.permanent.Permanent; import mage.players.Player; import mage.target.TargetCard; -import mage.target.common.TargetCardInHand; -import mage.target.common.TargetCardInYourGraveyard; + +import java.util.UUID; /** * @@ -84,29 +81,27 @@ class DanithaBenaliasHopeEffect extends OneShotEffect { } Permanent sourcePermanent = source.getSourcePermanentIfItStillExists(game); UUID sourcePermanentId = sourcePermanent == null ? null : sourcePermanent.getId(); + String sourcePermanentName = sourcePermanent == null ? "" : sourcePermanent.getName(); FilterCard filter = new FilterCard("an Aura or Equipment card"); filter.add(Predicates.or( Predicates.and(SubType.AURA.getPredicate(), new AuraCardCanAttachToPermanentId(sourcePermanentId)), SubType.EQUIPMENT.getPredicate() )); - TargetCard target; - if (controller.chooseUse(outcome, "Look in Hand or Graveyard?", null, "Hand", "Graveyard", source, game)) { - target = new TargetCardInHand(filter); - } else { - target = new TargetCardInYourGraveyard(filter); - } + Cards cards = new CardsImpl(); + cards.addAllCards(controller.getHand().getCards(filter, game)); + cards.addAllCards(controller.getGraveyard().getCards(filter, game)); + TargetCard target = new TargetCard(Zone.ALL, filter); target.withNotTarget(true); - if (target.canChoose(controller.getId(), source, game)) { - controller.chooseTarget(outcome, target, source, game); - Card card = game.getCard(target.getFirstTarget()); - if (card != null) { - if (sourcePermanent != null) { - game.getState().setValue("attachTo:" + card.getId(), sourcePermanent); - } - controller.moveCards(card, Zone.BATTLEFIELD, source, game); - if (sourcePermanent != null) { - sourcePermanent.addAttachment(card.getId(), source, game); - } + target.withChooseHint("to attach to " + sourcePermanentName); + controller.choose(outcome, cards, target, source, game); + Card card = game.getCard(target.getFirstTarget()); + if (card != null) { + if (sourcePermanent != null) { + game.getState().setValue("attachTo:" + card.getId(), sourcePermanent); + } + controller.moveCards(card, Zone.BATTLEFIELD, source, game); + if (sourcePermanent != null) { + sourcePermanent.addAttachment(card.getId(), source, game); } } return true; diff --git a/Mage.Tests/src/test/java/org/mage/test/cards/single/dmu/DanithaBenaliasHopeTest.java b/Mage.Tests/src/test/java/org/mage/test/cards/single/dmu/DanithaBenaliasHopeTest.java new file mode 100644 index 00000000000..f6b7e534670 --- /dev/null +++ b/Mage.Tests/src/test/java/org/mage/test/cards/single/dmu/DanithaBenaliasHopeTest.java @@ -0,0 +1,119 @@ +package org.mage.test.cards.single.dmu; + +import mage.abilities.keyword.DeathtouchAbility; +import mage.abilities.keyword.FlyingAbility; +import mage.constants.PhaseStep; +import mage.constants.Zone; +import org.junit.Test; +import org.mage.test.player.TestPlayer; +import org.mage.test.serverside.base.CardTestPlayerBase; + +/** + * @author xenohedron + */ +public class DanithaBenaliasHopeTest extends CardTestPlayerBase { + + private static final String danitha = "Danitha, Benalia's Hope"; // {4}{W} 4/4 First strike, vigilance, lifelink + // When Danitha, Benalia's Hope enters the battlefield, you may put an Aura or Equipment card + // from your hand or graveyard onto the battlefield attached to Danitha. + private static final String wings = "Nimbus Wings"; // Enchanted creature gets +1/+2 and has flying. + private static final String flail = "Gorgon Flail"; // Equipped creature gets +1/+1 and has deathtouch. + private static final String swords = "Swords to Plowshares"; // Exile target creature. Its controller gains life equal to its power. + + @Test + public void testAuraFromGraveyard() { + addCard(Zone.BATTLEFIELD, playerA, "Plains", 5); + addCard(Zone.GRAVEYARD, playerA, wings); + addCard(Zone.HAND, playerA, danitha); + + castSpell(1, PhaseStep.PRECOMBAT_MAIN, playerA, danitha); + setChoice(playerA, true); // use ability + setChoice(playerA, wings); + + setStrictChooseMode(true); + setStopAt(1, PhaseStep.END_TURN); + execute(); + + assertPowerToughness(playerA, danitha, 5, 6); + assertAbility(playerA, danitha, FlyingAbility.getInstance(), true); + } + + @Test + public void testNothingToAttach() { + addCard(Zone.BATTLEFIELD, playerA, "Plains", 5); + addCard(Zone.HAND, playerA, danitha); + + castSpell(1, PhaseStep.PRECOMBAT_MAIN, playerA, danitha); + setChoice(playerA, true); // attempt to use ability + setChoice(playerA, TestPlayer.CHOICE_SKIP); + + setStrictChooseMode(true); + setStopAt(1, PhaseStep.END_TURN); + execute(); + + assertPowerToughness(playerA, danitha, 4, 4); + } + + @Test + public void testEquipmentFromHand() { + addCard(Zone.BATTLEFIELD, playerA, "Plains", 5); + addCard(Zone.HAND, playerA, flail); + addCard(Zone.HAND, playerA, danitha); + + castSpell(1, PhaseStep.PRECOMBAT_MAIN, playerA, danitha); + setChoice(playerA, true); // use ability + setChoice(playerA, flail); + + setStrictChooseMode(true); + setStopAt(1, PhaseStep.END_TURN); + execute(); + + assertPowerToughness(playerA, danitha, 5, 5); + assertAbility(playerA, danitha, DeathtouchAbility.getInstance(), true); + } + + @Test + public void testEquipmentFromHandButExiled() { + addCard(Zone.BATTLEFIELD, playerA, "Plains", 6); + addCard(Zone.HAND, playerA, flail); + addCard(Zone.HAND, playerA, danitha); + addCard(Zone.HAND, playerA, swords); + + castSpell(1, PhaseStep.PRECOMBAT_MAIN, playerA, danitha); + setChoice(playerA, true); // use ability + waitStackResolved(1, PhaseStep.PRECOMBAT_MAIN, 1); + castSpell(1, PhaseStep.PRECOMBAT_MAIN, playerA, swords, danitha); + setChoice(playerA, flail); + + setStrictChooseMode(true); + setStopAt(1, PhaseStep.END_TURN); + execute(); + + assertPermanentCount(playerA, flail, 1); + assertExileCount(playerA, danitha, 1); + assertLife(playerA, 24); + } + + @Test + public void testAuraFromGraveyardButExiled() { + addCard(Zone.BATTLEFIELD, playerA, "Plains", 6); + addCard(Zone.GRAVEYARD, playerA, wings); + addCard(Zone.HAND, playerA, danitha); + addCard(Zone.HAND, playerA, swords); + + castSpell(1, PhaseStep.PRECOMBAT_MAIN, playerA, danitha); + setChoice(playerA, true); // use ability + waitStackResolved(1, PhaseStep.PRECOMBAT_MAIN, 1); + castSpell(1, PhaseStep.PRECOMBAT_MAIN, playerA, swords, danitha); + setChoice(playerA, TestPlayer.CHOICE_SKIP); // no longer can attach Aura + + setStrictChooseMode(true); + setStopAt(1, PhaseStep.END_TURN); + execute(); + + assertGraveyardCount(playerA, wings, 1); + assertExileCount(playerA, danitha, 1); + assertLife(playerA, 24); + } + +}