mirror of
https://github.com/Card-Forge/forge.git
synced 2025-11-16 18:58:00 +00:00
arrange Predicates for CardEdition
This commit is contained in:
1
.gitattributes
vendored
1
.gitattributes
vendored
@@ -14806,7 +14806,6 @@ forge-gui/src/main/java/forge/ai/ability/UntapAi.java -text
|
||||
forge-gui/src/main/java/forge/ai/ability/UntapAllAi.java -text
|
||||
forge-gui/src/main/java/forge/ai/ability/ZoneExchangeAi.java -text
|
||||
forge-gui/src/main/java/forge/card/CardBlock.java -text
|
||||
forge-gui/src/main/java/forge/card/CardEditionPredicates.java -text
|
||||
forge-gui/src/main/java/forge/card/MetaSet.java -text
|
||||
forge-gui/src/main/java/forge/card/UnOpenedMeta.java -text
|
||||
forge-gui/src/main/java/forge/card/package-info.java svneol=native#text/plain
|
||||
|
||||
@@ -33,9 +33,13 @@ import org.apache.commons.lang3.StringUtils;
|
||||
|
||||
|
||||
import com.google.common.base.Function;
|
||||
import com.google.common.base.Predicate;
|
||||
import com.google.common.collect.Iterables;
|
||||
import com.google.common.collect.Lists;
|
||||
|
||||
import forge.StaticData;
|
||||
import forge.item.SealedProduct;
|
||||
import forge.util.Aggregates;
|
||||
import forge.util.FileSection;
|
||||
import forge.util.FileUtil;
|
||||
import forge.util.IItemReader;
|
||||
@@ -403,4 +407,49 @@ public final class CardEdition implements Comparable<CardEdition> { // immutable
|
||||
};
|
||||
}
|
||||
}
|
||||
public static class Predicates {
|
||||
|
||||
/** The Constant canMakeBooster. */
|
||||
public static final Predicate<CardEdition> CAN_MAKE_BOOSTER = new CanMakeBooster();
|
||||
|
||||
private static class CanMakeBooster implements Predicate<CardEdition> {
|
||||
@Override
|
||||
public boolean apply(final CardEdition subject) {
|
||||
return subject.hasBoosterTemplate();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public final static CardEdition getRandomSetWithAllBasicLands(Iterable<CardEdition> allEditions) {
|
||||
return Aggregates.random(Iterables.filter(allEditions, hasBasicLands));
|
||||
}
|
||||
|
||||
public static final Predicate<CardEdition> HAS_TOURNAMENT_PACK = new CanMakeStarter();
|
||||
private static class CanMakeStarter implements Predicate<CardEdition> {
|
||||
@Override
|
||||
public boolean apply(final CardEdition subject) {
|
||||
return StaticData.instance().getTournamentPacks().contains(subject.getCode());
|
||||
}
|
||||
}
|
||||
|
||||
public static final Predicate<CardEdition> HAS_FAT_PACK = new CanMakeFatPack();
|
||||
private static class CanMakeFatPack implements Predicate<CardEdition> {
|
||||
@Override
|
||||
public boolean apply(final CardEdition subject) {
|
||||
return StaticData.instance().getFatPacks().contains(subject.getCode());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public static final Predicate<CardEdition> hasBasicLands = new Predicate<CardEdition>() {
|
||||
@Override
|
||||
public boolean apply(CardEdition ed) {
|
||||
for(String landName : MagicColor.Constant.BASIC_LANDS) {
|
||||
if (null == StaticData.instance().getCommonCards().tryGetCard(landName, ed.getCode(), 0))
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
};
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -29,6 +29,7 @@ import com.google.common.base.Predicates;
|
||||
import com.google.common.collect.Lists;
|
||||
|
||||
import forge.StaticData;
|
||||
import forge.card.CardEdition;
|
||||
import forge.item.PaperCard;
|
||||
import forge.item.IPaperCard;
|
||||
import forge.util.FileSection;
|
||||
@@ -237,4 +238,12 @@ public class GameFormat implements Comparable<GameFormat> {
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// declared here because
|
||||
public final Predicate<CardEdition> editionLegalPredicate = new Predicate<CardEdition>() {
|
||||
@Override
|
||||
public boolean apply(final CardEdition subject) {
|
||||
return GameFormat.this.isSetLegal(subject.getCode());
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@@ -1,80 +0,0 @@
|
||||
package forge.card;
|
||||
|
||||
import com.google.common.base.Predicate;
|
||||
import com.google.common.collect.Iterables;
|
||||
|
||||
import forge.Singletons;
|
||||
import forge.game.GameFormat;
|
||||
import forge.util.Aggregates;
|
||||
|
||||
/**
|
||||
* The Class Predicates.
|
||||
*/
|
||||
public abstract class CardEditionPredicates {
|
||||
|
||||
/** The Constant canMakeBooster. */
|
||||
public static final Predicate<CardEdition> CAN_MAKE_BOOSTER = new CanMakeBooster();
|
||||
|
||||
private static class CanMakeBooster implements Predicate<CardEdition> {
|
||||
@Override
|
||||
public boolean apply(final CardEdition subject) {
|
||||
return subject.hasBoosterTemplate();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public final static CardEdition getRandomSetWithAllBasicLands(Iterable<CardEdition> allEditions) {
|
||||
return Aggregates.random(Iterables.filter(allEditions, CardEditionPredicates.hasBasicLands));
|
||||
}
|
||||
|
||||
public static final Predicate<CardEdition> HAS_TOURNAMENT_PACK = new CanMakeStarter();
|
||||
private static class CanMakeStarter implements Predicate<CardEdition> {
|
||||
@Override
|
||||
public boolean apply(final CardEdition subject) {
|
||||
return Singletons.getMagicDb().getTournamentPacks().contains(subject.getCode());
|
||||
}
|
||||
}
|
||||
|
||||
public static final Predicate<CardEdition> HAS_FAT_PACK = new CanMakeFatPack();
|
||||
private static class CanMakeFatPack implements Predicate<CardEdition> {
|
||||
@Override
|
||||
public boolean apply(final CardEdition subject) {
|
||||
return Singletons.getMagicDb().getFatPacks().contains(subject.getCode());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if is legal in format.
|
||||
*
|
||||
* @param format the format
|
||||
* @return the predicate
|
||||
*/
|
||||
public static final Predicate<CardEdition> isLegalInFormat(final GameFormat format) {
|
||||
return new LegalInFormat(format);
|
||||
}
|
||||
|
||||
private static class LegalInFormat implements Predicate<CardEdition> {
|
||||
private final GameFormat format;
|
||||
|
||||
public LegalInFormat(final GameFormat fmt) {
|
||||
this.format = fmt;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean apply(final CardEdition subject) {
|
||||
return this.format.isSetLegal(subject.getCode());
|
||||
}
|
||||
}
|
||||
|
||||
public static final Predicate<CardEdition> hasBasicLands = new Predicate<CardEdition>() {
|
||||
@Override
|
||||
public boolean apply(CardEdition ed) {
|
||||
for(String landName : MagicColor.Constant.BASIC_LANDS) {
|
||||
if (null == Singletons.getMagicDb().getCommonCards().tryGetCard(landName, ed.getCode(), 0))
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
};
|
||||
};
|
||||
|
||||
}
|
||||
@@ -24,7 +24,6 @@ import java.util.Set;
|
||||
|
||||
import forge.Constant;
|
||||
import forge.Singletons;
|
||||
import forge.Constant.Keywords;
|
||||
import forge.card.CardCharacteristicName;
|
||||
import forge.card.ColorSet;
|
||||
import forge.card.MagicColor;
|
||||
|
||||
@@ -36,7 +36,6 @@ import forge.Constant.Preferences;
|
||||
import forge.Singletons;
|
||||
import forge.card.CardBlock;
|
||||
import forge.card.CardEdition;
|
||||
import forge.card.CardEditionPredicates;
|
||||
import forge.card.IUnOpenedProduct;
|
||||
import forge.card.UnOpenedProduct;
|
||||
import forge.deck.Deck;
|
||||
@@ -89,7 +88,7 @@ public final class BoosterDraft implements IBoosterDraft {
|
||||
Supplier<List<PaperCard>> s = new UnOpenedProduct(SealedProduct.Template.genericBooster);
|
||||
|
||||
for (int i = 0; i < 3; i++) this.product.add(s);
|
||||
IBoosterDraft.LAND_SET_CODE[0] = CardEditionPredicates.getRandomSetWithAllBasicLands(Singletons.getMagicDb().getEditions());
|
||||
IBoosterDraft.LAND_SET_CODE[0] = CardEdition.Predicates.getRandomSetWithAllBasicLands(Singletons.getMagicDb().getEditions());
|
||||
break;
|
||||
|
||||
case Block: case FantasyBlock: // Draft from cards by block or set
|
||||
|
||||
@@ -25,7 +25,7 @@ import org.apache.commons.lang3.tuple.ImmutablePair;
|
||||
import org.apache.commons.lang3.tuple.Pair;
|
||||
|
||||
import forge.Singletons;
|
||||
import forge.card.CardEditionPredicates;
|
||||
import forge.card.CardEdition;
|
||||
import forge.deck.Deck;
|
||||
import forge.deck.DeckBase;
|
||||
import forge.item.PaperCard;
|
||||
@@ -66,7 +66,7 @@ public class CustomLimited extends DeckBase {
|
||||
private transient ItemPoolView<PaperCard> cardPool;
|
||||
|
||||
/** The Land set code. */
|
||||
private String landSetCode = CardEditionPredicates.getRandomSetWithAllBasicLands(Singletons.getMagicDb().getEditions()).getCode();
|
||||
private String landSetCode = CardEdition.Predicates.getRandomSetWithAllBasicLands(Singletons.getMagicDb().getEditions()).getCode();
|
||||
|
||||
private boolean singleton;
|
||||
|
||||
|
||||
@@ -20,7 +20,6 @@ import forge.Singletons;
|
||||
|
||||
import forge.card.CardAiHints;
|
||||
import forge.card.CardEdition;
|
||||
import forge.card.CardEditionPredicates;
|
||||
import forge.card.CardRules;
|
||||
import forge.card.CardRulesPredicates;
|
||||
import forge.card.ColorSet;
|
||||
@@ -278,7 +277,7 @@ public class LimitedDeckBuilder extends DeckGeneratorBase{
|
||||
Set<String> sets = new HashSet<String>();
|
||||
for (PaperCard cp : aiPlayables) {
|
||||
CardEdition ee = Singletons.getMagicDb().getEditions().get(cp.edition);
|
||||
if( !sets.contains(cp.getEdition()) && CardEditionPredicates.hasBasicLands.apply(ee))
|
||||
if( !sets.contains(cp.getEdition()) && CardEdition.Predicates.hasBasicLands.apply(ee))
|
||||
sets.add(cp.getEdition());
|
||||
}
|
||||
setsWithBasicLands.addAll(sets);
|
||||
|
||||
@@ -29,7 +29,6 @@ import org.apache.commons.lang3.ArrayUtils;
|
||||
import forge.Singletons;
|
||||
import forge.card.CardBlock;
|
||||
import forge.card.CardEdition;
|
||||
import forge.card.CardEditionPredicates;
|
||||
import forge.card.IUnOpenedProduct;
|
||||
import forge.card.UnOpenedMeta;
|
||||
import forge.card.UnOpenedProduct;
|
||||
@@ -72,7 +71,7 @@ public class SealedCardPoolGenerator {
|
||||
// Choose number of boosters
|
||||
|
||||
chooseNumberOfBoosters(new UnOpenedProduct(SealedProduct.Template.genericBooster));
|
||||
landSetCode = CardEditionPredicates.getRandomSetWithAllBasicLands(Singletons.getMagicDb().getEditions()).getCode();
|
||||
landSetCode = CardEdition.Predicates.getRandomSetWithAllBasicLands(Singletons.getMagicDb().getEditions()).getCode();
|
||||
break;
|
||||
|
||||
case Block:
|
||||
|
||||
@@ -32,7 +32,6 @@ import com.google.common.collect.Lists;
|
||||
import forge.Singletons;
|
||||
import forge.card.BoosterSlots;
|
||||
import forge.card.CardEdition;
|
||||
import forge.card.CardEditionPredicates;
|
||||
import forge.card.CardRarity;
|
||||
import forge.card.ICardDatabase;
|
||||
import forge.card.MagicColor;
|
||||
@@ -101,7 +100,7 @@ public final class QuestUtilCards {
|
||||
for (String edCode : availableEditions) {
|
||||
CardEdition ed = Singletons.getMagicDb().getEditions().get(edCode);
|
||||
// Duel decks might have only 2 types of basic lands
|
||||
if (CardEditionPredicates.hasBasicLands.apply(ed)) {
|
||||
if (CardEdition.Predicates.hasBasicLands.apply(ed)) {
|
||||
landCodes.add(edCode);
|
||||
}
|
||||
}
|
||||
@@ -113,7 +112,7 @@ public final class QuestUtilCards {
|
||||
}
|
||||
} else {
|
||||
Iterable<CardEdition> allEditions = Singletons.getMagicDb().getEditions();
|
||||
for (CardEdition edition : Iterables.filter(allEditions, CardEditionPredicates.hasBasicLands)) {
|
||||
for (CardEdition edition : Iterables.filter(allEditions, CardEdition.Predicates.hasBasicLands)) {
|
||||
landCodes.add(edition.getCode());
|
||||
}
|
||||
snowLandCodes.add("ICE");
|
||||
@@ -429,20 +428,19 @@ public final class QuestUtilCards {
|
||||
* Generate cards in shop.
|
||||
*/
|
||||
private final GameFormat.Collection formats = Singletons.getModel().getFormats();
|
||||
private final Predicate<CardEdition> filterExt = CardEditionPredicates.isLegalInFormat(this.formats.getExtended());
|
||||
private final Predicate<CardEdition> filterExt = this.formats.getExtended().editionLegalPredicate;
|
||||
|
||||
/** The filter t2booster. */
|
||||
private final Predicate<CardEdition> filterT2booster = Predicates.and(CardEditionPredicates.CAN_MAKE_BOOSTER,
|
||||
CardEditionPredicates.isLegalInFormat(this.formats.getStandard()));
|
||||
private final Predicate<CardEdition> filterT2booster = Predicates.and(CardEdition.Predicates.CAN_MAKE_BOOSTER,
|
||||
this.formats.getStandard().editionLegalPredicate);
|
||||
|
||||
/** The filter ext but t2. */
|
||||
private final Predicate<CardEdition> filterExtButT2 = Predicates.and(
|
||||
CardEditionPredicates.CAN_MAKE_BOOSTER,
|
||||
Predicates.and(this.filterExt,
|
||||
Predicates.not(CardEditionPredicates.isLegalInFormat(this.formats.getStandard()))));
|
||||
CardEdition.Predicates.CAN_MAKE_BOOSTER,
|
||||
Predicates.and(this.filterExt, this.formats.getStandard().editionLegalPredicate));
|
||||
|
||||
/** The filter not ext. */
|
||||
private final Predicate<CardEdition> filterNotExt = Predicates.and(CardEditionPredicates.CAN_MAKE_BOOSTER,
|
||||
private final Predicate<CardEdition> filterNotExt = Predicates.and(CardEdition.Predicates.CAN_MAKE_BOOSTER,
|
||||
Predicates.not(this.filterExt));
|
||||
|
||||
/**
|
||||
@@ -468,7 +466,7 @@ public final class QuestUtilCards {
|
||||
Predicate<CardEdition> filter = rollD100 < 40 ? this.filterT2booster
|
||||
: (rollD100 < 75 ? this.filterExtButT2 : this.filterNotExt);
|
||||
if (qc.getFormat() != null) {
|
||||
filter = Predicates.and(CardEditionPredicates.CAN_MAKE_BOOSTER, isLegalInQuestFormat(qc.getFormat()));
|
||||
filter = Predicates.and(CardEdition.Predicates.CAN_MAKE_BOOSTER, isLegalInQuestFormat(qc.getFormat()));
|
||||
}
|
||||
Iterable<CardEdition> rightEditions = Iterables.filter(Singletons.getMagicDb().getEditions(), filter);
|
||||
this.qa.getShopList().add(BoosterPack.FN_FROM_SET.apply(Aggregates.random(rightEditions)));
|
||||
@@ -482,7 +480,7 @@ public final class QuestUtilCards {
|
||||
* the count
|
||||
*/
|
||||
private void generateTournamentsInShop(final int count) {
|
||||
Predicate<CardEdition> formatFilter = CardEditionPredicates.HAS_TOURNAMENT_PACK;
|
||||
Predicate<CardEdition> formatFilter = CardEdition.Predicates.HAS_TOURNAMENT_PACK;
|
||||
if (qc.getFormat() != null) {
|
||||
formatFilter = Predicates.and(formatFilter, isLegalInQuestFormat(qc.getFormat()));
|
||||
}
|
||||
@@ -497,7 +495,7 @@ public final class QuestUtilCards {
|
||||
* the count
|
||||
*/
|
||||
private void generateFatPacksInShop(final int count) {
|
||||
Predicate<CardEdition> formatFilter = CardEditionPredicates.HAS_FAT_PACK;
|
||||
Predicate<CardEdition> formatFilter = CardEdition.Predicates.HAS_FAT_PACK;
|
||||
if (qc.getFormat() != null) {
|
||||
formatFilter = Predicates.and(formatFilter, isLegalInQuestFormat(qc.getFormat()));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user