* Cipher - Fixed that the selection of the creature was handled targeted (e.g. checking for protection) fixes #1240).

This commit is contained in:
LevelX2 2015-09-01 21:39:34 +02:00
parent 1213fd22c8
commit df4dfc16d7

View file

@ -28,8 +28,6 @@
package mage.abilities.effects.common; package mage.abilities.effects.common;
import java.util.UUID; import java.util.UUID;
import mage.constants.Duration;
import mage.constants.Outcome;
import mage.abilities.Ability; import mage.abilities.Ability;
import mage.abilities.SpellAbility; import mage.abilities.SpellAbility;
import mage.abilities.common.DealsCombatDamageToAPlayerTriggeredAbility; import mage.abilities.common.DealsCombatDamageToAPlayerTriggeredAbility;
@ -38,6 +36,9 @@ import mage.abilities.effects.Effect;
import mage.abilities.effects.OneShotEffect; import mage.abilities.effects.OneShotEffect;
import mage.abilities.effects.common.continuous.GainAbilityTargetEffect; import mage.abilities.effects.common.continuous.GainAbilityTargetEffect;
import mage.cards.Card; import mage.cards.Card;
import mage.constants.Duration;
import mage.constants.Outcome;
import mage.constants.Zone;
import mage.game.Game; import mage.game.Game;
import mage.game.permanent.Permanent; import mage.game.permanent.Permanent;
import mage.players.Player; import mage.players.Player;
@ -49,34 +50,34 @@ import mage.target.targetpointer.FixedTarget;
* *
* 702.97. Cipher * 702.97. Cipher
* *
* 702.97a Cipher appears on some instants and sorceries. It represents two static * 702.97a Cipher appears on some instants and sorceries. It represents two
* abilities, one that functions while the spell is on the stack and one that functions * static abilities, one that functions while the spell is on the stack and one
* while the card with cipher is in the exile zone. "Cipher" means "If this spell is * that functions while the card with cipher is in the exile zone. "Cipher"
* represented by a card, you may exile this card encoded on a creature you control" * means "If this spell is represented by a card, you may exile this card
* and "As long as this card is encoded on that creature, that creature has 'Whenever * encoded on a creature you control" and "As long as this card is encoded on
* this creature deals combat damage to a player, you may copy this card and you may * that creature, that creature has 'Whenever this creature deals combat damage
* cast the copy without paying its mana cost.'" * 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 * 702.97b The term "encoded" describes the relationship between the card with
* while in the exile zone and the creature chosen when the spell represented by that * cipher while in the exile zone and the creature chosen when the spell
* card resolves. * represented by that card resolves.
* *
* 702.97c The card with cipher remains encoded on the chosen creature as long as the * 702.97c The card with cipher remains encoded on the chosen creature as long
* card with cipher remains exiled and the creature remains on the battlefield. The * as the card with cipher remains exiled and the creature remains on the
* card remains encoded on that object even if it changes controller or stops being * battlefield. The card remains encoded on that object even if it changes
* a creature, as long as it remains on the battlefield. * controller or stops being a creature, as long as it remains on the
* battlefield.
* *
* TODO: Implement Cipher as two static abilities concerning the rules. * TODO: Implement Cipher as two static abilities concerning the rules.
* *
* @author LevelX2 * @author LevelX2
*/ */
public class CipherEffect extends OneShotEffect { public class CipherEffect extends OneShotEffect {
public CipherEffect() { public CipherEffect() {
super(Outcome.Copy); super(Outcome.Copy);
staticText ="<br><br/>Cipher <i>(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.)</i>"; staticText = "<br><br/>Cipher <i>(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.)</i>";
} }
public CipherEffect(final CipherEffect effect) { public CipherEffect(final CipherEffect effect) {
@ -86,10 +87,11 @@ public class CipherEffect extends OneShotEffect {
@Override @Override
public boolean apply(Game game, Ability source) { public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId()); Player controller = game.getPlayer(source.getControllerId());
TargetControlledCreaturePermanent target = new TargetControlledCreaturePermanent();
if (controller != null) { if (controller != null) {
TargetControlledCreaturePermanent target = new TargetControlledCreaturePermanent();
target.setNotTarget(true);
if (target.canChoose(source.getControllerId(), game) 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); controller.chooseTarget(outcome, target, source, game);
Card sourceCard = game.getCard(source.getSourceId()); Card sourceCard = game.getCard(source.getSourceId());
Permanent targetCreature = game.getPermanent(target.getFirstTarget()); Permanent targetCreature = game.getPermanent(target.getFirstTarget());
@ -99,9 +101,10 @@ public class CipherEffect extends OneShotEffect {
ContinuousEffect effect = new GainAbilityTargetEffect(ability, Duration.Custom); ContinuousEffect effect = new GainAbilityTargetEffect(ability, Duration.Custom);
effect.setTargetPointer(new FixedTarget(target.getFirstTarget())); effect.setTargetPointer(new FixedTarget(target.getFirstTarget()));
game.addEffect(effect, source); game.addEffect(effect, source);
if (!game.isSimulation()) if (!game.isSimulation()) {
game.informPlayers(new StringBuilder(sourceCard.getLogName()).append(": Spell ciphered to ").append(targetCreature.getLogName()).toString()); 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 { } else {
return false; return false;
} }
@ -119,7 +122,7 @@ public class CipherEffect extends OneShotEffect {
class CipherStoreEffect extends OneShotEffect { class CipherStoreEffect extends OneShotEffect {
private UUID cipherCardId; private final UUID cipherCardId;
public CipherStoreEffect(UUID cipherCardId, String ruleText) { public CipherStoreEffect(UUID cipherCardId, String ruleText) {
super(Outcome.Copy); super(Outcome.Copy);
@ -141,13 +144,13 @@ class CipherStoreEffect extends OneShotEffect {
SpellAbility ability = copyCard.getSpellAbility(); SpellAbility ability = copyCard.getSpellAbility();
// remove the cipher effect from the copy // remove the cipher effect from the copy
Effect cipherEffect = null; Effect cipherEffect = null;
for (Effect effect :ability.getEffects()) { for (Effect effect : ability.getEffects()) {
if (effect instanceof CipherEffect) { if (effect instanceof CipherEffect) {
cipherEffect = effect; cipherEffect = effect;
} }
} }
ability.getEffects().remove(cipherEffect); ability.getEffects().remove(cipherEffect);
if (ability != null && ability instanceof SpellAbility) { if (ability instanceof SpellAbility) {
controller.cast(ability, game, true); controller.cast(ability, game, true);
} }
} }