From 20138891fe79f6a70d31260b5b4c5ff79fe93ab9 Mon Sep 17 00:00:00 2001 From: LevelX2 Date: Mon, 16 May 2016 11:07:18 +0200 Subject: [PATCH] * Fixed that a delayed sacrifice source effect could create a null pointer exception. --- .../abilities/keywords/TransformTest.java | 32 +++++++++++++++++++ .../cards/abilities/other/NecromancyTest.java | 23 +++++++++++++ .../effects/common/SacrificeSourceEffect.java | 2 +- 3 files changed, 56 insertions(+), 1 deletion(-) diff --git a/Mage.Tests/src/test/java/org/mage/test/cards/abilities/keywords/TransformTest.java b/Mage.Tests/src/test/java/org/mage/test/cards/abilities/keywords/TransformTest.java index 4b0227da37c..39a27bafa77 100644 --- a/Mage.Tests/src/test/java/org/mage/test/cards/abilities/keywords/TransformTest.java +++ b/Mage.Tests/src/test/java/org/mage/test/cards/abilities/keywords/TransformTest.java @@ -213,4 +213,36 @@ public class TransformTest extends CardTestPlayerBase { Assert.assertFalse("Has not to have sorcery card type", nightmare.getCardType().contains(CardType.SORCERY)); } + /** + * When copy token of Lambholt Pacifist transforms with "its transform + * ability", I see below error. Then rollback. + * + * 701.25a Only permanents represented by double-faced cards can transform. + * (See rule 711, “Double-Faced Cards.”) If a spell or ability instructs a + * player to transform any permanent that isn‘t represented by a + * double-faced card, nothing happens. + */ + @Test + public void testTransformCopy() { + addCard(Zone.BATTLEFIELD, playerA, "Forest", 2); + // Lambholt Pacifist can't attack unless you control a creature with power 4 or greater. + // At the beginning of each upkeep, if no spells were cast last turn, transform Lambholt Pacifist. + addCard(Zone.HAND, playerA, "Lambholt Pacifist"); // {1}{G} + + addCard(Zone.BATTLEFIELD, playerB, "Island", 4); + // You may have Clone enter the battlefield as a copy of any creature on the battlefield. + addCard(Zone.HAND, playerB, "Clone"); // {3}{U} + + castSpell(1, PhaseStep.PRECOMBAT_MAIN, playerA, "Lambholt Pacifist"); + + castSpell(2, PhaseStep.PRECOMBAT_MAIN, playerB, "Clone"); + setChoice(playerB, "Lambholt Pacifist"); + + setStopAt(4, PhaseStep.PRECOMBAT_MAIN); + execute(); + + assertPermanentCount(playerA, "Lambholt Butcher", 1); + + assertPermanentCount(playerB, "Lambholt Pacifist", 1); + } } diff --git a/Mage.Tests/src/test/java/org/mage/test/cards/abilities/other/NecromancyTest.java b/Mage.Tests/src/test/java/org/mage/test/cards/abilities/other/NecromancyTest.java index 4cf62035433..8c95a1fcd29 100644 --- a/Mage.Tests/src/test/java/org/mage/test/cards/abilities/other/NecromancyTest.java +++ b/Mage.Tests/src/test/java/org/mage/test/cards/abilities/other/NecromancyTest.java @@ -128,4 +128,27 @@ public class NecromancyTest extends CardTestPlayerBase { assertGraveyardCount(playerA, "Craw Wurm", 1); } + /** + * I was playing a legendary cube, flashed in a Necromancy to block and when + * the creature I reanimated died the game bugged out and I lost. + */ + @Test + public void testBlockWithNecromancyCreature() { + addCard(Zone.BATTLEFIELD, playerB, "Silvercoat Lion"); + + addCard(Zone.BATTLEFIELD, playerA, "Swamp", 3); + addCard(Zone.HAND, playerA, "Necromancy"); // {2}{B} + addCard(Zone.GRAVEYARD, playerA, "Silvercoat Lion"); + + attack(2, playerB, "Silvercoat Lion"); + castSpell(2, PhaseStep.DECLARE_ATTACKERS, playerA, "Necromancy"); // enchanting the Silvercoat Lion + block(2, playerA, "Silvercoat Lion", "Silvercoat Lion"); + + setStopAt(3, PhaseStep.END_TURN); + execute(); + + assertGraveyardCount(playerA, "Necromancy", 1); + assertGraveyardCount(playerA, "Silvercoat Lion", 1); + assertGraveyardCount(playerB, "Silvercoat Lion", 1); + } } diff --git a/Mage/src/main/java/mage/abilities/effects/common/SacrificeSourceEffect.java b/Mage/src/main/java/mage/abilities/effects/common/SacrificeSourceEffect.java index 2dfc09db98e..f3a09503315 100644 --- a/Mage/src/main/java/mage/abilities/effects/common/SacrificeSourceEffect.java +++ b/Mage/src/main/java/mage/abilities/effects/common/SacrificeSourceEffect.java @@ -62,7 +62,7 @@ public class SacrificeSourceEffect extends OneShotEffect { // Check if the effect was installed by the spell the source was cast by (e.g. Necromancy), if not don't sacrifice the permanent if (source.getSourceObject(game) instanceof Spell) { sourceObject = game.getPermanent(source.getSourceId()); - if (sourceObject.getZoneChangeCounter(game) > source.getSourceObjectZoneChangeCounter() + 1) { + if (sourceObject != null && sourceObject.getZoneChangeCounter(game) > source.getSourceObjectZoneChangeCounter() + 1) { return false; } }