From 7ad70640314b008f7d1c2faa0bbd0c807330832e Mon Sep 17 00:00:00 2001 From: jeffwadsworth Date: Wed, 18 Dec 2019 18:13:30 -0600 Subject: [PATCH] - Reverted Fixed #6096. The CopySpellForEachItCouldTargetEffect() needs some fixes. --- .../src/mage/cards/z/ZadaHedronGrinder.java | 217 ++++++++++-------- 1 file changed, 118 insertions(+), 99 deletions(-) diff --git a/Mage.Sets/src/mage/cards/z/ZadaHedronGrinder.java b/Mage.Sets/src/mage/cards/z/ZadaHedronGrinder.java index 0e8cd2766ad..7b76cdcb2f4 100644 --- a/Mage.Sets/src/mage/cards/z/ZadaHedronGrinder.java +++ b/Mage.Sets/src/mage/cards/z/ZadaHedronGrinder.java @@ -1,30 +1,30 @@ + package mage.cards.z; import java.util.UUID; import mage.MageInt; import mage.abilities.Ability; +import mage.abilities.Mode; import mage.abilities.TriggeredAbilityImpl; -import mage.abilities.effects.common.CopySpellForEachItCouldTargetEffect; +import mage.abilities.effects.OneShotEffect; import mage.cards.CardImpl; import mage.cards.CardSetInfo; import mage.constants.*; -import mage.filter.FilterInPlay; -import mage.filter.common.FilterControlledCreaturePermanent; +import mage.filter.StaticFilters; import mage.game.Game; import mage.game.events.GameEvent; -import mage.game.events.GameEvent.EventType; import mage.game.permanent.Permanent; import mage.game.stack.Spell; import mage.players.Player; import mage.target.Target; -import mage.util.TargetAddress; +import mage.target.targetpointer.FixedTarget; /** * * @author LevelX2 */ public final class ZadaHedronGrinder extends CardImpl { - + public ZadaHedronGrinder(UUID ownerId, CardSetInfo setInfo) { super(ownerId, setInfo, new CardType[]{CardType.CREATURE}, "{3}{R}"); addSuperType(SuperType.LEGENDARY); @@ -32,17 +32,15 @@ public final class ZadaHedronGrinder extends CardImpl { this.power = 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()); - + } - + public ZadaHedronGrinder(final ZadaHedronGrinder card) { super(card); } - + @Override public ZadaHedronGrinder copy() { return new ZadaHedronGrinder(this); @@ -50,115 +48,136 @@ public final class ZadaHedronGrinder extends CardImpl { } class ZadaHedronGrinderTriggeredAbility extends TriggeredAbilityImpl { - + ZadaHedronGrinderTriggeredAbility() { - super(Zone.BATTLEFIELD, new ZadaHedronGrinderCopySpellEffect(), false); + super(Zone.BATTLEFIELD, new ZadaHedronGrinderEffect(), false); } - + ZadaHedronGrinderTriggeredAbility(final ZadaHedronGrinderTriggeredAbility ability) { super(ability); } - + @Override public ZadaHedronGrinderTriggeredAbility copy() { return new ZadaHedronGrinderTriggeredAbility(this); } - + @Override public boolean checkEventType(GameEvent event, Game game) { - return event.getType() == EventType.SPELL_CAST; + return event.getType() == GameEvent.EventType.SPELL_CAST; } - + @Override public boolean checkTrigger(GameEvent event, Game game) { - Spell spell = game.getStack().getSpell(event.getTargetId()); - return checkSpell(spell, game) - && event.getPlayerId().equals(controllerId); + if (event.getPlayerId().equals(this.getControllerId())) { + Spell spell = game.getStack().getSpell(event.getTargetId()); + if (isControlledInstantOrSorcery(spell)) { + boolean targetsSource = false; + 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()) { + for (UUID targetId : target.getTargets()) { + if (targetId.equals(getSourceId())) { + targetsSource = true; + } else { + return false; + } + } + } + } + } + } + if (targetsSource) { + this.getEffects().get(0).setTargetPointer(new FixedTarget(spell.getId())); + return true; + } + } + } + return false; } - - private boolean checkSpell(Spell spell, Game game) { - if (spell != null - && (spell.isInstant() || spell.isSorcery())) { - boolean noTargets = true; - for (TargetAddress addr : TargetAddress.walk(spell)) { - noTargets = false; - Target targetInstance = addr.getTarget(spell); - for (UUID target : targetInstance.getTargets()) { - Permanent permanent = game.getPermanent(target); - if (permanent == null || !permanent.getId().equals(getSourceId())) { - 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 (noTargets) { + if (usedTarget == null) { return false; } - getEffects().get(0).setValue("triggeringSpell", spell); + for (Permanent creature : game.getState().getBattlefield().getAllActivePermanents(StaticFilters.FILTER_PERMANENT_CREATURE, source.getControllerId(), game)) { + 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 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 { - - 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 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); - } }