From 4e12b06bc768f8d6bf59cbfb931923cd1a880bbb Mon Sep 17 00:00:00 2001 From: Oleg Agafonov Date: Sun, 22 Apr 2018 04:58:24 +0400 Subject: [PATCH] Fixed not working opponent or planeswalker filter (count all permanents instead planeswalkers); --- .../single/HuntmasterOfTheFellsTest.java | 87 ++++++++++++++----- .../java/mage/filter/FilterPermanent.java | 8 ++ .../common/FilterOpponentOrPlaneswalker.java | 3 +- 3 files changed, 77 insertions(+), 21 deletions(-) diff --git a/Mage.Tests/src/test/java/org/mage/test/cards/single/HuntmasterOfTheFellsTest.java b/Mage.Tests/src/test/java/org/mage/test/cards/single/HuntmasterOfTheFellsTest.java index f204c8f50fd..c0287193a76 100644 --- a/Mage.Tests/src/test/java/org/mage/test/cards/single/HuntmasterOfTheFellsTest.java +++ b/Mage.Tests/src/test/java/org/mage/test/cards/single/HuntmasterOfTheFellsTest.java @@ -27,48 +27,95 @@ public class HuntmasterOfTheFellsTest extends CardTestPlayerBase { * controls. At the beginning of each upkeep, if a player cast two or more * spells last turn, transform Ravager of the Fells. */ - @Ignore + @Test - public void testCard() { + public void test_CantTransformOnSecondTurn() { addCard(Zone.BATTLEFIELD, playerA, "Forest", 3); addCard(Zone.BATTLEFIELD, playerA, "Mountain"); addCard(Zone.HAND, playerA, "Huntmaster of the Fells"); + // need one turn to transform, but create token and gain 2 life castSpell(1, PhaseStep.PRECOMBAT_MAIN, playerA, "Huntmaster of the Fells"); - setStopAt(3, PhaseStep.DRAW); + setStopAt(2, PhaseStep.PRECOMBAT_MAIN); execute(); - assertLife(playerA, 22); - assertLife(playerB, 18); + assertLife(playerA, 20 + 2); + assertLife(playerB, 20); + assertPermanentCount(playerA, "Huntmaster of the Fells", 1); assertPermanentCount(playerA, "Wolf", 1); + assertPermanentCount(playerA, "Ravager of the Fells", 0); + } + + @Test + public void test_TransformOneTime() { + addCard(Zone.BATTLEFIELD, playerA, "Forest", 3); + addCard(Zone.BATTLEFIELD, playerA, "Mountain"); + addCard(Zone.HAND, playerA, "Huntmaster of the Fells"); + + // transform, create token and gain 2 life, make 2 damage to other player + castSpell(1, PhaseStep.PRECOMBAT_MAIN, playerA, "Huntmaster of the Fells"); + setStopAt(3, PhaseStep.PRECOMBAT_MAIN); + execute(); + + assertLife(playerA, 20 + 2); + assertLife(playerB, 20 - 2); assertPermanentCount(playerA, "Huntmaster of the Fells", 0); + assertPermanentCount(playerA, "Wolf", 1); assertPermanentCount(playerA, "Ravager of the Fells", 1); } - /** - * Tests first trigger happens both on enter battlefield and transform - * events - */ - @Ignore @Test - public void testCard2() { + public void test_TransformTwoTimes() { addCard(Zone.BATTLEFIELD, playerA, "Forest", 3); addCard(Zone.BATTLEFIELD, playerA, "Mountain"); addCard(Zone.HAND, playerA, "Huntmaster of the Fells"); - addCard(Zone.BATTLEFIELD, playerB, "Mountain", 2); - addCard(Zone.HAND, playerB, "Lightning Bolt", 2); + addCard(Zone.BATTLEFIELD, playerA, "Mountain", 2); + addCard(Zone.HAND, playerA, "Lightning Bolt", 2); + // etb: new token, gain 2 life + // first transform: make 2 damage to player + // second transform: new token, gain 2 life castSpell(1, PhaseStep.PRECOMBAT_MAIN, playerA, "Huntmaster of the Fells"); - castSpell(3, PhaseStep.PRECOMBAT_MAIN, playerB, "Lightning Bolt", playerA); - castSpell(3, PhaseStep.PRECOMBAT_MAIN, playerB, "Lightning Bolt", playerA); - setStopAt(4, PhaseStep.DRAW); + castSpell(3, PhaseStep.PRECOMBAT_MAIN, playerA, "Lightning Bolt", playerB); + castSpell(3, PhaseStep.PRECOMBAT_MAIN, playerA, "Lightning Bolt", playerB); + setStopAt(4, PhaseStep.PRECOMBAT_MAIN); execute(); - assertLife(playerA, 18); // -6 damage, +4 life - assertLife(playerB, 18); - assertPermanentCount(playerA, "Wolf", 2); - assertPermanentCount(playerA, "Ravager of the Fells", 0); // transformed back + assertLife(playerA, 20 + 2 + 2); + assertLife(playerB, 20 - 2 - 3 * 2); assertPermanentCount(playerA, "Huntmaster of the Fells", 1); + assertPermanentCount(playerA, "Wolf", 2); + assertPermanentCount(playerA, "Ravager of the Fells", 0); + assertPermanentCount(playerA, "Lightning Bolt", 0); + } + + @Test + public void test_TransformTwoTimesWithCreatureDamage() { + addCard(Zone.BATTLEFIELD, playerA, "Forest", 3); + addCard(Zone.BATTLEFIELD, playerA, "Mountain"); + addCard(Zone.HAND, playerA, "Huntmaster of the Fells"); + + addCard(Zone.BATTLEFIELD, playerA, "Mountain", 2); + addCard(Zone.HAND, playerA, "Lightning Bolt", 2); + + addCard(Zone.BATTLEFIELD, playerB, "Balduvian Bears", 1); + + // etb: new token, gain 2 life + // first transform: make 2 damage to player and 2 damage to bear + // second transform: new token, gain 2 life + castSpell(1, PhaseStep.PRECOMBAT_MAIN, playerA, "Huntmaster of the Fells"); + castSpell(3, PhaseStep.PRECOMBAT_MAIN, playerA, "Lightning Bolt", playerB); + castSpell(3, PhaseStep.PRECOMBAT_MAIN, playerA, "Lightning Bolt", playerB); + setStopAt(4, PhaseStep.PRECOMBAT_MAIN); + execute(); + + assertLife(playerA, 20 + 2 + 2); + assertLife(playerB, 20 - 2 - 3 * 2); + assertPermanentCount(playerA, "Huntmaster of the Fells", 1); + assertPermanentCount(playerA, "Wolf", 2); + assertPermanentCount(playerA, "Ravager of the Fells", 0); + assertPermanentCount(playerA, "Lightning Bolt", 0); + assertPermanentCount(playerB, "Balduvian Bears", 0); } } diff --git a/Mage/src/main/java/mage/filter/FilterPermanent.java b/Mage/src/main/java/mage/filter/FilterPermanent.java index 1f4acaa17ac..8201680d040 100644 --- a/Mage/src/main/java/mage/filter/FilterPermanent.java +++ b/Mage/src/main/java/mage/filter/FilterPermanent.java @@ -29,6 +29,7 @@ package mage.filter; import java.util.ArrayList; import java.util.List; +import java.util.Set; import java.util.UUID; import mage.constants.SubType; @@ -66,6 +67,13 @@ public class FilterPermanent extends FilterObject implements FilterIn this.add(new SubtypePredicate(subtype)); } + public FilterPermanent(Set subtypesList, String name) { + super(name); + for (SubType subtype: subtypesList) { + this.add(new SubtypePredicate(subtype)); + } + } + @Override public boolean checkObjectClass(Object object) { return object instanceof Permanent; diff --git a/Mage/src/main/java/mage/filter/common/FilterOpponentOrPlaneswalker.java b/Mage/src/main/java/mage/filter/common/FilterOpponentOrPlaneswalker.java index c191ec868e1..381fb61e91f 100644 --- a/Mage/src/main/java/mage/filter/common/FilterOpponentOrPlaneswalker.java +++ b/Mage/src/main/java/mage/filter/common/FilterOpponentOrPlaneswalker.java @@ -5,6 +5,7 @@ */ package mage.filter.common; +import mage.constants.SubType; import mage.filter.FilterOpponent; import mage.filter.FilterPermanent; @@ -19,7 +20,7 @@ public class FilterOpponentOrPlaneswalker extends FilterPermanentOrPlayer { } public FilterOpponentOrPlaneswalker(String name) { - super(name, new FilterPermanent(), new FilterOpponent()); + super(name, new FilterPermanent(SubType.getPlaneswalkerTypes(true), "planeswalker"), new FilterOpponent()); } public FilterOpponentOrPlaneswalker(final FilterOpponentOrPlaneswalker filter) {