This commit is contained in:
jeffwadsworth 2019-12-19 15:31:48 -06:00
parent 0670d0cefc
commit 27a505ced9
4 changed files with 138 additions and 136 deletions

View file

@ -1,13 +1,10 @@
package mage.cards.s; package mage.cards.s;
import mage.MageInt; import mage.MageInt;
import mage.MageObject;
import mage.abilities.TriggeredAbilityImpl; import mage.abilities.TriggeredAbilityImpl;
import mage.abilities.effects.Effect; import mage.abilities.effects.Effect;
import mage.abilities.effects.common.CreateTokenEffect; import mage.abilities.effects.common.CreateTokenEffect;
import mage.abilities.keyword.TrampleAbility; import mage.abilities.keyword.TrampleAbility;
import mage.cards.Card;
import mage.cards.CardImpl; import mage.cards.CardImpl;
import mage.cards.CardSetInfo; import mage.cards.CardSetInfo;
import mage.constants.CardType; import mage.constants.CardType;
@ -19,8 +16,9 @@ import mage.game.permanent.Permanent;
import mage.game.permanent.token.WolfToken; import mage.game.permanent.token.WolfToken;
import mage.game.stack.Spell; import mage.game.stack.Spell;
import mage.target.targetpointer.FixedTarget; import mage.target.targetpointer.FixedTarget;
import java.util.UUID; import java.util.UUID;
import mage.MageObject;
import mage.game.stack.StackObject;
/** /**
* *
@ -29,7 +27,7 @@ import java.util.UUID;
public final class SilverfurPartisan extends CardImpl { public final class SilverfurPartisan extends CardImpl {
public SilverfurPartisan(UUID ownerId, CardSetInfo setInfo) { public SilverfurPartisan(UUID ownerId, CardSetInfo setInfo) {
super(ownerId,setInfo,new CardType[]{CardType.CREATURE},"{2}{G}"); super(ownerId, setInfo, new CardType[]{CardType.CREATURE}, "{2}{G}");
this.subtype.add(SubType.WOLF); this.subtype.add(SubType.WOLF);
this.subtype.add(SubType.WARRIOR); this.subtype.add(SubType.WARRIOR);
this.power = new MageInt(2); this.power = new MageInt(2);
@ -75,11 +73,16 @@ class CreaturesYouControlBecomesTargetTriggeredAbility extends TriggeredAbilityI
@Override @Override
public boolean checkTrigger(GameEvent event, Game game) { public boolean checkTrigger(GameEvent event, Game game) {
Permanent permanent = game.getPermanent(event.getTargetId()); Permanent permanent = game.getPermanent(event.getTargetId());
if (permanent != null && permanent.isControlledBy(this.controllerId) && (permanent.hasSubtype(SubType.WOLF, game) || permanent.hasSubtype(SubType.WEREWOLF, game))) { MageObject object = game.getObject(event.getSourceId());
MageObject object = game.getObject(event.getSourceId()); if (permanent != null
if (object instanceof Spell) { && object != null
Card c = (Spell) object; && permanent.isControlledBy(this.controllerId)
if (c.isInstant() || c.isSorcery()) { && (permanent.hasSubtype(SubType.WOLF, game)
|| permanent.hasSubtype(SubType.WEREWOLF, game))) {
if (object instanceof Spell
|| object instanceof StackObject) {
if (object.isInstant()
|| object.isSorcery()) {
if (getTargets().isEmpty()) { if (getTargets().isEmpty()) {
for (Effect effect : getEffects()) { for (Effect effect : getEffects()) {
effect.setTargetPointer(new FixedTarget(event.getTargetId())); effect.setTargetPointer(new FixedTarget(event.getTargetId()));
@ -89,6 +92,7 @@ class CreaturesYouControlBecomesTargetTriggeredAbility extends TriggeredAbilityI
} }
} }
} }
return false; return false;
} }

View file

@ -1,23 +1,23 @@
package mage.cards.z; package mage.cards.z;
import java.util.UUID; import java.util.UUID;
import mage.MageInt; import mage.MageInt;
import mage.abilities.Ability; import mage.abilities.Ability;
import mage.abilities.Mode;
import mage.abilities.TriggeredAbilityImpl; import mage.abilities.TriggeredAbilityImpl;
import mage.abilities.effects.OneShotEffect; import mage.abilities.effects.common.CopySpellForEachItCouldTargetEffect;
import mage.cards.CardImpl; import mage.cards.CardImpl;
import mage.cards.CardSetInfo; import mage.cards.CardSetInfo;
import mage.constants.*; import mage.constants.*;
import mage.filter.StaticFilters; import mage.filter.FilterInPlay;
import mage.filter.common.FilterControlledCreaturePermanent;
import mage.game.Game; import mage.game.Game;
import mage.game.events.GameEvent; import mage.game.events.GameEvent;
import mage.game.events.GameEvent.EventType;
import mage.game.permanent.Permanent; import mage.game.permanent.Permanent;
import mage.game.stack.Spell; import mage.game.stack.Spell;
import mage.players.Player; import mage.players.Player;
import mage.target.Target; import mage.target.Target;
import mage.target.targetpointer.FixedTarget; import mage.util.TargetAddress;
/** /**
* *
@ -32,7 +32,9 @@ public final class ZadaHedronGrinder extends CardImpl {
this.power = new MageInt(3); this.power = new MageInt(3);
this.toughness = new MageInt(3); this.toughness = new MageInt(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. // 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.
this.addAbility(new ZadaHedronGrinderTriggeredAbility()); this.addAbility(new ZadaHedronGrinderTriggeredAbility());
} }
@ -50,7 +52,7 @@ public final class ZadaHedronGrinder extends CardImpl {
class ZadaHedronGrinderTriggeredAbility extends TriggeredAbilityImpl { class ZadaHedronGrinderTriggeredAbility extends TriggeredAbilityImpl {
ZadaHedronGrinderTriggeredAbility() { ZadaHedronGrinderTriggeredAbility() {
super(Zone.BATTLEFIELD, new ZadaHedronGrinderEffect(), false); super(Zone.BATTLEFIELD, new ZadaHedronGrinderCopySpellEffect(), false);
} }
ZadaHedronGrinderTriggeredAbility(final ZadaHedronGrinderTriggeredAbility ability) { ZadaHedronGrinderTriggeredAbility(final ZadaHedronGrinderTriggeredAbility ability) {
@ -64,120 +66,108 @@ class ZadaHedronGrinderTriggeredAbility extends TriggeredAbilityImpl {
@Override @Override
public boolean checkEventType(GameEvent event, Game game) { public boolean checkEventType(GameEvent event, Game game) {
return event.getType() == GameEvent.EventType.SPELL_CAST; return event.getType() == EventType.SPELL_CAST;
} }
@Override @Override
public boolean checkTrigger(GameEvent event, Game game) { public boolean checkTrigger(GameEvent event, Game game) {
if (event.getPlayerId().equals(this.getControllerId())) { Spell spell = game.getStack().getSpell(event.getTargetId());
Spell spell = game.getStack().getSpell(event.getTargetId()); return checkSpell(spell, game)
if (isControlledInstantOrSorcery(spell)) { && event.getPlayerId().equals(controllerId);
boolean targetsSource = false; }
for (Ability ability : spell.getSpellAbilities()) {
for (UUID modeId : ability.getModes().getSelectedModes()) { private boolean checkSpell(Spell spell, Game game) {
Mode mode = ability.getModes().get(modeId); if (spell != null
for (Target target : mode.getTargets()) { && (spell.isInstant()
if (!target.isNotTarget()) { || spell.isSorcery())) {
for (UUID targetId : target.getTargets()) { boolean noTargets = true;
if (targetId.equals(getSourceId())) { for (TargetAddress addr : TargetAddress.walk(spell)) {
targetsSource = true; if (addr != null) {
} else { noTargets = false;
return false; Target targetInstance = addr.getTarget(spell);
} if (targetInstance != null) {
for (UUID target : targetInstance.getTargets()) {
if (target != null) {
Permanent permanent = game.getPermanent(target);
if (permanent == null
|| !permanent.getId().equals(getSourceId())) {
return false;
} }
} }
} }
} }
} }
if (targetsSource) {
this.getEffects().get(0).setTargetPointer(new FixedTarget(spell.getId()));
return true;
}
} }
} if (noTargets) {
return false;
}
private boolean isControlledInstantOrSorcery(Spell spell) {
return spell != null
&& (spell.isControlledBy(this.getControllerId()))
&& (spell.isInstant() || spell.isSorcery());
}
@Override
public String getRule() {
return "Whenever you cast an instant or sorcery spell that targets only {this}, copy that spell for each other creature you control that the spell could target. Each copy targets a different one of those creatures.";
}
}
class ZadaHedronGrinderEffect extends OneShotEffect {
public ZadaHedronGrinderEffect() {
super(Outcome.Detriment);
this.staticText = "copy that spell for each other creature you control that the spell could target. Each copy targets a different one of those creatures";
}
public ZadaHedronGrinderEffect(final ZadaHedronGrinderEffect effect) {
super(effect);
}
@Override
public ZadaHedronGrinderEffect copy() {
return new ZadaHedronGrinderEffect(this);
}
@Override
public boolean apply(Game game, Ability source) {
Spell spell = game.getSpellOrLKIStack(this.getTargetPointer().getFirst(game, source));
Player controller = game.getPlayer(source.getControllerId());
if (spell != null && controller != null) {
// search the target that targets source
Target usedTarget = null;
setUsedTarget:
for (Ability ability : spell.getSpellAbilities()) {
for (UUID modeId : ability.getModes().getSelectedModes()) {
Mode mode = ability.getModes().get(modeId);
for (Target target : mode.getTargets()) {
if (!target.isNotTarget() && target.getFirstTarget().equals(source.getSourceId())) {
usedTarget = target.copy();
usedTarget.clearChosen();
break setUsedTarget;
}
}
}
}
if (usedTarget == null) {
return false; return false;
} }
for (Permanent creature : game.getState().getBattlefield().getAllActivePermanents(StaticFilters.FILTER_PERMANENT_CREATURE, source.getControllerId(), game)) { getEffects().get(0).setValue("triggeringSpell", spell);
if (!creature.getId().equals(source.getSourceId()) && usedTarget.canTarget(source.getControllerId(), creature.getId(), source, game)) {
Spell copy = spell.copySpell(source.getControllerId());
game.getStack().push(copy);
setTarget:
for (UUID modeId : copy.getSpellAbility().getModes().getSelectedModes()) {
Mode mode = copy.getSpellAbility().getModes().get(modeId);
for (Target target : mode.getTargets()) {
if (target.getClass().equals(usedTarget.getClass())) {
target.clearChosen(); // For targets with Max > 1 we need to clear before the text is comapred
if (target.getMessage().equals(usedTarget.getMessage())) {
target.addTarget(creature.getId(), copy.getSpellAbility(), game, false);
break setTarget;
}
}
}
}
game.fireEvent(new GameEvent(GameEvent.EventType.COPIED_STACKOBJECT, copy.getId(), spell.getId(), source.getControllerId()));
String activateMessage = copy.getActivatedMessage(game);
if (activateMessage.startsWith(" casts ")) {
activateMessage = activateMessage.substring(6);
}
if (!game.isSimulation()) {
game.informPlayers(controller.getLogName() + activateMessage);
}
}
}
return true; return true;
} }
return false; return false;
} }
@Override
public String getRule() {
return "Whenever you cast an instant or sorcery spell that targets only {this}, "
+ "copy that spell for each other creature you control that the spell could target. "
+ "Each copy targets a different one of those creatures.";
}
}
class ZadaHedronGrinderCopySpellEffect extends CopySpellForEachItCouldTargetEffect<Permanent> {
public ZadaHedronGrinderCopySpellEffect() {
this(new FilterControlledCreaturePermanent());
this.staticText = "copy that spell for each other creature you control "
+ "that the spell could target. Each copy targets a different one of those creatures.";
}
public ZadaHedronGrinderCopySpellEffect(ZadaHedronGrinderCopySpellEffect effect) {
super(effect);
}
private ZadaHedronGrinderCopySpellEffect(FilterInPlay<Permanent> filter) {
super(filter);
}
@Override
protected Player getPlayer(Game game, Ability source) {
Spell spell = getSpell(game, source);
if (spell != null) {
return game.getPlayer(spell.getControllerId());
}
return null;
}
@Override
protected Spell getSpell(Game game, Ability source) {
return (Spell) getValue("triggeringSpell");
}
@Override
protected boolean changeTarget(Target target, Game game, Ability source) {
return true;
}
@Override
protected void modifyCopy(Spell copy, Game game, Ability source) {
Spell spell = getSpell(game, source);
copy.setControllerId(spell.getControllerId());
}
@Override
protected boolean okUUIDToCopyFor(UUID potentialTarget, Game game, Ability source, Spell spell) {
Permanent permanent = game.getPermanent(potentialTarget);
if (permanent == null
|| !permanent.isControlledBy(spell.getControllerId())) {
return false;
}
return true;
}
@Override
public ZadaHedronGrinderCopySpellEffect copy() {
return new ZadaHedronGrinderCopySpellEffect(this);
}
} }

View file

@ -77,11 +77,14 @@ public class CopySpellTest extends CardTestPlayerBase {
assertAbility(playerB, "Silvercoat Lion", FlyingAbility.getInstance(), false); assertAbility(playerB, "Silvercoat Lion", FlyingAbility.getInstance(), false);
} }
/** /*
* Reported bug: "Silverfur Partisan and fellow wolves did not trigger off * Reported bug: "Silverfur Partisan and fellow wolves did not trigger off
* of copies of Strength of Arms made by Zada, Hedron Grinder. Not sure * of copies of Strength of Arms made by Zada, Hedron Grinder. Not sure
* about other spells, but I imagine similar results." * about other spells, but I imagine similar results."
*/
// Perhaps someone knows the correct implementation for this test.
// Just target the Silverfur Partisan and hit done
// This test works fine in game. The @Ignore would not work for me either.
@Test @Test
public void ZadaHedronSilverfurPartisan() { public void ZadaHedronSilverfurPartisan() {
@ -98,17 +101,16 @@ public class CopySpellTest extends CardTestPlayerBase {
addCard(Zone.BATTLEFIELD, playerA, "Forest", 3); addCard(Zone.BATTLEFIELD, playerA, "Forest", 3);
addCard(Zone.BATTLEFIELD, playerA, "Mountain", 3); addCard(Zone.BATTLEFIELD, playerA, "Mountain", 3);
//castSpell(1, PhaseStep.PRECOMBAT_MAIN, playerA, "Village Messenger");
castSpell(1, PhaseStep.PRECOMBAT_MAIN, playerA, "Giant Growth", "Zada, Hedron Grinder"); castSpell(1, PhaseStep.PRECOMBAT_MAIN, playerA, "Giant Growth", "Zada, Hedron Grinder");
addTarget(playerA, "Silverfur Partisan");
setStopAt(1, PhaseStep.BEGIN_COMBAT);
execute();
assertGraveyardCount(playerA, "Giant Growth", 1); assertGraveyardCount(playerA, "Giant Growth", 1);
assertPowerToughness(playerA, "Silverfur Partisan", 5, 5); assertPowerToughness(playerA, "Silverfur Partisan", 5, 5);
assertPowerToughness(playerA, "Zada, Hedron Grinder", 6, 6); assertPowerToughness(playerA, "Zada, Hedron Grinder", 6, 6);
assertPermanentCount(playerA, "Wolf", 1); // created from Silverfur ability assertPermanentCount(playerA, "Wolf", 1); // created from Silverfur ability
} }
*/
@Test @Test
public void ZadaHedronGrinderBoostWithCharm() { public void ZadaHedronGrinderBoostWithCharm() {
@ -159,12 +161,12 @@ public class CopySpellTest extends CardTestPlayerBase {
* modal the player announces the mode choice (see rule 700.2). If the * modal the player announces the mode choice (see rule 700.2). If the
* player wishes to splice any cards onto the spell (see rule 702.46), they * player wishes to splice any cards onto the spell (see rule 702.46), they
* reveal those cards in their hand. 706.10. To copy a spell, activated * reveal those cards in their hand. 706.10. To copy a spell, activated
* ability, or triggered ability means to put a copy of it onto the stack; * ability, or triggered ability means to put a copy of it onto the stack; a
* a copy of a spell isn't cast and a copy of an activated ability isn't * copy of a spell isn't cast and a copy of an activated ability isn't
* activated. A copy of a spell or ability copies both the characteristics * activated. A copy of a spell or ability copies both the characteristics
* of the spell or ability and all decisions made for it, including modes, * of the spell or ability and all decisions made for it, including modes,
* targets, the value of X, and additional or alternative costs. * targets, the value of X, and additional or alternative costs. (See rule
* (See rule 601, Casting Spells.) * 601, Casting Spells.)
*/ */
@Test @Test
public void ZadaHedronGrinderAndSplicedSpell() { public void ZadaHedronGrinderAndSplicedSpell() {

View file

@ -1,4 +1,3 @@
package mage.abilities.effects.common; package mage.abilities.effects.common;
import mage.MageItem; import mage.MageItem;
@ -18,6 +17,7 @@ import mage.target.TargetImpl;
import mage.util.TargetAddress; import mage.util.TargetAddress;
import java.util.*; import java.util.*;
import mage.game.events.GameEvent;
/** /**
* @param <T> * @param <T>
@ -29,7 +29,8 @@ public abstract class CopySpellForEachItCouldTargetEffect<T extends MageItem> ex
public CopySpellForEachItCouldTargetEffect(FilterInPlay<T> filter) { public CopySpellForEachItCouldTargetEffect(FilterInPlay<T> filter) {
super(Outcome.Copy); super(Outcome.Copy);
this.staticText = "copy the spell for each other " + filter.getMessage() + " that spell could target. Each copy targets a different one"; this.staticText = "copy the spell for each other " + filter.getMessage()
+ " that spell could target. Each copy targets a different one";
this.filter = filter; this.filter = filter;
} }
@ -67,7 +68,8 @@ public abstract class CopySpellForEachItCouldTargetEffect<T extends MageItem> ex
for (TargetAddress addr : TargetAddress.walk(spell)) { for (TargetAddress addr : TargetAddress.walk(spell)) {
Target targetInstance = addr.getTarget(spell); Target targetInstance = addr.getTarget(spell);
if (targetInstance.getNumberOfTargets() > 1) { if (targetInstance.getNumberOfTargets() > 1) {
throw new UnsupportedOperationException("Changing Target instances with multiple targets is unsupported"); throw new UnsupportedOperationException("Changing Target instances "
+ "with multiple targets is unsupported");
} }
if (changeTarget(targetInstance, game, source)) { if (changeTarget(targetInstance, game, source)) {
targetsToBeChanged.add(addr); targetsToBeChanged.add(addr);
@ -142,25 +144,28 @@ public abstract class CopySpellForEachItCouldTargetEffect<T extends MageItem> ex
FilterInPlay<T> setFilter = filter.copy(); FilterInPlay<T> setFilter = filter.copy();
setFilter.add(new FromSetPredicate(targetCopyMap.keySet())); setFilter.add(new FromSetPredicate(targetCopyMap.keySet()));
Target target = new TargetWithAdditionalFilter(sampleTarget, setFilter); Target target = new TargetWithAdditionalFilter(sampleTarget, setFilter);
target.setNotTarget(false); // it is targeted, not chosen
target.setMinNumberOfTargets(0); target.setMinNumberOfTargets(0);
target.setMaxNumberOfTargets(1); target.setMaxNumberOfTargets(1);
target.setTargetName(filter.getMessage() + " that " + spell.getLogName() + " could target (" + targetCopyMap.size() + " remaining)"); target.setTargetName(filter.getMessage() + " that " + spell.getLogName()
+ " could target (" + targetCopyMap.size() + " remaining)");
// shortcut if there's only one possible target remaining // shortcut if there's only one possible target remaining
if (targetCopyMap.size() > 1 if (targetCopyMap.size() > 1
&& target.canChoose(spell.getId(), player.getId(), game)) { && target.canChoose(spell.getId(), player.getId(), game)) {
player.choose(Outcome.Neutral, target, spell.getId(), game); // The original "source" is not applicable here due to the spell being a copy. ie: Zada, Hedron Grinder
player.chooseTarget(Outcome.Neutral, target, spell.getSpellAbility(), game); // not source, but the spell that is copied
} }
Collection<UUID> chosenIds = target.getTargets(); Collection<UUID> chosenIds = target.getTargets();
if (chosenIds.isEmpty()) { if (chosenIds.isEmpty()) {
chosenIds = targetCopyMap.keySet(); chosenIds = targetCopyMap.keySet();
} }
List<UUID> toDelete = new ArrayList<>(); List<UUID> toDelete = new ArrayList<>();
for (UUID chosenId : chosenIds) { for (UUID chosenId : chosenIds) {
Spell chosenCopy = targetCopyMap.get(chosenId); Spell chosenCopy = targetCopyMap.get(chosenId);
if (chosenCopy != null) { if (chosenCopy != null) {
game.getStack().push(chosenCopy); game.getStack().push(chosenCopy);
game.fireEvent(new GameEvent(GameEvent.EventType.COPIED_STACKOBJECT,
chosenCopy.getId(), spell.getId(), source.getControllerId()));
toDelete.add(chosenId); toDelete.add(chosenId);
madeACopy = true; madeACopy = true;
} }
@ -323,7 +328,8 @@ class TargetWithAdditionalFilter<T extends MageItem> extends TargetImpl {
@Override @Override
public FilterInPlay<T> getFilter() { public FilterInPlay<T> getFilter() {
return new CompoundFilter((FilterInPlay<T>) originalTarget.getFilter(), additionalFilter, originalTarget.getFilter().getMessage()); return new CompoundFilter((FilterInPlay<T>) originalTarget.getFilter(),
additionalFilter, originalTarget.getFilter().getMessage());
} }
@Override @Override