diff --git a/Mage.Sets/src/mage/sets/tenth/Clone.java b/Mage.Sets/src/mage/sets/tenth/Clone.java index fae67f41e2..7d701a0a92 100644 --- a/Mage.Sets/src/mage/sets/tenth/Clone.java +++ b/Mage.Sets/src/mage/sets/tenth/Clone.java @@ -33,10 +33,10 @@ import mage.Constants.CardType; import mage.Constants.Rarity; import mage.MageInt; import mage.abilities.Ability; +import mage.abilities.common.CopyPermanentEffect; import mage.abilities.common.EntersBattlefieldAbility; -import mage.abilities.effects.common.CopyEffect; +import mage.abilities.effects.EntersBattlefieldEffect; import mage.cards.CardImpl; -import mage.target.common.TargetCreaturePermanent; /** * @@ -52,8 +52,7 @@ public class Clone extends CardImpl { this.power = new MageInt(0); this.toughness = new MageInt(0); - Ability ability = new EntersBattlefieldAbility(new CopyEffect(), "You may have {this} enter the battlefield as a copy of any creature on the battlefield"); - ability.addTarget(new TargetCreaturePermanent()); + Ability ability = new EntersBattlefieldAbility(new EntersBattlefieldEffect(new CopyPermanentEffect()), "You may have {this} enter the battlefield as a copy of any creature on the battlefield"); this.addAbility(ability); } @@ -66,4 +65,4 @@ public class Clone extends CardImpl { return new Clone(this); } -} \ No newline at end of file +} diff --git a/Mage/src/mage/abilities/common/CopyPermanentEffect.java b/Mage/src/mage/abilities/common/CopyPermanentEffect.java new file mode 100644 index 0000000000..5e85af1573 --- /dev/null +++ b/Mage/src/mage/abilities/common/CopyPermanentEffect.java @@ -0,0 +1,91 @@ +/* + * Copyright 2011 BetaSteward_at_googlemail.com. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, are + * permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this list of + * conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, this list + * of conditions and the following disclaimer in the documentation and/or other materials + * provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY BetaSteward_at_googlemail.com ``AS IS'' AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL BetaSteward_at_googlemail.com OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * The views and conclusions contained in the software and documentation are those of the + * authors and should not be interpreted as representing official policies, either expressed + * or implied, of BetaSteward_at_googlemail.com. + */ +package mage.abilities.common; + +import mage.Constants.Outcome; +import mage.abilities.Ability; +import mage.abilities.effects.OneShotEffect; +import mage.abilities.effects.common.CopyEffect; +import mage.filter.FilterPermanent; +import mage.filter.common.FilterCreaturePermanent; +import mage.game.Game; +import mage.game.permanent.Permanent; +import mage.players.Player; +import mage.target.Target; +import mage.target.TargetPermanent; + +/** + * + * @author BetaSteward_at_googlemail.com + */ +public class CopyPermanentEffect extends OneShotEffect { + + private FilterPermanent filter; + + public CopyPermanentEffect() { + this(FilterCreaturePermanent.getDefault()); + } + + public CopyPermanentEffect(FilterPermanent filter) { + super(Outcome.Copy); + this.filter = filter; + this.staticText = "You may have {this} enter the battlefield as a copy of any " + filter.getMessage() + " on the battlefield"; + } + + public CopyPermanentEffect(final CopyPermanentEffect effect) { + super(effect); + this.filter = effect.filter.copy(); + } + + @Override + public boolean apply(Game game, Ability source) { + //TODO: handle copying copies + Player player = game.getPlayer(source.getControllerId()); + if (player != null) { + Target target = new TargetPermanent(filter); + if (target.canChoose(source.getControllerId(), game)) { + player.choose(Outcome.Copy, target, game); + Permanent perm = game.getPermanent(target.getFirstTarget()); + if (perm != null) { + perm = perm.copy(); + perm.reset(game); + perm.assignNewId(); + game.addEffect(new CopyEffect(perm), source); + return true; + } + } + } + return false; + } + + @Override + public CopyPermanentEffect copy() { + return new CopyPermanentEffect(this); + } + +} \ No newline at end of file diff --git a/Mage/src/mage/abilities/effects/common/CopyEffect.java b/Mage/src/mage/abilities/effects/common/CopyEffect.java index 5a102245c7..f165ac592b 100644 --- a/Mage/src/mage/abilities/effects/common/CopyEffect.java +++ b/Mage/src/mage/abilities/effects/common/CopyEffect.java @@ -33,10 +33,9 @@ import mage.Constants.Duration; import mage.Constants.Layer; import mage.Constants.Outcome; import mage.Constants.SubLayer; +import mage.MageObject; import mage.abilities.Ability; -import mage.abilities.Mode; import mage.abilities.effects.ContinuousEffectImpl; -import mage.cards.Card; import mage.game.Game; import mage.game.permanent.Permanent; @@ -46,45 +45,45 @@ import mage.game.permanent.Permanent; */ public class CopyEffect extends ContinuousEffectImpl { - public CopyEffect() { + private MageObject target; + + public CopyEffect(MageObject target) { super(Duration.WhileOnBattlefield, Layer.CopyEffects_1, SubLayer.NA, Outcome.BecomeCreature); + this.target = target; } public CopyEffect(final CopyEffect effect) { super(effect); + this.target = effect.target.copy(); } @Override public boolean apply(Game game, Ability source) { - Card card = game.getCard(source.getFirstTarget()); - Permanent permanent = game.getPermanent(source.getSourceId()); - permanent.setName(card.getName()); - permanent.getColor().setColor(card.getColor()); - permanent.getManaCost().clear(); - permanent.getManaCost().add(card.getManaCost()); - permanent.getCardType().clear(); - for (CardType type: card.getCardType()) { - permanent.getCardType().add(type); - } - permanent.getSubtype().clear(); - for (String type: card.getSubtype()) { - permanent.getSubtype().add(type); - } - permanent.getSupertype().clear(); - for (String type: card.getSupertype()) { - permanent.getSupertype().add(type); - } - permanent.setExpansionSetCode(card.getExpansionSetCode()); - permanent.getAbilities().clear(); - for (Ability ability: card.getAbilities()) { - permanent.addAbility(ability); - } - permanent.getPower().setValue(card.getPower().getValue()); - permanent.getToughness().setValue(card.getToughness().getValue()); - //permanent.getLoyalty().setValue(card.getLoyalty().getValue()); - - return true; + Permanent permanent = game.getPermanent(source.getSourceId()); + permanent.setName(target.getName()); + permanent.getColor().setColor(target.getColor()); + permanent.getManaCost().clear(); + permanent.getManaCost().add(target.getManaCost()); + permanent.getCardType().clear(); + for (CardType type: target.getCardType()) { + permanent.getCardType().add(type); + } + permanent.getSubtype().clear(); + for (String type: target.getSubtype()) { + permanent.getSubtype().add(type); + } + permanent.getSupertype().clear(); + for (String type: target.getSupertype()) { + permanent.getSupertype().add(type); + } + permanent.getAbilities().clear(); + for (Ability ability: target.getAbilities()) { + permanent.addAbility(ability); + } + permanent.getPower().setValue(target.getPower().getValue()); + permanent.getToughness().setValue(target.getToughness().getValue()); + return true; } @Override @@ -92,9 +91,4 @@ public class CopyEffect extends ContinuousEffectImpl { return new CopyEffect(this); } - @Override - public String getText(Mode mode) { - return "You may have {this} enter the battlefield as a copy of any " + mode.getTargets().get(0).getTargetName() + " on the battlefield"; - } - }