From 457557852e1fd24d2f30aff731792716de34cbb0 Mon Sep 17 00:00:00 2001 From: LevelX2 Date: Fri, 7 Aug 2020 17:15:06 +0200 Subject: [PATCH] * Benthic Explorer - Fixed mana type calculation. * DynamicManaEffect - Fixed mana type calculation. Some code clean up. --- .../src/mage/cards/b/BenthicExplorers.java | 77 ++------------ .../src/mage/cards/s/SquanderedResources.java | 49 +-------- .../modification/CostReduceForEachTest.java | 24 +++++ .../abilities/effects/common/ManaEffect.java | 35 +----- .../effects/mana/DynamicManaEffect.java | 7 ++ .../mana/AnyColorLandsProduceManaAbility.java | 49 +-------- .../main/java/mage/constants/ManaType.java | 100 ++++++++++++++++++ 7 files changed, 148 insertions(+), 193 deletions(-) diff --git a/Mage.Sets/src/mage/cards/b/BenthicExplorers.java b/Mage.Sets/src/mage/cards/b/BenthicExplorers.java index 89dd8b6202..3388e40e7c 100644 --- a/Mage.Sets/src/mage/cards/b/BenthicExplorers.java +++ b/Mage.Sets/src/mage/cards/b/BenthicExplorers.java @@ -23,7 +23,10 @@ import mage.target.common.TargetLandPermanent; import mage.util.CardUtil; import java.util.ArrayList; +import java.util.EnumSet; +import java.util.HashSet; import java.util.List; +import java.util.Set; import java.util.UUID; /** @@ -135,46 +138,20 @@ class BenthicExplorersManaEffect extends ManaEffect { @Override public List getNetMana(Game game, Ability source) { - List netManas = new ArrayList<>(); if (game == null) { - return netManas; + return new ArrayList<>(); } - - Mana types = new Mana(); + Set manaTypes = EnumSet.noneOf(ManaType.class); for (UUID opponentId : game.getOpponents(source.getControllerId())) { for (Permanent permanent : game.getBattlefield().getAllActivePermanents(opponentId)) { if (permanent.isLand() && permanent.isTapped()) { for (ActivatedManaAbilityImpl ability : permanent.getAbilities(game).getActivatedManaAbilities(Zone.BATTLEFIELD)) { - for (Mana mana : ability.getNetMana(game)) { - types.add(mana); - } + manaTypes.addAll(ability.getProducableManaTypes(game)); } } } } - - if (types.getBlack() > 0) { - netManas.add(new Mana(ColoredManaSymbol.B)); - } - if (types.getRed() > 0) { - netManas.add(new Mana(ColoredManaSymbol.R)); - } - if (types.getBlue() > 0) { - netManas.add(new Mana(ColoredManaSymbol.U)); - } - if (types.getGreen() > 0) { - netManas.add(new Mana(ColoredManaSymbol.G)); - } - if (types.getWhite() > 0) { - netManas.add(new Mana(ColoredManaSymbol.W)); - } - if (types.getColorless() > 0) { - netManas.add(Mana.ColorlessMana(1)); - } - if (types.getAny() > 0) { - netManas.add(Mana.AnyMana(1)); - } - return netManas; + return ManaType.getManaListFromManaTypes(manaTypes, false); } @Override @@ -183,37 +160,7 @@ class BenthicExplorersManaEffect extends ManaEffect { if (game == null) { return mana; } - Mana types = getManaTypes(game, source); - Choice choice = new ChoiceColor(true); - choice.getChoices().clear(); - choice.setMessage("Pick a mana color"); - if (types.getBlack() > 0) { - choice.getChoices().add("Black"); - } - if (types.getRed() > 0) { - choice.getChoices().add("Red"); - } - if (types.getBlue() > 0) { - choice.getChoices().add("Blue"); - } - if (types.getGreen() > 0) { - choice.getChoices().add("Green"); - } - if (types.getWhite() > 0) { - choice.getChoices().add("White"); - } - if (types.getColorless() > 0) { - choice.getChoices().add("Colorless"); - } - if (types.getAny() > 0) { - choice.getChoices().add("Black"); - choice.getChoices().add("Red"); - choice.getChoices().add("Blue"); - choice.getChoices().add("Green"); - choice.getChoices().add("White"); - choice.getChoices().add("Colorless"); - - } + Choice choice = ManaType.getChoiceOfManaTypes(getManaTypes(game, source), false); if (!choice.getChoices().isEmpty()) { Player player = game.getPlayer(source.getControllerId()); if (choice.getChoices().size() == 1) { @@ -250,8 +197,8 @@ class BenthicExplorersManaEffect extends ManaEffect { return mana; } - private Mana getManaTypes(Game game, Ability source) { - Mana types = new Mana(); + private Set getManaTypes(Game game, Ability source) { + Set types = EnumSet.noneOf(ManaType.class); if (game == null || game.getPhase() == null) { return types; @@ -261,9 +208,7 @@ class BenthicExplorersManaEffect extends ManaEffect { Abilities mana = land.getAbilities().getActivatedManaAbilities(Zone.BATTLEFIELD); for (ActivatedManaAbilityImpl ability : mana) { if (ability.definesMana(game)) { - for (Mana netMana : ability.getNetMana(game)) { - types.add(netMana); - } + types.addAll(ability.getProducableManaTypes(game)); } } } diff --git a/Mage.Sets/src/mage/cards/s/SquanderedResources.java b/Mage.Sets/src/mage/cards/s/SquanderedResources.java index 689301ff7b..fd042fb5a6 100644 --- a/Mage.Sets/src/mage/cards/s/SquanderedResources.java +++ b/Mage.Sets/src/mage/cards/s/SquanderedResources.java @@ -66,7 +66,6 @@ class SquanderedResourcesEffect extends ManaEffect { @Override public List getNetMana(Game game, Ability source) { - List netManas = new ArrayList<>(); if (game != null && game.inCheckPlayableState()) { // add color combinations of available mana ManaOptions allPossibleMana = new ManaOptions(); @@ -88,30 +87,7 @@ class SquanderedResourcesEffect extends ManaEffect { allPossibleMana.removeDuplicated(); return allPossibleMana.stream().collect(Collectors.toList()); } - Set manaTypes = getManaTypesFromSacrificedPermanent(game, source); - if (manaTypes.size() == 5 && !manaTypes.contains(ManaType.COLORLESS) && !manaTypes.contains(ManaType.GENERIC)) { - netManas.add(Mana.AnyMana(1)); - } else { - if (manaTypes.contains(ManaType.BLACK)) { - netManas.add(Mana.BlackMana(1)); - } - if (manaTypes.contains(ManaType.RED)) { - netManas.add(Mana.RedMana(1)); - } - if (manaTypes.contains(ManaType.BLUE)) { - netManas.add(Mana.BlueMana(1)); - } - if (manaTypes.contains(ManaType.GREEN)) { - netManas.add(Mana.GreenMana(1)); - } - if (manaTypes.contains(ManaType.WHITE)) { - netManas.add(Mana.WhiteMana(1)); - } - if (manaTypes.contains(ManaType.COLORLESS)) { - netManas.add(Mana.ColorlessMana(1)); - } - } - return netManas; + return ManaType.getManaListFromManaTypes(getManaTypesFromSacrificedPermanent(game, source), false); } @Override @@ -120,28 +96,7 @@ class SquanderedResourcesEffect extends ManaEffect { if (game == null) { return mana; } - Set manaTypes = getManaTypesFromSacrificedPermanent(game, source); - Choice choice = new ChoiceColor(true); - choice.getChoices().clear(); - choice.setMessage("Pick a mana color"); - if (manaTypes.contains(ManaType.BLACK)) { - choice.getChoices().add("Black"); - } - if (manaTypes.contains(ManaType.RED)) { - choice.getChoices().add("Red"); - } - if (manaTypes.contains(ManaType.BLUE)) { - choice.getChoices().add("Blue"); - } - if (manaTypes.contains(ManaType.GREEN)) { - choice.getChoices().add("Green"); - } - if (manaTypes.contains(ManaType.WHITE)) { - choice.getChoices().add("White"); - } - if (manaTypes.contains(ManaType.COLORLESS)) { - choice.getChoices().add("Colorless"); - } + Choice choice = ManaType.getChoiceOfManaTypes(getManaTypesFromSacrificedPermanent(game, source), false); if (!choice.getChoices().isEmpty()) { Player player = game.getPlayer(source.getControllerId()); if (player == null) { diff --git a/Mage.Tests/src/test/java/org/mage/test/cards/cost/modification/CostReduceForEachTest.java b/Mage.Tests/src/test/java/org/mage/test/cards/cost/modification/CostReduceForEachTest.java index 0128bbeb5e..4c318e556e 100644 --- a/Mage.Tests/src/test/java/org/mage/test/cards/cost/modification/CostReduceForEachTest.java +++ b/Mage.Tests/src/test/java/org/mage/test/cards/cost/modification/CostReduceForEachTest.java @@ -1,9 +1,12 @@ package org.mage.test.cards.cost.modification; +import mage.abilities.mana.ManaOptions; import mage.constants.PhaseStep; import mage.constants.Zone; +import org.junit.Assert; import org.junit.Test; import org.mage.test.serverside.base.CardTestPlayerBaseWithAIHelps; +import static org.mage.test.utils.ManaOptionsTestUtils.assertManaOptions; /** * @author JayDi85 @@ -215,6 +218,27 @@ public class CostReduceForEachTest extends CardTestPlayerBaseWithAIHelps { assertPermanentCount(playerA, "Balduvian Bears", 1); } + @Test + public void test_BenthicExplorers_BottomlessVault() { + // {T}, Untap a tapped land an opponent controls: Add one mana of any type that land could produce. + addCard(Zone.BATTLEFIELD, playerA, "Benthic Explorers", 1); + + // Bottomless Vault enters the battlefield tapped. + // You may choose not to untap Bottomless Vault during your untap step. + // At the beginning of your upkeep, if Bottomless Vault is tapped, put a storage counter on it. + // Tap, Remove any number of storage counters from Bottomless Vault: Add Black for each storage counter removed this way. + addCard(Zone.BATTLEFIELD, playerB, "Bottomless Vault", 1); // give 1 mana + + setStrictChooseMode(true); + setStopAt(1, PhaseStep.PRECOMBAT_MAIN); + execute(); + assertAllCommandsUsed(); + + ManaOptions manaOptions = playerA.getAvailableManaTest(currentGame); + Assert.assertEquals("mana variations don't fit", 1, manaOptions.size()); + assertManaOptions("{B}", manaOptions); + + } @Test public void test_CloudKey_ChooseCardTypeForCostReduce() { diff --git a/Mage/src/main/java/mage/abilities/effects/common/ManaEffect.java b/Mage/src/main/java/mage/abilities/effects/common/ManaEffect.java index cc3ea6300b..554199b62f 100644 --- a/Mage/src/main/java/mage/abilities/effects/common/ManaEffect.java +++ b/Mage/src/main/java/mage/abilities/effects/common/ManaEffect.java @@ -92,41 +92,10 @@ public abstract class ManaEffect extends OneShotEffect { * @return */ public Set getProducableManaTypes(Game game, Ability source) { - return getManaTypesFromManaList(getNetMana(game, source)); - } - - public static Set getManaTypesFromManaList(List manaList) { - Set manaTypes = new HashSet<>(); - for (Mana mana : manaList) { - if (mana.getAny() > 0) { - manaTypes.add(ManaType.BLACK); - manaTypes.add(ManaType.BLUE); - manaTypes.add(ManaType.GREEN); - manaTypes.add(ManaType.WHITE); - manaTypes.add(ManaType.RED); - } - if (mana.getBlack() > 0) { - manaTypes.add(ManaType.BLACK); - } - if (mana.getBlue() > 0) { - manaTypes.add(ManaType.BLUE); - } - if (mana.getGreen() > 0) { - manaTypes.add(ManaType.GREEN); - } - if (mana.getWhite() > 0) { - manaTypes.add(ManaType.WHITE); - } - if (mana.getRed() > 0) { - manaTypes.add(ManaType.RED); - } - if (mana.getColorless() > 0) { - manaTypes.add(ManaType.COLORLESS); - } - } - return manaTypes; + return ManaType.getManaTypesFromManaList(getNetMana(game, source)); } + /** * Produced the mana the effect can produce (DO NOT add it to mana pool -- * return all added as mana object to process by replace events) diff --git a/Mage/src/main/java/mage/abilities/effects/mana/DynamicManaEffect.java b/Mage/src/main/java/mage/abilities/effects/mana/DynamicManaEffect.java index 5f33416ba8..38234d62f6 100644 --- a/Mage/src/main/java/mage/abilities/effects/mana/DynamicManaEffect.java +++ b/Mage/src/main/java/mage/abilities/effects/mana/DynamicManaEffect.java @@ -12,6 +12,8 @@ import mage.players.Player; import java.util.ArrayList; import java.util.List; +import java.util.Set; +import mage.constants.ManaType; /** * @author North @@ -116,6 +118,11 @@ public class DynamicManaEffect extends ManaEffect { return netMana; } + @Override + public Set getProducableManaTypes(Game game, Ability source) { + return ManaType.getManaTypesFromManaList(baseMana); + } + @Override public Mana produceMana(Game game, Ability source) { Mana computedMana = new Mana(); diff --git a/Mage/src/main/java/mage/abilities/mana/AnyColorLandsProduceManaAbility.java b/Mage/src/main/java/mage/abilities/mana/AnyColorLandsProduceManaAbility.java index b57d040745..ae0fd8f5f8 100644 --- a/Mage/src/main/java/mage/abilities/mana/AnyColorLandsProduceManaAbility.java +++ b/Mage/src/main/java/mage/abilities/mana/AnyColorLandsProduceManaAbility.java @@ -6,8 +6,6 @@ import mage.abilities.Ability; import mage.abilities.costs.common.TapSourceCost; import mage.abilities.effects.common.ManaEffect; import mage.choices.Choice; -import mage.choices.ChoiceColor; -import mage.constants.ColoredManaSymbol; import mage.constants.TargetController; import mage.constants.Zone; import mage.filter.FilterPermanent; @@ -101,29 +99,7 @@ class AnyColorLandsProduceManaEffect extends ManaEffect { public List getNetMana(Game game, Ability source) { List netManas = new ArrayList<>(); if (game != null) { - Set manaTypes = getManaTypes(game, source); - if ((manaTypes.size() == 5 && !manaTypes.contains(ManaType.COLORLESS)) || manaTypes.size() == 6) { // GENERIC should never be returned from getManaTypes - netManas.add(Mana.AnyMana(1)); - } else { - if (manaTypes.contains(ManaType.BLACK)) { - netManas.add(Mana.BlackMana(1)); - } - if (manaTypes.contains(ManaType.RED)) { - netManas.add(Mana.RedMana(1)); - } - if (manaTypes.contains(ManaType.BLUE)) { - netManas.add(Mana.BlueMana(1)); - } - if (manaTypes.contains(ManaType.GREEN)) { - netManas.add(Mana.GreenMana(1)); - } - if (manaTypes.contains(ManaType.WHITE)) { - netManas.add(Mana.WhiteMana(1)); - } - } - if (!onlyColors && manaTypes.contains(ManaType.COLORLESS)) { - netManas.add(Mana.ColorlessMana(1)); - } + netManas = ManaType.getManaListFromManaTypes(getManaTypes(game, source), onlyColors); } return netManas; } @@ -134,28 +110,7 @@ class AnyColorLandsProduceManaEffect extends ManaEffect { if (game == null) { return mana; } - Set types = getManaTypes(game, source); - Choice choice = new ChoiceColor(true); - choice.getChoices().clear(); - choice.setMessage("Pick a mana " + (onlyColors ? "color" : "type")); - if (types.contains(ManaType.BLACK)) { - choice.getChoices().add("Black"); - } - if (types.contains(ManaType.RED)) { - choice.getChoices().add("Red"); - } - if (types.contains(ManaType.BLUE)) { - choice.getChoices().add("Blue"); - } - if (types.contains(ManaType.GREEN)) { - choice.getChoices().add("Green"); - } - if (types.contains(ManaType.WHITE)) { - choice.getChoices().add("White"); - } - if (types.contains(ManaType.COLORLESS)) { - choice.getChoices().add("Colorless"); - } + Choice choice = ManaType.getChoiceOfManaTypes(getManaTypes(game, source), onlyColors); if (!choice.getChoices().isEmpty()) { Player player = game.getPlayer(source.getControllerId()); if (choice.getChoices().size() == 1) { diff --git a/Mage/src/main/java/mage/constants/ManaType.java b/Mage/src/main/java/mage/constants/ManaType.java index 3539dbfd6e..e08407fda9 100644 --- a/Mage/src/main/java/mage/constants/ManaType.java +++ b/Mage/src/main/java/mage/constants/ManaType.java @@ -1,5 +1,14 @@ package mage.constants; +import java.util.ArrayList; +import java.util.EnumSet; +import java.util.HashSet; +import java.util.List; +import java.util.Set; +import mage.Mana; +import mage.choices.Choice; +import mage.choices.ChoiceColor; + /** * * @author North @@ -24,4 +33,95 @@ public enum ManaType { public String toString() { return text; } + + public static Choice getChoiceOfManaTypes(Set types, boolean onlyColors) { + Choice choice = new ChoiceColor(true); + choice.getChoices().clear(); + choice.setMessage("Pick a mana " + (onlyColors ? "color" : "type")); + if (types.contains(ManaType.BLACK)) { + choice.getChoices().add("Black"); + } + if (types.contains(ManaType.RED)) { + choice.getChoices().add("Red"); + } + if (types.contains(ManaType.BLUE)) { + choice.getChoices().add("Blue"); + } + if (types.contains(ManaType.GREEN)) { + choice.getChoices().add("Green"); + } + if (types.contains(ManaType.WHITE)) { + choice.getChoices().add("White"); + } + if (types.contains(ManaType.COLORLESS)) { + choice.getChoices().add("Colorless"); + } + return choice; + } + + public static List getManaListFromManaTypes(Set manaTypes, boolean onlyColors) { + List netManas = new ArrayList<>(); + if ((manaTypes.size() == 5 && !manaTypes.contains(ManaType.COLORLESS)) || manaTypes.size() == 6) { // GENERIC should never be returned from getManaTypes + netManas.add(Mana.AnyMana(1)); + } else { + if (manaTypes.contains(ManaType.BLACK)) { + netManas.add(Mana.BlackMana(1)); + } + if (manaTypes.contains(ManaType.RED)) { + netManas.add(Mana.RedMana(1)); + } + if (manaTypes.contains(ManaType.BLUE)) { + netManas.add(Mana.BlueMana(1)); + } + if (manaTypes.contains(ManaType.GREEN)) { + netManas.add(Mana.GreenMana(1)); + } + if (manaTypes.contains(ManaType.WHITE)) { + netManas.add(Mana.WhiteMana(1)); + } + } + if (!onlyColors && manaTypes.contains(ManaType.COLORLESS)) { + netManas.add(Mana.ColorlessMana(1)); + } + + return netManas; + } + + public static Set getManaTypesFromManaList(Mana mana) { + Set manaTypes = EnumSet.noneOf(ManaType.class); + if (mana.getAny() > 0) { + manaTypes.add(ManaType.BLACK); + manaTypes.add(ManaType.BLUE); + manaTypes.add(ManaType.GREEN); + manaTypes.add(ManaType.WHITE); + manaTypes.add(ManaType.RED); + } + if (mana.getBlack() > 0) { + manaTypes.add(ManaType.BLACK); + } + if (mana.getBlue() > 0) { + manaTypes.add(ManaType.BLUE); + } + if (mana.getGreen() > 0) { + manaTypes.add(ManaType.GREEN); + } + if (mana.getWhite() > 0) { + manaTypes.add(ManaType.WHITE); + } + if (mana.getRed() > 0) { + manaTypes.add(ManaType.RED); + } + if (mana.getColorless() > 0) { + manaTypes.add(ManaType.COLORLESS); + } + return manaTypes; + } + + public static Set getManaTypesFromManaList(List manaList) { + Set manaTypes = new HashSet<>(); + for (Mana mana : manaList) { + manaTypes.addAll(getManaTypesFromManaList(mana)); + } + return manaTypes; + } }