From 4368bae50c529a0e2ad8c5ff2a30eed47f780891 Mon Sep 17 00:00:00 2001 From: Alex Vasile <48962821+Alex-Vasile@users.noreply.github.com> Date: Fri, 26 Aug 2022 20:19:41 -0400 Subject: [PATCH] [LGN] Fixed Ward Sliver not properly giving protection. Closes #9418 --- Mage.Sets/src/mage/cards/w/WardSliver.java | 6 +- .../test/cards/single/lgn/WardSliverTest.java | 127 ++++++++++++++++++ 2 files changed, 131 insertions(+), 2 deletions(-) create mode 100644 Mage.Tests/src/test/java/org/mage/test/cards/single/lgn/WardSliverTest.java diff --git a/Mage.Sets/src/mage/cards/w/WardSliver.java b/Mage.Sets/src/mage/cards/w/WardSliver.java index a4d02eb8fe..24ffcae3d3 100644 --- a/Mage.Sets/src/mage/cards/w/WardSliver.java +++ b/Mage.Sets/src/mage/cards/w/WardSliver.java @@ -3,6 +3,7 @@ package mage.cards.w; import java.util.UUID; import mage.MageInt; +import mage.MageObject; import mage.ObjectColor; import mage.abilities.Ability; import mage.abilities.common.AsEntersBattlefieldAbility; @@ -13,6 +14,7 @@ import mage.abilities.keyword.ProtectionAbility; import mage.cards.CardImpl; import mage.cards.CardSetInfo; import mage.constants.*; +import mage.filter.FilterObject; import mage.filter.FilterPermanent; import mage.filter.StaticFilters; import mage.filter.common.FilterCreaturePermanent; @@ -57,7 +59,7 @@ public final class WardSliver extends CardImpl { class WardSliverGainAbilityControlledEffect extends ContinuousEffectImpl { - protected FilterPermanent protectionFilter; + protected FilterObject protectionFilter; public WardSliverGainAbilityControlledEffect() { super(Duration.WhileOnBattlefield, Layer.AbilityAddingRemovingEffects_6, SubLayer.NA, Outcome.AddAbility); @@ -81,7 +83,7 @@ class WardSliverGainAbilityControlledEffect extends ContinuousEffectImpl { if (permanent != null) { ObjectColor color = (ObjectColor) game.getState().getValue(permanent.getId() + "_color"); if (color != null) { - protectionFilter = new FilterPermanent(color.getDescription()); + protectionFilter = new FilterObject<>(color.getDescription()); protectionFilter.add(new ColorPredicate(color)); } } diff --git a/Mage.Tests/src/test/java/org/mage/test/cards/single/lgn/WardSliverTest.java b/Mage.Tests/src/test/java/org/mage/test/cards/single/lgn/WardSliverTest.java new file mode 100644 index 0000000000..a5b2c3428f --- /dev/null +++ b/Mage.Tests/src/test/java/org/mage/test/cards/single/lgn/WardSliverTest.java @@ -0,0 +1,127 @@ +package org.mage.test.cards.single.lgn; + +import mage.ObjectColor; +import mage.abilities.keyword.ProtectionAbility; +import mage.constants.PhaseStep; +import mage.constants.Zone; +import mage.filter.FilterPermanent; +import mage.filter.predicate.mageobject.ColorPredicate; +import org.junit.Test; +import org.mage.test.serverside.base.CardTestPlayerBase; + +/** + * {@link mage.cards.w.WardSliver Ward Sliver} + * {4}{W} + * + * As Ward Sliver enters the battlefield, choose a color. + * All Slivers have protection from the chosen color. + * + * @author Alex-Vasile + */ +public class WardSliverTest extends CardTestPlayerBase { + private static final String wardSliver = "Ward Sliver"; + // {W} + // Exile target creature + String pathToExile = "Path to Exile"; + + /** + * Test that it gives protection to itself. + */ + @Test + public void givesItselfProtection() { + addCard(Zone.HAND, playerA, wardSliver); + addCard(Zone.BATTLEFIELD, playerA, "Plains", 5); + + addCard(Zone.HAND, playerB, pathToExile); + addCard(Zone.BATTLEFIELD, playerB, "Plains"); + + castSpell(1, PhaseStep.PRECOMBAT_MAIN, playerA, wardSliver); + setChoice(playerA, "White"); + + waitStackResolved(1, PhaseStep.PRECOMBAT_MAIN); + + setStopAt(1, PhaseStep.PRECOMBAT_MAIN); + execute(); + + FilterPermanent filter = new FilterPermanent(ObjectColor.WHITE.getDescription()); + filter.add(new ColorPredicate(ObjectColor.WHITE)); + assertAbility(playerA, wardSliver, new ProtectionAbility(filter), true); + + checkPlayableAbility("Can't exile", 1, PhaseStep.POSTCOMBAT_MAIN, playerB, "Cast " + pathToExile, false); + + setStopAt(1, PhaseStep.POSTCOMBAT_MAIN); + execute(); + } + + /** + * Test that it gives protection to another sliver. + */ + @Test + public void givesOtherSliversProtection() { + // {1} + String metalicSliver = "Metallic Sliver"; + + addCard(Zone.HAND, playerA, wardSliver); + addCard(Zone.BATTLEFIELD, playerA, metalicSliver); + addCard(Zone.BATTLEFIELD, playerA, "Plains", 5); + + addCard(Zone.HAND, playerB, pathToExile); + addCard(Zone.BATTLEFIELD, playerB, "Plains"); + + castSpell(1, PhaseStep.PRECOMBAT_MAIN, playerA, wardSliver); + setChoice(playerA, "White"); + waitStackResolved(1, PhaseStep.PRECOMBAT_MAIN); + + setStopAt(1, PhaseStep.PRECOMBAT_MAIN); + execute(); + + FilterPermanent filter = new FilterPermanent(ObjectColor.WHITE.getDescription()); + filter.add(new ColorPredicate(ObjectColor.WHITE)); + assertAbility(playerA, metalicSliver, new ProtectionAbility(filter), true); + + checkPlayableAbility("Can't exile", 1, PhaseStep.POSTCOMBAT_MAIN, playerB, "Cast " + pathToExile, false); + + setStopAt(1, PhaseStep.POSTCOMBAT_MAIN); + execute(); + } + + /** + * Reported bug: https://github.com/magefree/mage/issues/9418 + * Player casts Ward Sliver and chooses white. + * Same player has a Morophon on the board. + * Another player was able to target Morophon with Path to Exile, even though it should have gotten protection from white. + */ + @Test + public void givesProtectionToChangeling() { + // {7} + // As Morophon, the Boundless enters the battlefield, choose a creature type. + String morophon = "Morophon, the Boundless"; + + addCard(Zone.HAND, playerA, wardSliver); + addCard(Zone.HAND, playerA, morophon); + addCard(Zone.BATTLEFIELD, playerA, "Plains", 12); + + addCard(Zone.HAND, playerB, pathToExile); + addCard(Zone.BATTLEFIELD, playerB, "Plains"); + + castSpell(1, PhaseStep.PRECOMBAT_MAIN, playerA, morophon); + setChoice(playerA, "Dragon"); + waitStackResolved(1, PhaseStep.PRECOMBAT_MAIN); + + castSpell(1, PhaseStep.PRECOMBAT_MAIN, playerA, wardSliver); + setChoice(playerA, "White"); + waitStackResolved(1, PhaseStep.PRECOMBAT_MAIN); + + setStopAt(1, PhaseStep.PRECOMBAT_MAIN); + execute(); + + FilterPermanent filter = new FilterPermanent(ObjectColor.WHITE.getDescription()); + filter.add(new ColorPredicate(ObjectColor.WHITE)); + assertAbility(playerA, morophon, new ProtectionAbility(filter), true); + + checkPlayableAbility("Can't exile", 1, PhaseStep.POSTCOMBAT_MAIN, playerB, "Cast " + pathToExile, false); + + setStopAt(1, PhaseStep.POSTCOMBAT_MAIN); + execute(); + } +}