From 6cc2ac0e707f73d63338811c49cac264660c66ed Mon Sep 17 00:00:00 2001 From: LevelX2 Date: Mon, 28 Sep 2015 19:27:51 +0200 Subject: [PATCH] * Zada, Hedron Grinder - Fixed a bug with checking and copying modal spells. --- .../battleforzendikar/ZadaHedronGrinder.java | 42 +++++++++----- .../mage/test/cards/copy/CopySpellTest.java | 58 +++++++++++++++++++ 2 files changed, 85 insertions(+), 15 deletions(-) diff --git a/Mage.Sets/src/mage/sets/battleforzendikar/ZadaHedronGrinder.java b/Mage.Sets/src/mage/sets/battleforzendikar/ZadaHedronGrinder.java index 2e2648a202..e34ac40666 100644 --- a/Mage.Sets/src/mage/sets/battleforzendikar/ZadaHedronGrinder.java +++ b/Mage.Sets/src/mage/sets/battleforzendikar/ZadaHedronGrinder.java @@ -102,12 +102,15 @@ class ZadaHedronGrinderTriggeredAbility extends TriggeredAbilityImpl { Spell spell = game.getStack().getSpell(event.getTargetId()); if (isControlledInstantOrSorcery(spell)) { boolean targetsSource = false; - for (Target target : spell.getSpellAbility().getTargets()) { - for (UUID targetId : target.getTargets()) { - if (targetId.equals(getSourceId())) { - targetsSource = true; - } else { - return false; + for (UUID modeId : spell.getSpellAbility().getModes().getSelectedModes()) { + spell.getSpellAbility().getModes().setActiveMode(modeId); + for (Target target : spell.getSpellAbility().getTargets()) { + for (UUID targetId : target.getTargets()) { + if (targetId.equals(getSourceId())) { + targetsSource = true; + } else { + return false; + } } } } @@ -157,10 +160,15 @@ class ZadaHedronGrinderEffect extends OneShotEffect { Player controller = game.getPlayer(source.getControllerId()); if (spell != null && controller != null) { Target usedTarget = null; - for (Target target : spell.getSpellAbility().getTargets()) { - if (target.getFirstTarget().equals(source.getSourceId())) { - usedTarget = target.copy(); - usedTarget.clearChosen(); + setUsedTarget: + for (UUID modeId : spell.getSpellAbility().getModes().getSelectedModes()) { + spell.getSpellAbility().getModes().setActiveMode(modeId); + for (Target target : spell.getSpellAbility().getTargets()) { + if (target.getFirstTarget().equals(source.getSourceId())) { + usedTarget = target.copy(); + usedTarget.clearChosen(); + break setUsedTarget; + } } } if (usedTarget == null) { @@ -169,11 +177,15 @@ class ZadaHedronGrinderEffect extends OneShotEffect { for (Permanent creature : game.getState().getBattlefield().getAllActivePermanents(new FilterCreaturePermanent(), source.getControllerId(), game)) { if (!creature.getId().equals(source.getSourceId()) && usedTarget.canTarget(source.getControllerId(), creature.getId(), source, game)) { Spell copy = spell.copySpell(); - for (Target target : spell.getSpellAbility().getTargets()) { - if (target.getClass().equals(usedTarget.getClass()) && target.getMessage().equals(usedTarget.getMessage())) { - target.clearChosen(); - target.add(creature.getId(), game); - break; + setTarget: + for (UUID modeId : spell.getSpellAbility().getModes().getSelectedModes()) { + copy.getSpellAbility().getModes().setActiveMode(modeId); + for (Target target : copy.getSpellAbility().getTargets()) { + if (target.getClass().equals(usedTarget.getClass()) && target.getMessage().equals(usedTarget.getMessage())) { + target.clearChosen(); + target.add(creature.getId(), game); + break setTarget; + } } } copy.setControllerId(source.getControllerId()); diff --git a/Mage.Tests/src/test/java/org/mage/test/cards/copy/CopySpellTest.java b/Mage.Tests/src/test/java/org/mage/test/cards/copy/CopySpellTest.java index c9736f2aa0..e3701dd6a4 100644 --- a/Mage.Tests/src/test/java/org/mage/test/cards/copy/CopySpellTest.java +++ b/Mage.Tests/src/test/java/org/mage/test/cards/copy/CopySpellTest.java @@ -27,6 +27,7 @@ */ package org.mage.test.cards.copy; +import mage.abilities.keyword.FlyingAbility; import mage.constants.PhaseStep; import mage.constants.Zone; import org.junit.Test; @@ -61,4 +62,61 @@ public class CopySpellTest extends CardTestPlayerBase { assertHandCount(playerA, "Silvercoat Lion", 1); } + @Test + public void ZadaHedronGrinderBoost() { + // Target creature gets +3/+3 and gains flying until end of turn. + addCard(Zone.HAND, playerA, "Angelic Blessing", 1); // {2}{W} + addCard(Zone.BATTLEFIELD, playerA, "Plains", 3); + + // Whenever you cast an instant or sorcery spell that targets only Zada, Hedron Grinder, copy that spell for each other creature you control that the spell could target. Each copy targets a different one of those creatures. + addCard(Zone.BATTLEFIELD, playerA, "Zada, Hedron Grinder", 1); + addCard(Zone.BATTLEFIELD, playerA, "Pillarfield Ox", 1); + + addCard(Zone.BATTLEFIELD, playerB, "Silvercoat Lion", 1); + + castSpell(1, PhaseStep.PRECOMBAT_MAIN, playerA, "Angelic Blessing", "Zada, Hedron Grinder"); + + setStopAt(1, PhaseStep.BEGIN_COMBAT); + execute(); + + assertGraveyardCount(playerA, "Angelic Blessing", 1); + assertPowerToughness(playerA, "Pillarfield Ox", 5, 7); + assertAbility(playerA, "Pillarfield Ox", FlyingAbility.getInstance(), true); + assertPowerToughness(playerA, "Zada, Hedron Grinder", 6, 6); + assertAbility(playerA, "Zada, Hedron Grinder", FlyingAbility.getInstance(), true); + + assertPowerToughness(playerB, "Silvercoat Lion", 2, 2); + assertAbility(playerB, "Silvercoat Lion", FlyingAbility.getInstance(), false); + } + + @Test + public void ZadaHedronGrinderBoostWithCharm() { + // Choose two - + // • Counter target spell. + // • Return target permanent to its owner's hand. + // • Tap all creatures your opponents control. + // • Draw a card. + addCard(Zone.HAND, playerA, "Cryptic Command", 1); // {2}{U}{U}{U} + addCard(Zone.BATTLEFIELD, playerA, "Island", 4); + + // Whenever you cast an instant or sorcery spell that targets only Zada, Hedron Grinder, copy that spell for each other creature you control that the spell could target. Each copy targets a different one of those creatures. + addCard(Zone.BATTLEFIELD, playerA, "Zada, Hedron Grinder", 1); + addCard(Zone.BATTLEFIELD, playerA, "Pillarfield Ox", 1); + + addCard(Zone.BATTLEFIELD, playerB, "Silvercoat Lion", 1); + + castSpell(1, PhaseStep.PRECOMBAT_MAIN, playerA, "Cryptic Command", "mode=2Zada, Hedron Grinder"); + setModeChoice(playerA, "2"); // Return target permanent to its owner's hand + setModeChoice(playerA, "4"); // Draw a card + + setStopAt(1, PhaseStep.BEGIN_COMBAT); + execute(); + + assertPowerToughness(playerB, "Silvercoat Lion", 2, 2); + + assertGraveyardCount(playerA, "Cryptic Command", 1); + assertPermanentCount(playerA, "Zada, Hedron Grinder", 0); + assertPermanentCount(playerA, "Pillarfield Ox", 0); + assertHandCount(playerA, 4); // 2 draw + 2 creatures returned to hand + } }