From c41fc0284dcacc9ed27d64d00df1255ad4043cbf Mon Sep 17 00:00:00 2001 From: LevelX2 Date: Thu, 18 Jun 2020 22:59:42 +0200 Subject: [PATCH] * Fixed missing check for restricting effects of activated abilities of permanents (fixes #6657). I guess that got lost by refactoring get playable abilities. --- Mage.Sets/src/mage/cards/s/SolRing.java | 2 + .../CantUseActivatedAbilitiesTest.java | 57 +++++++++++++++++++ .../java/org/mage/test/player/TestPlayer.java | 4 +- .../main/java/mage/players/PlayerImpl.java | 9 ++- 4 files changed, 67 insertions(+), 5 deletions(-) create mode 100644 Mage.Tests/src/test/java/org/mage/test/cards/restriction/CantUseActivatedAbilitiesTest.java diff --git a/Mage.Sets/src/mage/cards/s/SolRing.java b/Mage.Sets/src/mage/cards/s/SolRing.java index 9b836f10fa9..55431f5ba13 100644 --- a/Mage.Sets/src/mage/cards/s/SolRing.java +++ b/Mage.Sets/src/mage/cards/s/SolRing.java @@ -18,6 +18,8 @@ public final class SolRing extends CardImpl { public SolRing(UUID ownerId, CardSetInfo setInfo) { super(ownerId,setInfo,new CardType[]{CardType.ARTIFACT},"{1}"); + + // Tap: Add {C}{C} this.addAbility(new SimpleManaAbility(Zone.BATTLEFIELD, Mana.ColorlessMana(2), new TapSourceCost())); } diff --git a/Mage.Tests/src/test/java/org/mage/test/cards/restriction/CantUseActivatedAbilitiesTest.java b/Mage.Tests/src/test/java/org/mage/test/cards/restriction/CantUseActivatedAbilitiesTest.java new file mode 100644 index 00000000000..f5bc8b2eff8 --- /dev/null +++ b/Mage.Tests/src/test/java/org/mage/test/cards/restriction/CantUseActivatedAbilitiesTest.java @@ -0,0 +1,57 @@ +package org.mage.test.cards.restriction; + +import mage.constants.PhaseStep; +import mage.constants.Zone; +import org.junit.Assert; +import org.junit.Test; +import org.mage.test.serverside.base.CardTestPlayerBase; + +/** + * + * @author LevelX2 + */ + +public class CantUseActivatedAbilitiesTest extends CardTestPlayerBase { + + /** + * I can activate artifacts despite my opponent having Collector Ouphe or + * Karn, the Great Creator in play. The artifact says it can't be activated, but that's a lie. + */ + @Test + public void testCantActivateManaAbility() { + // Activated abilities of artifacts can't be activated. + addCard(Zone.HAND, playerA, "Collector Ouphe"); // Creature {1}{G} 2/2 + addCard(Zone.BATTLEFIELD, playerA, "Forest", 2); + // {T}: Add {C}{C} + addCard(Zone.BATTLEFIELD, playerB, "Sol Ring"); // Artifact + + castSpell(1, PhaseStep.PRECOMBAT_MAIN, playerA, "Collector Ouphe"); + + setStopAt(1, PhaseStep.END_COMBAT); + setStrictChooseMode(true); + execute(); + assertAllCommandsUsed(); + + // Sol Ring can't produce mana + Assert.assertTrue("PlayerB may not be able to produce any mana but he he can produce " + playerB.getManaAvailable(currentGame).toString(), playerB.getManaAvailable(currentGame).toString().equals("[]")); + } + + @Test + public void testCantActivateActivatedAbility() { + // Activated abilities of artifacts can't be activated. + addCard(Zone.BATTLEFIELD, playerA, "Collector Ouphe"); // Creature {1}{G} 2/2 + + // {1}: Adarkar Sentinel gets +0/+1 until end of turn. + addCard(Zone.BATTLEFIELD, playerB, "Adarkar Sentinel"); // Artifact Creature — Soldier (3/3) + addCard(Zone.BATTLEFIELD, playerB, "Island"); + + activateAbility(1, PhaseStep.PRECOMBAT_MAIN, playerB, "{1}: "); + + setStopAt(1, PhaseStep.BEGIN_COMBAT); + + execute(); + + assertPowerToughness(playerB, "Adarkar Sentinel", 3, 3); + + } +} diff --git a/Mage.Tests/src/test/java/org/mage/test/player/TestPlayer.java b/Mage.Tests/src/test/java/org/mage/test/player/TestPlayer.java index d50d6888447..d83cb859ff2 100644 --- a/Mage.Tests/src/test/java/org/mage/test/player/TestPlayer.java +++ b/Mage.Tests/src/test/java/org/mage/test/player/TestPlayer.java @@ -1165,9 +1165,9 @@ public class TestPlayer implements Player { } if (mustHave) { - Assert.assertEquals(action.getActionName() + " - permanent " + permanentName + " must have ability " + abilityClass, true, founded); + Assert.assertEquals(action.getActionName() + " - permanent " + permanentName + " must have the ability " + abilityClass, true, founded); } else { - Assert.assertEquals(action.getActionName() + " - permanent " + permanentName + " must have not ability " + abilityClass, false, founded); + Assert.assertEquals(action.getActionName() + " - permanent " + permanentName + " must not have the ability " + abilityClass, false, founded); } } diff --git a/Mage/src/main/java/mage/players/PlayerImpl.java b/Mage/src/main/java/mage/players/PlayerImpl.java index c7005478da2..742f456bb48 100644 --- a/Mage/src/main/java/mage/players/PlayerImpl.java +++ b/Mage/src/main/java/mage/players/PlayerImpl.java @@ -3365,11 +3365,14 @@ public abstract class PlayerImpl implements Player, Serializable { // activated abilities from battlefield objects if (fromAll || fromZone == Zone.BATTLEFIELD) { for (Permanent permanent : game.getBattlefield().getAllActivePermanents(playerId)) { + boolean canUseActivated = permanent.canUseActivatedAbilities(game); List battlePlayable = new ArrayList<>(); getPlayableFromCardAll(game, Zone.BATTLEFIELD, permanent, availableMana, battlePlayable); for (ActivatedAbility ability : battlePlayable) { - activatedUnique.putIfAbsent(ability.toString(), ability); - activatedAll.add(ability); + if (ability instanceof SpecialAction || canUseActivated) { + activatedUnique.putIfAbsent(ability.toString(), ability); + activatedAll.add(ability); + } } } } @@ -4272,7 +4275,7 @@ public abstract class PlayerImpl implements Player, Serializable { cards.addAll(getLibrary().getTopCards(game, value)); if (!cards.isEmpty()) { TargetCard target = new TargetCard(0, cards.size(), Zone.LIBRARY, - new FilterCard("card" + (cards.size() == 1 ? "":"s") + new FilterCard("card" + (cards.size() == 1 ? "" : "s") + " to PUT on the BOTTOM of your library (Scry)")); chooseTarget(Outcome.Benefit, cards, target, source, game); putCardsOnBottomOfLibrary(new CardsImpl(target.getTargets()), game, source, true);