diff --git a/forge-gui/src/main/java/forge/deck/DeckProxy.java b/forge-gui/src/main/java/forge/deck/DeckProxy.java index 522421f11c1..16b43babb36 100644 --- a/forge-gui/src/main/java/forge/deck/DeckProxy.java +++ b/forge-gui/src/main/java/forge/deck/DeckProxy.java @@ -16,6 +16,7 @@ import forge.StaticData; import forge.card.CardEdition; import forge.card.CardRarity; import forge.card.CardRules; +import forge.card.CardType; import forge.card.ColorSet; import forge.card.MagicColor; import forge.card.mana.ManaCostShard; @@ -52,6 +53,7 @@ public class DeckProxy implements InventoryItem { protected Set formats; private Integer mainSize = null; private Integer sbSize = null; + private Integer avgCMC = null; private final String path; private final Function fnGetDeck; private CardEdition edition; @@ -286,6 +288,32 @@ public class DeckProxy implements InventoryItem { return sbSize; } + public Integer getAverageCMC() { + if (avgCMC == null) { + int totalCMC = 0; + int totalCount = 0; + for (final Entry deckEntry : getDeck()) { + switch (deckEntry.getKey()) { + case Main: + case Commander: + for (final Entry poolEntry : deckEntry.getValue()) { + CardRules rules = poolEntry.getKey().getRules(); + CardType type = rules.getType(); + if (!type.isLand() && (type.isArtifact() || type.isCreature() || type.isEnchantment() || type.isPlaneswalker() || type.isInstant() || type.isSorcery())) { + totalCMC += rules.getManaCost().getCMC(); + totalCount++; + } + } + break; + default: + break; //ignore other sections + } + } + avgCMC = Math.round(totalCMC / totalCount); + } + return avgCMC; + } + public boolean isGeneratedDeck() { return false; } diff --git a/forge-gui/src/main/java/forge/itemmanager/AdvancedSearch.java b/forge-gui/src/main/java/forge/itemmanager/AdvancedSearch.java index 473907a1912..5a028964874 100644 --- a/forge-gui/src/main/java/forge/itemmanager/AdvancedSearch.java +++ b/forge-gui/src/main/java/forge/itemmanager/AdvancedSearch.java @@ -76,6 +76,12 @@ public class AdvancedSearch { return input.getRules().getColorIdentity().toEnumSet(); } }), + CARD_COLOR_COUNT("Color Count", PaperCard.class, FilterOperator.NUMBER_OPS, new NumericEvaluator(0, 5) { + @Override + protected Integer getItemValue(PaperCard input) { + return input.getRules().getColor().countColors(); + } + }), CARD_TYPE("Type", PaperCard.class, FilterOperator.MULTI_LIST_OPS, new CustomListEvaluator(CardType.getSortedCoreAndSuperTypes()) { @Override protected String getItemValue(PaperCard input) { @@ -116,12 +122,6 @@ public class AdvancedSearch { return input.getRules().getManaCost().getGenericCost(); } }), - CARD_COLOR_COUNT("Color Count", PaperCard.class, FilterOperator.NUMBER_OPS, new NumericEvaluator(0, 5) { - @Override - protected Integer getItemValue(PaperCard input) { - return input.getRules().getColor().countColors(); - } - }), CARD_POWER("Power", PaperCard.class, FilterOperator.NUMBER_OPS, new NumericEvaluator(0, 20) { @Override protected Integer getItemValue(PaperCard input) { @@ -196,6 +196,18 @@ public class AdvancedSearch { return input.getColorIdentity().toEnumSet(); } }), + DECK_COLOR_COUNT("Color Count", DeckProxy.class, FilterOperator.NUMBER_OPS, new NumericEvaluator(0, 5) { + @Override + protected Integer getItemValue(DeckProxy input) { + return input.getColor().countColors(); + } + }), + DECK_AVERAGE_CMC("Average CMC", DeckProxy.class, FilterOperator.NUMBER_OPS, new NumericEvaluator(0, 20) { + @Override + protected Integer getItemValue(DeckProxy input) { + return input.getAverageCMC(); + } + }), DECK_MAIN_SIZE("Main Deck Size", DeckProxy.class, FilterOperator.NUMBER_OPS, new NumericEvaluator(40, 250) { @Override protected Integer getItemValue(DeckProxy input) {