From bdaa78e144b537e747401754ab0180ea266c12e9 Mon Sep 17 00:00:00 2001 From: LevelX2 Date: Mon, 3 Oct 2016 10:00:48 +0200 Subject: [PATCH] Some minor changes. --- .../client/util/sets/ConstructedFormats.java | 217 +++++++++--------- Mage.Server/config/config.xml | 1 + Mage.Server/release/config/config.xml | 1 + .../java/mage/cards/decks/Constructed.java | 22 +- 4 files changed, 121 insertions(+), 120 deletions(-) diff --git a/Mage.Client/src/main/java/mage/client/util/sets/ConstructedFormats.java b/Mage.Client/src/main/java/mage/client/util/sets/ConstructedFormats.java index 66a3358220..cf424ae636 100644 --- a/Mage.Client/src/main/java/mage/client/util/sets/ConstructedFormats.java +++ b/Mage.Client/src/main/java/mage/client/util/sets/ConstructedFormats.java @@ -13,7 +13,6 @@ import mage.cards.repository.ExpansionRepository; import mage.constants.SetType; import mage.deck.Standard; - /** * Utility class for constructed formats (expansions and other editions). * @@ -21,8 +20,6 @@ import mage.deck.Standard; */ public class ConstructedFormats { - private static final GregorianCalendar calendar = new GregorianCalendar(); - public static final String ALL = "- All Sets"; public static final String STANDARD = "- Standard"; public static final String EXTENDED = "- Extended"; @@ -45,9 +42,9 @@ public class ConstructedFormats { } public static List getSetsByFormat(final String format) { - if(!format.equals(ALL)) { + if (!format.equals(ALL)) { return underlyingSetCodesPerFormat.get(format); - } + } return all; } @@ -62,158 +59,155 @@ public class ConstructedFormats { final Map expansionInfo = new HashMap<>(); formats.clear(); // prevent NPE on sorting if this is not the first try for (ExpansionInfo set : ExpansionRepository.instance.getAll()) { - expansionInfo.put(set.getName(), set); - formats.add(set.getName()); + expansionInfo.put(set.getName(), set); + formats.add(set.getName()); if (set.getType().equals(SetType.CORE) || set.getType().equals(SetType.EXPANSION) || set.getType().equals(SetType.SUPPLEMENTAL_STANDARD_LEGAL)) { if (STANDARD_CARDS.getSetCodes().contains(set.getCode())) { - if(underlyingSetCodesPerFormat.get(STANDARD) == null) { - underlyingSetCodesPerFormat.put(STANDARD, new ArrayList()); + if (underlyingSetCodesPerFormat.get(STANDARD) == null) { + underlyingSetCodesPerFormat.put(STANDARD, new ArrayList<>()); } underlyingSetCodesPerFormat.get(STANDARD).add(set.getCode()); } if (set.getReleaseDate().after(extendedDate)) { - if(underlyingSetCodesPerFormat.get(EXTENDED) == null) { - underlyingSetCodesPerFormat.put(EXTENDED, new ArrayList()); + if (underlyingSetCodesPerFormat.get(EXTENDED) == null) { + underlyingSetCodesPerFormat.put(EXTENDED, new ArrayList<>()); } underlyingSetCodesPerFormat.get(EXTENDED).add(set.getCode()); } if (set.getReleaseDate().after(frontierDate)) { - if(underlyingSetCodesPerFormat.get(FRONTIER) == null) { - underlyingSetCodesPerFormat.put(FRONTIER, new ArrayList()); + if (underlyingSetCodesPerFormat.get(FRONTIER) == null) { + underlyingSetCodesPerFormat.put(FRONTIER, new ArrayList<>()); } underlyingSetCodesPerFormat.get(FRONTIER).add(set.getCode()); } if (set.getReleaseDate().after(modernDate)) { - if(underlyingSetCodesPerFormat.get(MODERN) == null) { - underlyingSetCodesPerFormat.put(MODERN, new ArrayList()); + if (underlyingSetCodesPerFormat.get(MODERN) == null) { + underlyingSetCodesPerFormat.put(MODERN, new ArrayList<>()); } underlyingSetCodesPerFormat.get(MODERN).add(set.getCode()); } } - if(underlyingSetCodesPerFormat.get(set.getName()) == null) { - underlyingSetCodesPerFormat.put(set.getName(), new ArrayList()); + if (underlyingSetCodesPerFormat.get(set.getName()) == null) { + underlyingSetCodesPerFormat.put(set.getName(), new ArrayList<>()); } underlyingSetCodesPerFormat.get(set.getName()).add(set.getCode()); - if(set.getType().equals(SetType.EXPANSION) && set.getBlockName() != null) { - String blockDisplayName = getBlockDisplayName(set.getBlockName()); - if(underlyingSetCodesPerFormat.get(blockDisplayName) == null) { - underlyingSetCodesPerFormat.put(blockDisplayName, new ArrayList()); - } + if (set.getType().equals(SetType.EXPANSION) && set.getBlockName() != null) { + String blockDisplayName = getBlockDisplayName(set.getBlockName()); + if (underlyingSetCodesPerFormat.get(blockDisplayName) == null) { + underlyingSetCodesPerFormat.put(blockDisplayName, new ArrayList<>()); + } - underlyingSetCodesPerFormat.get(blockDisplayName).add(set.getCode()); + underlyingSetCodesPerFormat.get(blockDisplayName).add(set.getCode()); - if(expansionInfo.get(blockDisplayName) == null) { - expansionInfo.put(blockDisplayName, set); - formats.add(blockDisplayName); - } + if (expansionInfo.get(blockDisplayName) == null) { + expansionInfo.put(blockDisplayName, set); + formats.add(blockDisplayName); + } - if(expansionInfo.get(blockDisplayName).getReleaseDate().after(set.getReleaseDate())) { - expansionInfo.put(blockDisplayName, set); - } + if (expansionInfo.get(blockDisplayName).getReleaseDate().after(set.getReleaseDate())) { + expansionInfo.put(blockDisplayName, set); + } } - if(set.getType().equals(SetType.SUPPLEMENTAL) && set.getBlockName() != null) { - if(expansionInfo.get(set.getBlockName()) == null) { - expansionInfo.put(set.getBlockName(), set); - } + if (set.getType().equals(SetType.SUPPLEMENTAL) && set.getBlockName() != null) { + if (expansionInfo.get(set.getBlockName()) == null) { + expansionInfo.put(set.getBlockName(), set); + } - if(expansionInfo.get(set.getBlockName()).getReleaseDate().before(set.getReleaseDate())) { - expansionInfo.put(set.getBlockName(), set); - } + if (expansionInfo.get(set.getBlockName()).getReleaseDate().before(set.getReleaseDate())) { + expansionInfo.put(set.getBlockName(), set); + } } } Collections.sort(formats, new Comparator() { - @Override - public int compare(String name1, String name2) { - ExpansionInfo expansionInfo1 = expansionInfo.get(name1); - ExpansionInfo expansionInfo2 = expansionInfo.get(name2); + @Override + public int compare(String name1, String name2) { + ExpansionInfo expansionInfo1 = expansionInfo.get(name1); + ExpansionInfo expansionInfo2 = expansionInfo.get(name2); - if(expansionInfo1.getType().compareTo(expansionInfo2.getType()) == 0) { - SetType setType = expansionInfo1.getType(); - if(setType.equals(SetType.EXPANSION)) { + if (expansionInfo1.getType().compareTo(expansionInfo2.getType()) == 0) { + SetType setType = expansionInfo1.getType(); + switch (setType) { + case EXPANSION: + if (expansionInfo1.getBlockName() == null) { + if (expansionInfo2.getBlockName() == null) { + return expansionInfo2.getReleaseDate().compareTo(expansionInfo1.getReleaseDate()); + } - if(expansionInfo1.getBlockName() == null) { - if(expansionInfo2.getBlockName() == null) { - return expansionInfo2.getReleaseDate().compareTo(expansionInfo1.getReleaseDate()); - } + return 1; + } - return 1; - } + if (expansionInfo2.getBlockName() == null) { + return -1; + } - if(expansionInfo2.getBlockName() == null) { - return -1; - } + //Block comparison + if (name1.endsWith("Block") && name2.endsWith("Block")) { + return expansionInfo2.getReleaseDate().compareTo(expansionInfo1.getReleaseDate()); + } - //Block comparison - if(name1.endsWith("Block") && name2.endsWith("Block")) { - return expansionInfo2.getReleaseDate().compareTo(expansionInfo1.getReleaseDate()); - } + if (name1.endsWith("Block")) { + if (expansionInfo1.getBlockName().equals(expansionInfo2.getBlockName())) { + return -1; + } + } - if(name1.endsWith("Block")) { - if(expansionInfo1.getBlockName().equals(expansionInfo2.getBlockName())) { - return -1; - } - } + if (name2.endsWith("Block")) { + if (expansionInfo1.getBlockName().equals(expansionInfo2.getBlockName())) { + return 1; + } + } - if(name2.endsWith("Block")) { - if(expansionInfo1.getBlockName().equals(expansionInfo2.getBlockName())) { - return 1; - } - } + return expansionInfo2.getReleaseDate().compareTo(expansionInfo1.getReleaseDate()); + case SUPPLEMENTAL: + if (expansionInfo1.getBlockName() == null) { + if (expansionInfo2.getBlockName() == null) { + return expansionInfo2.getReleaseDate().compareTo(expansionInfo1.getReleaseDate()); + } - return expansionInfo2.getReleaseDate().compareTo(expansionInfo1.getReleaseDate()); + return -1; + } - } else if(setType.equals(SetType.SUPPLEMENTAL)) { - if(expansionInfo1.getBlockName() == null) { - if(expansionInfo2.getBlockName() == null) { - return expansionInfo2.getReleaseDate().compareTo(expansionInfo1.getReleaseDate()); - } + if (expansionInfo2.getBlockName() == null) { + return 1; + } - return -1; - } + if (expansionInfo1.getBlockName().equals(expansionInfo2.getBlockName())) { + //If release date is the same, sort alphabetically. + if (expansionInfo2.getReleaseDate().compareTo(expansionInfo1.getReleaseDate()) == 0) { + return name1.compareTo(name2); + } + return expansionInfo2.getReleaseDate().compareTo(expansionInfo1.getReleaseDate()); + } - if(expansionInfo2.getBlockName() == null) { - return 1; - } + if (expansionInfo1.getBlockName().startsWith("Duel Decks")) { + if (expansionInfo1.getBlockName().startsWith("Duel Decks: Anthology")) { + return 1; + } + return 1; + } + if (expansionInfo2.getBlockName().startsWith("Duel Decks")) { + return -1; + } - if(expansionInfo1.getBlockName().equals(expansionInfo2.getBlockName())) { - //If release date is the same, sort alphabetically. - if(expansionInfo2.getReleaseDate().compareTo(expansionInfo1.getReleaseDate()) == 0) { - return name1.compareTo(name2); - } - return expansionInfo2.getReleaseDate().compareTo(expansionInfo1.getReleaseDate()); - } + ExpansionInfo blockInfo1 = expansionInfo.get(expansionInfo1.getBlockName()); + ExpansionInfo blockInfo2 = expansionInfo.get(expansionInfo2.getBlockName()); - if(expansionInfo1.getBlockName().startsWith("Duel Decks")) { - if(expansionInfo1.getBlockName().startsWith("Duel Decks: Anthology")) { - return 1; - } - return 1; - } - if(expansionInfo2.getBlockName().startsWith("Duel Decks")) { - return -1; - } + return blockInfo2.getReleaseDate().compareTo(blockInfo1.getReleaseDate()); + default: + return expansionInfo2.getReleaseDate().compareTo(expansionInfo1.getReleaseDate()); + } + } + return expansionInfo1.getType().compareTo(expansionInfo2.getType()); + } - ExpansionInfo blockInfo1 = expansionInfo.get(expansionInfo1.getBlockName()); - ExpansionInfo blockInfo2 = expansionInfo.get(expansionInfo2.getBlockName()); - - return blockInfo2.getReleaseDate().compareTo(blockInfo1.getReleaseDate()); - - - } else { - return expansionInfo2.getReleaseDate().compareTo(expansionInfo1.getReleaseDate()); - } - } - return expansionInfo1.getType().compareTo(expansionInfo2.getType()); - } - - }); + }); if (!formats.isEmpty()) { formats.add(0, MODERN); formats.add(0, FRONTIER); @@ -224,13 +218,12 @@ public class ConstructedFormats { } private static String getBlockDisplayName(String blockName) { - StringBuilder builder = new StringBuilder(); - builder.append("* ").append(blockName).append(" Block"); + StringBuilder builder = new StringBuilder(); + builder.append("* ").append(blockName).append(" Block"); - return builder.toString(); + return builder.toString(); } - private static final Date extendedDate = new GregorianCalendar(2009, 8, 20).getTime(); private static final Date frontierDate = new GregorianCalendar(2014, 7, 17).getTime(); private static final Date modernDate = new GregorianCalendar(2003, 7, 20).getTime(); diff --git a/Mage.Server/config/config.xml b/Mage.Server/config/config.xml index 3f8f90557b..7c8737ca20 100644 --- a/Mage.Server/config/config.xml +++ b/Mage.Server/config/config.xml @@ -142,6 +142,7 @@ + diff --git a/Mage.Server/release/config/config.xml b/Mage.Server/release/config/config.xml index c74c4e85d2..2bf3d638dc 100644 --- a/Mage.Server/release/config/config.xml +++ b/Mage.Server/release/config/config.xml @@ -139,6 +139,7 @@ + diff --git a/Mage/src/main/java/mage/cards/decks/Constructed.java b/Mage/src/main/java/mage/cards/decks/Constructed.java index ad4a541365..5851f1ec66 100644 --- a/Mage/src/main/java/mage/cards/decks/Constructed.java +++ b/Mage/src/main/java/mage/cards/decks/Constructed.java @@ -30,7 +30,6 @@ package mage.cards.decks; import java.util.*; import java.util.Map.Entry; import mage.cards.Card; -import mage.cards.Sets; import mage.cards.repository.CardInfo; import mage.cards.repository.CardRepository; import mage.constants.Rarity; @@ -112,14 +111,14 @@ public class Constructed extends DeckValidator { if (!rarities.isEmpty()) { for (Card card : deck.getCards()) { if (!rarities.contains(card.getRarity())) { - if( !legalRarity(card) ){ + if (!legalRarity(card)) { valid = false; } } } for (Card card : deck.getSideboard()) { if (!rarities.contains(card.getRarity())) { - if( !legalRarity(card) ){ + if (!legalRarity(card)) { valid = false; } } @@ -128,14 +127,14 @@ public class Constructed extends DeckValidator { for (Card card : deck.getCards()) { if (!isSetAllowed(card.getExpansionSetCode())) { - if( !legalSets(card) ){ + if (!legalSets(card)) { valid = false; } } } for (Card card : deck.getSideboard()) { if (!isSetAllowed(card.getExpansionSetCode())) { - if( !legalSets(card) ){ + if (!legalSets(card)) { valid = false; } } @@ -147,10 +146,11 @@ public class Constructed extends DeckValidator { /** * Checks if the given card is legal in any of the given rarities + * * @param card - the card to check * @return Whether the card was printed at any of the given rarities. */ - protected boolean legalRarity(Card card){ + protected boolean legalRarity(Card card) { // check if card is legal if taken from other set boolean legal = false; List cardInfos = CardRepository.instance.findCards(card.getName()); @@ -168,16 +168,22 @@ public class Constructed extends DeckValidator { /** * Checks if a given set is legal in this format. + * * @param code - the set code to check * @return Whether the set is legal in this format. */ protected boolean isSetAllowed(String code) { - if(Sets.isCustomSet(code)) return allowAllCustomSets || allowedCustomSetCodes.contains(code); - else return setCodes.isEmpty() || setCodes.contains(code); + // To check here for custom set makes no sens IMHO because the format does define what's aloowed and what not +// if (Sets.isCustomSet(code)) { +// return allowAllCustomSets || allowedCustomSetCodes.contains(code); +// } else { + return setCodes.isEmpty() || setCodes.contains(code); +// } } /** * Checks if the given card is legal in any of the given sets + * * @param card - the card to check * @return Whether the card was printed in any of this format's sets. */