* Heartsone - Fixed that mana cost was reduced to less than one mana (fixes #7070).

This commit is contained in:
LevelX2 2020-12-23 13:20:00 +01:00
parent dd7c1939d3
commit dfa035d9dc
6 changed files with 39 additions and 43 deletions

View file

@ -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;
}

View file

@ -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;
}

View file

@ -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;
}

View file

@ -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;
}

View file

@ -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;
}

View file

@ -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.
*