mirror of
https://github.com/Card-Forge/forge.git
synced 2025-11-18 11:48:02 +00:00
Add Average CMC filter for decks
This commit is contained in:
@@ -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<GameFormat> formats;
|
||||
private Integer mainSize = null;
|
||||
private Integer sbSize = null;
|
||||
private Integer avgCMC = null;
|
||||
private final String path;
|
||||
private final Function<IHasName, Deck> 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<DeckSection, CardPool> deckEntry : getDeck()) {
|
||||
switch (deckEntry.getKey()) {
|
||||
case Main:
|
||||
case Commander:
|
||||
for (final Entry<PaperCard, Integer> 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;
|
||||
}
|
||||
|
||||
@@ -76,6 +76,12 @@ public class AdvancedSearch {
|
||||
return input.getRules().getColorIdentity().toEnumSet();
|
||||
}
|
||||
}),
|
||||
CARD_COLOR_COUNT("Color Count", PaperCard.class, FilterOperator.NUMBER_OPS, new NumericEvaluator<PaperCard>(0, 5) {
|
||||
@Override
|
||||
protected Integer getItemValue(PaperCard input) {
|
||||
return input.getRules().getColor().countColors();
|
||||
}
|
||||
}),
|
||||
CARD_TYPE("Type", PaperCard.class, FilterOperator.MULTI_LIST_OPS, new CustomListEvaluator<PaperCard, String>(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<PaperCard>(0, 5) {
|
||||
@Override
|
||||
protected Integer getItemValue(PaperCard input) {
|
||||
return input.getRules().getColor().countColors();
|
||||
}
|
||||
}),
|
||||
CARD_POWER("Power", PaperCard.class, FilterOperator.NUMBER_OPS, new NumericEvaluator<PaperCard>(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<DeckProxy>(0, 5) {
|
||||
@Override
|
||||
protected Integer getItemValue(DeckProxy input) {
|
||||
return input.getColor().countColors();
|
||||
}
|
||||
}),
|
||||
DECK_AVERAGE_CMC("Average CMC", DeckProxy.class, FilterOperator.NUMBER_OPS, new NumericEvaluator<DeckProxy>(0, 20) {
|
||||
@Override
|
||||
protected Integer getItemValue(DeckProxy input) {
|
||||
return input.getAverageCMC();
|
||||
}
|
||||
}),
|
||||
DECK_MAIN_SIZE("Main Deck Size", DeckProxy.class, FilterOperator.NUMBER_OPS, new NumericEvaluator<DeckProxy>(40, 250) {
|
||||
@Override
|
||||
protected Integer getItemValue(DeckProxy input) {
|
||||
|
||||
Reference in New Issue
Block a user