diff --git a/Mage.Client/src/main/java/mage/client/cards/DragCardGrid.java b/Mage.Client/src/main/java/mage/client/cards/DragCardGrid.java index 17810f9239..29fdc8336e 100644 --- a/Mage.Client/src/main/java/mage/client/cards/DragCardGrid.java +++ b/Mage.Client/src/main/java/mage/client/cards/DragCardGrid.java @@ -1398,11 +1398,7 @@ public class DragCardGrid extends JPanel implements DragCardSource, DragCardTarg } // Casting cost if (!s) { - String mc = ""; - for (String m : card.getManaCost()) { - mc += m; - } - s |= mc.toLowerCase(Locale.ENGLISH).contains(searchStr); + s |= card.getManaCostStr().toLowerCase(Locale.ENGLISH).contains(searchStr); } // Rules if (!s) { @@ -1473,10 +1469,7 @@ public class DragCardGrid extends JPanel implements DragCardSource, DragCardTarg } // Mana Cost - String mc = ""; - for (String m : card.getManaCost()) { - mc += m; - } + String mc = card.getManaCostStr(); mc = mc.replaceAll("\\{([WUBRG]).([WUBRG])\\}", "{$1}{$2}"); mc = mc.replaceAll("\\{", "#"); mc = mc.replaceAll("#2\\/", "#"); diff --git a/Mage.Client/src/main/java/mage/client/deckeditor/table/TableModel.java b/Mage.Client/src/main/java/mage/client/deckeditor/table/TableModel.java index 62b549e7cc..91b0f514ac 100644 --- a/Mage.Client/src/main/java/mage/client/deckeditor/table/TableModel.java +++ b/Mage.Client/src/main/java/mage/client/deckeditor/table/TableModel.java @@ -215,7 +215,7 @@ public class TableModel extends AbstractTableModel implements ICardGrid { return c.getDisplayFullName(); // show full name in deck editor table, e.g. adventure with spell name case 2: // new svg images version - return ManaSymbols.getStringManaCost(c.getManaCost()); + return ManaSymbols.getClearManaCost(c.getManaCostStr()); /* // old html images version String manaCost = ""; diff --git a/Mage.Client/src/main/java/mage/client/util/comparators/CardViewColorIdentityComparator.java b/Mage.Client/src/main/java/mage/client/util/comparators/CardViewColorIdentityComparator.java index f644f69eee..c66f110877 100644 --- a/Mage.Client/src/main/java/mage/client/util/comparators/CardViewColorIdentityComparator.java +++ b/Mage.Client/src/main/java/mage/client/util/comparators/CardViewColorIdentityComparator.java @@ -24,7 +24,7 @@ public class CardViewColorIdentityComparator implements CardViewComparator { } public static FilterMana calcIdentity(CardView cardView) { - return ManaUtil.getColorIdentity(cardView.getColor(), cardView.getManaCost(), cardView.getRules(), null); + return ManaUtil.getColorIdentity(cardView.getColor(), cardView.getManaCostStr(), cardView.getRules(), null); } public static int calcHash(CardView cardView) { diff --git a/Mage.Client/src/main/java/mage/client/util/gui/GuiDisplayUtil.java b/Mage.Client/src/main/java/mage/client/util/gui/GuiDisplayUtil.java index 18ecf4b509..9e860593aa 100644 --- a/Mage.Client/src/main/java/mage/client/util/gui/GuiDisplayUtil.java +++ b/Mage.Client/src/main/java/mage/client/util/gui/GuiDisplayUtil.java @@ -97,7 +97,7 @@ public final class GuiDisplayUtil { j.add(cardText); TextLines textLines = GuiDisplayUtil.getTextLinesfromCardView(card); - cardText.setText(getRulefromCardView(card, textLines).toString()); + cardText.setText(getRulesFromCardView(card, textLines).toString()); descriptionPanel.add(j); @@ -227,11 +227,8 @@ public final class GuiDisplayUtil { return "" + iconName + ""; } - public static StringBuilder getRulefromCardView(CardView card, TextLines textLines) { - String manaCost = ""; - for (String m : card.getManaCost()) { - manaCost += m; - } + public static StringBuilder getRulesFromCardView(CardView card, TextLines textLines) { + String manaCost = card.getManaCostStr(); String castingCost = UI.getDisplayManaCost(manaCost); castingCost = ManaSymbols.replaceSymbolsWithHTML(castingCost, ManaSymbols.Type.TOOLTIP); @@ -347,9 +344,9 @@ public final class GuiDisplayUtil { rule.append(""); rule.append(card.getLeftSplitName()); rule.append(""); - rule.append(card.getLeftSplitCosts().getText()); + rule.append(card.getLeftSplitCostsStr()); rule.append(""); for (String ruling : card.getLeftSplitRules()) { if (ruling != null && !ruling.replace(".", "").trim().isEmpty()) { @@ -362,9 +359,9 @@ public final class GuiDisplayUtil { rule.append(""); rule.append(card.getRightSplitName()); rule.append(""); - rule.append(card.getRightSplitCosts().getText()); + rule.append(card.getRightSplitCostsStr()); rule.append(""); for (String ruling : card.getRightSplitRules()) { if (ruling != null && !ruling.replace(".", "").trim().isEmpty()) { diff --git a/Mage.Client/src/main/java/org/mage/card/arcane/CardPanel.java b/Mage.Client/src/main/java/org/mage/card/arcane/CardPanel.java index 038abf71eb..3ecda635ac 100644 --- a/Mage.Client/src/main/java/org/mage/card/arcane/CardPanel.java +++ b/Mage.Client/src/main/java/org/mage/card/arcane/CardPanel.java @@ -789,8 +789,8 @@ public abstract class CardPanel extends MagePermanent implements ComponentListen } } else { sb.append(card.getName()); - if (!card.getManaCost().isEmpty()) { - sb.append('\n').append(card.getManaCost()); + if (!card.getManaCostStr().isEmpty()) { + sb.append('\n').append(card.getManaCostStr()); } sb.append('\n').append(cardType); if (card.getColor().hasColor()) { diff --git a/Mage.Client/src/main/java/org/mage/card/arcane/CardPanelRenderModeImage.java b/Mage.Client/src/main/java/org/mage/card/arcane/CardPanelRenderModeImage.java index 65ee832b7a..73a8bd1392 100644 --- a/Mage.Client/src/main/java/org/mage/card/arcane/CardPanelRenderModeImage.java +++ b/Mage.Client/src/main/java/org/mage/card/arcane/CardPanelRenderModeImage.java @@ -529,7 +529,7 @@ public class CardPanelRenderModeImage extends CardPanel { int symbolMarginX = 2; // 2 px between icons - String manaCost = ManaSymbols.getStringManaCost(getGameCard().getManaCost()); + String manaCost = ManaSymbols.getClearManaCost(getGameCard().getManaCostStr()); int manaWidth = getManaWidth(manaCost, symbolMarginX); // right top corner with margin (sizes from any sample card, length from black border to mana icon) diff --git a/Mage.Client/src/main/java/org/mage/card/arcane/CardPanelRenderModeMTGO.java b/Mage.Client/src/main/java/org/mage/card/arcane/CardPanelRenderModeMTGO.java index 00315d0532..54426314c4 100644 --- a/Mage.Client/src/main/java/org/mage/card/arcane/CardPanelRenderModeMTGO.java +++ b/Mage.Client/src/main/java/org/mage/card/arcane/CardPanelRenderModeMTGO.java @@ -56,7 +56,7 @@ public class CardPanelRenderModeMTGO extends CardPanel { if (!a.getSuperTypes().equals(b.getSuperTypes())) { return false; } - if (!a.getManaCost().equals(b.getManaCost())) { + if (!a.getManaCostStr().equals(b.getManaCostStr())) { return false; } if (!a.getRules().equals(b.getRules())) { @@ -166,9 +166,7 @@ public class CardPanelRenderModeMTGO extends CardPanel { for (SubType s : this.view.getSubTypes()) { sb.append(s); } - for (String s : this.view.getManaCost()) { - sb.append(s); - } + sb.append(this.view.getManaCostStr()); for (String s : this.view.getRules()) { sb.append(s); } diff --git a/Mage.Client/src/main/java/org/mage/card/arcane/ManaSymbols.java b/Mage.Client/src/main/java/org/mage/card/arcane/ManaSymbols.java index 4c09becc72..350d87fd3e 100644 --- a/Mage.Client/src/main/java/org/mage/card/arcane/ManaSymbols.java +++ b/Mage.Client/src/main/java/org/mage/card/arcane/ManaSymbols.java @@ -550,18 +550,35 @@ public final class ManaSymbols { } - public static String getStringManaCost(java.util.List manaCost) { + public static String getClearManaCost(java.util.List manaCost) { StringBuilder sb = new StringBuilder(); for (String s : manaCost) { sb.append(s); } - return sb.toString() + return getClearManaCost(sb.toString()); + } + + public static String getClearManaCost(String manaCost) { + return manaCost .replace("/", "") .replace("{", "") - .replace("}", " ") + .replace("}", " ") // each mana symbol splits by space .trim(); } + public static int getClearManaSymbolsCount(String manaCost) { + // find mana symbols amount in the cost + if (manaCost.isEmpty()) { + return 0; + } else { + String clearManaCost = getClearManaCost(manaCost); + String checkManaCost = clearManaCost.replace(" ", ""); + return clearManaCost.length() - checkManaCost.length() + 1; + } + } + + + public enum Type { TABLE, CHAT, diff --git a/Mage.Client/src/main/java/org/mage/card/arcane/ModernCardRenderer.java b/Mage.Client/src/main/java/org/mage/card/arcane/ModernCardRenderer.java index 3a737ee396..ef1ed073b7 100644 --- a/Mage.Client/src/main/java/org/mage/card/arcane/ModernCardRenderer.java +++ b/Mage.Client/src/main/java/org/mage/card/arcane/ModernCardRenderer.java @@ -221,7 +221,7 @@ public class ModernCardRenderer extends CardRenderer { super(card); // Mana cost string - manaCostString = ManaSymbols.getStringManaCost(cardView.getManaCost()); + manaCostString = ManaSymbols.getClearManaCost(cardView.getManaCostStr()); } @Override diff --git a/Mage.Client/src/main/java/org/mage/card/arcane/ModernSplitCardRenderer.java b/Mage.Client/src/main/java/org/mage/card/arcane/ModernSplitCardRenderer.java index 9b18efeee1..15d4448891 100644 --- a/Mage.Client/src/main/java/org/mage/card/arcane/ModernSplitCardRenderer.java +++ b/Mage.Client/src/main/java/org/mage/card/arcane/ModernSplitCardRenderer.java @@ -1,7 +1,6 @@ package org.mage.card.arcane; import mage.ObjectColor; -import mage.abilities.costs.mana.ManaCosts; import mage.cards.ArtRect; import mage.constants.CardType; import mage.view.CardView; @@ -50,11 +49,11 @@ public class ModernSplitCardRenderer extends ModernCardRenderer { public ModernSplitCardRenderer(CardView view) { super(view); - rightHalf.manaCostString = ManaSymbols.getStringManaCost(cardView.getRightSplitCosts().getSymbols()); - leftHalf.manaCostString = ManaSymbols.getStringManaCost(cardView.getLeftSplitCosts().getSymbols()); + rightHalf.manaCostString = ManaSymbols.getClearManaCost(cardView.getRightSplitCostsStr()); + leftHalf.manaCostString = ManaSymbols.getClearManaCost(cardView.getLeftSplitCostsStr()); - rightHalf.color = getColorFromManaCostHack(cardView.getRightSplitCosts()); - leftHalf.color = getColorFromManaCostHack(cardView.getLeftSplitCosts()); + rightHalf.color = getColorFromManaCostHack(cardView.getRightSplitCostsStr()); + leftHalf.color = getColorFromManaCostHack(cardView.getLeftSplitCostsStr()); parseRules(view.getRightSplitRules(), rightHalf.keywords, rightHalf.rules); parseRules(view.getLeftSplitRules(), leftHalf.keywords, leftHalf.rules); @@ -129,21 +128,18 @@ public class ModernSplitCardRenderer extends ModernCardRenderer { // Ugly hack used here because the card database doesn't actually store color // for each half of split cards separately. - private ObjectColor getColorFromManaCostHack(ManaCosts costs) { + private ObjectColor getColorFromManaCostHack(String costs) { ObjectColor c = new ObjectColor(); - List symbols = costs.getSymbols(); - for (String symbol : symbols) { - if (symbol.contains("W")) { - c.setWhite(true); - } else if (symbol.contains("U")) { - c.setBlue(true); - } else if (symbol.contains("B")) { - c.setBlack(true); - } else if (symbol.contains("R")) { - c.setRed(true); - } else if (symbol.contains("G")) { - c.setGreen(true); - } + if (costs.contains("W")) { + c.setWhite(true); + } else if (costs.contains("U")) { + c.setBlue(true); + } else if (costs.contains("B")) { + c.setBlack(true); + } else if (costs.contains("R")) { + c.setRed(true); + } else if (costs.contains("G")) { + c.setGreen(true); } return c; } diff --git a/Mage.Client/src/main/java/org/mage/plugins/card/info/CardInfoPaneImpl.java b/Mage.Client/src/main/java/org/mage/plugins/card/info/CardInfoPaneImpl.java index 1ec644ec77..4cf531e0d5 100644 --- a/Mage.Client/src/main/java/org/mage/plugins/card/info/CardInfoPaneImpl.java +++ b/Mage.Client/src/main/java/org/mage/plugins/card/info/CardInfoPaneImpl.java @@ -56,7 +56,7 @@ public class CardInfoPaneImpl extends JEditorPane implements CardInfoPane { try { SwingUtilities.invokeLater(() -> { TextLines textLines = GuiDisplayUtil.getTextLinesfromCardView(card); - StringBuilder buffer = GuiDisplayUtil.getRulefromCardView(card, textLines); + StringBuilder buffer = GuiDisplayUtil.getRulesFromCardView(card, textLines); resizeTooltipIfNeeded(container, textLines.getBasicTextLength(), textLines.getLines().size()); setText(buffer.toString()); setCaretPosition(0); diff --git a/Mage.Client/src/main/java/org/mage/plugins/card/utils/CardImageUtils.java b/Mage.Client/src/main/java/org/mage/plugins/card/utils/CardImageUtils.java index 6349fe9172..b6573b0295 100644 --- a/Mage.Client/src/main/java/org/mage/plugins/card/utils/CardImageUtils.java +++ b/Mage.Client/src/main/java/org/mage/plugins/card/utils/CardImageUtils.java @@ -308,6 +308,10 @@ public final class CardImageUtils { // search broken files and delete it (zero size files) // search temp files and delete it (.tmp files from zip library) Path rootPath = new File(CardImageUtils.getImagesDir()).toPath(); + if (!Files.exists(rootPath)) { + return; + } + Collection brokenFilesList = new ArrayList<>(); Collection tempFilesList = new ArrayList<>(); try { diff --git a/Mage.Common/src/main/java/mage/view/AbilityView.java b/Mage.Common/src/main/java/mage/view/AbilityView.java index f6d20dfc33..2c0c57eb80 100644 --- a/Mage.Common/src/main/java/mage/view/AbilityView.java +++ b/Mage.Common/src/main/java/mage/view/AbilityView.java @@ -31,8 +31,8 @@ public class AbilityView extends CardView { this.subTypes = new SubTypes(); this.superTypes = EnumSet.noneOf(SuperType.class); this.color = new ObjectColor(); - this.manaCostLeft = ability.getManaCosts().getSymbols(); - this.manaCostRight = new ArrayList<>(); + this.manaCostLeftStr = String.join("", ability.getManaCosts().getSymbols()); + this.manaCostRightStr = ""; } public CardView getSourceCard() { diff --git a/Mage.Common/src/main/java/mage/view/CardView.java b/Mage.Common/src/main/java/mage/view/CardView.java index 4469f2df7f..5cdabeb640 100644 --- a/Mage.Common/src/main/java/mage/view/CardView.java +++ b/Mage.Common/src/main/java/mage/view/CardView.java @@ -7,7 +7,6 @@ import mage.abilities.Abilities; import mage.abilities.Ability; import mage.abilities.Mode; import mage.abilities.SpellAbility; -import mage.abilities.costs.mana.ManaCosts; import mage.abilities.effects.Effect; import mage.abilities.effects.Effects; import mage.abilities.icon.CardIcon; @@ -65,8 +64,8 @@ public class CardView extends SimpleCardView { protected ObjectColor frameColor; protected FrameStyle frameStyle; // can combine multiple costs for MockCard from deck editor or db (left/right, card/adventure) - protected List manaCostLeft; - protected List manaCostRight; + protected String manaCostLeftStr; + protected String manaCostRightStr; protected int convertedManaCost; protected Rarity rarity; @@ -91,11 +90,11 @@ public class CardView extends SimpleCardView { protected boolean isSplitCard; protected String leftSplitName; - protected ManaCosts leftSplitCosts; + protected String leftSplitCostsStr; protected List leftSplitRules; protected String leftSplitTypeLine; protected String rightSplitName; - protected ManaCosts rightSplitCosts; + protected String rightSplitCostsStr; protected List rightSplitRules; protected String rightSplitTypeLine; @@ -173,8 +172,8 @@ public class CardView extends SimpleCardView { this.color = cardView.color; this.frameColor = cardView.frameColor; this.frameStyle = cardView.frameStyle; - this.manaCostLeft = new ArrayList<>(cardView.manaCostLeft); - this.manaCostRight = new ArrayList<>(cardView.manaCostRight); + this.manaCostLeftStr = cardView.manaCostLeftStr; + this.manaCostRightStr = cardView.manaCostRightStr; this.convertedManaCost = cardView.convertedManaCost; this.rarity = cardView.rarity; @@ -195,11 +194,11 @@ public class CardView extends SimpleCardView { this.isSplitCard = cardView.isSplitCard; this.leftSplitName = cardView.leftSplitName; - this.leftSplitCosts = cardView.leftSplitCosts == null ? null : cardView.leftSplitCosts.copy(); + this.leftSplitCostsStr = cardView.leftSplitCostsStr; this.leftSplitRules = cardView.leftSplitRules == null ? null : new ArrayList<>(cardView.leftSplitRules); this.leftSplitTypeLine = cardView.leftSplitTypeLine; this.rightSplitName = cardView.rightSplitName; - this.rightSplitCosts = cardView.rightSplitCosts == null ? null : cardView.rightSplitCosts.copy(); + this.rightSplitCostsStr = cardView.rightSplitCostsStr; this.rightSplitRules = cardView.rightSplitRules == null ? null : new ArrayList<>(cardView.rightSplitRules); this.rightSplitTypeLine = cardView.rightSplitTypeLine; @@ -348,40 +347,39 @@ public class CardView extends SimpleCardView { if (splitCard != null) { this.isSplitCard = true; leftSplitName = splitCard.getLeftHalfCard().getName(); - leftSplitCosts = splitCard.getLeftHalfCard().getManaCost(); + leftSplitCostsStr = String.join("", splitCard.getLeftHalfCard().getManaCost().getSymbols()); leftSplitRules = splitCard.getLeftHalfCard().getRules(game); leftSplitTypeLine = getCardTypeLine(game, splitCard.getLeftHalfCard()); rightSplitName = splitCard.getRightHalfCard().getName(); - rightSplitCosts = splitCard.getRightHalfCard().getManaCost(); + rightSplitCostsStr = String.join("", splitCard.getRightHalfCard().getManaCost().getSymbols()); rightSplitRules = splitCard.getRightHalfCard().getRules(game); rightSplitTypeLine = getCardTypeLine(game, splitCard.getRightHalfCard()); fullCardName = card.getName(); // split card contains full name as normal - this.manaCostLeft = splitCard.getLeftHalfCard().getManaCost().getSymbols(); - this.manaCostRight = splitCard.getRightHalfCard().getManaCost().getSymbols(); + this.manaCostLeftStr = String.join("", splitCard.getLeftHalfCard().getManaCost().getSymbols()); + this.manaCostRightStr = String.join("", splitCard.getRightHalfCard().getManaCost().getSymbols()); } else if (card instanceof ModalDoubleFacesCard) { this.isModalDoubleFacesCard = true; ModalDoubleFacesCard mainCard = ((ModalDoubleFacesCard) card); fullCardName = mainCard.getLeftHalfCard().getName() + MockCard.MODAL_DOUBLE_FACES_NAME_SEPARATOR + mainCard.getRightHalfCard().getName(); - this.manaCostLeft = mainCard.getLeftHalfCard().getManaCost().getSymbols(); - this.manaCostRight = mainCard.getRightHalfCard().getManaCost().getSymbols(); + this.manaCostLeftStr = String.join("", mainCard.getLeftHalfCard().getManaCost().getSymbols()); + this.manaCostRightStr = String.join("", mainCard.getRightHalfCard().getManaCost().getSymbols()); } else if (card instanceof AdventureCard) { AdventureCard adventureCard = ((AdventureCard) card); AdventureCardSpell adventureCardSpell = ((AdventureCardSpell) adventureCard.getSpellCard()); fullCardName = adventureCard.getName() + MockCard.ADVENTURE_NAME_SEPARATOR + adventureCardSpell.getName(); - this.manaCostLeft = adventureCardSpell.getManaCost().getSymbols(); - this.manaCostRight = adventureCard.getManaCost().getSymbols(); + this.manaCostLeftStr = String.join("", adventureCardSpell.getManaCost().getSymbols()); + this.manaCostRightStr = String.join("", adventureCard.getManaCost().getSymbols()); } else if (card instanceof MockCard) { // deck editor cards fullCardName = ((MockCard) card).getFullName(true); - this.manaCostLeft = ((MockCard) card).getManaCost(CardInfo.ManaCostSide.LEFT).getSymbols(); - this.manaCostRight = ((MockCard) card).getManaCost(CardInfo.ManaCostSide.RIGHT).getSymbols(); + this.manaCostLeftStr = String.join("", ((MockCard) card).getManaCostStr(CardInfo.ManaCostSide.LEFT)); + this.manaCostRightStr = String.join("", ((MockCard) card).getManaCostStr(CardInfo.ManaCostSide.RIGHT)); } else { fullCardName = card.getName(); - this.manaCostLeft = card.getManaCost().getSymbols(); - this.manaCostRight = new ArrayList<>(); + this.manaCostLeftStr = String.join("", card.getManaCost().getSymbols()); + this.manaCostRightStr = ""; } - //this.manaCost = card.getManaCost().getSymbols(); this.name = card.getImageName(); this.displayName = card.getName(); @@ -565,8 +563,8 @@ public class CardView extends SimpleCardView { this.subTypes = object.getSubtype(game); this.superTypes = object.getSuperType(); this.color = object.getColor(game); - this.manaCostLeft = object.getManaCost().getSymbols(); - this.manaCostRight = new ArrayList<>(); + this.manaCostLeftStr = String.join("", object.getManaCost().getSymbols()); + this.manaCostRightStr = ""; this.convertedManaCost = object.getManaCost().convertedManaCost(); if (object instanceof PermanentToken) { this.mageObjectType = MageObjectType.TOKEN; @@ -686,8 +684,8 @@ public class CardView extends SimpleCardView { this.color = new ObjectColor(); this.frameColor = new ObjectColor(); this.frameStyle = FrameStyle.M15_NORMAL; - this.manaCostLeft = new ArrayList<>(); - this.manaCostRight = new ArrayList<>(); + this.manaCostLeftStr = ""; + this.manaCostRightStr = ""; this.convertedManaCost = 0; // the controller can see more information (e.g. enlarged image) than other players for face down cards (e.g. Morph played face down) @@ -735,8 +733,8 @@ public class CardView extends SimpleCardView { this.color = token.getColor(game); this.frameColor = token.getFrameColor(game); this.frameStyle = token.getFrameStyle(); - this.manaCostLeft = token.getManaCost().getSymbols(); - this.manaCostRight = new ArrayList<>(); + this.manaCostLeftStr = String.join("", token.getManaCost().getSymbols()); + this.manaCostRightStr = ""; this.rarity = Rarity.SPECIAL; this.type = token.getTokenType(); this.tokenDescriptor = token.getTokenDescriptor(); @@ -846,8 +844,8 @@ public class CardView extends SimpleCardView { return frameStyle; } - public List getManaCost() { - return CardUtil.concatManaSymbols(CardInfo.SPLIT_MANA_SEPARATOR_FULL, this.manaCostLeft, this.manaCostRight); + public String getManaCostStr() { + return CardUtil.concatManaSymbols(CardInfo.SPLIT_MANA_SEPARATOR_FULL, this.manaCostLeftStr, this.manaCostRightStr); } public int getConvertedManaCost() { @@ -963,8 +961,8 @@ public class CardView extends SimpleCardView { return leftSplitName; } - public ManaCosts getLeftSplitCosts() { - return leftSplitCosts; + public String getLeftSplitCostsStr() { + return leftSplitCostsStr; } public List getLeftSplitRules() { @@ -979,8 +977,8 @@ public class CardView extends SimpleCardView { return rightSplitName; } - public ManaCosts getRightSplitCosts() { - return rightSplitCosts; + public String getRightSplitCostsStr() { + return rightSplitCostsStr; } public List getRightSplitRules() { diff --git a/Mage.Common/src/main/java/mage/view/StackAbilityView.java b/Mage.Common/src/main/java/mage/view/StackAbilityView.java index cfe29e4786..a021b5349a 100644 --- a/Mage.Common/src/main/java/mage/view/StackAbilityView.java +++ b/Mage.Common/src/main/java/mage/view/StackAbilityView.java @@ -44,8 +44,8 @@ public class StackAbilityView extends CardView { this.subTypes = ability.getSubtype(game); this.superTypes = ability.getSuperType(); this.color = ability.getColor(game); - this.manaCostLeft = ability.getManaCost().getSymbols(); - this.manaCostRight = new ArrayList<>(); + this.manaCostLeftStr = String.join("", ability.getManaCost().getSymbols()); + this.manaCostRightStr = ""; this.cardTypes = ability.getCardType(); this.subTypes = ability.getSubtype(game); this.superTypes = ability.getSuperType(); @@ -60,8 +60,8 @@ public class StackAbilityView extends CardView { tmpSourceCard.subTypes.clear(); tmpSourceCard.cardTypes.clear(); tmpSourceCard.cardTypes.add(CardType.CREATURE); - tmpSourceCard.manaCostLeft.clear(); - tmpSourceCard.manaCostRight.clear(); + tmpSourceCard.manaCostLeftStr = ""; + tmpSourceCard.manaCostRightStr = ""; tmpSourceCard.power = "2"; tmpSourceCard.toughness = "2"; nameToShow = "creature without name"; diff --git a/Mage.Verify/src/test/java/mage/verify/VerifyCardDataTest.java b/Mage.Verify/src/test/java/mage/verify/VerifyCardDataTest.java index db9f94bfa0..ea3ff51401 100644 --- a/Mage.Verify/src/test/java/mage/verify/VerifyCardDataTest.java +++ b/Mage.Verify/src/test/java/mage/verify/VerifyCardDataTest.java @@ -1621,7 +1621,7 @@ public class VerifyCardDataTest { } String expected = ref.manaCost; - String cost = join(card.getManaCost().getSymbols()); + String cost = String.join("", card.getManaCost().getSymbols()); if (cost.isEmpty()) { cost = null; } @@ -1674,14 +1674,6 @@ public class VerifyCardDataTest { } } - private String join(Iterable items) { - StringBuilder result = new StringBuilder(); - for (Object item : items) { - result.append(item); - } - return result.toString(); - } - @Test public void test_checkCardRatingConsistency() { // all cards with same name must have same rating (see RateCard.rateCard) diff --git a/Mage/src/main/java/mage/MageObjectImpl.java b/Mage/src/main/java/mage/MageObjectImpl.java index d6d56a068d..47110ebef0 100644 --- a/Mage/src/main/java/mage/MageObjectImpl.java +++ b/Mage/src/main/java/mage/MageObjectImpl.java @@ -57,7 +57,7 @@ public abstract class MageObjectImpl implements MageObject { color = new ObjectColor(); frameColor = new ObjectColor(); frameStyle = FrameStyle.M15_NORMAL; - manaCost = new ManaCostsImpl<>(""); + manaCost = new ManaCostsImpl<>(); abilities = new AbilitiesImpl<>(); textParts = new ArrayList<>(); } diff --git a/Mage/src/main/java/mage/Mana.java b/Mage/src/main/java/mage/Mana.java index 5bb92c6d1e..d9f11a8aec 100644 --- a/Mage/src/main/java/mage/Mana.java +++ b/Mage/src/main/java/mage/Mana.java @@ -24,6 +24,10 @@ public class Mana implements Comparable, Serializable, Copyable { private ManaColor() { } + protected ManaColor(final ManaColor manaColor) { + this.copyFrom(manaColor); + } + private ManaColor(int amount) { this.amount = amount; } @@ -76,9 +80,12 @@ public class Mana implements Comparable, Serializable, Copyable { } protected ManaColor copy() { - ManaColor copy = new ManaColor(); - copy.incrementAmount(this); - return copy; + return new ManaColor(this); + } + + protected void copyFrom(final ManaColor manaColor) { + this.amount = manaColor.amount; + this.snowAmount = manaColor.snowAmount; } @Override @@ -1202,14 +1209,15 @@ public class Mana implements Comparable, Serializable, Copyable { * @param mana the mana to set this object to. */ public void setToMana(final Mana mana) { - this.any = mana.any.copy(); - this.white = mana.white.copy(); - this.blue = mana.blue.copy(); - this.black = mana.black.copy(); - this.red = mana.red.copy(); - this.green = mana.green.copy(); - this.colorless = mana.colorless.copy(); - this.generic = mana.generic.copy(); + this.any.copyFrom(mana.any); + this.white.copyFrom(mana.white); + this.blue.copyFrom(mana.blue.copy()); + this.black.copyFrom(mana.black.copy()); + this.red.copyFrom(mana.red.copy()); + this.green.copyFrom(mana.green.copy()); + this.colorless.copyFrom(mana.colorless.copy()); + this.generic.copyFrom(mana.generic.copy()); + //this.flag = mana.flag; } /** diff --git a/Mage/src/main/java/mage/abilities/costs/mana/ManaCostsImpl.java b/Mage/src/main/java/mage/abilities/costs/mana/ManaCostsImpl.java index b07eb4cf25..e5ae8b6d74 100644 --- a/Mage/src/main/java/mage/abilities/costs/mana/ManaCostsImpl.java +++ b/Mage/src/main/java/mage/abilities/costs/mana/ManaCostsImpl.java @@ -194,11 +194,11 @@ public class ManaCostsImpl extends ArrayList implements M private void handleLikePhyrexianManaCosts(Player player, Ability source, Game game) { if (this.isEmpty()) { return; // nothing to be done without any mana costs. prevents NRE from occurring here - } + } FilterMana phyrexianColors = player.getPhyrexianColors(); if (player.getPhyrexianColors() != null) { Costs tempCosts = new CostsImpl<>(); - + Iterator manaCostIterator = this.iterator(); while (manaCostIterator.hasNext()) { ManaCost manaCost = manaCostIterator.next(); @@ -440,15 +440,16 @@ public class ManaCostsImpl extends ArrayList implements M @Override public final void load(String mana, boolean extractMonoHybridGenericValue) { this.clear(); - if (!extractMonoHybridGenericValue && mana != null && costsCache.containsKey(mana)) { + if (mana == null || mana.isEmpty()) { + return; + } + + if (!extractMonoHybridGenericValue && costsCache.containsKey(mana)) { ManaCosts savedCosts = costsCache.get(mana); for (ManaCost cost : savedCosts) { this.add(cost.copy()); } } else { - if (mana == null || mana.isEmpty()) { - return; - } String[] symbols = mana.split("^\\{|}\\{|}$"); int modifierForX = 0; for (String symbol : symbols) { @@ -463,15 +464,15 @@ public class ManaCostsImpl extends ArrayList implements M } else if (!symbol.equals("X")) { this.add(new ColoredManaCost(ColoredManaSymbol.lookup(symbol.charAt(0)))); } else // check X wasn't added before - if (modifierForX == 0) { - // count X occurence - for (String s : symbols) { - if (s.equals("X")) { - modifierForX++; + if (modifierForX == 0) { + // count X occurence + for (String s : symbols) { + if (s.equals("X")) { + modifierForX++; + } } - } - this.add(new VariableManaCost(modifierForX)); - } //TODO: handle multiple {X} and/or {Y} symbols + this.add(new VariableManaCost(modifierForX)); + } //TODO: handle multiple {X} and/or {Y} symbols } else if (Character.isDigit(symbol.charAt(0))) { MonoHybridManaCost cost; if (extractMonoHybridGenericValue) { @@ -534,14 +535,7 @@ public class ManaCostsImpl extends ArrayList implements M StringBuilder sbText = new StringBuilder(); for (ManaCost cost : this) { - if (cost instanceof GenericManaCost) { - sbText.append(cost.getText()); - } - } - for (ManaCost cost : this) { - if (!(cost instanceof GenericManaCost)) { - sbText.append(cost.getText()); - } + sbText.append(cost.getText()); } return sbText.toString(); } diff --git a/Mage/src/main/java/mage/cards/mock/MockCard.java b/Mage/src/main/java/mage/cards/mock/MockCard.java index 3221ffda4f..cf49ba7705 100644 --- a/Mage/src/main/java/mage/cards/mock/MockCard.java +++ b/Mage/src/main/java/mage/cards/mock/MockCard.java @@ -29,8 +29,10 @@ public class MockCard extends CardImpl { private int startingLoyalty; // mana cost extra info for multiple mana drawing - protected ManaCosts manaCostLeft; - protected ManaCosts manaCostRight; + // warning, don't use ManaCost objects here due too much memory consumptions + protected List manaCostLeftStr; + protected List manaCostRightStr; + protected List manaCostStr; protected String adventureSpellName; protected boolean isModalDoubleFacesCard; @@ -47,9 +49,10 @@ public class MockCard extends CardImpl { this.usesVariousArt = card.usesVariousArt(); - this.manaCostLeft = new ManaCostsImpl(join(card.getManaCosts(CardInfo.ManaCostSide.LEFT))); - this.manaCostRight = new ManaCostsImpl(join(card.getManaCosts(CardInfo.ManaCostSide.RIGHT))); this.manaCost = new ManaCostsImpl(join(card.getManaCosts(CardInfo.ManaCostSide.ALL))); + this.manaCostLeftStr = card.getManaCosts(CardInfo.ManaCostSide.LEFT); + this.manaCostRightStr = card.getManaCosts(CardInfo.ManaCostSide.RIGHT); + this.manaCostStr = card.getManaCosts(CardInfo.ManaCostSide.ALL); this.color = card.getColor(); @@ -112,7 +115,8 @@ public class MockCard extends CardImpl { return manaCost; } - public ManaCosts getManaCost(CardInfo.ManaCostSide manaCostSide) { + /* + private ManaCosts getManaCost(CardInfo.ManaCostSide manaCostSide) { switch (manaCostSide) { case LEFT: return manaCostLeft; @@ -122,6 +126,18 @@ public class MockCard extends CardImpl { case ALL: return manaCost; } + }*/ + + public List getManaCostStr(CardInfo.ManaCostSide manaCostSide) { + switch (manaCostSide) { + case LEFT: + return manaCostLeftStr; + case RIGHT: + return manaCostRightStr; + default: + case ALL: + return manaCostStr; + } } public String getFullName(boolean showSecondName) { diff --git a/Mage/src/main/java/mage/cards/repository/CardInfo.java b/Mage/src/main/java/mage/cards/repository/CardInfo.java index 2c60fcd896..2e6875a87b 100644 --- a/Mage/src/main/java/mage/cards/repository/CardInfo.java +++ b/Mage/src/main/java/mage/cards/repository/CardInfo.java @@ -293,7 +293,7 @@ public class CardInfo { return sb.toString(); } - private List parseList(String list, ManaCostSide manaCostSide) { + public static List parseList(String list, ManaCostSide manaCostSide) { if (list.isEmpty()) { return Collections.emptyList(); } diff --git a/Mage/src/main/java/mage/util/CardUtil.java b/Mage/src/main/java/mage/util/CardUtil.java index 77067d962c..3b73944333 100644 --- a/Mage/src/main/java/mage/util/CardUtil.java +++ b/Mage/src/main/java/mage/util/CardUtil.java @@ -791,6 +791,15 @@ public final class CardUtil { return res; } + public static String concatManaSymbols(String delimeter, String mana1, String mana2) { + String res = mana1; + if (!res.isEmpty() && !mana2.isEmpty() && delimeter != null && !delimeter.isEmpty()) { + res += delimeter; + } + res += mana2; + return res; + } + public static ColoredManaSymbol manaTypeToColoredManaSymbol(ManaType manaType) { switch (manaType) { case BLACK: diff --git a/Mage/src/main/java/mage/util/ManaUtil.java b/Mage/src/main/java/mage/util/ManaUtil.java index db6e85b77f..743adde3a7 100644 --- a/Mage/src/main/java/mage/util/ManaUtil.java +++ b/Mage/src/main/java/mage/util/ManaUtil.java @@ -523,7 +523,7 @@ public final class ManaUtil { * @param secondSideCard second side of double faces card * @return */ - public static FilterMana getColorIdentity(ObjectColor cardColor, List cardManaSymbols, List cardRules, Card secondSideCard) { + public static FilterMana getColorIdentity(ObjectColor cardColor, String cardManaSymbols, List cardRules, Card secondSideCard) { // 20210121 // 903.4 // The Commander variant uses color identity to determine what cards can be in a deck with a certain @@ -612,6 +612,11 @@ public final class ManaUtil { return cardManaSymbols.stream().anyMatch(s -> s.contains(needSymbol)); } + private static boolean containsManaSymbol(String cardManaSymbols, String needSymbol) { + // search R in {R/B} + return cardManaSymbols.contains(needSymbol); + } + public static FilterMana getColorIdentity(Card card) { Card secondSide; if (card instanceof SplitCard) { @@ -623,7 +628,7 @@ public final class ManaUtil { } else { secondSide = card.getSecondCardFace(); } - return getColorIdentity(card.getColor(), card.getManaCost().getSymbols(), card.getRules(), secondSide); + return getColorIdentity(card.getColor(), String.join("", card.getManaCost().getSymbols()), card.getRules(), secondSide); } public static int getColorIdentityHash(FilterMana colorIdentity) {