* Zada, Hedron Grinder - Fixed a bug with checking and copying modal spells.

This commit is contained in:
LevelX2 2015-09-28 19:27:51 +02:00
parent 0680560225
commit 6cc2ac0e70
2 changed files with 85 additions and 15 deletions

View file

@ -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());

View file

@ -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
}
}