diff --git a/Mage.Sets/src/mage/cards/b/BiomancersFamiliar.java b/Mage.Sets/src/mage/cards/b/BiomancersFamiliar.java index e6518e1d41..7767c8baeb 100644 --- a/Mage.Sets/src/mage/cards/b/BiomancersFamiliar.java +++ b/Mage.Sets/src/mage/cards/b/BiomancersFamiliar.java @@ -74,14 +74,7 @@ class BiomancersFamiliarCostReductionEffect extends CostModificationEffectImpl { if (controller == null) { return false; } - Mana mana = abilityToModify.getManaCostsToPay().getMana(); - int reduceMax = mana.getGeneric(); - if (reduceMax > 0 && mana.count() == mana.getGeneric()) { - reduceMax--; - } - if (reduceMax > 2) { - reduceMax = 2; - } + int reduceMax = CardUtil.calculateActualPossibleGenericManaReduction(abilityToModify.getManaCostsToPay().getMana(), 2, 1); if (reduceMax <= 0) { return true; } diff --git a/Mage.Sets/src/mage/cards/h/Heartstone.java b/Mage.Sets/src/mage/cards/h/Heartstone.java index 65c244fea5..3aca43a06f 100644 --- a/Mage.Sets/src/mage/cards/h/Heartstone.java +++ b/Mage.Sets/src/mage/cards/h/Heartstone.java @@ -14,6 +14,7 @@ import mage.players.Player; import mage.util.CardUtil; import java.util.UUID; +import mage.Mana; /** * @author pcasaretto_at_gmail.com @@ -42,8 +43,7 @@ public final class Heartstone extends CardImpl { class HeartstoneEffect extends CostModificationEffectImpl { private static final String effectText = "Activated abilities of creatures cost " - + "{1} less to activate. This effect can't reduce the mana in that cost to less than one mana."; - private static final FilterCreaturePermanent filter = new FilterCreaturePermanent(); + + "{1} less to activate. This effect can't reduce the mana in that cost to less than one mana"; public HeartstoneEffect() { super(Duration.Custom, Outcome.Benefit, CostModificationType.REDUCE_COST); @@ -58,7 +58,11 @@ class HeartstoneEffect extends CostModificationEffectImpl { public boolean apply(Game game, Ability source, Ability abilityToModify) { Player controller = game.getPlayer(abilityToModify.getControllerId()); if (controller != null) { - CardUtil.reduceCost(abilityToModify, 1); + int reduceMax = CardUtil.calculateActualPossibleGenericManaReduction(abilityToModify.getManaCostsToPay().getMana(), 1, 1); + if (reduceMax <= 0) { + return true; + } + CardUtil.reduceCost(abilityToModify, reduceMax); return true; } return false; @@ -71,10 +75,7 @@ class HeartstoneEffect extends CostModificationEffectImpl { && (abilityToModify instanceof ActivatedAbility))) { // Activated abilities of creatures Permanent permanent = game.getPermanentOrLKIBattlefield(abilityToModify.getSourceId()); - if (permanent != null - && filter.match(permanent, source.getSourceId(), source.getControllerId(), game)) { - return true; - } + return permanent != null && permanent.isCreature(); } return false; } diff --git a/Mage.Sets/src/mage/cards/p/PowerArtifact.java b/Mage.Sets/src/mage/cards/p/PowerArtifact.java index dbf2a960ab..bc477661ea 100644 --- a/Mage.Sets/src/mage/cards/p/PowerArtifact.java +++ b/Mage.Sets/src/mage/cards/p/PowerArtifact.java @@ -35,8 +35,8 @@ public final class PowerArtifact extends CardImpl { Ability ability = new EnchantAbility(auraTarget.getTargetName()); this.addAbility(ability); - // Enchanted artifact's activated abilities cost less to activate. - // This effect can't reduce the amount of mana an ability costs to activate to less than one mana. + // Enchanted artifact's activated abilities cost {2} less to activate. + // This effect can't reduce the mana in that cost to less than one mana. this.addAbility(new SimpleStaticAbility(Zone.BATTLEFIELD, new PowerArtifactCostModificationEffect())); } @@ -55,7 +55,7 @@ class PowerArtifactCostModificationEffect extends CostModificationEffectImpl { PowerArtifactCostModificationEffect() { super(Duration.WhileOnBattlefield, Outcome.Benefit, CostModificationType.REDUCE_COST); staticText = "Enchanted artifact's activated abilities cost {2} less to activate. " - + "This effect can't reduce the amount of mana an ability costs to activate to less than one mana."; + + "This effect can't reduce the mana in that cost to less than one mana"; } @@ -67,15 +67,11 @@ class PowerArtifactCostModificationEffect extends CostModificationEffectImpl { public boolean apply(Game game, Ability source, Ability abilityToModify) { Player controller = game.getPlayer(abilityToModify.getControllerId()); if (controller != null) { - Mana mana = abilityToModify.getManaCostsToPay().getMana(); - int reduce = mana.getGeneric(); - if (reduce > 0 && mana.count() == mana.getGeneric()) { - reduce--; - } - if (reduce > 2) { - reduce = 2; - } - CardUtil.reduceCost(abilityToModify, reduce); + int reduceMax = CardUtil.calculateActualPossibleGenericManaReduction(abilityToModify.getManaCostsToPay().getMana(), 2, 1); + if (reduceMax <= 0) { + return true; + } + CardUtil.reduceCost(abilityToModify, reduceMax); } return true; } diff --git a/Mage.Sets/src/mage/cards/t/TrainingGrounds.java b/Mage.Sets/src/mage/cards/t/TrainingGrounds.java index 4e4488b5d4..14e5770001 100644 --- a/Mage.Sets/src/mage/cards/t/TrainingGrounds.java +++ b/Mage.Sets/src/mage/cards/t/TrainingGrounds.java @@ -61,14 +61,7 @@ class TrainingGroundsEffect extends CostModificationEffectImpl { if (controller == null) { return false; } - Mana mana = abilityToModify.getManaCostsToPay().getMana(); - int reduceMax = mana.getGeneric(); - if (reduceMax > 0 && mana.count() == mana.getGeneric()) { - reduceMax--; - } - if (reduceMax > 2) { - reduceMax = 2; - } + int reduceMax = CardUtil.calculateActualPossibleGenericManaReduction(abilityToModify.getManaCostsToPay().getMana(), 2, 1); if (reduceMax <= 0) { return true; } diff --git a/Mage.Sets/src/mage/cards/z/ZirdaTheDawnwaker.java b/Mage.Sets/src/mage/cards/z/ZirdaTheDawnwaker.java index f86246c513..1efe933963 100644 --- a/Mage.Sets/src/mage/cards/z/ZirdaTheDawnwaker.java +++ b/Mage.Sets/src/mage/cards/z/ZirdaTheDawnwaker.java @@ -91,7 +91,7 @@ class ZirdaTheDawnwakerEffect extends CostModificationEffectImpl { ZirdaTheDawnwakerEffect() { super(Duration.Custom, Outcome.Benefit, CostModificationType.REDUCE_COST); staticText = "Abilities you activate that aren't mana abilities cost {2} less to activate. " - + "This effect can't reduce the mana in that cost to less than one mana."; + + "This effect can't reduce the mana in that cost to less than one mana"; } private ZirdaTheDawnwakerEffect(final ZirdaTheDawnwakerEffect effect) { @@ -100,13 +100,7 @@ class ZirdaTheDawnwakerEffect extends CostModificationEffectImpl { @Override public boolean apply(Game game, Ability source, Ability abilityToModify) { - Mana mana = abilityToModify.getManaCostsToPay().getMana(); - int reduceMax = mana.getGeneric(); - if (reduceMax > 0 - && mana.count() == mana.getGeneric()) { - reduceMax--; - } - reduceMax = Math.min(reduceMax, 2); + int reduceMax = CardUtil.calculateActualPossibleGenericManaReduction(abilityToModify.getManaCostsToPay().getMana(), 2, 1); if (reduceMax <= 0) { return true; } diff --git a/Mage/src/main/java/mage/util/CardUtil.java b/Mage/src/main/java/mage/util/CardUtil.java index 33b016c412..90d2e36ca7 100644 --- a/Mage/src/main/java/mage/util/CardUtil.java +++ b/Mage/src/main/java/mage/util/CardUtil.java @@ -72,6 +72,25 @@ public final class CardUtil { adjustAbilityCost(ability, -increaseCount); } + /** + * calculates the maximal possible generic mana reduction for a given mana cost + * + * @param mana mana costs that should be reduced + * @param maxPossibleReduction max possible generic mana reduction + * @param notLessThan the complete costs may not be reduced more than this CMC mana costs + */ + public static int calculateActualPossibleGenericManaReduction(Mana mana, int maxPossibleReduction, int notLessThan) { + int nonGeneric = mana.count() - mana.getGeneric(); + int notPossibleGenericReduction = Math.max(0, notLessThan - nonGeneric); + int actualPossibleGenericManaReduction = Math.max(0, mana.getGeneric() - notPossibleGenericReduction); + if (actualPossibleGenericManaReduction > maxPossibleReduction) { + actualPossibleGenericManaReduction = maxPossibleReduction; + } + return actualPossibleGenericManaReduction; + } + + + /** * Reduces ability cost to be paid. *