* Copy effect - Fixed that continuous copy effects were not removed as the related permanent left the battlefield.

This commit is contained in:
LevelX2 2015-06-13 00:25:31 +02:00
parent ad186480a3
commit 3dc081e1a6
4 changed files with 151 additions and 67 deletions

View file

@ -36,8 +36,10 @@ import mage.constants.Zone;
import mage.MageInt;
import mage.abilities.Ability;
import mage.abilities.common.SimpleStaticAbility;
import mage.abilities.effects.Effect;
import mage.abilities.effects.EntersBattlefieldEffect;
import mage.abilities.effects.OneShotEffect;
import mage.abilities.effects.common.CopyPermanentEffect;
import mage.cards.CardImpl;
import mage.filter.FilterPermanent;
import mage.filter.predicate.Predicates;
@ -55,6 +57,14 @@ import mage.util.functions.ApplyToPermanent;
*/
public class PhyrexianMetamorph extends CardImpl {
private static final FilterPermanent filter = new FilterPermanent("artifact or creature");
static {
filter.add(Predicates.or(
new CardTypePredicate(CardType.ARTIFACT),
new CardTypePredicate(CardType.CREATURE)));
}
public PhyrexianMetamorph (UUID ownerId) {
super(ownerId, 42, "Phyrexian Metamorph", Rarity.RARE, new CardType[]{CardType.ARTIFACT, CardType.CREATURE}, "{3}{UP}");
this.expansionSetCode = "NPH";
@ -63,10 +73,21 @@ public class PhyrexianMetamorph extends CardImpl {
this.power = new MageInt(0);
this.toughness = new MageInt(0);
Ability ability = new SimpleStaticAbility(Zone.BATTLEFIELD, new EntersBattlefieldEffect(
new PhyrexianMetamorphEffect(),
"You may have {this} enter the battlefield as a copy of any artifact or creature on the battlefield, except it's an artifact in addition to its other types",
true));
ApplyToPermanent phyrexianMetamorphApplier = new ApplyToPermanent() {
@Override
public Boolean apply(Game game, Permanent permanent) {
if (!permanent.getCardType().contains(CardType.ARTIFACT)) {
permanent.getCardType().add(CardType.ARTIFACT);
}
return true;
}
};
// {UP} ( can be paid with either {U} or 2 life.)
// You may have Phyrexian Metamorph enter the battlefield as a copy of any artifact or creature on the battlefield, except it's an artifact in addition to its other types.
Effect effect = new CopyPermanentEffect(filter, phyrexianMetamorphApplier);
effect.setText("You may have {this} enter the battlefield as a copy of any artifact or creature on the battlefield, except it's an artifact in addition to its other types");
Ability ability = new SimpleStaticAbility(Zone.BATTLEFIELD, new EntersBattlefieldEffect(effect));
this.addAbility(ability);
}
@ -80,56 +101,3 @@ public class PhyrexianMetamorph extends CardImpl {
}
}
class PhyrexianMetamorphEffect extends OneShotEffect {
private static final FilterPermanent filter = new FilterPermanent("artifact or creature");
static {
filter.add(Predicates.or(
new CardTypePredicate(CardType.ARTIFACT),
new CardTypePredicate(CardType.CREATURE)));
}
public PhyrexianMetamorphEffect() {
super(Outcome.Copy);
}
public PhyrexianMetamorphEffect(final PhyrexianMetamorphEffect effect) {
super(effect);
}
@Override
public boolean apply(Game game, Ability source) {
Player player = game.getPlayer(source.getControllerId());
Permanent sourcePermanent = game.getPermanent(source.getSourceId());
if (player != null && sourcePermanent != null) {
Target target = new TargetPermanent(filter);
target.setNotTarget(true);
if (target.canChoose(source.getControllerId(), game)) {
player.choose(Outcome.Copy, target, source.getSourceId(), game);
Permanent copyFromPermanent = game.getPermanent(target.getFirstTarget());
if (copyFromPermanent != null) {
game.copyPermanent(copyFromPermanent, sourcePermanent, source, new ApplyToPermanent() {
@Override
public Boolean apply(Game game, Permanent permanent) {
if (!permanent.getCardType().contains(CardType.ARTIFACT)) {
permanent.getCardType().add(CardType.ARTIFACT);
}
return true;
}
});
return true;
}
}
}
return false;
}
@Override
public PhyrexianMetamorphEffect copy() {
return new PhyrexianMetamorphEffect(this);
}
}

View file

@ -40,7 +40,6 @@ import mage.constants.CardType;
import mage.constants.Rarity;
import mage.constants.Zone;
import mage.filter.common.FilterControlledPermanent;
import mage.filter.common.FilterNonlandPermanent;
import mage.filter.predicate.Predicates;
import mage.filter.predicate.mageobject.CardTypePredicate;
import mage.target.common.TargetControlledPermanent;

View file

@ -0,0 +1,124 @@
/*
* Copyright 2010 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 org.mage.test.cards.copy;
import mage.constants.PhaseStep;
import mage.constants.Zone;
import org.junit.Test;
import org.mage.test.serverside.base.CardTestPlayerBase;
/**
*
* @author LevelX2
*/
public class PhyrexianMetamorphTest extends CardTestPlayerBase {
@Test
public void testCopyCreature() {
addCard(Zone.BATTLEFIELD, playerA, "Island", 1);
addCard(Zone.BATTLEFIELD, playerA, "Plains", 5);
// You may have Phyrexian Metamorph enter the battlefield as a copy of any artifact or creature on the battlefield, except it's an artifact in addition to its other types.
addCard(Zone.HAND, playerA, "Phyrexian Metamorph"); // {3}{UP}
addCard(Zone.HAND, playerA, "Cloudshift");
//Flying
// Vanishing 3 (This permanent enters the battlefield with three time counters on it. At the beginning of your upkeep, remove a time counter from it. When the last is removed, sacrifice it.)
// When Aven Riftwatcher enters the battlefield or leaves the battlefield, you gain 2 life.
addCard(Zone.BATTLEFIELD, playerB, "Aven Riftwatcher"); // 2/3
// When Ponyback Brigade enters the battlefield or is turned face up, put three 1/1 red Goblin creature tokens onto the battlefield.
addCard(Zone.BATTLEFIELD, playerB, "Ponyback Brigade"); // 2/2
castSpell(1, PhaseStep.PRECOMBAT_MAIN, playerA, "Phyrexian Metamorph");
setChoice(playerA, "Aven Riftwatcher");
castSpell(1, PhaseStep.POSTCOMBAT_MAIN, playerA, "Cloudshift", "Aven Riftwatcher");
setChoice(playerA, "Ponyback Brigade");
setStopAt(1, PhaseStep.END_TURN);
execute();
assertLife(playerA, 24);
assertLife(playerB, 20);
assertGraveyardCount(playerA, "Cloudshift", 1);
assertPermanentCount(playerA, "Ponyback Brigade", 1);
assertPermanentCount(playerA, "Goblin", 3);
}
/**
* An opponent cast Phyrexian Metamorph and cloned another opponent's
* Maelstrom Wanderer(his Commander). The first opponent then dealt combat
* damage with Brago, King Eternal and chose to flicker several permanents,
* including the Phyrexian Metamorph/Maelstrom Wanderer, but he was not able
* to choose a new creature to clone when the Phyrexian Metamorph re-entered
* the battlefield.
*/
@Test
public void testFlickerWithBrago() {
addCard(Zone.BATTLEFIELD, playerA, "Island", 4);
// You may have Phyrexian Metamorph enter the battlefield as a copy of any artifact or creature on the battlefield, except it's an artifact in addition to its other types.
addCard(Zone.HAND, playerA, "Phyrexian Metamorph"); // {3}{UP}
// Flying
// When Brago, King Eternal deals combat damage to a player, exile any number of target nonland permanents you control, then return those cards to the battlefield under their owner's control.
addCard(Zone.BATTLEFIELD, playerA, "Brago, King Eternal"); // 2/4
// Creatures you control have haste.
// Cascade, cascade
addCard(Zone.BATTLEFIELD, playerB, "Maelstrom Wanderer"); // 7/5
// When Ponyback Brigade enters the battlefield or is turned face up, put three 1/1 red Goblin creature tokens onto the battlefield.
addCard(Zone.BATTLEFIELD, playerB, "Ponyback Brigade"); // 2/2
castSpell(1, PhaseStep.PRECOMBAT_MAIN, playerA, "Phyrexian Metamorph");
setChoice(playerA, "Maelstrom Wanderer");
attack(3, playerA, "Brago, King Eternal");
addTarget(playerA, "Maelstrom Wanderer");
setChoice(playerA, "Ponyback Brigade");
setStopAt(3, PhaseStep.END_COMBAT);
execute();
assertLife(playerA, 20);
assertLife(playerB, 18);
assertPermanentCount(playerA, "Ponyback Brigade", 1);
assertPermanentCount(playerA, "Goblin", 3);
}
}

View file

@ -81,19 +81,12 @@ public class CopyEffect extends ContinuousEffectImpl {
@Override
public void init(Ability source, Game game) {
super.init(source, game);
if (affectedObjectsSet) {
affectedObjectList.add(new MageObjectReference(sourceId, game));
}
affectedObjectList.add(new MageObjectReference(getSourceId(), game));
}
@Override
public boolean apply(Game game, Ability source) {
Permanent permanent;
if (affectedObjectsSet) {
permanent = affectedObjectList.get(0).getPermanent(game);
} else {
permanent = game.getPermanent(this.sourceId);
}
Permanent permanent = affectedObjectList.get(0).getPermanent(game);
if (permanent == null) {
permanent = (Permanent) game.getLastKnownInformation(getSourceId(), Zone.BATTLEFIELD, source.getSourceObjectZoneChangeCounter());
// As long as the permanent is still in the LKI continue to copy to get triggered abilities to TriggeredAbilites for dies events.