From 676b099590beed711936a3c679dc738ce3b7d6fd Mon Sep 17 00:00:00 2001 From: xenohedron Date: Fri, 30 Aug 2024 01:18:52 -0400 Subject: [PATCH] fix #12743 (Nearby Planet), add test closes #12746 --- Mage.Sets/src/mage/cards/n/NearbyPlanet.java | 34 +++++++++++ .../cards/single/unf/NearbyPlanetTest.java | 61 +++++++++++++++++++ 2 files changed, 95 insertions(+) create mode 100644 Mage.Tests/src/test/java/org/mage/test/cards/single/unf/NearbyPlanetTest.java diff --git a/Mage.Sets/src/mage/cards/n/NearbyPlanet.java b/Mage.Sets/src/mage/cards/n/NearbyPlanet.java index 32f502ac8e9..2451d46f832 100644 --- a/Mage.Sets/src/mage/cards/n/NearbyPlanet.java +++ b/Mage.Sets/src/mage/cards/n/NearbyPlanet.java @@ -8,10 +8,12 @@ import mage.abilities.common.SimpleStaticAbility; import mage.abilities.costs.mana.GenericManaCost; import mage.abilities.effects.ContinuousEffectImpl; import mage.abilities.effects.common.SacrificeSourceUnlessPaysEffect; +import mage.abilities.mana.*; import mage.cards.CardImpl; import mage.cards.CardSetInfo; import mage.constants.*; import mage.game.Game; +import mage.game.permanent.Permanent; import java.util.UUID; @@ -52,8 +54,21 @@ public final class NearbyPlanet extends CardImpl { class NearbyPlanetEffect extends ContinuousEffectImpl { + private static final Ability[] basicManaAbilities = { + new WhiteManaAbility(), + new BlueManaAbility(), + new BlackManaAbility(), + new RedManaAbility(), + new GreenManaAbility() + }; + NearbyPlanetEffect() { super(Duration.Custom, Layer.TypeChangingEffects_4, SubLayer.NA, Outcome.Benefit); + dependendToTypes.add(DependencyType.BecomeMountain); + dependendToTypes.add(DependencyType.BecomeForest); + dependendToTypes.add(DependencyType.BecomeSwamp); + dependendToTypes.add(DependencyType.BecomeIsland); + dependendToTypes.add(DependencyType.BecomePlains); staticText = "Rangeling (This card is every land type, including Plains, Island, Swamp, " + "Mountain, Forest, Desert, Gate, Lair, Locus, and all those Urza's ones.)"; } @@ -75,6 +90,25 @@ class NearbyPlanetEffect extends ContinuousEffectImpl { } sourceObject.addSubType(game, SubType.PLAINS, SubType.ISLAND, SubType.SWAMP, SubType.MOUNTAIN, SubType.FOREST); sourceObject.setIsAllNonbasicLandTypes(game, true); + // subtypes apply in all zones ^ + // mana abilities apply to permanent + Permanent permanent = source.getSourcePermanentIfItStillExists(game); + if (permanent == null) { + return true; + } + // Optimization: Remove basic mana abilities since they are redundant with AnyColorManaAbility + // and keeping them will only produce too many combinations inside ManaOptions + for (Ability basicManaAbility : basicManaAbilities) { + if (permanent.getAbilities(game).containsRule(basicManaAbility)) { + permanent.removeAbility(basicManaAbility, source.getSourceId(), game); + } + } + // Add the {T}: Add one mana of any color ability + // This is functionally equivalent to having five "{T}: Add {COLOR}" for each COLOR in {W}{U}{B}{R}{G} + AnyColorManaAbility ability = new AnyColorManaAbility(); + if (!permanent.getAbilities(game).containsRule(ability)) { + permanent.addAbility(ability, source.getSourceId(), game); + } return true; } } diff --git a/Mage.Tests/src/test/java/org/mage/test/cards/single/unf/NearbyPlanetTest.java b/Mage.Tests/src/test/java/org/mage/test/cards/single/unf/NearbyPlanetTest.java new file mode 100644 index 00000000000..b16d217728f --- /dev/null +++ b/Mage.Tests/src/test/java/org/mage/test/cards/single/unf/NearbyPlanetTest.java @@ -0,0 +1,61 @@ +package org.mage.test.cards.single.unf; + +import mage.abilities.keyword.LifelinkAbility; +import mage.constants.PhaseStep; +import mage.constants.Zone; +import org.junit.Test; +import org.mage.test.serverside.base.CardTestPlayerBase; + +/** + * @author xenohedron + */ +public class NearbyPlanetTest extends CardTestPlayerBase { + + /* + * Rangeling (This card is every land type, including Plains, Island, Swamp, Mountain, Forest, + * Desert, Gate, Lair, Locus, and all those Urza’s ones.) + * Nearby Planet enters tapped. + * When Nearby Planet enters, sacrifice it unless you pay {1}. + */ + private final static String nearbyPlanet = "Nearby Planet"; + + @Test + public void testDomain() { + addCard(Zone.BATTLEFIELD, playerA, "Wastes"); + addCard(Zone.HAND, playerA, nearbyPlanet); + addCard(Zone.HAND, playerA, "Might of Alara"); + // Domain - Target creature gets +1/+1 until end of turn for each basic land type among lands you control. + addCard(Zone.BATTLEFIELD, playerA, "Kraken Hatchling"); // 0/4 + + playLand(1, PhaseStep.PRECOMBAT_MAIN, playerA, nearbyPlanet); + setChoice(playerA, true); // pay {1} + + castSpell(3, PhaseStep.PRECOMBAT_MAIN, playerA, "Might of Alara", "Kraken Hatchling"); + setChoice(playerA, "Green"); // color of mana to add + + setStrictChooseMode(true); + setStopAt(3, PhaseStep.BEGIN_COMBAT); + execute(); + + assertGraveyardCount(playerA, "Might of Alara", 1); + assertPowerToughness(playerA, "Kraken Hatchling", 5, 9); + } + + @Test + public void testDesert() { + addCard(Zone.BATTLEFIELD, playerA, "Wastes"); + addCard(Zone.HAND, playerA, nearbyPlanet); + addCard(Zone.BATTLEFIELD, playerA, "Solitary Camel"); // 3/2 + // Solitary Camel has lifelink as long as you control a Desert or there is a Desert card in your graveyard. + + playLand(1, PhaseStep.PRECOMBAT_MAIN, playerA, nearbyPlanet); + setChoice(playerA, true); // pay {1} + + setStrictChooseMode(true); + setStopAt(1, PhaseStep.BEGIN_COMBAT); + execute(); + + assertAbility(playerA, "Solitary Camel", LifelinkAbility.getInstance(), true); + } + +}