* Progenitor Mimic - Fixed that the created copies could select a new target.

This commit is contained in:
LevelX2 2013-09-01 11:13:03 +02:00
parent 182839d41a
commit 5456a908a8
3 changed files with 154 additions and 10 deletions

View file

@ -34,13 +34,16 @@ import mage.constants.Rarity;
import mage.constants.TargetController;
import mage.constants.Zone;
import mage.MageInt;
import mage.MageObject;
import mage.abilities.Ability;
import mage.abilities.common.BeginningOfUpkeepTriggeredAbility;
import mage.abilities.common.SimpleStaticAbility;
import mage.abilities.condition.common.SourceMatchesFilterCondition;
import mage.abilities.decorator.ConditionalTriggeredAbility;
import mage.abilities.effects.Effect;
import mage.abilities.effects.EntersBattlefieldEffect;
import mage.abilities.effects.OneShotEffect;
import mage.abilities.effects.common.CopyEffect;
import mage.abilities.effects.common.CopyPermanentEffect;
import mage.cards.CardImpl;
import mage.filter.common.FilterCreaturePermanent;
@ -68,7 +71,9 @@ public class ProgenitorMimic extends CardImpl<ProgenitorMimic> {
this.power = new MageInt(0);
this.toughness = new MageInt(0);
// You may have Progenitor Mimic enter the battlefield as a copy of any creature on the battlefield except it gains "At the beginning of your upkeep, if this creature isn't a token, put a token onto the battlefield that's a copy of this creature."
// You may have Progenitor Mimic enter the battlefield as a copy of any creature on the battlefield
// except it gains "At the beginning of your upkeep, if this creature isn't a token,
// put a token onto the battlefield that's a copy of this creature."
this.addAbility(new SimpleStaticAbility(
Zone.BATTLEFIELD,
new EntersBattlefieldEffect(new CopyPermanentEffect(new ProgenitorMimicApplyToPermanent()),
@ -85,6 +90,7 @@ public class ProgenitorMimic extends CardImpl<ProgenitorMimic> {
return new ProgenitorMimic(this);
}
}
class ProgenitorMimicApplyToPermanent extends ApplyToPermanent {
private static final FilterCreaturePermanent filter = new FilterCreaturePermanent("no Token");
@ -94,7 +100,7 @@ class ProgenitorMimicApplyToPermanent extends ApplyToPermanent {
@Override
public Boolean apply(Game game, Permanent permanent) {
Ability ability = new ConditionalTriggeredAbility(
new BeginningOfUpkeepTriggeredAbility(new CopySourceEffect(), TargetController.YOU, false),
new BeginningOfUpkeepTriggeredAbility(new ProgenitorMimicCopyEffect(), TargetController.YOU, false),
new SourceMatchesFilterCondition(filter),
"At the beginning of your upkeep, if this creature isn't a token, put a token onto the battlefield that's a copy of this creature.");
permanent.addAbility(ability, game);
@ -102,30 +108,46 @@ class ProgenitorMimicApplyToPermanent extends ApplyToPermanent {
}
}
class CopySourceEffect extends OneShotEffect<CopySourceEffect> {
class ProgenitorMimicCopyEffect extends OneShotEffect<ProgenitorMimicCopyEffect> {
public CopySourceEffect() {
public ProgenitorMimicCopyEffect() {
super(Outcome.PutCreatureInPlay);
this.staticText = "put a token onto the battlefield that's a copy of this creature";
}
public CopySourceEffect(final CopySourceEffect effect) {
public ProgenitorMimicCopyEffect(final ProgenitorMimicCopyEffect effect) {
super(effect);
}
@Override
public CopySourceEffect copy() {
return new CopySourceEffect(this);
public ProgenitorMimicCopyEffect copy() {
return new ProgenitorMimicCopyEffect(this);
}
@Override
public boolean apply(Game game, Ability source) {
Permanent copyFromPermanent = game.getPermanent(source.getSourceId());
Permanent copyFromPermanent = null;
// retrieve the copied permanent of Progenitor Mimic
for (Effect effect : game.getState().getContinuousEffects().getLayeredEffects(game)) {
if (effect instanceof CopyEffect) {
CopyEffect copyEffect = (CopyEffect) effect;
// take the exiting copy effect of Progenitor Mimic
if (copyEffect.getSourceId().equals(source.getSourceId())) {
MageObject object = ((CopyEffect) effect).getTarget();
if (object instanceof Permanent) {
copyFromPermanent = (Permanent)object;
}
}
}
}
if (copyFromPermanent != null) {
EmptyToken token = new EmptyToken();
CardUtil.copyTo(token).from(copyFromPermanent);
token.putOntoBattlefield(1, game, source.getSourceId(), source.getControllerId());
return true;
Permanent sourcePermanent = game.getPermanent(token.getLastAddedToken());
if (sourcePermanent != null) {
game.copyPermanent(copyFromPermanent, sourcePermanent, source, new ProgenitorMimicApplyToPermanent());
return true;
}
}
return false;
}

View file

@ -0,0 +1,114 @@
package org.mage.test.cards.copy;
import junit.framework.Assert;
import mage.constants.CardType;
import mage.constants.PhaseStep;
import mage.constants.Zone;
import mage.game.permanent.Permanent;
import mage.game.permanent.PermanentToken;
import org.junit.Test;
import org.mage.test.serverside.base.CardTestPlayerBase;
/**
* @author LevelX2
*/
public class ProgenitorMimicTest extends CardTestPlayerBase {
/**
* Tests triggers working on both sides after Clone coming onto battlefield
*/
@Test
public void testCloneTriggered() {
addCard(Zone.BATTLEFIELD, playerA, "Runeclaw Bear", 1);
addCard(Zone.BATTLEFIELD, playerA, "Forest", 4);
addCard(Zone.HAND, playerB, "Progenitor Mimic");
addCard(Zone.BATTLEFIELD, playerB, "Island", 3);
addCard(Zone.BATTLEFIELD, playerB, "Forest", 3);
castSpell(2, PhaseStep.PRECOMBAT_MAIN, playerB, "Progenitor Mimic");
castSpell(2, PhaseStep.POSTCOMBAT_MAIN, playerA, "Anaconda");
setStopAt(4, PhaseStep.END_TURN);
execute();
assertLife(playerA, 20);
assertLife(playerB, 20);
assertPermanentCount(playerA, "Runeclaw Bear", 1);
assertPermanentCount(playerB, "Runeclaw Bear", 2);
int tokens = 0;
int nonTokens = 0;
for (Permanent permanent : currentGame.getBattlefield().getAllPermanents()) {
if (permanent.getControllerId().equals(playerB.getId())) {
if (permanent.getCardType().contains(CardType.CREATURE)) {
if (permanent instanceof PermanentToken) {
tokens++;
} else {
nonTokens++;
}
}
}
}
Assert.assertTrue("Only one non token permanent ",nonTokens == 1);
Assert.assertTrue("Only one token permanent ",tokens == 1);
}
// /**
// * Tests Clone is sacrificed and only one effect is turned on
// */
// @Test
// public void testCloneSacrifice() {
// addCard(Zone.BATTLEFIELD, playerA, "Bloodgift Demon", 1);
//
// addCard(Zone.HAND, playerA, "Diabolic Edict");
// addCard(Zone.BATTLEFIELD, playerA, "Swamp", 2);
//
// addCard(Zone.HAND, playerB, "Clone");
// addCard(Zone.BATTLEFIELD, playerB, "Island", 4);
//
// castSpell(2, PhaseStep.PRECOMBAT_MAIN, playerB, "Clone");
// castSpell(3, PhaseStep.POSTCOMBAT_MAIN, playerA, "Diabolic Edict", playerB);
//
// setStopAt(4, PhaseStep.END_TURN);
// execute();
//
// assertPermanentCount(playerA, "Bloodgift Demon", 1);
// assertGraveyardCount(playerA, "Diabolic Edict", 1);
// assertPermanentCount(playerB, "Bloodgift Demon", 0);
// assertGraveyardCount(playerB, "Clone", 1);
//
// // 1 from draw steps + 2 from Demon
// assertHandCount(playerA, 3);
// // 2 from draw steps + no from Demon (should be sacrificed)
// assertHandCount(playerB, 2);
//
// assertLife(playerA, 18);
// assertLife(playerB, 20);
// }
//
// @Test
// public void testCard3() {
// addCard(Zone.BATTLEFIELD, playerA, "Island", 6);
// addCard(Zone.BATTLEFIELD, playerA, "Swamp", 6);
// addCard(Zone.HAND, playerA, "Public Execution");
// addCard(Zone.HAND, playerA, "Clone");
//
// addCard(Zone.BATTLEFIELD, playerB, "Llanowar Elves");
// addCard(Zone.BATTLEFIELD, playerB, "Craw Wurm");
//
// castSpell(1, PhaseStep.PRECOMBAT_MAIN, playerA, "Public Executio", "Llanowar Elves");
// castSpell(1, PhaseStep.POSTCOMBAT_MAIN, playerA, "Clone");
//
// setStopAt(1, PhaseStep.END_TURN);
// execute();
//
// assertPermanentCount(playerB, "Llanowar Elves", 0);
// assertPowerToughness(playerB, "Craw Wurm", 4, 4);
// assertPowerToughness(playerA, "Craw Wurm", 6, 4);
// }
}

View file

@ -36,6 +36,8 @@ import mage.game.Game;
import mage.game.permanent.Permanent;
import java.util.UUID;
import mage.cards.Card;
import mage.game.permanent.PermanentCard;
/**
*
@ -98,6 +100,12 @@ public class CopyEffect extends ContinuousEffectImpl<CopyEffect> {
permanent.setTransformed(((Permanent)target).isTransformed());
permanent.setSecondCardFace(((Permanent) target).getSecondCardFace());
}
// to get the image of the copied permanent copy number und expansionCode
if (target instanceof PermanentCard) {
permanent.setCardNumber(((PermanentCard) target).getCard().getCardNumber());
permanent.setExpansionSetCode(((PermanentCard) target).getCard().getExpansionSetCode());
}
permanent.setCopy(true);
return true;