diff --git a/Mage.Tests/src/test/java/org/mage/test/cards/continuous/LandTypeChangingEffectsTest.java b/Mage.Tests/src/test/java/org/mage/test/cards/continuous/LandTypeChangingEffectsTest.java index a973ff839ba..3184641c2df 100644 --- a/Mage.Tests/src/test/java/org/mage/test/cards/continuous/LandTypeChangingEffectsTest.java +++ b/Mage.Tests/src/test/java/org/mage/test/cards/continuous/LandTypeChangingEffectsTest.java @@ -27,6 +27,7 @@ */ package org.mage.test.cards.continuous; +import mage.abilities.keyword.IndestructibleAbility; import mage.abilities.mana.AnyColorManaAbility; import mage.constants.CardType; import mage.constants.PhaseStep; @@ -142,7 +143,7 @@ public class LandTypeChangingEffectsTest extends CardTestPlayerBase { /* TODO: NOTE: this test is currently failing due to bug in code. See issue #3072 */ - @Ignore + //@Ignore @Test public void testBloodMoonBeforeUrborg() { // Blood Moon 2R @@ -175,7 +176,7 @@ public class LandTypeChangingEffectsTest extends CardTestPlayerBase { /* TODO: NOTE: this test is currently failing due to bug in code. See issue #3072 */ - @Ignore + //@Ignore @Test public void testBloodMoonAfterUrborg() { // Blood Moon 2R @@ -267,4 +268,30 @@ public class LandTypeChangingEffectsTest extends CardTestPlayerBase { Assert.assertTrue("4 lands have to be creatures but there are " + creatures, creatures == 4); } + @Test + public void testBloodSunWithUrborgtoyAndStormtideLeviathanMan() { + + addCard(Zone.BATTLEFIELD, playerA, urborgtoy); // all lands are swamps in addition to their other types + addCard(Zone.BATTLEFIELD, playerA, "Mountain", 4); + addCard(Zone.BATTLEFIELD, playerA, "Blood Sun"); // all lands lose all abilities except for mana-producing + addCard(Zone.BATTLEFIELD, playerA, "Stormtide Leviathan"); // all lands are islands in addition to their other types + addCard(Zone.BATTLEFIELD, playerA, "Darksteel Citadel"); // land has indestructible ability + + setStopAt(3, PhaseStep.POSTCOMBAT_MAIN); + execute(); + + Permanent darksteel = getPermanent("Darksteel Citadel", playerA.getId()); + Assert.assertNotNull(darksteel); + Assert.assertFalse(darksteel.getAbilities().contains(IndestructibleAbility.getInstance())); // The ability is removed + + /* + If a continuous effect has started applying in an earlier layer, it will continue to apply in + later layers even if the ability that created that effect has been removed. + Urborg ability is applied in the 4th layer. The Blood Sun works in the 6th. So the effect still applies to the lands. + */ + assertType(urborgtoy, CardType.LAND, SubType.SWAMP); + assertType("Mountain", CardType.LAND, SubType.SWAMP); + assertType(urborgtoy, CardType.LAND, SubType.ISLAND); + assertType("Mountain", CardType.LAND, SubType.ISLAND); + } } diff --git a/Mage/src/main/java/mage/abilities/effects/ContinuousEffects.java b/Mage/src/main/java/mage/abilities/effects/ContinuousEffects.java index f7933a870f4..0cbe7af6e2a 100644 --- a/Mage/src/main/java/mage/abilities/effects/ContinuousEffects.java +++ b/Mage/src/main/java/mage/abilities/effects/ContinuousEffects.java @@ -33,8 +33,10 @@ import java.util.Map.Entry; import java.util.stream.Collectors; import mage.MageObject; import mage.abilities.*; +import mage.abilities.effects.common.continuous.BecomesFaceDownCreatureEffect; import mage.abilities.effects.common.continuous.CommanderReplacementEffect; import mage.abilities.keyword.SpliceOntoArcaneAbility; +import mage.cards.Card; import mage.cards.Cards; import mage.cards.CardsImpl; import mage.constants.*; @@ -1037,10 +1039,25 @@ public class ContinuousEffects implements Serializable { private void applyContinuousEffect(ContinuousEffect effect, Layer currentLayer, Game game) { Set abilities = layeredEffects.getAbility(effect.getId()); for (Ability ability : abilities) { - effect.apply(currentLayer, SubLayer.NA, ability, game); + //effect.apply(currentLayer, SubLayer.NA, ability, game); + if (isAbilityStillExists(game, ability, effect)) { + effect.apply(currentLayer, SubLayer.NA, ability, game); + } } } + private boolean isAbilityStillExists(final Game game, final Ability ability, ContinuousEffect effect) { + final Card card = game.getPermanentOrLKIBattlefield(ability.getSourceId()); + if (!(effect instanceof BecomesFaceDownCreatureEffect)) { + if (card != null) { + if (!card.getAbilities(game).contains(ability)) { + return false; + } + } + } + return true; + } + public Set getLayeredEffectAbilities(ContinuousEffect effect) { return layeredEffects.getAbility(effect.getId()); }