diff --git a/Mage.Sets/src/mage/cards/c/CopyEnchantment.java b/Mage.Sets/src/mage/cards/c/CopyEnchantment.java index fed00a94a06..f84ee371ddd 100644 --- a/Mage.Sets/src/mage/cards/c/CopyEnchantment.java +++ b/Mage.Sets/src/mage/cards/c/CopyEnchantment.java @@ -14,7 +14,7 @@ import mage.constants.CardType; import mage.constants.SubType; import mage.constants.Outcome; import mage.filter.FilterPermanent; -import mage.filter.common.FilterEnchantmentPermanent; +import mage.filter.StaticFilters; import mage.game.Game; import mage.game.permanent.Permanent; import mage.players.Player; @@ -31,7 +31,8 @@ public final class CopyEnchantment extends CardImpl { super(ownerId,setInfo,new CardType[]{CardType.ENCHANTMENT},"{2}{U}"); // You may have Copy Enchantment enter the battlefield as a copy of any enchantment on the battlefield. - this.addAbility(new EntersBattlefieldAbility(new CopyEnchantmentEffect(new FilterEnchantmentPermanent("any enchantment")), true)); + //this.addAbility(new EntersBattlefieldAbility(new CopyEnchantmentEffect(new FilterEnchantmentPermanent("any enchantment")), true)); + this.addAbility(new EntersBattlefieldAbility(new CopyPermanentEffect(StaticFilters.FILTER_ENCHANTMENT_PERMANENT), true)); } public CopyEnchantment(final CopyEnchantment card) { diff --git a/Mage/src/main/java/mage/abilities/effects/common/CopyPermanentEffect.java b/Mage/src/main/java/mage/abilities/effects/common/CopyPermanentEffect.java index 1fb1364e36f..d74258916fa 100644 --- a/Mage/src/main/java/mage/abilities/effects/common/CopyPermanentEffect.java +++ b/Mage/src/main/java/mage/abilities/effects/common/CopyPermanentEffect.java @@ -1,10 +1,14 @@ package mage.abilities.effects.common; +import java.util.UUID; import mage.MageObject; import mage.abilities.Ability; +import mage.abilities.SpellAbility; +import mage.abilities.effects.Effect; import mage.abilities.effects.OneShotEffect; import mage.constants.Outcome; +import mage.constants.SubType; import mage.filter.FilterPermanent; import mage.filter.StaticFilters; import mage.filter.common.FilterCreaturePermanent; @@ -61,25 +65,64 @@ public class CopyPermanentEffect extends OneShotEffect { @Override public boolean apply(Game game, Ability source) { - Player player = game.getPlayer(source.getControllerId()); - MageObject sourceObject = game.getPermanentEntering(source.getSourceId()); - if (sourceObject == null) { - sourceObject = game.getObject(source.getSourceId()); + Player controller = game.getPlayer(source.getControllerId()); + MageObject sourcePermanent = game.getPermanentEntering(source.getSourceId()); + if (sourcePermanent == null) { + sourcePermanent = game.getObject(source.getSourceId()); } - if (player != null && sourceObject != null) { + if (controller != null && sourcePermanent != null) { Permanent copyFromPermanent = null; if (useTargetOfAbility) { copyFromPermanent = game.getPermanent(getTargetPointer().getFirst(game, source)); } else { Target target = new TargetPermanent(filter); target.setNotTarget(true); - if (target.canChoose(source.getSourceId(), player.getId(), game)) { - player.choose(Outcome.Copy, target, source.getSourceId(), game); + if (target.canChoose(source.getSourceId(), controller.getId(), game)) { + controller.choose(Outcome.Copy, target, source.getSourceId(), game); copyFromPermanent = game.getPermanent(target.getFirstTarget()); } } if (copyFromPermanent != null) { - bluePrintPermanent = game.copyPermanent(copyFromPermanent, sourceObject.getId(), source, applier); + bluePrintPermanent = game.copyPermanent(copyFromPermanent, sourcePermanent.getId(), source, applier); + + //if object is a copy of an aura, it needs to attach + if (bluePrintPermanent.hasSubtype(SubType.AURA, game)){ + //copied from mage.cards.c.CopyEnchantment.java + Target target = bluePrintPermanent.getSpellAbility().getTargets().get(0); + Outcome auraOutcome = Outcome.BoostCreature; + for (Ability ability : bluePrintPermanent.getAbilities()) { + if (ability instanceof SpellAbility) { + for (Effect effect : ability.getEffects()) { + if (effect instanceof AttachEffect) { + auraOutcome = effect.getOutcome(); + } + } + } + } + + /*if this is a copy of a copy, the copy's target has been + *copied and needs to be cleared + */ + { + UUID targetId = target.getFirstTarget(); + if(targetId != null) + target.remove(targetId); + } + + target.setNotTarget(true); + if (controller.choose(auraOutcome, target, source.getSourceId(), game)) { + UUID targetId = target.getFirstTarget(); + Permanent targetPermanent = game.getPermanent(targetId); + Player targetPlayer = game.getPlayer(targetId); + if (targetPermanent != null) { + targetPermanent.addAttachment(sourcePermanent.getId(), game); + } else if (targetPlayer != null) { + targetPlayer.addAttachment(sourcePermanent.getId(), game); + } else { + return false; + } + } + } } return true; }