From 27aea04820d2edc39f79ed0e13e8decd5873bacf Mon Sep 17 00:00:00 2001 From: igoudt Date: Wed, 26 Apr 2017 09:29:38 +0200 Subject: [PATCH 1/9] move methods from cardutil to magepermanent, cardview:getColorText now uses ObjectColor.getDescription --- .../org/mage/plugins/card/CardPluginImpl.java | 8 ++++---- .../main/java/mage/cards/MagePermanent.java | 8 ++++++++ .../src/main/java/mage/utils/CardUtil.java | 19 ------------------- .../src/main/java/mage/view/CardView.java | 19 +++---------------- 4 files changed, 15 insertions(+), 39 deletions(-) diff --git a/Mage.Client/src/main/java/org/mage/plugins/card/CardPluginImpl.java b/Mage.Client/src/main/java/org/mage/plugins/card/CardPluginImpl.java index ba7356c073..080772869e 100644 --- a/Mage.Client/src/main/java/org/mage/plugins/card/CardPluginImpl.java +++ b/Mage.Client/src/main/java/org/mage/plugins/card/CardPluginImpl.java @@ -151,7 +151,7 @@ public class CardPluginImpl implements CardPlugin { outerLoop: // for (MagePermanent permanent : permanents) { - if (!CardUtil.isLand(permanent) || CardUtil.isCreature(permanent)) { + if (!permanent.isLand() || permanent.isCreature()) { continue; } @@ -418,11 +418,11 @@ public class CardPluginImpl implements CardPlugin { public boolean isType(MagePermanent card) { switch (this) { case land: - return CardUtil.isLand(card); + return card.isLand(); case creature: - return CardUtil.isCreature(card); + return card.isCreature(); case other: - return !CardUtil.isLand(card) && !CardUtil.isCreature(card); + return !card.isLand() && !card.isCreature(); case attached: return card.getOriginalPermanent().isAttachedToPermanent(); default: diff --git a/Mage.Common/src/main/java/mage/cards/MagePermanent.java b/Mage.Common/src/main/java/mage/cards/MagePermanent.java index acbcd5de07..a8320821b5 100644 --- a/Mage.Common/src/main/java/mage/cards/MagePermanent.java +++ b/Mage.Common/src/main/java/mage/cards/MagePermanent.java @@ -10,4 +10,12 @@ public abstract class MagePermanent extends MageCard { public abstract void update(PermanentView card); public abstract PermanentView getOriginalPermanent(); + public boolean isCreature(){ + return getOriginal().isCreature(); + } + + public boolean isLand(){ + return getOriginal().isLand(); + } + } diff --git a/Mage.Common/src/main/java/mage/utils/CardUtil.java b/Mage.Common/src/main/java/mage/utils/CardUtil.java index da99b4de7f..ccd928f988 100644 --- a/Mage.Common/src/main/java/mage/utils/CardUtil.java +++ b/Mage.Common/src/main/java/mage/utils/CardUtil.java @@ -21,25 +21,6 @@ public final class CardUtil { private static final String regexGreen = ".*\\x7b.{0,2}G.{0,2}\\x7d.*"; private static final String regexWhite = ".*\\x7b.{0,2}W.{0,2}\\x7d.*"; - - - - public static boolean isCreature(MagePermanent card) { - return is(card.getOriginal(), CardType.CREATURE); - } - - public static boolean isPlaneswalker(MagePermanent card) { - return is(card.getOriginal(), CardType.PLANESWALKER); - } - - public static boolean isLand(MagePermanent card) { - return is(card.getOriginal(), CardType.LAND); - } - - public static boolean is(CardView card, CardType type) { - return card.getCardTypes().contains(type); - } - public static int getColorIdentitySortValue(List manaCost, ObjectColor originalColor, List rules) { ObjectColor color = new ObjectColor(originalColor); for (String rule : rules) { diff --git a/Mage.Common/src/main/java/mage/view/CardView.java b/Mage.Common/src/main/java/mage/view/CardView.java index 8b567d89da..f2abab2320 100644 --- a/Mage.Common/src/main/java/mage/view/CardView.java +++ b/Mage.Common/src/main/java/mage/view/CardView.java @@ -28,6 +28,8 @@ package mage.view; import java.util.*; + +import com.sun.xml.internal.ws.util.StringUtils; import mage.MageObject; import mage.ObjectColor; import mage.abilities.Abilities; @@ -963,22 +965,7 @@ public class CardView extends SimpleCardView { } public String getColorText() { - if (getColor().getColorCount() == 0) { - return "Colorless"; - } else if (getColor().getColorCount() > 1) { - return "Gold"; - } else if (getColor().isBlack()) { - return "Black"; - } else if (getColor().isBlue()) { - return "Blue"; - } else if (getColor().isWhite()) { - return "White"; - } else if (getColor().isGreen()) { - return "Green"; - } else if (getColor().isRed()) { - return "Red"; - } - return ""; + return StringUtils.capitalize(getColor().getDescription()); } public String getTypeText() { From 5b21f3494180a1300c0c8407683b2e2c94b162da Mon Sep 17 00:00:00 2001 From: igoudt Date: Wed, 26 Apr 2017 10:12:55 +0200 Subject: [PATCH 2/9] rewrote gettypetext, added removeIf to TableModel --- .../client/deckeditor/table/TableModel.java | 14 +------ .../src/main/java/mage/view/CardView.java | 40 ++++++++----------- 2 files changed, 19 insertions(+), 35 deletions(-) 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 e7d73e423b..cc54162334 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 @@ -181,12 +181,7 @@ public class TableModel extends AbstractTableModel implements ICardGrid { } } } else { - for (CardView cv : view) { - if (cv.getId().equals(entry.getKey())) { - view.remove(cv); - break; - } - } + view.removeIf(cardView -> cardView.getId().equals(entry.getKey())); } } } @@ -296,12 +291,7 @@ public class TableModel extends AbstractTableModel implements ICardGrid { public void removeCard(UUID cardId) { cards.remove(cardId); - for (CardView cv : view) { - if (cv.getId().equals(cardId)) { - view.remove(cv); - break; - } - } + view.removeIf(cardView -> cardView.getId().equals(cardId)); } @Override diff --git a/Mage.Common/src/main/java/mage/view/CardView.java b/Mage.Common/src/main/java/mage/view/CardView.java index f2abab2320..8ef39ea5fc 100644 --- a/Mage.Common/src/main/java/mage/view/CardView.java +++ b/Mage.Common/src/main/java/mage/view/CardView.java @@ -28,6 +28,7 @@ package mage.view; import java.util.*; +import java.util.stream.Collectors; import com.sun.xml.internal.ws.util.StringUtils; import mage.MageObject; @@ -220,8 +221,8 @@ public class CardView extends SimpleCardView { * @param card * @param game * @param controlled is the card view created for the card controller - used - * for morph / face down cards to know which player may see information for - * the card + * for morph / face down cards to know which player may see information for + * the card */ public CardView(Card card, Game game, boolean controlled) { this(card, game, controlled, false, false); @@ -247,12 +248,12 @@ public class CardView extends SimpleCardView { /** * @param card * @param game - * @param controlled is the card view created for the card controller - used - * for morph / face down cards to know which player may see information for - * the card + * @param controlled is the card view created for the card controller - used + * for morph / face down cards to know which player may see information for + * the card * @param showFaceDownCard if true and the card is not on the battlefield, - * also a face down card is shown in the view, face down cards will be shown - * @param storeZone if true the card zone will be set in the zone attribute. + * also a face down card is shown in the view, face down cards will be shown + * @param storeZone if true the card zone will be set in the zone attribute. */ public CardView(Card card, Game game, boolean controlled, boolean showFaceDownCard, boolean storeZone) { super(card.getId(), card.getExpansionSetCode(), card.getCardNumber(), card.getUsesVariousArt(), card.getTokenSetCode(), game != null, card.getTokenDescriptor()); @@ -965,29 +966,22 @@ public class CardView extends SimpleCardView { } public String getColorText() { - return StringUtils.capitalize(getColor().getDescription()); + return StringUtils.capitalize(getColor().getDescription()); } public String getTypeText() { StringBuilder type = new StringBuilder(); - for (SuperType superType : getSuperTypes()) { - type.append(superType.toString()); - type.append(' '); + if (!getSuperTypes().isEmpty()) { + type.append(String.join(" ", getSuperTypes().stream().map(SuperType::toString).collect(Collectors.toList()))); + type.append(" "); } - for (CardType cardType : getCardTypes()) { - type.append(cardType.toString()); - type.append(' '); + if (!getCardTypes().isEmpty()) { + type.append(String.join(" ", getCardTypes().stream().map(CardType::toString).collect(Collectors.toList()))); + type.append(" "); } if (!getSubTypes().isEmpty()) { - type.append("- "); - for (String subType : getSubTypes()) { - type.append(subType); - type.append(' '); - } - } - if (type.length() > 0) { - // remove trailing space - type.deleteCharAt(type.length() - 1); + type.append(" - "); + type.append(String.join(" ", getSubTypes())); } return type.toString(); } From ce26e5c8dda9deda74141ee86f274f7c41167184 Mon Sep 17 00:00:00 2001 From: igoudt Date: Wed, 26 Apr 2017 10:21:24 +0200 Subject: [PATCH 3/9] make the combatmanager an enum --- .../main/java/mage/client/combat/CombatManager.java | 10 ++-------- .../src/main/java/mage/client/game/GamePanel.java | 4 ++-- 2 files changed, 4 insertions(+), 10 deletions(-) diff --git a/Mage.Client/src/main/java/mage/client/combat/CombatManager.java b/Mage.Client/src/main/java/mage/client/combat/CombatManager.java index 695a507133..b9be142a83 100644 --- a/Mage.Client/src/main/java/mage/client/combat/CombatManager.java +++ b/Mage.Client/src/main/java/mage/client/combat/CombatManager.java @@ -19,20 +19,14 @@ import java.util.UUID; /** * @author noxx */ -public class CombatManager { +public enum CombatManager { - private static CombatManager combatManager; + instance; private final Map combatAttackers = new HashMap<>(); private final Map combatBlockers = new HashMap<>(); private int globalBlockersCount; // we need global counter as there are several combat groups - public static CombatManager getInstance() { - if (combatManager == null) { - combatManager = new CombatManager(); - } - return combatManager; - } private Point parentPoint; diff --git a/Mage.Client/src/main/java/mage/client/game/GamePanel.java b/Mage.Client/src/main/java/mage/client/game/GamePanel.java index 2cb9a38765..9b61573a4c 100644 --- a/Mage.Client/src/main/java/mage/client/game/GamePanel.java +++ b/Mage.Client/src/main/java/mage/client/game/GamePanel.java @@ -860,9 +860,9 @@ public final class GamePanel extends javax.swing.JPanel { showRevealed(game); showLookedAt(game); if (!game.getCombat().isEmpty()) { - CombatManager.getInstance().showCombat(game.getCombat(), gameId); + CombatManager.instance.showCombat(game.getCombat(), gameId); } else { - CombatManager.getInstance().hideCombat(gameId); + CombatManager.instance.hideCombat(gameId); } for (PlayerView player : game.getPlayers()) { From 0528555075e61ee1ee989331f4b9ba183edfddaa Mon Sep 17 00:00:00 2001 From: igoudt Date: Wed, 26 Apr 2017 10:23:49 +0200 Subject: [PATCH 4/9] make DefaulActionCallback an enum and remove unused parameter --- .../src/main/java/mage/client/cards/Card.java | 3 +-- .../client/plugins/adapters/MageActionCallback.java | 5 ++--- .../java/mage/client/util/DefaultActionCallback.java | 12 +++--------- 3 files changed, 6 insertions(+), 14 deletions(-) diff --git a/Mage.Client/src/main/java/mage/client/cards/Card.java b/Mage.Client/src/main/java/mage/client/cards/Card.java index 1869334557..09806d887e 100644 --- a/Mage.Client/src/main/java/mage/client/cards/Card.java +++ b/Mage.Client/src/main/java/mage/client/cards/Card.java @@ -68,7 +68,6 @@ import static mage.client.constants.Constants.*; @SuppressWarnings("serial") public class Card extends MagePermanent implements MouseMotionListener, MouseListener, FocusListener, ComponentListener { - protected static final DefaultActionCallback callback = DefaultActionCallback.getInstance(); protected Point p; protected final CardDimensions dimension; @@ -367,7 +366,7 @@ public class Card extends MagePermanent implements MouseMotionListener, MouseLis @Override public void mousePressed(MouseEvent e) { requestFocusInWindow(); - callback.mouseClicked(e, gameId, card); + DefaultActionCallback.instance.mouseClicked(gameId, card); } @Override diff --git a/Mage.Client/src/main/java/mage/client/plugins/adapters/MageActionCallback.java b/Mage.Client/src/main/java/mage/client/plugins/adapters/MageActionCallback.java index baddaf08b1..6bbf237cce 100644 --- a/Mage.Client/src/main/java/mage/client/plugins/adapters/MageActionCallback.java +++ b/Mage.Client/src/main/java/mage/client/plugins/adapters/MageActionCallback.java @@ -67,7 +67,6 @@ public class MageActionCallback implements ActionCallback { private Popup tooltipPopup; private JPopupMenu jPopupMenu; private BigCard bigCard; - protected static final DefaultActionCallback defaultCallback = DefaultActionCallback.getInstance(); private CardView tooltipCard; private TransferData popupData; @@ -236,14 +235,14 @@ public class MageActionCallback implements ActionCallback { this.startedDragging = false; if (maxXOffset < MIN_X_OFFSET_REQUIRED) { // we need this for protection from small card movements transferData.component.requestFocusInWindow(); - defaultCallback.mouseClicked(e, transferData.gameId, transferData.card); + DefaultActionCallback.instance.mouseClicked(transferData.gameId, transferData.card); // Closes popup & enlarged view if a card/Permanent is selected hideTooltipPopup(); } e.consume(); } else { transferData.component.requestFocusInWindow(); - defaultCallback.mouseClicked(e, transferData.gameId, transferData.card); + DefaultActionCallback.instance.mouseClicked(transferData.gameId, transferData.card); // Closes popup & enlarged view if a card/Permanent is selected hideTooltipPopup(); e.consume(); diff --git a/Mage.Client/src/main/java/mage/client/util/DefaultActionCallback.java b/Mage.Client/src/main/java/mage/client/util/DefaultActionCallback.java index 7a678e49be..33fc7f803c 100644 --- a/Mage.Client/src/main/java/mage/client/util/DefaultActionCallback.java +++ b/Mage.Client/src/main/java/mage/client/util/DefaultActionCallback.java @@ -7,17 +7,11 @@ import mage.client.SessionHandler; import mage.view.CardView; -public class DefaultActionCallback { +public enum DefaultActionCallback { - private static final DefaultActionCallback INSTANCE = new DefaultActionCallback(); + instance; - private DefaultActionCallback() {} - - public static DefaultActionCallback getInstance() { - return INSTANCE; - } - - public void mouseClicked(MouseEvent e, UUID gameId, CardView card) { + public void mouseClicked(UUID gameId, CardView card) { if (gameId != null) { if (card.isAbility() && card.getAbility() != null) { SessionHandler.sendPlayerUUID(gameId, card.getAbility().getId()); From 3f47d5a253bc086c420612244b7ad867d9e763e8 Mon Sep 17 00:00:00 2001 From: igoudt Date: Wed, 26 Apr 2017 11:19:52 +0200 Subject: [PATCH 5/9] put inputstream in try body so it can be autoclosed --- .../src/main/java/mage/client/util/ImageHelper.java | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/Mage.Client/src/main/java/mage/client/util/ImageHelper.java b/Mage.Client/src/main/java/mage/client/util/ImageHelper.java index 05eecea9a1..0759447298 100644 --- a/Mage.Client/src/main/java/mage/client/util/ImageHelper.java +++ b/Mage.Client/src/main/java/mage/client/util/ImageHelper.java @@ -140,13 +140,8 @@ public final class ImageHelper { * @return */ public static Image getImageFromResources(String path) { - InputStream stream; - stream = UI.class.getResourceAsStream(path); - if (stream == null) { - throw new IllegalArgumentException("Couldn't find image in resources: " + path); - } - try { + try(InputStream stream = UI.class.getResourceAsStream(path)) { ImageIO.setUseCache(false); BufferedImage image = ImageIO.read(stream); return image; From 05785f71b92d3c5efb898b4e0c4700449670ce2a Mon Sep 17 00:00:00 2001 From: igoudt Date: Wed, 26 Apr 2017 21:00:14 +0200 Subject: [PATCH 6/9] Make the implementations of CardImageSource an enum --- .../dl/sources/AltMtgOnlTokensImageSource.java | 11 ++--------- .../card/dl/sources/GrabbagImageSource.java | 11 ++--------- .../card/dl/sources/MagicCardsImageSource.java | 11 ++--------- .../card/dl/sources/MagidexImageSource.java | 10 ++-------- .../card/dl/sources/MtgImageSource.java | 11 ++--------- .../dl/sources/MtgOnlTokensImageSource.java | 11 ++--------- .../dl/sources/MythicspoilerComSource.java | 18 ++++++------------ .../card/dl/sources/TokensMtgImageSource.java | 11 ++--------- .../dl/sources/WizardCardsImageSource.java | 18 ++++++------------ .../plugins/card/images/DownloadPictures.java | 18 +++++++++--------- .../client/game/TokensMtgImageSourceTest.java | 2 +- 11 files changed, 36 insertions(+), 96 deletions(-) diff --git a/Mage.Client/src/main/java/org/mage/plugins/card/dl/sources/AltMtgOnlTokensImageSource.java b/Mage.Client/src/main/java/org/mage/plugins/card/dl/sources/AltMtgOnlTokensImageSource.java index 55a30c8fb0..517fa64221 100644 --- a/Mage.Client/src/main/java/org/mage/plugins/card/dl/sources/AltMtgOnlTokensImageSource.java +++ b/Mage.Client/src/main/java/org/mage/plugins/card/dl/sources/AltMtgOnlTokensImageSource.java @@ -37,19 +37,12 @@ import java.util.HashMap; * * @author spjspj */ -public class AltMtgOnlTokensImageSource implements CardImageSource { +public enum AltMtgOnlTokensImageSource implements CardImageSource { + instance; private static final Logger logger = Logger.getLogger(AltMtgOnlTokensImageSource.class); - private static CardImageSource instance = new AltMtgOnlTokensImageSource(); private static int maxTimes = 0; - public static CardImageSource getInstance() { - if (instance == null) { - instance = new AltMtgOnlTokensImageSource(); - } - return instance; - } - @Override public String getSourceName() { return "http://alternative.mtg.onl/tokens/"; diff --git a/Mage.Client/src/main/java/org/mage/plugins/card/dl/sources/GrabbagImageSource.java b/Mage.Client/src/main/java/org/mage/plugins/card/dl/sources/GrabbagImageSource.java index e7750f0801..f0b6aa02d4 100644 --- a/Mage.Client/src/main/java/org/mage/plugins/card/dl/sources/GrabbagImageSource.java +++ b/Mage.Client/src/main/java/org/mage/plugins/card/dl/sources/GrabbagImageSource.java @@ -37,19 +37,12 @@ import org.mage.plugins.card.images.CardDownloadData; * * @author spjspj */ -public class GrabbagImageSource implements CardImageSource { +public enum GrabbagImageSource implements CardImageSource { + instance; private static final Logger logger = Logger.getLogger(GrabbagImageSource.class); - private static CardImageSource instance = new GrabbagImageSource(); private static int maxTimes = 0; - public static CardImageSource getInstance() { - if (instance == null) { - instance = new GrabbagImageSource(); - } - return instance; - } - @Override public String getSourceName() { return ""; diff --git a/Mage.Client/src/main/java/org/mage/plugins/card/dl/sources/MagicCardsImageSource.java b/Mage.Client/src/main/java/org/mage/plugins/card/dl/sources/MagicCardsImageSource.java index 1dbab36890..fc51c866b9 100644 --- a/Mage.Client/src/main/java/org/mage/plugins/card/dl/sources/MagicCardsImageSource.java +++ b/Mage.Client/src/main/java/org/mage/plugins/card/dl/sources/MagicCardsImageSource.java @@ -10,10 +10,9 @@ import org.mage.plugins.card.utils.CardImageUtils; * * @author North */ -public class MagicCardsImageSource implements CardImageSource { - - private static CardImageSource instance = new MagicCardsImageSource(); +public enum MagicCardsImageSource implements CardImageSource { + instance; private static final Map setNameTokenReplacement = new HashMap() { { put("10E", "tenth-edition"); @@ -146,12 +145,6 @@ public class MagicCardsImageSource implements CardImageSource { return "magiccards.info"; } - public static CardImageSource getInstance() { - if (instance == null) { - instance = new MagicCardsImageSource(); - } - return instance; - } @Override public String getNextHttpImageUrl() { diff --git a/Mage.Client/src/main/java/org/mage/plugins/card/dl/sources/MagidexImageSource.java b/Mage.Client/src/main/java/org/mage/plugins/card/dl/sources/MagidexImageSource.java index 2c36c20333..2c0ab80e75 100644 --- a/Mage.Client/src/main/java/org/mage/plugins/card/dl/sources/MagidexImageSource.java +++ b/Mage.Client/src/main/java/org/mage/plugins/card/dl/sources/MagidexImageSource.java @@ -36,15 +36,9 @@ import java.net.URI; * @author Pete Rossi */ -public class MagidexImageSource implements CardImageSource { - private static CardImageSource instance = new MagidexImageSource(); +public enum MagidexImageSource implements CardImageSource { + instance; - public static CardImageSource getInstance() { - if (instance == null) { - instance = new MagidexImageSource(); - } - return instance; - } @Override public String getSourceName() { return "magidex.com"; diff --git a/Mage.Client/src/main/java/org/mage/plugins/card/dl/sources/MtgImageSource.java b/Mage.Client/src/main/java/org/mage/plugins/card/dl/sources/MtgImageSource.java index 6473257293..e8e811e34f 100644 --- a/Mage.Client/src/main/java/org/mage/plugins/card/dl/sources/MtgImageSource.java +++ b/Mage.Client/src/main/java/org/mage/plugins/card/dl/sources/MtgImageSource.java @@ -39,16 +39,9 @@ import org.mage.plugins.card.images.CardDownloadData; * @author LevelX2 */ -public class MtgImageSource implements CardImageSource { +public enum MtgImageSource implements CardImageSource { - private static CardImageSource instance = new MtgImageSource(); - - public static CardImageSource getInstance() { - if (instance == null) { - instance = new MtgImageSource(); - } - return instance; - } + instance; @Override public String getSourceName() { diff --git a/Mage.Client/src/main/java/org/mage/plugins/card/dl/sources/MtgOnlTokensImageSource.java b/Mage.Client/src/main/java/org/mage/plugins/card/dl/sources/MtgOnlTokensImageSource.java index 16b01a508e..56f42fac5a 100644 --- a/Mage.Client/src/main/java/org/mage/plugins/card/dl/sources/MtgOnlTokensImageSource.java +++ b/Mage.Client/src/main/java/org/mage/plugins/card/dl/sources/MtgOnlTokensImageSource.java @@ -37,19 +37,12 @@ import java.util.HashMap; * * @author spjspj */ -public class MtgOnlTokensImageSource implements CardImageSource { +public enum MtgOnlTokensImageSource implements CardImageSource { + instance; private static final Logger logger = Logger.getLogger(MtgOnlTokensImageSource.class); - private static CardImageSource instance = new MtgOnlTokensImageSource(); private static int maxTimes = 0; - public static CardImageSource getInstance() { - if (instance == null) { - instance = new MtgOnlTokensImageSource(); - } - return instance; - } - @Override public String getSourceName() { return "http://mtg.onl/token-list/tokens/"; diff --git a/Mage.Client/src/main/java/org/mage/plugins/card/dl/sources/MythicspoilerComSource.java b/Mage.Client/src/main/java/org/mage/plugins/card/dl/sources/MythicspoilerComSource.java index 47661ee8d4..6f6d8cce20 100644 --- a/Mage.Client/src/main/java/org/mage/plugins/card/dl/sources/MythicspoilerComSource.java +++ b/Mage.Client/src/main/java/org/mage/plugins/card/dl/sources/MythicspoilerComSource.java @@ -54,27 +54,21 @@ import org.mage.plugins.card.images.CardDownloadData; * * @author LevelX2 */ -public class MythicspoilerComSource implements CardImageSource { +public enum MythicspoilerComSource implements CardImageSource { - private static CardImageSource instance; - private static Map setsAliases; - private static Map cardNameAliases; - private static Map> cardNameAliasesStart; + instance; + private Map setsAliases; + private Map cardNameAliases; + private Map> cardNameAliasesStart; private final Map> sets; - public static CardImageSource getInstance() { - if (instance == null) { - instance = new MythicspoilerComSource(); - } - return instance; - } @Override public String getSourceName() { return "mythicspoiler.com"; } - public MythicspoilerComSource() { + MythicspoilerComSource() { sets = new LinkedHashMap<>(); setsAliases = new HashMap<>(); setsAliases.put("exp", "bfz"); diff --git a/Mage.Client/src/main/java/org/mage/plugins/card/dl/sources/TokensMtgImageSource.java b/Mage.Client/src/main/java/org/mage/plugins/card/dl/sources/TokensMtgImageSource.java index 25ee59c06a..2f58b13a2c 100644 --- a/Mage.Client/src/main/java/org/mage/plugins/card/dl/sources/TokensMtgImageSource.java +++ b/Mage.Client/src/main/java/org/mage/plugins/card/dl/sources/TokensMtgImageSource.java @@ -44,23 +44,16 @@ import java.util.Map; * * @author Quercitron */ -public class TokensMtgImageSource implements CardImageSource { +public enum TokensMtgImageSource implements CardImageSource { + instance; private static final Logger logger = Logger.getLogger(TokensMtgImageSource.class); - private static CardImageSource instance = new TokensMtgImageSource(); private List tokensData; private final Object tokensDataSync = new Object(); - public static CardImageSource getInstance() { - if (instance == null) { - instance = new TokensMtgImageSource(); - } - return instance; - } - @Override public String getSourceName() { return "tokens.mtg.onl"; diff --git a/Mage.Client/src/main/java/org/mage/plugins/card/dl/sources/WizardCardsImageSource.java b/Mage.Client/src/main/java/org/mage/plugins/card/dl/sources/WizardCardsImageSource.java index d75337f6bb..b9f13e5f23 100644 --- a/Mage.Client/src/main/java/org/mage/plugins/card/dl/sources/WizardCardsImageSource.java +++ b/Mage.Client/src/main/java/org/mage/plugins/card/dl/sources/WizardCardsImageSource.java @@ -42,6 +42,7 @@ import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; import java.util.concurrent.TimeUnit; import java.util.prefs.Preferences; + import mage.client.MageFrame; import mage.client.dialog.PreferencesDialog; import mage.remote.Connection; @@ -53,29 +54,22 @@ import org.jsoup.select.Elements; import org.mage.plugins.card.images.CardDownloadData; /** - * * @author North */ -public class WizardCardsImageSource implements CardImageSource { +public enum WizardCardsImageSource implements CardImageSource { - private static CardImageSource instance; - private static Map setsAliases; - private static Map languageAliases; + instance; + private Map setsAliases; + private Map languageAliases; private final Map> sets; - public static CardImageSource getInstance() { - if (instance == null) { - instance = new WizardCardsImageSource(); - } - return instance; - } @Override public String getSourceName() { return "WOTC Gatherer"; } - public WizardCardsImageSource() { + WizardCardsImageSource() { sets = new HashMap<>(); setsAliases = new HashMap<>(); setsAliases.put("2ED", "Unlimited Edition"); diff --git a/Mage.Client/src/main/java/org/mage/plugins/card/images/DownloadPictures.java b/Mage.Client/src/main/java/org/mage/plugins/card/images/DownloadPictures.java index e93a4f881d..b99308f3d0 100644 --- a/Mage.Client/src/main/java/org/mage/plugins/card/images/DownloadPictures.java +++ b/Mage.Client/src/main/java/org/mage/plugins/card/images/DownloadPictures.java @@ -117,7 +117,7 @@ public class DownloadPictures extends DefaultBoundedRangeModel implements Runnab }); jComboBox1 = new JComboBox(); - cardImageSource = MagicCardsImageSource.getInstance(); + cardImageSource = MagicCardsImageSource.instance; jComboBox1.setModel(jComboBox1Model); jComboBox1.setAlignmentX(Component.LEFT_ALIGNMENT); @@ -125,28 +125,28 @@ public class DownloadPictures extends DefaultBoundedRangeModel implements Runnab JComboBox cb = (JComboBox) e.getSource(); switch (cb.getSelectedIndex()) { case 0: - cardImageSource = MagicCardsImageSource.getInstance(); + cardImageSource = MagicCardsImageSource.instance; break; case 1: - cardImageSource = WizardCardsImageSource.getInstance(); + cardImageSource = WizardCardsImageSource.instance; break; case 2: - cardImageSource = MythicspoilerComSource.getInstance(); + cardImageSource = MythicspoilerComSource.instance; break; case 3: - cardImageSource = TokensMtgImageSource.getInstance(); + cardImageSource = TokensMtgImageSource.instance; break; case 4: - cardImageSource = MtgOnlTokensImageSource.getInstance(); + cardImageSource = MtgOnlTokensImageSource.instance; break; case 5: - cardImageSource = AltMtgOnlTokensImageSource.getInstance(); + cardImageSource = AltMtgOnlTokensImageSource.instance; break; case 6: - cardImageSource = GrabbagImageSource.getInstance(); + cardImageSource = GrabbagImageSource.instance; break; case 7: - cardImageSource = MagidexImageSource.getInstance(); + cardImageSource = MagidexImageSource.instance; break; } updateCardsToDownload(); diff --git a/Mage.Client/src/test/java/mage/client/game/TokensMtgImageSourceTest.java b/Mage.Client/src/test/java/mage/client/game/TokensMtgImageSourceTest.java index 16599a8379..8e485c801e 100644 --- a/Mage.Client/src/test/java/mage/client/game/TokensMtgImageSourceTest.java +++ b/Mage.Client/src/test/java/mage/client/game/TokensMtgImageSourceTest.java @@ -16,7 +16,7 @@ public class TokensMtgImageSourceTest { @Test public void generateTokenUrlTest() throws Exception { - CardImageSource imageSource = TokensMtgImageSource.getInstance(); + CardImageSource imageSource = TokensMtgImageSource.instance; String url = imageSource.generateTokenUrl(new CardDownloadData("Thopter", "ORI", "0", false, 1, "ORI", "")); Assert.assertEquals("http://tokens.mtg.onl/tokens/ORI_010-Thopter.jpg", url); From 7a4a0b9faa0f175d065d5759e48287a06ed5f6b9 Mon Sep 17 00:00:00 2001 From: igoudt Date: Wed, 26 Apr 2017 21:01:27 +0200 Subject: [PATCH 7/9] move removeVariableManaCost from CardUtil to ManaCosts interface --- .../java/mage/abilities/costs/mana/ManaCosts.java | 12 ++++++++++++ Mage/src/main/java/mage/util/CardUtil.java | 10 +--------- 2 files changed, 13 insertions(+), 9 deletions(-) diff --git a/Mage/src/main/java/mage/abilities/costs/mana/ManaCosts.java b/Mage/src/main/java/mage/abilities/costs/mana/ManaCosts.java index 2fe86c5345..4a129a6cc1 100644 --- a/Mage/src/main/java/mage/abilities/costs/mana/ManaCosts.java +++ b/Mage/src/main/java/mage/abilities/costs/mana/ManaCosts.java @@ -61,4 +61,16 @@ public interface ManaCosts extends List, ManaCost { @Override ManaCosts copy(); + + static ManaCosts removeVariableManaCost(ManaCosts m) { + ManaCosts manaCosts = new ManaCostsImpl<>(); + for(ManaCost manaCost : m){ + if(!(manaCost instanceof VariableManaCost)){ + manaCosts.add(manaCost); + + } + } + return manaCosts; + } + } diff --git a/Mage/src/main/java/mage/util/CardUtil.java b/Mage/src/main/java/mage/util/CardUtil.java index 2a89380ec7..7298f274c6 100644 --- a/Mage/src/main/java/mage/util/CardUtil.java +++ b/Mage/src/main/java/mage/util/CardUtil.java @@ -163,15 +163,7 @@ public final class CardUtil { return adjustedCost; } - public static ManaCosts removeVariableManaCost(ManaCosts manaCosts) { - ManaCosts adjustedCost = new ManaCostsImpl<>(); - for (ManaCost manaCost : manaCosts) { - if (!(manaCost instanceof VariableManaCost)) { - adjustedCost.add(manaCost); - } - } - return adjustedCost; - } + public static void reduceCost(SpellAbility spellAbility, ManaCosts manaCostsToReduce) { adjustCost(spellAbility, manaCostsToReduce, true); From 8a809761712113762ceb85b055adf84ab58cda74 Mon Sep 17 00:00:00 2001 From: igoudt Date: Wed, 26 Apr 2017 21:02:21 +0200 Subject: [PATCH 8/9] have Flash and Tariff use the moved removeVariableManaCost method --- Mage.Sets/src/mage/cards/f/Flash.java | 2 +- Mage.Sets/src/mage/cards/t/Tariff.java | 4 +++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/Mage.Sets/src/mage/cards/f/Flash.java b/Mage.Sets/src/mage/cards/f/Flash.java index 2fd40a12b1..f7a1fcb359 100644 --- a/Mage.Sets/src/mage/cards/f/Flash.java +++ b/Mage.Sets/src/mage/cards/f/Flash.java @@ -101,7 +101,7 @@ class FlashEffect extends OneShotEffect { if (card != null) { card.putOntoBattlefield(game, Zone.HAND, source.getSourceId(), source.getControllerId()); - ManaCosts reducedCost = CardUtil.removeVariableManaCost(CardUtil.reduceCost(card.getManaCost(), 2)); + ManaCosts reducedCost = ManaCosts.removeVariableManaCost(CardUtil.reduceCost(card.getManaCost(), 2)); StringBuilder sb = new StringBuilder("Pay ").append(reducedCost.getText()).append('?'); if (player.chooseUse(Outcome.Benefit, sb.toString(), source, game)) { reducedCost.clearPaid(); diff --git a/Mage.Sets/src/mage/cards/t/Tariff.java b/Mage.Sets/src/mage/cards/t/Tariff.java index a11d11ec6b..df12602769 100644 --- a/Mage.Sets/src/mage/cards/t/Tariff.java +++ b/Mage.Sets/src/mage/cards/t/Tariff.java @@ -33,6 +33,8 @@ import java.util.UUID; import mage.MageObject; import mage.abilities.Ability; import mage.abilities.costs.mana.ManaCost; +import mage.abilities.costs.mana.ManaCostImpl; +import mage.abilities.costs.mana.ManaCosts; import mage.abilities.effects.OneShotEffect; import mage.cards.CardImpl; import mage.cards.CardSetInfo; @@ -113,7 +115,7 @@ class TariffEffect extends OneShotEffect { Permanent creatureToPayFor = chooseOnePermanent(game, player, creatures); if (creatureToPayFor != null) { - ManaCost manaCost = CardUtil.removeVariableManaCost(creatureToPayFor.getManaCost()); + ManaCosts manaCost = ManaCosts.removeVariableManaCost(creatureToPayFor.getManaCost()); String message = new StringBuilder("Pay ").append(manaCost.getText()).append(" (otherwise sacrifice ") .append(creatureToPayFor.getName()).append(")?").toString(); if (player.chooseUse(Outcome.Benefit, message, source, game)) { From 2c34870bf06500126aa1eda6f3f9f7cf2ae2f89b Mon Sep 17 00:00:00 2001 From: igoudt Date: Thu, 27 Apr 2017 10:54:03 +0200 Subject: [PATCH 9/9] remove util function on converted manacost, make getColorIdentity default interface method --- .../src/mage/deck/Commander.java | 6 +- .../src/mage/deck/TinyLeaders.java | 4 +- .../src/mage/cards/c/Counterbalance.java | 2 +- .../src/mage/cards/h/HisokaMinamoSensei.java | 2 +- .../commander/CommanderColorIdentityTest.java | 2 +- .../CommanderColorIdentityManaAbility.java | 4 +- Mage/src/main/java/mage/cards/Card.java | 71 +++++++++ Mage/src/main/java/mage/util/CardUtil.java | 140 +++--------------- 8 files changed, 105 insertions(+), 126 deletions(-) diff --git a/Mage.Server.Plugins/Mage.Deck.Constructed/src/mage/deck/Commander.java b/Mage.Server.Plugins/Mage.Deck.Constructed/src/mage/deck/Commander.java index 5d3bf90c67..1854a9ff3e 100644 --- a/Mage.Server.Plugins/Mage.Deck.Constructed/src/mage/deck/Commander.java +++ b/Mage.Server.Plugins/Mage.Deck.Constructed/src/mage/deck/Commander.java @@ -150,7 +150,7 @@ public class Commander extends Constructed { invalid.put("Commander", "Commander without Partner (" + commander.getName() + ')'); valid = false; } - FilterMana commanderColor = CardUtil.getColorIdentity(commander); + FilterMana commanderColor = commander.getColorIdentity(); if (commanderColor.isWhite()) { colorIdentity.setWhite(true); } @@ -194,7 +194,7 @@ public class Commander extends Constructed { } public boolean cardHasValidColor(FilterMana commander, Card card) { - FilterMana cardColor = CardUtil.getColorIdentity(card); + FilterMana cardColor = card.getColorIdentity(); return !(cardColor.isBlack() && !commander.isBlack() || cardColor.isBlue() && !commander.isBlue() || cardColor.isGreen() && !commander.isGreen() @@ -654,7 +654,7 @@ public class Commander extends Constructed { color = color.union(commander.getColor(null)); } - FilterMana commanderColor = CardUtil.getColorIdentity(commander); + FilterMana commanderColor = commander.getColorIdentity(); if (commanderColor.isWhite()) { color.setWhite(true); } diff --git a/Mage.Server.Plugins/Mage.Deck.Constructed/src/mage/deck/TinyLeaders.java b/Mage.Server.Plugins/Mage.Deck.Constructed/src/mage/deck/TinyLeaders.java index 6fb852e129..11a170899a 100644 --- a/Mage.Server.Plugins/Mage.Deck.Constructed/src/mage/deck/TinyLeaders.java +++ b/Mage.Server.Plugins/Mage.Deck.Constructed/src/mage/deck/TinyLeaders.java @@ -177,7 +177,7 @@ public class TinyLeaders extends Constructed { if ((commander.isCreature() && commander.isLegendary()) || (commander.isPlaneswalker() && commander.getAbilities().contains(CanBeYourCommanderAbility.getInstance()))) { if (!bannedCommander.contains(commander.getName())) { - FilterMana color = CardUtil.getColorIdentity(commander); + FilterMana color = commander.getColorIdentity(); for (Card card : deck.getCards()) { if (!isCardFormatValid(card, commander, color)) { valid = false; @@ -249,7 +249,7 @@ public class TinyLeaders extends Constructed { * @return True if card has a valid color identity */ public boolean cardHasValideColor(FilterMana commander, Card card) { - FilterMana cardColor = CardUtil.getColorIdentity(card); + FilterMana cardColor = card.getColorIdentity(); return !(cardColor.isBlack() && !commander.isBlack() || cardColor.isBlue() && !commander.isBlue() || cardColor.isGreen() && !commander.isGreen() diff --git a/Mage.Sets/src/mage/cards/c/Counterbalance.java b/Mage.Sets/src/mage/cards/c/Counterbalance.java index 920c06f7b2..7149248f74 100644 --- a/Mage.Sets/src/mage/cards/c/Counterbalance.java +++ b/Mage.Sets/src/mage/cards/c/Counterbalance.java @@ -99,7 +99,7 @@ class CounterbalanceEffect extends OneShotEffect { CardsImpl cards = new CardsImpl(); cards.add(topcard); controller.revealCards(sourcePermanent.getName(), cards, game); - if (CardUtil.convertedManaCostsIsEqual(topcard, spell)) { + if (topcard.getConvertedManaCost() == spell.getConvertedManaCost()) { return game.getStack().counter(spell.getId(), source.getSourceId(), game); } } diff --git a/Mage.Sets/src/mage/cards/h/HisokaMinamoSensei.java b/Mage.Sets/src/mage/cards/h/HisokaMinamoSensei.java index af67d55df0..bd37ebd2f8 100644 --- a/Mage.Sets/src/mage/cards/h/HisokaMinamoSensei.java +++ b/Mage.Sets/src/mage/cards/h/HisokaMinamoSensei.java @@ -145,7 +145,7 @@ class HisokaMinamoSenseiCounterEffect extends OneShotEffect { Spell spell = game.getStack().getSpell(targetPointer.getFirst(game, source)); if (spell != null) { HisokaMinamoSenseiDiscardTargetCost cost = (HisokaMinamoSenseiDiscardTargetCost) source.getCosts().get(0); - if (cost != null && CardUtil.convertedManaCostsIsEqual(cost.getDiscardedCard(), spell)) { + if (cost != null && cost.getDiscardedCard().getConvertedManaCost() == spell.getConvertedManaCost()) { return game.getStack().counter(targetPointer.getFirst(game, source), source.getSourceId(), game); } } diff --git a/Mage.Tests/src/test/java/org/mage/test/commander/CommanderColorIdentityTest.java b/Mage.Tests/src/test/java/org/mage/test/commander/CommanderColorIdentityTest.java index 346839bac5..f6d0fc77bf 100644 --- a/Mage.Tests/src/test/java/org/mage/test/commander/CommanderColorIdentityTest.java +++ b/Mage.Tests/src/test/java/org/mage/test/commander/CommanderColorIdentityTest.java @@ -96,7 +96,7 @@ public class CommanderColorIdentityTest extends CardTestCommander3PlayersFFA { throw new IllegalArgumentException("Couldn't find the card " + cardName + " in the DB."); } Card card = cardInfo.getCard(); - FilterMana filterMana = CardUtil.getColorIdentity(card); + FilterMana filterMana = card.getColorIdentity(); return filterMana.toString(); } } diff --git a/Mage/src/main/java/mage/abilities/mana/CommanderColorIdentityManaAbility.java b/Mage/src/main/java/mage/abilities/mana/CommanderColorIdentityManaAbility.java index 8e2a7c2330..3f0a768997 100644 --- a/Mage/src/main/java/mage/abilities/mana/CommanderColorIdentityManaAbility.java +++ b/Mage/src/main/java/mage/abilities/mana/CommanderColorIdentityManaAbility.java @@ -75,7 +75,7 @@ public class CommanderColorIdentityManaAbility extends ActivatedManaAbilityImpl for (UUID commanderId : controller.getCommandersIds()) { Card commander = game.getCard(commanderId); if (commander != null) { - FilterMana commanderMana = CardUtil.getColorIdentity(commander); + FilterMana commanderMana = commander.getColorIdentity(); if (commanderMana.isBlack()) { netMana.add(new Mana(ColoredManaSymbol.B)); } @@ -130,7 +130,7 @@ class CommanderIdentityManaEffect extends ManaEffect { for (UUID commanderId : controller.getCommandersIds()) { Card commander = game.getCard(commanderId); if (commander != null) { - FilterMana commanderMana = CardUtil.getColorIdentity(commander); + FilterMana commanderMana = commander.getColorIdentity(); if (commanderMana.isWhite()) { choice.getChoices().add("White"); } diff --git a/Mage/src/main/java/mage/cards/Card.java b/Mage/src/main/java/mage/cards/Card.java index 49e41a9b21..8e7debf751 100644 --- a/Mage/src/main/java/mage/cards/Card.java +++ b/Mage/src/main/java/mage/cards/Card.java @@ -32,6 +32,7 @@ import java.util.List; import java.util.UUID; import mage.MageObject; import mage.Mana; +import mage.ObjectColor; import mage.abilities.Abilities; import mage.abilities.Ability; import mage.abilities.SpellAbility; @@ -40,12 +41,21 @@ import mage.constants.Rarity; import mage.constants.Zone; import mage.counters.Counter; import mage.counters.Counters; +import mage.filter.FilterMana; import mage.game.Game; import mage.game.GameState; import mage.game.permanent.Permanent; public interface Card extends MageObject { + + final String regexBlack = ".*\\x7b.{0,2}B.{0,2}\\x7d.*"; + final String regexBlue = ".*\\x7b.{0,2}U.{0,2}\\x7d.*"; + final String regexRed = ".*\\x7b.{0,2}R.{0,2}\\x7d.*"; + final String regexGreen = ".*\\x7b.{0,2}G.{0,2}\\x7d.*"; + final String regexWhite = ".*\\x7b.{0,2}W.{0,2}\\x7d.*"; + + UUID getOwnerId(); String getCardNumber(); @@ -176,6 +186,67 @@ public interface Card extends MageObject { */ Card getMainCard(); + /** + * Gets the colors that are in the casting cost but also in the rules text + * as far as not included in reminder text. + * + * @return + */ + default FilterMana getColorIdentity() { + FilterMana mana = new FilterMana(); + mana.setBlack(getManaCost().getText().matches(regexBlack)); + mana.setBlue(getManaCost().getText().matches(regexBlue)); + mana.setGreen(getManaCost().getText().matches(regexGreen)); + mana.setRed(getManaCost().getText().matches(regexRed)); + mana.setWhite(getManaCost().getText().matches(regexWhite)); + for (String rule : getRules()) { + rule = rule.replaceAll("(?i)", ""); // Ignoring reminder text in italic + if (!mana.isBlack() && rule.matches(regexBlack)) { + mana.setBlack(true); + } + if (!mana.isBlue() && rule.matches(regexBlue)) { + mana.setBlue(true); + } + if (!mana.isGreen() && rule.matches(regexGreen)) { + mana.setGreen(true); + } + if (!mana.isRed() && rule.matches(regexRed)) { + mana.setRed(true); + } + if (!mana.isWhite() && rule.matches(regexWhite)) { + mana.setWhite(true); + } + } + if (isTransformable()) { + Card secondCard = getSecondCardFace(); + ObjectColor color = secondCard.getColor(null); + mana.setBlack(mana.isBlack() || color.isBlack()); + mana.setGreen(mana.isGreen() || color.isGreen()); + mana.setRed(mana.isRed() || color.isRed()); + mana.setBlue(mana.isBlue() || color.isBlue()); + mana.setWhite(mana.isWhite() || color.isWhite()); + for (String rule : secondCard.getRules()) { + rule = rule.replaceAll("(?i)", ""); // Ignoring reminder text in italic + if (!mana.isBlack() && rule.matches(regexBlack)) { + mana.setBlack(true); + } + if (!mana.isBlue() && rule.matches(regexBlue)) { + mana.setBlue(true); + } + if (!mana.isGreen() && rule.matches(regexGreen)) { + mana.setGreen(true); + } + if (!mana.isRed() && rule.matches(regexRed)) { + mana.setRed(true); + } + if (!mana.isWhite() && rule.matches(regexWhite)) { + mana.setWhite(true); + } + } + } + + return mana; + } } diff --git a/Mage/src/main/java/mage/util/CardUtil.java b/Mage/src/main/java/mage/util/CardUtil.java index 7298f274c6..676967c654 100644 --- a/Mage/src/main/java/mage/util/CardUtil.java +++ b/Mage/src/main/java/mage/util/CardUtil.java @@ -31,6 +31,7 @@ import java.util.Arrays; import java.util.HashSet; import java.util.Set; import java.util.UUID; + import mage.MageObject; import mage.Mana; import mage.ObjectColor; @@ -52,38 +53,30 @@ import mage.util.functions.CopyTokenFunction; */ public final class CardUtil { - private static final String regexBlack = ".*\\x7b.{0,2}B.{0,2}\\x7d.*"; - private static final String regexBlue = ".*\\x7b.{0,2}U.{0,2}\\x7d.*"; - private static final String regexRed = ".*\\x7b.{0,2}R.{0,2}\\x7d.*"; - private static final String regexGreen = ".*\\x7b.{0,2}G.{0,2}\\x7d.*"; - private static final String regexWhite = ".*\\x7b.{0,2}W.{0,2}\\x7d.*"; private static final String SOURCE_EXILE_ZONE_TEXT = "SourceExileZone"; static final String[] numberStrings = {"zero", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine", - "ten", "eleven", "twelve", "thirteen", "fourteen", "fifteen", "sixteen", "seventeen", "eighteen", "ninteen", "twenty"}; + "ten", "eleven", "twelve", "thirteen", "fourteen", "fifteen", "sixteen", "seventeen", "eighteen", "ninteen", "twenty"}; public static final String[] NON_CHANGELING_SUBTYPES_VALUES = new String[]{ - // basic lands subtypes - "Mountain", "Forest", "Plains", "Swamp", "Island", - // Enchantment subtypes - "Aura", "Curse", "Shrine", - // Artifact subtypes - "Clue", "Equipment", "Fortification", "Contraption", "Vehicle", - // Land subtypes - "Desert", "Gate", "Lair", "Locus", "Urza's", "Mine", "Power-Plant", "Tower", - // Planeswalker subtypes - "Ajani", "Arlinn", "Ashiok", "Bolas", "Chandra", "Dack", "Daretti", "Domri", "Dovin", "Elspeth", "Freyalise", "Garruk", "Gideon", "Jace", - "Karn", "Kiora", "Koth", "Liliana", "Nahiri", "Nissa", "Narset", "Nixilis", "Ral", "Saheeli", "Sarkhan", "Sorin", "Tamiyo", "Teferi", - "Tezzeret", "Tibalt", "Ugin", "Venser", "Vraska", "Xenagos", - // Instant sorcery subtypes - "Trap", "Arcane"}; + // basic lands subtypes + "Mountain", "Forest", "Plains", "Swamp", "Island", + // Enchantment subtypes + "Aura", "Curse", "Shrine", + // Artifact subtypes + "Clue", "Equipment", "Fortification", "Contraption", "Vehicle", + // Land subtypes + "Desert", "Gate", "Lair", "Locus", "Urza's", "Mine", "Power-Plant", "Tower", + // Planeswalker subtypes + "Ajani", "Arlinn", "Ashiok", "Bolas", "Chandra", "Dack", "Daretti", "Domri", "Dovin", "Elspeth", "Freyalise", "Garruk", "Gideon", "Jace", + "Karn", "Kiora", "Koth", "Liliana", "Nahiri", "Nissa", "Narset", "Nixilis", "Ral", "Saheeli", "Sarkhan", "Sorin", "Tamiyo", "Teferi", + "Tezzeret", "Tibalt", "Ugin", "Venser", "Vraska", "Xenagos", + // Instant sorcery subtypes + "Trap", "Arcane"}; public static final Set NON_CREATURE_SUBTYPES = new HashSet<>(Arrays.asList(NON_CHANGELING_SUBTYPES_VALUES)); - - - /** * Increase spell or ability cost to be paid. * @@ -164,7 +157,6 @@ public final class CardUtil { } - public static void reduceCost(SpellAbility spellAbility, ManaCosts manaCostsToReduce) { adjustCost(spellAbility, manaCostsToReduce, true); } @@ -185,8 +177,8 @@ public final class CardUtil { * * @param spellAbility * @param manaCostsToReduce costs to reduce - * @param convertToGeneric colored mana does reduce generic mana if no - * appropriate colored mana is in the costs included + * @param convertToGeneric colored mana does reduce generic mana if no + * appropriate colored mana is in the costs included */ public static void adjustCost(SpellAbility spellAbility, ManaCosts manaCostsToReduce, boolean convertToGeneric) { ManaCosts previousCost = spellAbility.getManaCostsToPay(); @@ -276,8 +268,8 @@ public final class CardUtil { } } - if(mana.getColorless() > 0 && reduceMana.getColorless() > 0) { - if(reduceMana.getColorless() > mana.getColorless()) { + if (mana.getColorless() > 0 && reduceMana.getColorless() > 0) { + if (reduceMana.getColorless() > mana.getColorless()) { reduceMana.setColorless(reduceMana.getColorless() - mana.getColorless()); mana.setColorless(0); } else { @@ -371,7 +363,7 @@ public final class CardUtil { * * @param number number to convert to text * @param forOne if the number is 1, this string will be returnedinstead of - * "one". + * "one". * @return */ public static String numberToText(int number, String forOne) { @@ -416,7 +408,7 @@ public final class CardUtil { /** * Creates and saves a (card + zoneChangeCounter) specific exileId. * - * @param game the current game + * @param game the current game * @param source source ability * @return the specific UUID */ @@ -451,9 +443,9 @@ public final class CardUtil { * be specific to a permanent instance. So they won't match, if a permanent * was e.g. exiled and came back immediately. * - * @param text short value to describe the value + * @param text short value to describe the value * @param cardId id of the card - * @param game the game + * @param game the game * @return */ public static String getCardZoneString(String text, UUID cardId, Game game) { @@ -513,91 +505,7 @@ public final class CardUtil { return "" + text + ""; } - public static boolean convertedManaCostsIsEqual(MageObject object1, MageObject object2) { - Set cmcObject1 = getCMC(object1); - Set cmcObject2 = getCMC(object2); - for (Integer integer : cmcObject1) { - if (cmcObject2.contains(integer)) { - return true; - } - } - return false; - } - public static Set getCMC(MageObject object) { - Set cmcObject = new HashSet<>(); - if (object instanceof Spell) { - cmcObject.add(object.getConvertedManaCost()); - } else if (object instanceof Card) { - Card card = (Card) object; - cmcObject.add(card.getConvertedManaCost()); - } - return cmcObject; - } - - /** - * Gets the colors that are in the casting cost but also in the rules text - * as far as not included in reminder text. - * - * @param card - * @return - */ - public static FilterMana getColorIdentity(Card card) { - FilterMana mana = new FilterMana(); - mana.setBlack(card.getManaCost().getText().matches(regexBlack)); - mana.setBlue(card.getManaCost().getText().matches(regexBlue)); - mana.setGreen(card.getManaCost().getText().matches(regexGreen)); - mana.setRed(card.getManaCost().getText().matches(regexRed)); - mana.setWhite(card.getManaCost().getText().matches(regexWhite)); - - for (String rule : card.getRules()) { - rule = rule.replaceAll("(?i)", ""); // Ignoring reminder text in italic - if (!mana.isBlack() && rule.matches(regexBlack)) { - mana.setBlack(true); - } - if (!mana.isBlue() && rule.matches(regexBlue)) { - mana.setBlue(true); - } - if (!mana.isGreen() && rule.matches(regexGreen)) { - mana.setGreen(true); - } - if (!mana.isRed() && rule.matches(regexRed)) { - mana.setRed(true); - } - if (!mana.isWhite() && rule.matches(regexWhite)) { - mana.setWhite(true); - } - } - if (card.isTransformable()) { - Card secondCard = card.getSecondCardFace(); - ObjectColor color = secondCard.getColor(null); - mana.setBlack(mana.isBlack() || color.isBlack()); - mana.setGreen(mana.isGreen() || color.isGreen()); - mana.setRed(mana.isRed() || color.isRed()); - mana.setBlue(mana.isBlue() || color.isBlue()); - mana.setWhite(mana.isWhite() || color.isWhite()); - for (String rule : secondCard.getRules()) { - rule = rule.replaceAll("(?i)", ""); // Ignoring reminder text in italic - if (!mana.isBlack() && rule.matches(regexBlack)) { - mana.setBlack(true); - } - if (!mana.isBlue() && rule.matches(regexBlue)) { - mana.setBlue(true); - } - if (!mana.isGreen() && rule.matches(regexGreen)) { - mana.setGreen(true); - } - if (!mana.isRed() && rule.matches(regexRed)) { - mana.setRed(true); - } - if (!mana.isWhite() && rule.matches(regexWhite)) { - mana.setWhite(true); - } - } - } - - return mana; - } public static boolean isNonCreatureSubtype(String subtype) { return NON_CREATURE_SUBTYPES.contains(subtype);