From bb1839f79bb03abe09aad16159939d1b9c6c22f5 Mon Sep 17 00:00:00 2001 From: LevelX2 Date: Tue, 1 Sep 2015 23:54:56 +0200 Subject: [PATCH] Added a test. --- .../mage/sets/eventide/DivinityOfPride.java | 21 +++--- .../sets/mirrodinbesieged/Cryptoplasm.java | 69 +++++++++---------- .../mage/test/AI/basic/CastCreaturesTest.java | 4 ++ .../mage/test/cards/copy/CryptoplasmTest.java | 59 ++++++++++++++++ 4 files changed, 108 insertions(+), 45 deletions(-) diff --git a/Mage.Sets/src/mage/sets/eventide/DivinityOfPride.java b/Mage.Sets/src/mage/sets/eventide/DivinityOfPride.java index 19558dcc7f..19190e1ec5 100644 --- a/Mage.Sets/src/mage/sets/eventide/DivinityOfPride.java +++ b/Mage.Sets/src/mage/sets/eventide/DivinityOfPride.java @@ -28,11 +28,6 @@ package mage.sets.eventide; import java.util.UUID; - -import mage.constants.CardType; -import mage.constants.Duration; -import mage.constants.Rarity; -import mage.constants.Zone; import mage.MageInt; import mage.abilities.Ability; import mage.abilities.common.SimpleStaticAbility; @@ -42,6 +37,10 @@ import mage.abilities.effects.common.continuous.BoostSourceEffect; import mage.abilities.keyword.FlyingAbility; import mage.abilities.keyword.LifelinkAbility; import mage.cards.CardImpl; +import mage.constants.CardType; +import mage.constants.Duration; +import mage.constants.Rarity; +import mage.constants.Zone; import mage.game.Game; import mage.players.Player; @@ -57,15 +56,19 @@ public class DivinityOfPride extends CardImpl { this.subtype.add("Spirit"); this.subtype.add("Avatar"); - this.power = new MageInt(4); this.toughness = new MageInt(4); + // Flying this.addAbility(FlyingAbility.getInstance()); + + // Lifelink this.addAbility(LifelinkAbility.getInstance()); + + // Divinity of Pride gets +4/+4 as long as you have 25 or more life. this.addAbility(new SimpleStaticAbility(Zone.BATTLEFIELD, new ConditionalContinuousEffect(new BoostSourceEffect(4, 4, Duration.WhileOnBattlefield), - new DivinityOfPrideCondition(), - "Divinity of Pride gets +4/+4 as long as you have 25 or more life"))); + new DivinityOfPrideCondition(), + "{this} gets +4/+4 as long as you have 25 or more life"))); } public DivinityOfPride(final DivinityOfPride card) { @@ -85,4 +88,4 @@ class DivinityOfPrideCondition implements Condition { Player player = game.getPlayer(source.getControllerId()); return player != null && player.getLife() >= 25; } -} \ No newline at end of file +} diff --git a/Mage.Sets/src/mage/sets/mirrodinbesieged/Cryptoplasm.java b/Mage.Sets/src/mage/sets/mirrodinbesieged/Cryptoplasm.java index 64202e88ca..3f02879da6 100644 --- a/Mage.Sets/src/mage/sets/mirrodinbesieged/Cryptoplasm.java +++ b/Mage.Sets/src/mage/sets/mirrodinbesieged/Cryptoplasm.java @@ -25,17 +25,19 @@ * authors and should not be interpreted as representing official policies, either expressed * or implied, of BetaSteward_at_googlemail.com. */ - package mage.sets.mirrodinbesieged; -import mage.constants.CardType; -import mage.constants.Rarity; +import java.util.UUID; import mage.MageInt; import mage.abilities.Ability; import mage.abilities.common.BeginningOfUpkeepTriggeredAbility; -import mage.abilities.effects.ContinuousEffectImpl; +import mage.abilities.effects.OneShotEffect; +import mage.abilities.effects.common.CopyEffect; import mage.cards.CardImpl; -import mage.constants.*; +import mage.constants.CardType; +import mage.constants.Outcome; +import mage.constants.Rarity; +import mage.constants.TargetController; import mage.filter.common.FilterCreaturePermanent; import mage.filter.predicate.permanent.AnotherPredicate; import mage.game.Game; @@ -43,12 +45,11 @@ import mage.game.permanent.Permanent; import mage.target.common.TargetCreaturePermanent; import mage.util.functions.ApplyToPermanent; -import java.util.UUID; - /** * @author Loki */ public class Cryptoplasm extends CardImpl { + final static FilterCreaturePermanent filter = new FilterCreaturePermanent(); static { @@ -64,7 +65,7 @@ public class Cryptoplasm extends CardImpl { this.toughness = new MageInt(2); // At the beginning of your upkeep, you may have Cryptoplasm become a copy of another target creature. If you do, Cryptoplasm gains this ability. - Ability ability = new BeginningOfUpkeepTriggeredAbility(new CryptoplasmTransformEffect(), TargetController.YOU, true); + Ability ability = new BeginningOfUpkeepTriggeredAbility(new CryptoplasmEffect(), TargetController.YOU, true); ability.addTarget(new TargetCreaturePermanent(filter)); this.addAbility(ability); } @@ -80,43 +81,39 @@ public class Cryptoplasm extends CardImpl { } -class CryptoplasmTransformEffect extends ContinuousEffectImpl { +class CryptoplasmEffect extends OneShotEffect { - CryptoplasmTransformEffect() { - super(Duration.WhileOnBattlefield, Layer.CopyEffects_1, SubLayer.NA, Outcome.Copy); - staticText = "you may have {this} become a copy of another target creature. If you do, {this} gains this ability"; + public CryptoplasmEffect() { + super(Outcome.Copy); + this.staticText = "you may have {this} become a copy of another target creature. If you do, {this} gains this ability"; } - CryptoplasmTransformEffect(final CryptoplasmTransformEffect effect) { + public CryptoplasmEffect(final CryptoplasmEffect effect) { super(effect); } @Override - public boolean apply(Game game, final Ability source) { - Permanent creature = game.getPermanent(targetPointer.getFirst(game, source)); - Permanent permanent = game.getPermanent(source.getSourceId()); - - if (creature == null || permanent == null) { - return false; - } - - game.copyPermanent(creature, permanent, source, new ApplyToPermanent() { - @Override - public Boolean apply(Game game, Permanent permanent) { - Ability upkeepAbility = new BeginningOfUpkeepTriggeredAbility(new CryptoplasmTransformEffect(), TargetController.YOU, true); - upkeepAbility.addTarget(new TargetCreaturePermanent()); - permanent.addAbility(upkeepAbility, source.getSourceId(), game); - return true; - } - }); - - - return true; + public CryptoplasmEffect copy() { + return new CryptoplasmEffect(this); } @Override - public CryptoplasmTransformEffect copy() { - return new CryptoplasmTransformEffect(this); - } + public boolean apply(Game game, final Ability source) { + Permanent creatureToCopy = game.getPermanent(getTargetPointer().getFirst(game, source)); + if (creatureToCopy != null) { + CopyEffect effect = new CopyEffect(creatureToCopy, source.getSourceId()); + effect.setApplier(new ApplyToPermanent() { + @Override + public Boolean apply(Game game, Permanent permanent) { + Ability upkeepAbility = new BeginningOfUpkeepTriggeredAbility(new CryptoplasmEffect(), TargetController.YOU, true); + upkeepAbility.addTarget(new TargetCreaturePermanent()); + permanent.addAbility(upkeepAbility, source.getSourceId(), game); + return true; + } + }); + game.addEffect(effect, source); + } + return true; + } } diff --git a/Mage.Tests/src/test/java/org/mage/test/AI/basic/CastCreaturesTest.java b/Mage.Tests/src/test/java/org/mage/test/AI/basic/CastCreaturesTest.java index 565fc57e36..7ec428cced 100644 --- a/Mage.Tests/src/test/java/org/mage/test/AI/basic/CastCreaturesTest.java +++ b/Mage.Tests/src/test/java/org/mage/test/AI/basic/CastCreaturesTest.java @@ -52,6 +52,10 @@ public class CastCreaturesTest extends CardTestPlayerBaseAI { assertPermanentCount(playerA, "Silvercoat Lion", 1); } + /** + * This test fails sometimes, probably because two plains are tapped for the + * first creature + */ @Test public void testSimpleCast2() { addCard(Zone.HAND, playerA, "Silvercoat Lion"); diff --git a/Mage.Tests/src/test/java/org/mage/test/cards/copy/CryptoplasmTest.java b/Mage.Tests/src/test/java/org/mage/test/cards/copy/CryptoplasmTest.java index 1f8926e2cf..f57e5f9342 100644 --- a/Mage.Tests/src/test/java/org/mage/test/cards/copy/CryptoplasmTest.java +++ b/Mage.Tests/src/test/java/org/mage/test/cards/copy/CryptoplasmTest.java @@ -55,4 +55,63 @@ public class CryptoplasmTest extends CardTestPlayerBase { assertPermanentCount(playerB, "Cryptoplasm", 0); assertPermanentCount(playerB, "Sigiled Paladin", 2); } + + /** + * I'm at 8 life, opponent (AI) is at 21. I have a Cryptoplasm currently + * copying my opponent's Divinity of Pride, the Crypto also has my Followed + * Footsteps attached to it. Additionally, I have another Cryptoplasm on the + * battlefield also copying the same Divinity, and a Clever Impersonator + * that ETB copying the first Cryptoplasm and is currently also a copy of + * the Divinity. + * + * Opponent attacks with his only Divinity of Pride (4/4) and a Serra + * Avenger (3/3). I block the Divinity with two of my Divinity copies (the + * Clever Impersonator and unenchanted Cryptoplasm) and the Avenger with the + * enchanted Divinity (originally a Cryptoplasm). My opponent's Divinity + * kills my two copies and dies, and then his Avenger dies and kills the + * Divinity blocking it, also sending my Followed Footsteps down with it. + * + * How does any of that add up? Not only should his Divinity only kill one + * of mine since it was a 4/4 and only becomes an 8/8 after dealing its + * damage (at which point it should be too late to go back and say the 4 + * damage are now 8, since it was that exact damage that put him at 25 + * life), but even more confusing is how the Serra Avenger, which is a 3/3, + * somehow kills my 4/4 that had suffered no other damage that turn. + * + * No other permanents in play at that moment had any influence in this + * either, they were only basic lands and a couple of creatures with no + * relevant abilities. + * + * I won't put aside me completely missing something here, but I really + * can't see any other explanation to this other than a game bug. + */ + @Test + public void testDamageLifelink() { + setLife(playerA, 21); + setLife(playerB, 8); + // First strike + // Exalted (Whenever a creature you control attacks alone, that creature gets +1/+1 until end of turn.) + addCard(Zone.BATTLEFIELD, playerA, "Divinity of Pride", 1); // {W}{W} + + addCard(Zone.BATTLEFIELD, playerB, "Island", 5); + // At the beginning of your upkeep, you may have Cryptoplasm become a copy of another target creature. If you do, Cryptoplasm gains this ability. + addCard(Zone.BATTLEFIELD, playerB, "Cryptoplasm", 2); // {1}{U}{U} + addTarget(playerB, "Divinity of Pride"); + addTarget(playerB, "Divinity of Pride"); + + attack(3, playerA, "Divinity of Pride"); + block(3, playerB, "Divinity of Pride", "Divinity of Pride"); + block(3, playerB, "Divinity of Pride", "Divinity of Pride"); + + setStopAt(3, PhaseStep.POSTCOMBAT_MAIN); + execute(); + + assertPermanentCount(playerB, "Cryptoplasm", 0); + + assertPermanentCount(playerA, "Divinity of Pride", 0); + assertPermanentCount(playerB, "Divinity of Pride", 1); + + assertLife(playerB, 16); + assertLife(playerA, 25); + } }