mirror of
https://github.com/Card-Forge/forge.git
synced 2025-11-15 18:28:00 +00:00
Fix places that assumed old format of ManaCost.toString() to either call new getCostString() function or assume {G} formatting
This fixes bugs with Rout ("may cast as instance if you pay 2 more" cards)
This also fixes bugs with Rune Snag ("unless player pays X" cards)
This commit is contained in:
@@ -226,6 +226,13 @@ public final class ManaCost implements Comparable<ManaCost> {
|
|||||||
return this.stringValue;
|
return this.stringValue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return unformatted cost string
|
||||||
|
*/
|
||||||
|
public String getCostString() {
|
||||||
|
return ManaCostParser.stripFormatting(this.toString());
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* TODO: Write javadoc for this method.
|
* TODO: Write javadoc for this method.
|
||||||
* @return
|
* @return
|
||||||
|
|||||||
@@ -22,6 +22,15 @@ public class ManaCostParser implements IParserManaCost {
|
|||||||
return manaCost.toString();
|
return manaCost.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Strip formatting from the given formatted cost string
|
||||||
|
*
|
||||||
|
* @param formattedCost
|
||||||
|
*/
|
||||||
|
public static String stripFormatting(final String formattedCost) {
|
||||||
|
return formattedCost.replaceAll("\\{([A-Z0-9/]+)\\}", "$1 ").trim();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Instantiates a new parser cardname txt mana cost.
|
* Instantiates a new parser cardname txt mana cost.
|
||||||
*
|
*
|
||||||
|
|||||||
@@ -375,7 +375,7 @@ public class ComputerUtilMana {
|
|||||||
|
|
||||||
if (abMana.isComboMana()) {
|
if (abMana.isComboMana()) {
|
||||||
int amount = manaAb.hasParam("Amount") ? AbilityUtils.calculateAmount(source, manaAb.getParam("Amount"), saRoot) : 1;
|
int amount = manaAb.hasParam("Amount") ? AbilityUtils.calculateAmount(source, manaAb.getParam("Amount"), saRoot) : 1;
|
||||||
final ManaCostBeingPaid testCost = new ManaCostBeingPaid(cost.toString().replace("X ", ""));
|
final ManaCostBeingPaid testCost = new ManaCostBeingPaid(cost.getCostString().replace("X ", ""));
|
||||||
final String[] comboColors = abMana.getComboColors().split(" ");
|
final String[] comboColors = abMana.getComboColors().split(" ");
|
||||||
for (int nMana = 1; nMana <= amount; nMana++) {
|
for (int nMana = 1; nMana <= amount; nMana++) {
|
||||||
String choice = "";
|
String choice = "";
|
||||||
|
|||||||
@@ -306,10 +306,10 @@ public final class GameActionUtil {
|
|||||||
if (sa.isSpell() && keyword.equals("You may cast CARDNAME any time you could cast an instant if you pay 2 more to cast it.")) {
|
if (sa.isSpell() && keyword.equals("You may cast CARDNAME any time you could cast an instant if you pay 2 more to cast it.")) {
|
||||||
final SpellAbility newSA = sa.copy();
|
final SpellAbility newSA = sa.copy();
|
||||||
newSA.setBasicSpell(false);
|
newSA.setBasicSpell(false);
|
||||||
String cost = source.getManaCost().toString();
|
String cost = source.getManaCost().getCostString();
|
||||||
ManaCostBeingPaid newCost = new ManaCostBeingPaid(cost);
|
ManaCostBeingPaid newCost = new ManaCostBeingPaid(cost);
|
||||||
newCost.increaseColorlessMana(2);
|
newCost.increaseColorlessMana(2);
|
||||||
cost = newCost.toString();
|
cost = newCost.getCostString();
|
||||||
final Cost actualcost = new Cost(cost, false);
|
final Cost actualcost = new Cost(cost, false);
|
||||||
newSA.setPayCosts(actualcost);
|
newSA.setPayCosts(actualcost);
|
||||||
SpellAbilityRestriction sar = new SpellAbilityRestriction();
|
SpellAbilityRestriction sar = new SpellAbilityRestriction();
|
||||||
|
|||||||
@@ -3,11 +3,11 @@ package forge.game.ability;
|
|||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
|
||||||
import forge.ai.ComputerUtil;
|
import forge.ai.ComputerUtil;
|
||||||
import forge.ai.ComputerUtilCost;
|
import forge.ai.ComputerUtilCost;
|
||||||
import forge.card.MagicColor;
|
import forge.card.MagicColor;
|
||||||
import forge.card.mana.ManaCostShard;
|
import forge.card.mana.ManaCostShard;
|
||||||
|
|
||||||
import org.apache.commons.lang3.StringUtils;
|
import org.apache.commons.lang3.StringUtils;
|
||||||
|
|
||||||
import com.google.common.collect.Iterables;
|
import com.google.common.collect.Iterables;
|
||||||
@@ -1133,17 +1133,17 @@ public class AbilityUtils {
|
|||||||
|
|
||||||
// The cost
|
// The cost
|
||||||
if (unlessCost.equals("CardManaCost")) {
|
if (unlessCost.equals("CardManaCost")) {
|
||||||
unlessCost = source.getManaCost().toString();
|
unlessCost = source.getManaCost().getCostString();
|
||||||
} else if (unlessCost.equals("RememberedCostMinus2")) {
|
} else if (unlessCost.equals("RememberedCostMinus2")) {
|
||||||
if (source.getRemembered().isEmpty() || !(source.getRemembered().get(0) instanceof Card)) {
|
if (source.getRemembered().isEmpty() || !(source.getRemembered().get(0) instanceof Card)) {
|
||||||
sa.resolve();
|
sa.resolve();
|
||||||
resolveSubAbilities(sa, game);
|
resolveSubAbilities(sa, game);
|
||||||
}
|
}
|
||||||
Card rememberedCard = (Card) source.getRemembered().get(0);
|
Card rememberedCard = (Card) source.getRemembered().get(0);
|
||||||
unlessCost = rememberedCard.getManaCost().toString();
|
unlessCost = rememberedCard.getManaCost().getCostString();
|
||||||
ManaCostBeingPaid newCost = new ManaCostBeingPaid(unlessCost.toString());
|
ManaCostBeingPaid newCost = new ManaCostBeingPaid(unlessCost.toString());
|
||||||
newCost.decreaseColorlessMana(2);
|
newCost.decreaseColorlessMana(2);
|
||||||
unlessCost = newCost.toString();
|
unlessCost = newCost.getCostString();
|
||||||
} else if( !StringUtils.isBlank(sa.getSVar(unlessCost)) || !StringUtils.isBlank(source.getSVar(unlessCost))) {
|
} else if( !StringUtils.isBlank(sa.getSVar(unlessCost)) || !StringUtils.isBlank(source.getSVar(unlessCost))) {
|
||||||
// check for X costs (stored in SVars
|
// check for X costs (stored in SVars
|
||||||
int xCost = calculateAmount(source, sa.getParam("UnlessCost").replace(" ", ""), sa);
|
int xCost = calculateAmount(source, sa.getParam("UnlessCost").replace(" ", ""), sa);
|
||||||
@@ -1151,12 +1151,11 @@ public class AbilityUtils {
|
|||||||
ManaCostBeingPaid toPay = new ManaCostBeingPaid("0");
|
ManaCostBeingPaid toPay = new ManaCostBeingPaid("0");
|
||||||
byte xColor = MagicColor.fromName(sa.hasParam("UnlessXColor") ? sa.getParam("UnlessXColor") : "1");
|
byte xColor = MagicColor.fromName(sa.hasParam("UnlessXColor") ? sa.getParam("UnlessXColor") : "1");
|
||||||
toPay.increaseShard(ManaCostShard.valueOf(xColor), xCost);
|
toPay.increaseShard(ManaCostShard.valueOf(xColor), xCost);
|
||||||
unlessCost = toPay.toString();
|
unlessCost = toPay.getCostString();
|
||||||
}
|
}
|
||||||
|
|
||||||
final Cost cost = new Cost(unlessCost, true);
|
final Cost cost = new Cost(unlessCost, true);
|
||||||
|
|
||||||
|
|
||||||
boolean paid = false;
|
boolean paid = false;
|
||||||
for (Player payer : payers) {
|
for (Player payer : payers) {
|
||||||
final Ability ability = new AbilityStatic(source, cost, sa.getTargetRestrictions()) { @Override public void resolve() { } };
|
final Ability ability = new AbilityStatic(source, cost, sa.getTargetRestrictions()) { @Override public void resolve() { } };
|
||||||
|
|||||||
@@ -168,7 +168,7 @@ public class ManaEffect extends SpellAbilityEffect {
|
|||||||
if (card.getEnchanting() != null ) {
|
if (card.getEnchanting() != null ) {
|
||||||
Card enchanted = card.getEnchantingCard();
|
Card enchanted = card.getEnchantingCard();
|
||||||
// Remove X and phyrexian mana
|
// Remove X and phyrexian mana
|
||||||
choice = enchanted.getManaCost().toString().replaceAll("X|/P", "").trim();
|
choice = enchanted.getManaCost().getCostString().replaceAll("X|/P", "").trim();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (choice.equals("no cost") || choice.isEmpty()) {
|
if (choice.equals("no cost") || choice.isEmpty()) {
|
||||||
|
|||||||
@@ -2113,7 +2113,6 @@ public class Card extends GameEntity implements Comparable<Card> {
|
|||||||
} else if (keyword.equals("Unblockable")) {
|
} else if (keyword.equals("Unblockable")) {
|
||||||
sbLong.append(this.getName()).append(" can't be blocked.\r\n");
|
sbLong.append(this.getName()).append(" can't be blocked.\r\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
else {
|
else {
|
||||||
if ((i != 0) && (sb.length() != 0)) {
|
if ((i != 0) && (sb.length() != 0)) {
|
||||||
sb.append(", ");
|
sb.append(", ");
|
||||||
|
|||||||
@@ -519,7 +519,7 @@ public class CardFactoryUtil {
|
|||||||
* @return a int.
|
* @return a int.
|
||||||
*/
|
*/
|
||||||
public static int getNumberOfManaSymbolsByColor(final String colorAbb, final Card card) {
|
public static int getNumberOfManaSymbolsByColor(final String colorAbb, final Card card) {
|
||||||
return countOccurrences(card.getManaCost().toString().trim(), colorAbb);
|
return countOccurrences(card.getManaCost().getCostString(), colorAbb);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -494,6 +494,13 @@ public class ManaCostBeingPaid {
|
|||||||
return this.toString(true);
|
return this.toString(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return unformatted cost string
|
||||||
|
*/
|
||||||
|
public String getCostString() {
|
||||||
|
return ManaCostParser.stripFormatting(this.toString());
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* <p>
|
* <p>
|
||||||
* getConvertedManaCost.
|
* getConvertedManaCost.
|
||||||
|
|||||||
@@ -165,7 +165,7 @@ public class StaticAbilityCostChange {
|
|||||||
|
|
||||||
if (!params.containsKey("Color")) {
|
if (!params.containsKey("Color")) {
|
||||||
manaCost.increaseColorlessMana(value);
|
manaCost.increaseColorlessMana(value);
|
||||||
if (manaCost.toString().equals("0") && params.containsKey("MinMana")) {
|
if (manaCost.toString().equals("{0}") && params.containsKey("MinMana")) {
|
||||||
manaCost.increaseColorlessMana(Integer.valueOf(params.get("MinMana")));
|
manaCost.increaseColorlessMana(Integer.valueOf(params.get("MinMana")));
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
@@ -195,7 +195,7 @@ public class StaticAbilityCostChange {
|
|||||||
*/
|
*/
|
||||||
public static void applyReduceCostAbility(final StaticAbility staticAbility, final SpellAbility sa, final ManaCostBeingPaid manaCost) {
|
public static void applyReduceCostAbility(final StaticAbility staticAbility, final SpellAbility sa, final ManaCostBeingPaid manaCost) {
|
||||||
//Can't reduce zero cost
|
//Can't reduce zero cost
|
||||||
if (manaCost.toString().equals("0")) {
|
if (manaCost.toString().equals("{0}")) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
final HashMap<String, String> params = staticAbility.getMapParams();
|
final HashMap<String, String> params = staticAbility.getMapParams();
|
||||||
|
|||||||
@@ -36,7 +36,7 @@ public class InputPayManaSimple extends InputPayMana {
|
|||||||
|
|
||||||
public InputPayManaSimple(final Game game, final SpellAbility sa, final ManaCostBeingPaid manaCostToPay) {
|
public InputPayManaSimple(final Game game, final SpellAbility sa, final ManaCostBeingPaid manaCostToPay) {
|
||||||
super(sa);
|
super(sa);
|
||||||
this.originalManaCost = manaCostToPay.toString(); // Change
|
this.originalManaCost = manaCostToPay.getCostString(); // Change
|
||||||
this.originalCard = sa.getSourceCard();
|
this.originalCard = sa.getSourceCard();
|
||||||
|
|
||||||
if (sa.getSourceCard().isCopiedSpell() && sa.isSpell()) {
|
if (sa.getSourceCard().isCopiedSpell() && sa.isSpell()) {
|
||||||
|
|||||||
@@ -379,10 +379,10 @@ public class ManaPartTest {
|
|||||||
this.check(35, p24.isAnyPartPayableWith(MagicColor.GREEN));
|
this.check(35, p24.isAnyPartPayableWith(MagicColor.GREEN));
|
||||||
|
|
||||||
p24.payMana("B");
|
p24.payMana("B");
|
||||||
this.check(36, p24.toString().equals("2/B 2/B"));
|
this.check(36, p24.toString().equals("{2/B}{2/B}"));
|
||||||
|
|
||||||
p24.payMana("B");
|
p24.payMana("B");
|
||||||
this.check(37, p24.toString().equals("2/B"));
|
this.check(37, p24.toString().equals("{2/B}"));
|
||||||
|
|
||||||
p24.payMana("B");
|
p24.payMana("B");
|
||||||
this.check(38, p24.isPaid());
|
this.check(38, p24.isPaid());
|
||||||
@@ -390,18 +390,18 @@ public class ManaPartTest {
|
|||||||
final ManaCostBeingPaid p25 = new ManaCostBeingPaid("2/G");
|
final ManaCostBeingPaid p25 = new ManaCostBeingPaid("2/G");
|
||||||
|
|
||||||
p25.payMana("1");
|
p25.payMana("1");
|
||||||
this.check(39, p25.toString().equals("1"));
|
this.check(39, p25.toString().equals("{1}"));
|
||||||
|
|
||||||
p25.payMana("W");
|
p25.payMana("W");
|
||||||
this.check(40, p25.isPaid());
|
this.check(40, p25.isPaid());
|
||||||
|
|
||||||
final ManaCostBeingPaid p27 = new ManaCostBeingPaid("2/R 2/R");
|
final ManaCostBeingPaid p27 = new ManaCostBeingPaid("{2/R}{2/R}");
|
||||||
|
|
||||||
p27.payMana("1");
|
p27.payMana("1");
|
||||||
this.check(41, p27.toString().equals("2/R 1"));
|
this.check(41, p27.toString().equals("{2/R}{1}"));
|
||||||
|
|
||||||
p27.payMana("W");
|
p27.payMana("W");
|
||||||
this.check(42, p27.toString().equals("2/R"));
|
this.check(42, p27.toString().equals("{2/R}"));
|
||||||
|
|
||||||
final ManaCostBeingPaid p26 = new ManaCostBeingPaid("2/W 2/W");
|
final ManaCostBeingPaid p26 = new ManaCostBeingPaid("2/W 2/W");
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user