From df4dfc16d7ebc85439fbc474172d3f2a4dcc65ac Mon Sep 17 00:00:00 2001 From: LevelX2 Date: Tue, 1 Sep 2015 21:39:34 +0200 Subject: [PATCH] * Cipher - Fixed that the selection of the creature was handled targeted (e.g. checking for protection) fixes #1240). --- .../effects/common/CipherEffect.java | 57 ++++++++++--------- 1 file changed, 30 insertions(+), 27 deletions(-) diff --git a/Mage/src/mage/abilities/effects/common/CipherEffect.java b/Mage/src/mage/abilities/effects/common/CipherEffect.java index d4bbdb20a20..89e6b391124 100644 --- a/Mage/src/mage/abilities/effects/common/CipherEffect.java +++ b/Mage/src/mage/abilities/effects/common/CipherEffect.java @@ -28,8 +28,6 @@ package mage.abilities.effects.common; import java.util.UUID; -import mage.constants.Duration; -import mage.constants.Outcome; import mage.abilities.Ability; import mage.abilities.SpellAbility; import mage.abilities.common.DealsCombatDamageToAPlayerTriggeredAbility; @@ -38,6 +36,9 @@ import mage.abilities.effects.Effect; import mage.abilities.effects.OneShotEffect; import mage.abilities.effects.common.continuous.GainAbilityTargetEffect; import mage.cards.Card; +import mage.constants.Duration; +import mage.constants.Outcome; +import mage.constants.Zone; import mage.game.Game; import mage.game.permanent.Permanent; import mage.players.Player; @@ -46,37 +47,37 @@ import mage.target.targetpointer.FixedTarget; /** * FAQ 2013/01/11 - * + * * 702.97. Cipher * - * 702.97a Cipher appears on some instants and sorceries. It represents two static - * abilities, one that functions while the spell is on the stack and one that functions - * while the card with cipher is in the exile zone. "Cipher" means "If this spell is - * represented by a card, you may exile this card encoded on a creature you control" - * and "As long as this card is encoded on that creature, that creature has 'Whenever - * this creature deals combat damage to a player, you may copy this card and you may - * cast the copy without paying its mana cost.'" + * 702.97a Cipher appears on some instants and sorceries. It represents two + * static abilities, one that functions while the spell is on the stack and one + * that functions while the card with cipher is in the exile zone. "Cipher" + * means "If this spell is represented by a card, you may exile this card + * encoded on a creature you control" and "As long as this card is encoded on + * that creature, that creature has 'Whenever this creature deals combat damage + * to a player, you may copy this card and you may cast the copy without paying + * its mana cost.'" * - * 702.97b The term "encoded" describes the relationship between the card with cipher - * while in the exile zone and the creature chosen when the spell represented by that - * card resolves. + * 702.97b The term "encoded" describes the relationship between the card with + * cipher while in the exile zone and the creature chosen when the spell + * represented by that card resolves. * - * 702.97c The card with cipher remains encoded on the chosen creature as long as the - * card with cipher remains exiled and the creature remains on the battlefield. The - * card remains encoded on that object even if it changes controller or stops being - * a creature, as long as it remains on the battlefield. + * 702.97c The card with cipher remains encoded on the chosen creature as long + * as the card with cipher remains exiled and the creature remains on the + * battlefield. The card remains encoded on that object even if it changes + * controller or stops being a creature, as long as it remains on the + * battlefield. * * TODO: Implement Cipher as two static abilities concerning the rules. * * @author LevelX2 */ - - public class CipherEffect extends OneShotEffect { public CipherEffect() { super(Outcome.Copy); - staticText ="

Cipher (Then you may exile this spell card encoded on a creature you control. Whenever that creature deals combat damage to a player, its controller may cast a copy of the encoded card without paying its mana cost.)"; + staticText = "

Cipher (Then you may exile this spell card encoded on a creature you control. Whenever that creature deals combat damage to a player, its controller may cast a copy of the encoded card without paying its mana cost.)"; } public CipherEffect(final CipherEffect effect) { @@ -86,10 +87,11 @@ public class CipherEffect extends OneShotEffect { @Override public boolean apply(Game game, Ability source) { Player controller = game.getPlayer(source.getControllerId()); - TargetControlledCreaturePermanent target = new TargetControlledCreaturePermanent(); if (controller != null) { + TargetControlledCreaturePermanent target = new TargetControlledCreaturePermanent(); + target.setNotTarget(true); if (target.canChoose(source.getControllerId(), game) - && controller.chooseUse(outcome, "Cipher this spell to a creature?", source, game)) { + && controller.chooseUse(outcome, "Cipher this spell to a creature?", source, game)) { controller.chooseTarget(outcome, target, source, game); Card sourceCard = game.getCard(source.getSourceId()); Permanent targetCreature = game.getPermanent(target.getFirstTarget()); @@ -99,9 +101,10 @@ public class CipherEffect extends OneShotEffect { ContinuousEffect effect = new GainAbilityTargetEffect(ability, Duration.Custom); effect.setTargetPointer(new FixedTarget(target.getFirstTarget())); game.addEffect(effect, source); - if (!game.isSimulation()) + if (!game.isSimulation()) { game.informPlayers(new StringBuilder(sourceCard.getLogName()).append(": Spell ciphered to ").append(targetCreature.getLogName()).toString()); - return sourceCard.moveToExile(null, "", source.getSourceId(), game); + } + return controller.moveCards(sourceCard, null, Zone.EXILED, source, game); } else { return false; } @@ -119,7 +122,7 @@ public class CipherEffect extends OneShotEffect { class CipherStoreEffect extends OneShotEffect { - private UUID cipherCardId; + private final UUID cipherCardId; public CipherStoreEffect(UUID cipherCardId, String ruleText) { super(Outcome.Copy); @@ -141,13 +144,13 @@ class CipherStoreEffect extends OneShotEffect { SpellAbility ability = copyCard.getSpellAbility(); // remove the cipher effect from the copy Effect cipherEffect = null; - for (Effect effect :ability.getEffects()) { + for (Effect effect : ability.getEffects()) { if (effect instanceof CipherEffect) { cipherEffect = effect; } } ability.getEffects().remove(cipherEffect); - if (ability != null && ability instanceof SpellAbility) { + if (ability instanceof SpellAbility) { controller.cast(ability, game, true); } }