diff --git a/Mage.Tests/src/test/java/org/mage/test/cards/cost/modification/CostModificationTest.java b/Mage.Tests/src/test/java/org/mage/test/cards/cost/modification/CostModificationTest.java index 7e79260273e..0e5db1f8e02 100644 --- a/Mage.Tests/src/test/java/org/mage/test/cards/cost/modification/CostModificationTest.java +++ b/Mage.Tests/src/test/java/org/mage/test/cards/cost/modification/CostModificationTest.java @@ -45,4 +45,51 @@ public class CostModificationTest extends CardTestPlayerBase { assertGraveyardCount(playerA, 1); } + /** + * Test that cost reduction also works with mana source restriction + * Myr Superion + * Spend only mana produced by creatures to cast Myr Superion + * + * Etherium Sculptor {1}{U} + * Artifact Creature - Vedalken Artificer + * 1/2 + * Artifact spells you cast cost {1} less to cast. + */ + + @Test + public void testCostReductionWithManaSourceRestrictionWorking() { + addCard(Zone.BATTLEFIELD, playerA, "Etherium Sculptor"); + addCard(Zone.BATTLEFIELD, playerA, "Llanowar Elves"); + + addCard(Zone.HAND, playerA, "Myr Superion"); + + activateAbility(3, PhaseStep.PRECOMBAT_MAIN, playerA, "Add {G} to your mana pool."); + castSpell(3, PhaseStep.PRECOMBAT_MAIN, playerA, "Myr Superion"); + setStopAt(3, PhaseStep.BEGIN_COMBAT); + execute(); + + assertLife(playerA, 20); + assertLife(playerB, 20); + + assertPermanentCount(playerA, "Myr Superion", 1); // Can be cast because mana was produced by a creature + } + + @Test + public void testCostReductionWithManaSourceRestrictionNotWorking() { + addCard(Zone.BATTLEFIELD, playerA, "Etherium Sculptor"); + addCard(Zone.BATTLEFIELD, playerA, "Mountain"); + + addCard(Zone.HAND, playerA, "Myr Superion"); + + castSpell(1, PhaseStep.PRECOMBAT_MAIN, playerA, "Myr Superion"); + setStopAt(1, PhaseStep.BEGIN_COMBAT); + execute(); + + assertLife(playerA, 20); + assertLife(playerB, 20); + + assertPermanentCount(playerA, "Myr Superion", 0); // Can't be cast because mana was not produced by a creature + assertHandCount(playerA, "Myr Superion", 1); // Can't be cast because mana was not produced by a creature + } + } diff --git a/Mage/src/mage/abilities/costs/mana/ManaCostsImpl.java b/Mage/src/mage/abilities/costs/mana/ManaCostsImpl.java index f81c63fbc16..6eabaf70262 100644 --- a/Mage/src/mage/abilities/costs/mana/ManaCostsImpl.java +++ b/Mage/src/mage/abilities/costs/mana/ManaCostsImpl.java @@ -422,7 +422,12 @@ public class ManaCostsImpl extends ArrayList implements M @Override public Filter getSourceFilter() { - throw new UnsupportedOperationException("Not supported yet."); + for (T cost : this) { + if (cost.getSourceFilter() != null) { + return cost.getSourceFilter(); + } + } + return null; } @Override diff --git a/Mage/src/mage/abilities/effects/common/cost/SpellsCostReductionControllerEffect.java b/Mage/src/mage/abilities/effects/common/cost/SpellsCostReductionControllerEffect.java index 6e408fe2151..a87b7ed6bc9 100644 --- a/Mage/src/mage/abilities/effects/common/cost/SpellsCostReductionControllerEffect.java +++ b/Mage/src/mage/abilities/effects/common/cost/SpellsCostReductionControllerEffect.java @@ -102,7 +102,7 @@ public class SpellsCostReductionControllerEffect extends CostModificationEffectI if (spell != null) { return this.filter.match(spell, game); } else { - // used at least for flashback ability because Flashback ability doesn't use stack + // used at least for flashback ability because Flashback ability doesn't use stack or for getPlayables where spell is not cast yet Card sourceCard = game.getCard(abilityToModify.getSourceId()); return sourceCard != null && this.filter.match(sourceCard, game); } diff --git a/Mage/src/mage/util/CardUtil.java b/Mage/src/mage/util/CardUtil.java index 91fa3829c5c..332f2ee8f55 100644 --- a/Mage/src/mage/util/CardUtil.java +++ b/Mage/src/mage/util/CardUtil.java @@ -195,7 +195,7 @@ public class CardUtil { private static ManaCosts adjustCost(ManaCosts manaCosts, int reduceCount) { int restToReduce = reduceCount; - ManaCosts adjustedCost = new ManaCostsImpl<>(); + ManaCosts adjustedCost = new ManaCostsImpl<>(); boolean updated = false; for (ManaCost manaCost : manaCosts) { Mana mana = manaCost.getOptions().get(0); @@ -217,7 +217,7 @@ public class CardUtil { if (!updated && reduceCount < 0) { adjustedCost.add(new GenericManaCost(-reduceCount)); } - + adjustedCost.setSourceFilter(manaCosts.getSourceFilter()); return adjustedCost; } @@ -255,7 +255,7 @@ public class CardUtil { */ public static void adjustCost(SpellAbility spellAbility, ManaCosts manaCostsToReduce, boolean convertToGeneric) { ManaCosts previousCost = spellAbility.getManaCostsToPay(); - ManaCosts adjustedCost = new ManaCostsImpl<>(); + ManaCosts adjustedCost = new ManaCostsImpl<>(); // save X value (e.g. convoke ability) for (VariableCost vCost: previousCost.getVariableCosts()) { if (vCost instanceof VariableManaCost) { @@ -352,7 +352,7 @@ public class CardUtil { adjustedCost.add(0, new GenericManaCost(mana.count())); } } - + adjustedCost.setSourceFilter(previousCost.getSourceFilter()); // keep mana source restrictions spellAbility.getManaCostsToPay().clear(); spellAbility.getManaCostsToPay().addAll(adjustedCost); }