From 0458778c44cce2e67a5ddc8a783a4d33f4379fc6 Mon Sep 17 00:00:00 2001 From: LevelX2 Date: Tue, 28 Jul 2020 13:28:24 +0200 Subject: [PATCH] * Fixed bug of Druids Repository (related to b5c93cf2da9d77f5bf703bd1a05e8f7512f02181), --- .../src/mage/cards/d/DruidsRepository.java | 7 +- .../mana/NonTappingManaAbilitiesTest.java | 130 ++++++++++++++++++ .../cards/mana/TappedForManaRelatedTest.java | 72 +--------- .../effects/mana/BasicManaEffect.java | 23 ++-- 4 files changed, 149 insertions(+), 83 deletions(-) create mode 100644 Mage.Tests/src/test/java/org/mage/test/cards/mana/NonTappingManaAbilitiesTest.java diff --git a/Mage.Sets/src/mage/cards/d/DruidsRepository.java b/Mage.Sets/src/mage/cards/d/DruidsRepository.java index 132f1be2ce..b02e250d6d 100644 --- a/Mage.Sets/src/mage/cards/d/DruidsRepository.java +++ b/Mage.Sets/src/mage/cards/d/DruidsRepository.java @@ -31,10 +31,9 @@ public final class DruidsRepository extends CardImpl { this.addAbility(new AttacksCreatureYouControlTriggeredAbility(new AddCountersSourceEffect(CounterType.CHARGE.createInstance()))); // Remove a charge counter from Druids' Repository: Add one mana of any color. - Ability ability = new SimpleManaAbility(Zone.BATTLEFIELD, Mana.AnyMana(1), - new RemoveCountersSourceCost(CounterType.CHARGE.createInstance()), - new CountersSourceCount(CounterType.CHARGE)); - this.addAbility(ability); + this.addAbility(new SimpleManaAbility(Zone.BATTLEFIELD, + new AddManaOfAnyColorEffect(1, new CountersSourceCount(CounterType.CHARGE), false), + new RemoveCountersSourceCost(CounterType.CHARGE.createInstance()))); } public DruidsRepository(final DruidsRepository card) { diff --git a/Mage.Tests/src/test/java/org/mage/test/cards/mana/NonTappingManaAbilitiesTest.java b/Mage.Tests/src/test/java/org/mage/test/cards/mana/NonTappingManaAbilitiesTest.java new file mode 100644 index 0000000000..0f98be25cb --- /dev/null +++ b/Mage.Tests/src/test/java/org/mage/test/cards/mana/NonTappingManaAbilitiesTest.java @@ -0,0 +1,130 @@ +package org.mage.test.cards.mana; + +import mage.abilities.mana.ManaOptions; +import mage.constants.PhaseStep; +import mage.constants.Zone; +import mage.counters.CounterType; +import org.junit.Assert; +import org.junit.Test; +import org.mage.test.serverside.base.CardTestPlayerBase; +import static org.mage.test.utils.ManaOptionsTestUtils.assertManaOptions; + +/** + * + * @author LevelX2 + */ + +public class NonTappingManaAbilitiesTest extends CardTestPlayerBase { + + @Test + public void druidsRepositoryTest() { + setStrictChooseMode(true); + + addCard(Zone.HAND, playerA, "Alaborn Grenadier", 1); //Creature {W}{W} + + addCard(Zone.BATTLEFIELD, playerA, "Silvercoat Lion", 2); + // Whenever a creature you control attacks, put a charge counter on Druids' Repository. + // Remove a charge counter from Druids' Repository: Add one mana of any color. + addCard(Zone.BATTLEFIELD, playerA, "Druids' Repository", 1); // Enchantment {1}{G}{G} + + attack(1, playerA, "Silvercoat Lion"); + attack(1, playerA, "Silvercoat Lion"); + setChoice(playerA, "Whenever a creature you control"); + + setStopAt(1, PhaseStep.END_COMBAT); + execute(); + + assertTappedCount("Silvercoat Lion", true, 2); + assertCounterCount(playerA,"Druids' Repository", CounterType.CHARGE, 2); + + ManaOptions manaOptions = playerA.getAvailableManaTest(currentGame); + Assert.assertEquals("mana variations don't fit", 1, manaOptions.size()); + assertManaOptions("{Any}{Any}", manaOptions); + + castSpell(1, PhaseStep.POSTCOMBAT_MAIN, playerA, "Alaborn Grenadier"); + setChoice(playerA, "White"); + setChoice(playerA, "White"); + + setStopAt(1, PhaseStep.END_TURN); + execute(); + + assertCounterCount(playerA,"Druids' Repository", CounterType.CHARGE, 0); + assertPermanentCount(playerA, "Alaborn Grenadier", 1); + } + + @Test + public void TestWorkhorse() { + setStrictChooseMode(true); + + // Workhorse enters the battlefield with four +1/+1 counters on it. + // Remove a +1/+1 counter from Workhorse: Add {C}. + addCard(Zone.BATTLEFIELD, playerA, "Workhorse", 1); + + setStopAt(1, PhaseStep.PRECOMBAT_MAIN); + execute(); + + assertAllCommandsUsed(); + + ManaOptions manaOptions = playerA.getAvailableManaTest(currentGame); + Assert.assertEquals("mana variations don't fit", 1, manaOptions.size()); + assertManaOptions("{C}{C}{C}{C}", manaOptions); + } + + @Test + public void TestMorselhoarder() { + setStrictChooseMode(true); + // Morselhoarder enters the battlefield with two -1/-1 counters on it. + // Remove a -1/-1 counter from Morselhoarder: Add one mana of any color. + addCard(Zone.BATTLEFIELD, playerA, "Morselhoarder", 2); + addCard(Zone.BATTLEFIELD, playerA, "Swamp", 2); + + setStopAt(1, PhaseStep.BEGIN_COMBAT); + execute(); + + assertAllCommandsUsed(); + + ManaOptions manaOptions = playerA.getAvailableManaTest(currentGame); + Assert.assertEquals("mana variations don't fit", 1, manaOptions.size()); + assertManaOptions("{B}{B}{Any}{Any}{Any}{Any}", manaOptions); + } + + @Test + public void TestFarrelitePriest() { + setStrictChooseMode(true); + // {1}: Add {W}. If this ability has been activated four or more times this turn, sacrifice Farrelite Priest at the beginning of the next end step. + addCard(Zone.BATTLEFIELD, playerA, "Farrelite Priest", 1); + addCard(Zone.BATTLEFIELD, playerA, "Swamp", 4); + + setStopAt(1, PhaseStep.BEGIN_COMBAT); + execute(); + + assertAllCommandsUsed(); + + ManaOptions manaOptions = playerA.getAvailableManaTest(currentGame); + Assert.assertEquals("mana variations don't fit", 5, manaOptions.size()); + assertManaOptions("{W}{W}{W}{W}", manaOptions); + assertManaOptions("{W}{W}{W}{B}", manaOptions); + assertManaOptions("{W}{W}{B}{B}", manaOptions); + assertManaOptions("{W}{B}{B}{B}", manaOptions); + assertManaOptions("{B}{B}{B}{B}", manaOptions); + } + @Test + public void TestCrystallineCrawler() { + setStrictChooseMode(true); + // Converge - Crystalline Crawler enters the battlefield with a +1/+1 counter on it for each color of mana spent to cast it. + // Remove a +1/+1 counter from Crystalline Crawler: Add one mana of any color. + // {T}: Put a +1/+1 counter on Crystalline Crawler. + addCard(Zone.BATTLEFIELD, playerA, "Crystalline Crawler", 1); + addCounters(1, PhaseStep.PRECOMBAT_MAIN, playerA, "Crystalline Crawler", CounterType.P1P1, 2); + + setStopAt(1, PhaseStep.BEGIN_COMBAT); + execute(); + + assertAllCommandsUsed(); + + ManaOptions manaOptions = playerA.getAvailableManaTest(currentGame); + Assert.assertEquals("mana variations don't fit", 1, manaOptions.size()); + assertManaOptions("{Any}{Any}", manaOptions); + } + +} \ No newline at end of file diff --git a/Mage.Tests/src/test/java/org/mage/test/cards/mana/TappedForManaRelatedTest.java b/Mage.Tests/src/test/java/org/mage/test/cards/mana/TappedForManaRelatedTest.java index a487708cff..39bdcdd1f2 100644 --- a/Mage.Tests/src/test/java/org/mage/test/cards/mana/TappedForManaRelatedTest.java +++ b/Mage.Tests/src/test/java/org/mage/test/cards/mana/TappedForManaRelatedTest.java @@ -201,24 +201,7 @@ public class TappedForManaRelatedTest extends CardTestPlayerBase { assertManaOptions("{R}", manaOptions); } - @Test - public void TestCrystallineCrawler() { - setStrictChooseMode(true); - // Converge - Crystalline Crawler enters the battlefield with a +1/+1 counter on it for each color of mana spent to cast it. - // Remove a +1/+1 counter from Crystalline Crawler: Add one mana of any color. - // {T}: Put a +1/+1 counter on Crystalline Crawler. - addCard(Zone.BATTLEFIELD, playerA, "Crystalline Crawler", 1); - addCounters(1, PhaseStep.PRECOMBAT_MAIN, playerA, "Crystalline Crawler", CounterType.P1P1, 2); - setStopAt(1, PhaseStep.BEGIN_COMBAT); - execute(); - - assertAllCommandsUsed(); - - ManaOptions manaOptions = playerA.getAvailableManaTest(currentGame); - Assert.assertEquals("mana variations don't fit", 1, manaOptions.size()); - assertManaOptions("{Any}{Any}", manaOptions); - } @Test @Ignore // Because this is no mana ability, this mana will not be calculated during available mana calculation @@ -258,44 +241,7 @@ public class TappedForManaRelatedTest extends CardTestPlayerBase { assertManaOptions("{U}{U}{U}{U}", manaOptions); } - @Test - public void TestFarrelitePriest() { - setStrictChooseMode(true); - // {1}: Add {W}. If this ability has been activated four or more times this turn, sacrifice Farrelite Priest at the beginning of the next end step. - addCard(Zone.BATTLEFIELD, playerA, "Farrelite Priest", 1); - addCard(Zone.BATTLEFIELD, playerA, "Swamp", 4); - setStopAt(1, PhaseStep.BEGIN_COMBAT); - execute(); - - assertAllCommandsUsed(); - - ManaOptions manaOptions = playerA.getAvailableManaTest(currentGame); - Assert.assertEquals("mana variations don't fit", 5, manaOptions.size()); - assertManaOptions("{W}{W}{W}{W}", manaOptions); - assertManaOptions("{W}{W}{W}{B}", manaOptions); - assertManaOptions("{W}{W}{B}{B}", manaOptions); - assertManaOptions("{W}{B}{B}{B}", manaOptions); - assertManaOptions("{B}{B}{B}{B}", manaOptions); - } - - @Test - public void TestMorselhoarder() { - setStrictChooseMode(true); - // Morselhoarder enters the battlefield with two -1/-1 counters on it. - // Remove a -1/-1 counter from Morselhoarder: Add one mana of any color. - addCard(Zone.BATTLEFIELD, playerA, "Morselhoarder", 2); - addCard(Zone.BATTLEFIELD, playerA, "Swamp", 2); - - setStopAt(1, PhaseStep.BEGIN_COMBAT); - execute(); - - assertAllCommandsUsed(); - - ManaOptions manaOptions = playerA.getAvailableManaTest(currentGame); - Assert.assertEquals("mana variations don't fit", 1, manaOptions.size()); - assertManaOptions("{B}{B}{Any}{Any}{Any}{Any}", manaOptions); - } @Test public void TestChromaticOrrery() { @@ -343,21 +289,5 @@ public class TappedForManaRelatedTest extends CardTestPlayerBase { assertManaOptions("{G}{G}{G}{G}{G}{G}{G}", manaOptions); } - @Test - public void TestWorkhorse() { - setStrictChooseMode(true); - - // Workhorse enters the battlefield with four +1/+1 counters on it. - // Remove a +1/+1 counter from Workhorse: Add {C}. - addCard(Zone.BATTLEFIELD, playerA, "Workhorse", 1); - - setStopAt(1, PhaseStep.PRECOMBAT_MAIN); - execute(); - - assertAllCommandsUsed(); - - ManaOptions manaOptions = playerA.getAvailableManaTest(currentGame); - Assert.assertEquals("mana variations don't fit", 1, manaOptions.size()); - assertManaOptions("{C}{C}{C}{C}", manaOptions); - } + } diff --git a/Mage/src/main/java/mage/abilities/effects/mana/BasicManaEffect.java b/Mage/src/main/java/mage/abilities/effects/mana/BasicManaEffect.java index 2371f386e7..9c1f272348 100644 --- a/Mage/src/main/java/mage/abilities/effects/mana/BasicManaEffect.java +++ b/Mage/src/main/java/mage/abilities/effects/mana/BasicManaEffect.java @@ -49,19 +49,26 @@ public class BasicManaEffect extends ManaEffect { Mana computedMana = new Mana(); if (manaTemplate.getBlack() > 0) { computedMana.setBlack(count * manaTemplate.getBlack()); - } else if (manaTemplate.getBlue() > 0) { + } + if (manaTemplate.getBlue() > 0) { computedMana.setBlue(count * manaTemplate.getBlue()); - } else if (manaTemplate.getGreen() > 0) { + } + if (manaTemplate.getGreen() > 0) { computedMana.setGreen(count * manaTemplate.getGreen()); - } else if (manaTemplate.getRed() > 0) { + } + if (manaTemplate.getRed() > 0) { computedMana.setRed(count * manaTemplate.getRed()); - } else if (manaTemplate.getWhite() > 0) { + } + if (manaTemplate.getWhite() > 0) { computedMana.setWhite(count * manaTemplate.getWhite()); - } else if (manaTemplate.getColorless() > 0) { + } + if (manaTemplate.getColorless() > 0) { computedMana.setColorless(count * manaTemplate.getColorless()); - } else if (manaTemplate.getAny() > 0) { - computedMana.setAny(count * manaTemplate.getAny()); - } else if (manaTemplate.getGeneric() > 0){ + } + if (manaTemplate.getAny() > 0) { + throw new IllegalArgumentException("BasicManaEffect does not support {Any} mana!"); + } + if (manaTemplate.getGeneric() > 0) { computedMana.setGeneric(count * manaTemplate.getGeneric()); } return new ArrayList<>(Arrays.asList(computedMana));