diff --git a/Mage.Sets/src/mage/sets/theros/NykthosShrineToNyx.java b/Mage.Sets/src/mage/sets/theros/NykthosShrineToNyx.java index d3c9aa2742b..a174dd8dc5d 100644 --- a/Mage.Sets/src/mage/sets/theros/NykthosShrineToNyx.java +++ b/Mage.Sets/src/mage/sets/theros/NykthosShrineToNyx.java @@ -167,6 +167,6 @@ class NykthosDynamicManaEffect extends ManaEffect { break; } } - return computedMana; + return computedMana.copy(); } } diff --git a/Mage.Tests/src/test/java/org/mage/test/utils/ManaOptionsTest.java b/Mage.Tests/src/test/java/org/mage/test/utils/ManaOptionsTest.java index 9b1b5e3816b..c1ae62abce0 100644 --- a/Mage.Tests/src/test/java/org/mage/test/utils/ManaOptionsTest.java +++ b/Mage.Tests/src/test/java/org/mage/test/utils/ManaOptionsTest.java @@ -164,6 +164,41 @@ public class ManaOptionsTest extends CardTestPlayerBase { Assert.assertEquals("{R}{G}{U}{W}{B}", getManaOption(1, manaOptions)); } + // Nykthos, Shrine to Nyx + // {T}: Add {1} to your mana pool. + // {2}, {T}: Choose a color. Add to your mana pool an amount of mana of that color equal to your devotion to that color. (Your devotion to a color is the number of mana symbols of that color in the mana costs of permanents you control.) + @Test + public void testNykthos1() { + addCard(Zone.BATTLEFIELD, playerA, "Sedge Scorpion", 4); + addCard(Zone.BATTLEFIELD, playerA, "Forest", 3); + addCard(Zone.BATTLEFIELD, playerA, "Nykthos, Shrine to Nyx", 1); + + setStopAt(1, PhaseStep. UPKEEP); + execute(); + + ManaOptions manaOptions = playerA.getAvailableManaTest(currentGame); + + Assert.assertEquals("mana variations don't fit",1, manaOptions.size()); + Assert.assertEquals("{G}{G}{G}{G}{G}", getManaOption(0, manaOptions)); + } + + @Test + public void testNykthos2() { + addCard(Zone.BATTLEFIELD, playerA, "Sedge Scorpion", 4); + addCard(Zone.BATTLEFIELD, playerA, "Akroan Crusader", 3); + addCard(Zone.BATTLEFIELD, playerA, "Forest", 3); + addCard(Zone.BATTLEFIELD, playerA, "Nykthos, Shrine to Nyx", 1); + + setStopAt(1, PhaseStep. UPKEEP); + execute(); + + ManaOptions manaOptions = playerA.getAvailableManaTest(currentGame); + + Assert.assertEquals("mana variations don't fit",2, manaOptions.size()); + Assert.assertEquals("{G}{G}{G}{G}{G}", getManaOption(0, manaOptions)); + Assert.assertEquals("{R}{R}{R}{G}", getManaOption(1, manaOptions)); + } + private String getManaOption(int index, ManaOptions manaOptions) { if (manaOptions.size() < index + 1) { return ""; diff --git a/Mage/src/mage/abilities/mana/ManaOptions.java b/Mage/src/mage/abilities/mana/ManaOptions.java index 73b2c4ad52e..370c9c5471b 100644 --- a/Mage/src/mage/abilities/mana/ManaOptions.java +++ b/Mage/src/mage/abilities/mana/ManaOptions.java @@ -114,7 +114,7 @@ public class ManaOptions extends ArrayList { if (abilities.size() == 1) { //if there is only one mana option available add it to all the existing options ManaAbility ability = abilities.get(0); - List netManas = abilities.get(0).getNetMana(game); + List netManas = abilities.get(0).getNetMana(game); // no mana costs if (ability.getManaCosts().isEmpty()) { if (netManas.size() == 1) { @@ -154,7 +154,9 @@ public class ManaOptions extends ArrayList { List copy = copy(); this.clear(); for (ManaAbility ability: abilities) { + List netManas = ability.getNetMana(game); + if (ability.getManaCosts().isEmpty()) { for (Mana netMana: netManas) { for (Mana mana: copy) { @@ -167,12 +169,22 @@ public class ManaOptions extends ArrayList { } else { for (Mana netMana: netManas) { + CombineWithExisting: for (Mana mana: copy) { Mana newMana = new Mana(); newMana.add(mana); - if (mana.includesMana(ability.getManaCosts().getMana())) { + if (mana.includesMana(ability.getManaCosts().getMana())) { // costs can be paid newMana.subtractCost(ability.getManaCosts().getMana()); newMana.add(netMana); + // if the new mana is more than another already existing than replace + for(Mana existingMana: this) { + Mana moreValuable = Mana.getMoreValuableMana(newMana, existingMana); + if (moreValuable != null) { + existingMana.setToMana(moreValuable); + continue CombineWithExisting; + } + } + // no existing Mana includes this new mana so add this.add(newMana); } }