mirror of
https://github.com/Card-Forge/forge.git
synced 2025-11-12 00:38:44 +00:00
Guava migration - Remove single use Predicate implementations
Remove unused parameters of other predicates
This commit is contained in:
@@ -1060,69 +1060,26 @@ public final class CardDb implements ICardDatabase, IDeckGenPool {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Predicate<? super PaperCard> wasPrintedInSets(List<String> setCodes) {
|
public Predicate<? super PaperCard> wasPrintedInSets(Collection<String> setCodes) {
|
||||||
return new PredicateExistsInSets(setCodes);
|
Set<String> sets = new HashSet<>(setCodes);
|
||||||
}
|
return paperCard -> getAllCards(paperCard.getName()).stream()
|
||||||
|
.map(PaperCard::getEdition)
|
||||||
private class PredicateExistsInSets implements Predicate<PaperCard> {
|
.anyMatch(sets::contains);
|
||||||
private final List<String> sets;
|
|
||||||
|
|
||||||
public PredicateExistsInSets(final List<String> wantSets) {
|
|
||||||
this.sets = wantSets; // maybe should make a copy here?
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean test(final PaperCard subject) {
|
|
||||||
for (PaperCard c : getAllCards(subject.getName())) {
|
|
||||||
if (sets.contains(c.getEdition())) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// This Predicate validates if a card is legal in a given format (identified by the list of allowed sets)
|
// This Predicate validates if a card is legal in a given format (identified by the list of allowed sets)
|
||||||
@Override
|
@Override
|
||||||
public Predicate<? super PaperCard> isLegal(List<String> allowedSetCodes){
|
public Predicate<? super PaperCard> isLegal(Collection<String> allowedSetCodes){
|
||||||
return new PredicateLegalInSets(allowedSetCodes);
|
Set<String> sets = new HashSet<>(allowedSetCodes);
|
||||||
}
|
return paperCard -> paperCard != null && sets.contains(paperCard.getEdition());
|
||||||
|
|
||||||
private class PredicateLegalInSets implements Predicate<PaperCard> {
|
|
||||||
private final List<String> sets = new ArrayList<>();
|
|
||||||
|
|
||||||
public PredicateLegalInSets(final List<String> allowedSets){
|
|
||||||
this.sets.addAll(allowedSets);
|
|
||||||
}
|
|
||||||
@Override
|
|
||||||
public boolean test(final PaperCard card){
|
|
||||||
if (card == null) return false;
|
|
||||||
return this.sets.contains(card.getEdition());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// This Predicate validates if a card was printed at [rarity], on any of its printings
|
// This Predicate validates if a card was printed at [rarity], on any of its printings
|
||||||
@Override
|
@Override
|
||||||
public Predicate<? super PaperCard> wasPrintedAtRarity(CardRarity rarity) {
|
public Predicate<? super PaperCard> wasPrintedAtRarity(CardRarity rarity) {
|
||||||
return new PredicatePrintedAtRarity(rarity);
|
return paperCard -> getAllCards(paperCard.getName()).stream()
|
||||||
}
|
.map(PaperCard::getRarity)
|
||||||
|
.anyMatch(rarity::equals);
|
||||||
private class PredicatePrintedAtRarity implements Predicate<PaperCard> {
|
|
||||||
private final Set<String> matchingCards;
|
|
||||||
|
|
||||||
public PredicatePrintedAtRarity(CardRarity rarity) {
|
|
||||||
this.matchingCards = new HashSet<>();
|
|
||||||
for (PaperCard c : getAllCards()) {
|
|
||||||
if (c.getRarity() == rarity) {
|
|
||||||
this.matchingCards.add(c.getName());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean test(final PaperCard subject) {
|
|
||||||
return matchingCards.contains(subject.getName());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public StringBuilder appendCardToStringBuilder(PaperCard card, StringBuilder sb) {
|
public StringBuilder appendCardToStringBuilder(PaperCard card, StringBuilder sb) {
|
||||||
|
|||||||
@@ -892,14 +892,7 @@ public final class CardEdition implements Comparable<CardEdition> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static class Predicates {
|
public static class Predicates {
|
||||||
public static final Predicate<CardEdition> CAN_MAKE_BOOSTER = new CanMakeBooster();
|
public static final Predicate<CardEdition> CAN_MAKE_BOOSTER = CardEdition::hasBoosterTemplate;
|
||||||
|
|
||||||
private static class CanMakeBooster implements Predicate<CardEdition> {
|
|
||||||
@Override
|
|
||||||
public boolean test(final CardEdition subject) {
|
|
||||||
return subject.hasBoosterTemplate();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static CardEdition getRandomSetWithAllBasicLands(Iterable<CardEdition> allEditions) {
|
public static CardEdition getRandomSetWithAllBasicLands(Iterable<CardEdition> allEditions) {
|
||||||
return Aggregates.random(Iterables.filter(allEditions, hasBasicLands));
|
return Aggregates.random(Iterables.filter(allEditions, hasBasicLands));
|
||||||
@@ -921,29 +914,11 @@ public final class CardEdition implements Comparable<CardEdition> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public static final Predicate<CardEdition> HAS_TOURNAMENT_PACK = new CanMakeStarter();
|
public static final Predicate<CardEdition> HAS_TOURNAMENT_PACK = edition -> StaticData.instance().getTournamentPacks().contains(edition.getCode());
|
||||||
private static class CanMakeStarter implements Predicate<CardEdition> {
|
|
||||||
@Override
|
|
||||||
public boolean test(final CardEdition subject) {
|
|
||||||
return StaticData.instance().getTournamentPacks().contains(subject.getCode());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static final Predicate<CardEdition> HAS_FAT_PACK = new CanMakeFatPack();
|
public static final Predicate<CardEdition> HAS_FAT_PACK = edition -> edition.getFatPackCount() > 0;
|
||||||
private static class CanMakeFatPack implements Predicate<CardEdition> {
|
|
||||||
@Override
|
|
||||||
public boolean test(final CardEdition subject) {
|
|
||||||
return subject.getFatPackCount() > 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static final Predicate<CardEdition> HAS_BOOSTER_BOX = new CanMakeBoosterBox();
|
public static final Predicate<CardEdition> HAS_BOOSTER_BOX = edition -> edition.getBoosterBoxCount() > 0;
|
||||||
private static class CanMakeBoosterBox implements Predicate<CardEdition> {
|
|
||||||
@Override
|
|
||||||
public boolean test(final CardEdition subject) {
|
|
||||||
return subject.getBoosterBoxCount() > 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static final Predicate<CardEdition> hasBasicLands = ed -> {
|
public static final Predicate<CardEdition> hasBasicLands = ed -> {
|
||||||
if (ed == null) {
|
if (ed == null) {
|
||||||
|
|||||||
@@ -85,14 +85,6 @@ public final class CardRulesPredicates {
|
|||||||
return new LeafString(LeafString.CardField.NAME, op, what);
|
return new LeafString(LeafString.CardField.NAME, op, what);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* TODO: Write javadoc for this method.
|
|
||||||
* @param transform
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
public static Predicate<CardRules> splitType(final CardSplitType transform) {
|
|
||||||
return new PredicateSplitType(transform);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sub type.
|
* Sub type.
|
||||||
@@ -105,15 +97,6 @@ public final class CardRulesPredicates {
|
|||||||
return new LeafString(LeafString.CardField.SUBTYPE, PredicateString.StringOp.CONTAINS, what);
|
return new LeafString(LeafString.CardField.SUBTYPE, PredicateString.StringOp.CONTAINS, what);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Sub type.
|
|
||||||
*
|
|
||||||
* @param op
|
|
||||||
* the op
|
|
||||||
* @param what
|
|
||||||
* the what
|
|
||||||
* @return the predicate
|
|
||||||
*/
|
|
||||||
public static Predicate<CardRules> subType(final PredicateString.StringOp op, final String what) {
|
public static Predicate<CardRules> subType(final PredicateString.StringOp op, final String what) {
|
||||||
return new LeafString(LeafString.CardField.SUBTYPE, op, what);
|
return new LeafString(LeafString.CardField.SUBTYPE, op, what);
|
||||||
}
|
}
|
||||||
@@ -172,64 +155,26 @@ public final class CardRulesPredicates {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
public static Predicate<CardRules> coreType(final String what) {
|
||||||
* Core type.
|
|
||||||
*
|
|
||||||
* @param isEqual
|
|
||||||
* the is equal
|
|
||||||
* @param what
|
|
||||||
* the what
|
|
||||||
* @return the predicate
|
|
||||||
*/
|
|
||||||
public static Predicate<CardRules> coreType(final boolean isEqual, final String what) {
|
|
||||||
try {
|
try {
|
||||||
return CardRulesPredicates.coreType(isEqual, Enum.valueOf(CardType.CoreType.class, what));
|
return CardRulesPredicates.coreType(Enum.valueOf(CardType.CoreType.class, what));
|
||||||
} catch (final Exception e) {
|
} catch (final Exception e) {
|
||||||
return x -> false;
|
return x -> false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Core type.
|
* @return a Predicate that matches cards that have the specified core type.
|
||||||
*
|
|
||||||
* @param isEqual
|
|
||||||
* the is equal
|
|
||||||
* @param type
|
|
||||||
* the type
|
|
||||||
* @return the predicate
|
|
||||||
*/
|
*/
|
||||||
public static Predicate<CardRules> coreType(final boolean isEqual, final CardType.CoreType type) {
|
public static Predicate<CardRules> coreType(final CardType.CoreType type) {
|
||||||
return new PredicateCoreType(type, isEqual);
|
return card -> card.getType().hasType(type);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Super type.
|
* @return a Predicate that matches cards that have the specified supertype.
|
||||||
*
|
|
||||||
* @param isEqual
|
|
||||||
* the is equal
|
|
||||||
* @param what
|
|
||||||
* the what
|
|
||||||
* @return the predicate
|
|
||||||
*/
|
*/
|
||||||
public static Predicate<CardRules> superType(final boolean isEqual, final String what) {
|
public static Predicate<CardRules> superType(final CardType.Supertype type) {
|
||||||
try {
|
return card -> card.getType().hasSupertype(type);
|
||||||
return CardRulesPredicates.superType(isEqual, Enum.valueOf(CardType.Supertype.class, what));
|
|
||||||
} catch (final Exception e) {
|
|
||||||
return x -> false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Super type.
|
|
||||||
*
|
|
||||||
* @param isEqual
|
|
||||||
* the is equal
|
|
||||||
* @param type
|
|
||||||
* the type
|
|
||||||
* @return the predicate
|
|
||||||
*/
|
|
||||||
public static Predicate<CardRules> superType(final boolean isEqual, final CardType.Supertype type) {
|
|
||||||
return new PredicateSuperType(type, isEqual);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -494,58 +439,12 @@ public final class CardRulesPredicates {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static class PredicateCoreType implements Predicate<CardRules> {
|
public static final Predicate<CardRules> IS_CREATURE = CardRulesPredicates.coreType(CardType.CoreType.Creature);
|
||||||
private final CardType.CoreType operand;
|
public static final Predicate<CardRules> IS_LEGENDARY = CardRulesPredicates.superType(CardType.Supertype.Legendary);
|
||||||
private final boolean shouldBeEqual;
|
public static final Predicate<CardRules> IS_ARTIFACT = CardRulesPredicates.coreType(CardType.CoreType.Artifact);
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean test(final CardRules card) {
|
|
||||||
if (null == card) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
return this.shouldBeEqual == card.getType().hasType(this.operand);
|
|
||||||
}
|
|
||||||
|
|
||||||
public PredicateCoreType(final CardType.CoreType type, final boolean wantEqual) {
|
|
||||||
this.operand = type;
|
|
||||||
this.shouldBeEqual = wantEqual;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private static class PredicateSuperType implements Predicate<CardRules> {
|
|
||||||
private final CardType.Supertype operand;
|
|
||||||
private final boolean shouldBeEqual;
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean test(final CardRules card) {
|
|
||||||
return this.shouldBeEqual == card.getType().hasSupertype(this.operand);
|
|
||||||
}
|
|
||||||
|
|
||||||
public PredicateSuperType(final CardType.Supertype type, final boolean wantEqual) {
|
|
||||||
this.operand = type;
|
|
||||||
this.shouldBeEqual = wantEqual;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private static class PredicateSplitType implements Predicate<CardRules> {
|
|
||||||
private final CardSplitType cst;
|
|
||||||
|
|
||||||
public PredicateSplitType(final CardSplitType type) {
|
|
||||||
cst = type;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean test(final CardRules subject) {
|
|
||||||
return subject.getSplitType() == cst;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static final Predicate<CardRules> IS_CREATURE = CardRulesPredicates.coreType(true, CardType.CoreType.Creature);
|
|
||||||
public static final Predicate<CardRules> IS_LEGENDARY = CardRulesPredicates.superType(true, CardType.Supertype.Legendary);
|
|
||||||
public static final Predicate<CardRules> IS_ARTIFACT = CardRulesPredicates.coreType(true, CardType.CoreType.Artifact);
|
|
||||||
public static final Predicate<CardRules> IS_ATTRACTION = CardRulesPredicates.IS_ARTIFACT.and(CardRulesPredicates.subType("Attraction"));
|
public static final Predicate<CardRules> IS_ATTRACTION = CardRulesPredicates.IS_ARTIFACT.and(CardRulesPredicates.subType("Attraction"));
|
||||||
public static final Predicate<CardRules> IS_EQUIPMENT = CardRulesPredicates.subType("Equipment");
|
public static final Predicate<CardRules> IS_EQUIPMENT = CardRulesPredicates.subType("Equipment");
|
||||||
public static final Predicate<CardRules> IS_LAND = CardRulesPredicates.coreType(true, CardType.CoreType.Land);
|
public static final Predicate<CardRules> IS_LAND = CardRulesPredicates.coreType(CardType.CoreType.Land);
|
||||||
public static final Predicate<CardRules> IS_BASIC_LAND = subject -> subject.getType().isBasicLand();
|
public static final Predicate<CardRules> IS_BASIC_LAND = subject -> subject.getType().isBasicLand();
|
||||||
public static final Predicate<CardRules> NOT_BASIC_LAND = subject -> !subject.getType().isBasicLand();
|
public static final Predicate<CardRules> NOT_BASIC_LAND = subject -> !subject.getType().isBasicLand();
|
||||||
/** Matches only Plains, Island, Swamp, Mountain, or Forest. */
|
/** Matches only Plains, Island, Swamp, Mountain, or Forest. */
|
||||||
@@ -557,25 +456,25 @@ public final class CardRulesPredicates {
|
|||||||
public static final Predicate<CardRules> CAN_BE_PARTNER_COMMANDER = CardRules::canBePartnerCommander;
|
public static final Predicate<CardRules> CAN_BE_PARTNER_COMMANDER = CardRules::canBePartnerCommander;
|
||||||
public static final Predicate<CardRules> CAN_BE_OATHBREAKER = CardRules::canBeOathbreaker;
|
public static final Predicate<CardRules> CAN_BE_OATHBREAKER = CardRules::canBeOathbreaker;
|
||||||
public static final Predicate<CardRules> CAN_BE_SIGNATURE_SPELL = CardRules::canBeSignatureSpell;
|
public static final Predicate<CardRules> CAN_BE_SIGNATURE_SPELL = CardRules::canBeSignatureSpell;
|
||||||
public static final Predicate<CardRules> IS_PLANESWALKER = CardRulesPredicates.coreType(true, CardType.CoreType.Planeswalker);
|
public static final Predicate<CardRules> IS_PLANESWALKER = CardRulesPredicates.coreType(CardType.CoreType.Planeswalker);
|
||||||
public static final Predicate<CardRules> CAN_BE_TINY_LEADERS_COMMANDER = CardRulesPredicates.IS_LEGENDARY.and(CardRulesPredicates.IS_CREATURE.or(CardRulesPredicates.IS_PLANESWALKER));
|
public static final Predicate<CardRules> CAN_BE_TINY_LEADERS_COMMANDER = CardRulesPredicates.IS_LEGENDARY.and(CardRulesPredicates.IS_CREATURE.or(CardRulesPredicates.IS_PLANESWALKER));
|
||||||
public static final Predicate<CardRules> CAN_BE_BRAWL_COMMANDER = CardRulesPredicates.IS_LEGENDARY.and(CardRulesPredicates.IS_CREATURE.or(CardRulesPredicates.IS_PLANESWALKER));
|
public static final Predicate<CardRules> CAN_BE_BRAWL_COMMANDER = CardRulesPredicates.IS_LEGENDARY.and(CardRulesPredicates.IS_CREATURE.or(CardRulesPredicates.IS_PLANESWALKER));
|
||||||
public static final Predicate<CardRules> IS_BATTLE = CardRulesPredicates.coreType(true, CardType.CoreType.Battle);
|
public static final Predicate<CardRules> IS_BATTLE = CardRulesPredicates.coreType(CardType.CoreType.Battle);
|
||||||
public static final Predicate<CardRules> IS_INSTANT = CardRulesPredicates.coreType(true, CardType.CoreType.Instant);
|
public static final Predicate<CardRules> IS_INSTANT = CardRulesPredicates.coreType(CardType.CoreType.Instant);
|
||||||
public static final Predicate<CardRules> IS_SORCERY = CardRulesPredicates.coreType(true, CardType.CoreType.Sorcery);
|
public static final Predicate<CardRules> IS_SORCERY = CardRulesPredicates.coreType(CardType.CoreType.Sorcery);
|
||||||
public static final Predicate<CardRules> IS_ENCHANTMENT = CardRulesPredicates.coreType(true, CardType.CoreType.Enchantment);
|
public static final Predicate<CardRules> IS_ENCHANTMENT = CardRulesPredicates.coreType(CardType.CoreType.Enchantment);
|
||||||
public static final Predicate<CardRules> IS_NON_CREATURE_SPELL = (
|
public static final Predicate<CardRules> IS_NON_CREATURE_SPELL = (
|
||||||
CardRulesPredicates.IS_CREATURE.or(CardRulesPredicates.IS_LAND).or(CardRules::isVariant)
|
CardRulesPredicates.IS_CREATURE.or(CardRulesPredicates.IS_LAND).or(CardRules::isVariant)
|
||||||
).negate();
|
).negate();
|
||||||
|
|
||||||
public static final Predicate<CardRules> IS_PLANE = CardRulesPredicates.coreType(true, CardType.CoreType.Plane);
|
public static final Predicate<CardRules> IS_PLANE = CardRulesPredicates.coreType(CardType.CoreType.Plane);
|
||||||
public static final Predicate<CardRules> IS_PHENOMENON = CardRulesPredicates.coreType(true, CardType.CoreType.Phenomenon);
|
public static final Predicate<CardRules> IS_PHENOMENON = CardRulesPredicates.coreType(CardType.CoreType.Phenomenon);
|
||||||
public static final Predicate<CardRules> IS_PLANE_OR_PHENOMENON = IS_PLANE.or(IS_PHENOMENON);
|
public static final Predicate<CardRules> IS_PLANE_OR_PHENOMENON = IS_PLANE.or(IS_PHENOMENON);
|
||||||
public static final Predicate<CardRules> IS_SCHEME = CardRulesPredicates.coreType(true, CardType.CoreType.Scheme);
|
public static final Predicate<CardRules> IS_SCHEME = CardRulesPredicates.coreType(CardType.CoreType.Scheme);
|
||||||
public static final Predicate<CardRules> IS_VANGUARD = CardRulesPredicates.coreType(true, CardType.CoreType.Vanguard);
|
public static final Predicate<CardRules> IS_VANGUARD = CardRulesPredicates.coreType(CardType.CoreType.Vanguard);
|
||||||
public static final Predicate<CardRules> IS_CONSPIRACY = CardRulesPredicates.coreType(true, CardType.CoreType.Conspiracy);
|
public static final Predicate<CardRules> IS_CONSPIRACY = CardRulesPredicates.coreType(CardType.CoreType.Conspiracy);
|
||||||
public static final Predicate<CardRules> IS_DUNGEON = CardRulesPredicates.coreType(true, CardType.CoreType.Dungeon);
|
public static final Predicate<CardRules> IS_DUNGEON = CardRulesPredicates.coreType(CardType.CoreType.Dungeon);
|
||||||
public static final Predicate<CardRules> IS_NON_LAND = CardRulesPredicates.coreType(false, CardType.CoreType.Land);
|
public static final Predicate<CardRules> IS_NON_LAND = CardRulesPredicates.coreType(CardType.CoreType.Land);
|
||||||
public static final Predicate<CardRules> IS_WHITE = CardRulesPredicates.isColor(MagicColor.WHITE);
|
public static final Predicate<CardRules> IS_WHITE = CardRulesPredicates.isColor(MagicColor.WHITE);
|
||||||
public static final Predicate<CardRules> IS_BLUE = CardRulesPredicates.isColor(MagicColor.BLUE);
|
public static final Predicate<CardRules> IS_BLUE = CardRulesPredicates.isColor(MagicColor.BLUE);
|
||||||
public static final Predicate<CardRules> IS_BLACK = CardRulesPredicates.isColor(MagicColor.BLACK);
|
public static final Predicate<CardRules> IS_BLACK = CardRulesPredicates.isColor(MagicColor.BLACK);
|
||||||
|
|||||||
@@ -2,6 +2,8 @@ package forge.card;
|
|||||||
|
|
||||||
import forge.card.CardFace.FaceSelectionMethod;
|
import forge.card.CardFace.FaceSelectionMethod;
|
||||||
|
|
||||||
|
import java.util.EnumSet;
|
||||||
|
|
||||||
public enum CardSplitType
|
public enum CardSplitType
|
||||||
{
|
{
|
||||||
None(FaceSelectionMethod.USE_PRIMARY_FACE, null),
|
None(FaceSelectionMethod.USE_PRIMARY_FACE, null),
|
||||||
@@ -13,6 +15,9 @@ public enum CardSplitType
|
|||||||
Modal(FaceSelectionMethod.USE_ACTIVE_FACE, CardStateName.Modal),
|
Modal(FaceSelectionMethod.USE_ACTIVE_FACE, CardStateName.Modal),
|
||||||
Specialize(FaceSelectionMethod.USE_ACTIVE_FACE, null);
|
Specialize(FaceSelectionMethod.USE_ACTIVE_FACE, null);
|
||||||
|
|
||||||
|
public static final EnumSet<CardSplitType> DUAL_FACED_CARDS = EnumSet.of(
|
||||||
|
CardSplitType.Transform, CardSplitType.Meld, CardSplitType.Modal);
|
||||||
|
|
||||||
CardSplitType(FaceSelectionMethod calcMode, CardStateName stateName) {
|
CardSplitType(FaceSelectionMethod calcMode, CardStateName stateName) {
|
||||||
method = calcMode;
|
method = calcMode;
|
||||||
this.changedStateName = stateName;
|
this.changedStateName = stateName;
|
||||||
|
|||||||
@@ -94,7 +94,7 @@ public interface ICardDatabase extends Iterable<PaperCard> {
|
|||||||
int getMaxArtIndex(String cardName);
|
int getMaxArtIndex(String cardName);
|
||||||
int getArtCount(String cardName, String edition);
|
int getArtCount(String cardName, String edition);
|
||||||
// Utility Predicates
|
// Utility Predicates
|
||||||
Predicate<? super PaperCard> wasPrintedInSets(List<String> allowedSetCodes);
|
Predicate<? super PaperCard> wasPrintedInSets(Collection<String> allowedSetCodes);
|
||||||
Predicate<? super PaperCard> isLegal(List<String> allowedSetCodes);
|
Predicate<? super PaperCard> isLegal(Collection<String> allowedSetCodes);
|
||||||
Predicate<? super PaperCard> wasPrintedAtRarity(CardRarity rarity);
|
Predicate<? super PaperCard> wasPrintedAtRarity(CardRarity rarity);
|
||||||
}
|
}
|
||||||
@@ -387,7 +387,7 @@ public abstract class DeckGeneratorBase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
//filter to provide all dual lands from pool matching 2 or 3 colors from current deck
|
//filter to provide all dual lands from pool matching 2 or 3 colors from current deck
|
||||||
Predicate<CardRules> dualLandFilter = CardRulesPredicates.coreType(true, CardType.CoreType.Land);
|
Predicate<CardRules> dualLandFilter = CardRulesPredicates.coreType(CardType.CoreType.Land);
|
||||||
Predicate<CardRules> exceptBasicLand = CardRulesPredicates.NOT_BASIC_LAND;
|
Predicate<CardRules> exceptBasicLand = CardRulesPredicates.NOT_BASIC_LAND;
|
||||||
|
|
||||||
Iterable<PaperCard> landCards = pool.getAllCards(PaperCardPredicates.fromRules(dualLandFilter.and(exceptBasicLand).and(canPlay)));
|
Iterable<PaperCard> landCards = pool.getAllCards(PaperCardPredicates.fromRules(dualLandFilter.and(exceptBasicLand).and(canPlay)));
|
||||||
|
|||||||
@@ -2,7 +2,6 @@ package forge.item;
|
|||||||
|
|
||||||
import com.google.common.collect.Lists;
|
import com.google.common.collect.Lists;
|
||||||
import forge.card.*;
|
import forge.card.*;
|
||||||
import forge.util.PredicateCard;
|
|
||||||
import forge.util.PredicateString;
|
import forge.util.PredicateString;
|
||||||
import org.apache.commons.lang3.StringUtils;
|
import org.apache.commons.lang3.StringUtils;
|
||||||
|
|
||||||
@@ -15,13 +14,6 @@ import java.util.function.Predicate;
|
|||||||
* Filters based on PaperCard values.
|
* Filters based on PaperCard values.
|
||||||
*/
|
*/
|
||||||
public abstract class PaperCardPredicates {
|
public abstract class PaperCardPredicates {
|
||||||
public static Predicate<PaperCard> rarity(final boolean isEqual, final CardRarity value) {
|
|
||||||
return new PredicateRarity(value, isEqual);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static Predicate<PaperCard> color(final boolean isEqual, final boolean noColor, final byte value) {
|
|
||||||
return new PredicateColor(value, noColor, isEqual);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static Predicate<PaperCard> printedInSets(final String[] sets) {
|
public static Predicate<PaperCard> printedInSets(final String[] sets) {
|
||||||
return printedInSets(Lists.newArrayList(sets), true);
|
return printedInSets(Lists.newArrayList(sets), true);
|
||||||
@@ -42,70 +34,50 @@ public abstract class PaperCardPredicates {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static Predicate<PaperCard> name(final String what) {
|
public static Predicate<PaperCard> name(final String what) {
|
||||||
return new PredicateName(PredicateString.StringOp.EQUALS_IC, what);
|
return new PredicateName(what);
|
||||||
}
|
|
||||||
|
|
||||||
public static Predicate<PaperCard> name(final PredicateString.StringOp op, final String what) {
|
|
||||||
return new PredicateName(op, what);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Predicate<PaperCard> names(final List<String> what) {
|
public static Predicate<PaperCard> names(final List<String> what) {
|
||||||
return new PredicateNames(what);
|
return new PredicateNames(what);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Predicate<PaperCard> cards(final List<PaperCard> what) {
|
|
||||||
return new PredicateCards(what);
|
|
||||||
}
|
|
||||||
|
|
||||||
private static final class PredicateColor implements Predicate<PaperCard> {
|
private static final class PredicateColor implements Predicate<PaperCard> {
|
||||||
|
|
||||||
private final byte operand;
|
private final byte operand;
|
||||||
private final boolean noColor;
|
|
||||||
private final boolean shouldBeEqual;
|
|
||||||
|
|
||||||
private PredicateColor(final byte color, final boolean noColor, final boolean wantEqual) {
|
private PredicateColor(final byte color) {
|
||||||
this.operand = color;
|
this.operand = color;
|
||||||
this.noColor = noColor;
|
|
||||||
this.shouldBeEqual = wantEqual;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean test(final PaperCard card) {
|
public boolean test(final PaperCard card) {
|
||||||
boolean colorFound = false;
|
|
||||||
if (noColor) {
|
|
||||||
return card.getRules().getColor().isColorless() == shouldBeEqual;
|
|
||||||
}
|
|
||||||
for (final byte color : card.getRules().getColor()) {
|
for (final byte color : card.getRules().getColor()) {
|
||||||
if (color == operand) {
|
if (color == operand) {
|
||||||
colorFound = true;
|
return true;
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (card.getRules().getType().hasType(CardType.CoreType.Land)) {
|
if (card.getRules().getType().hasType(CardType.CoreType.Land)) {
|
||||||
for (final byte color : card.getRules().getColorIdentity()) {
|
for (final byte color : card.getRules().getColorIdentity()) {
|
||||||
if (color == operand) {
|
if (color == operand) {
|
||||||
colorFound = true;
|
return true;
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return colorFound == shouldBeEqual;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private static final class PredicateRarity implements Predicate<PaperCard> {
|
private static final class PredicateRarity implements Predicate<PaperCard> {
|
||||||
private final CardRarity operand;
|
private final CardRarity operand;
|
||||||
private final boolean shouldBeEqual;
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean test(final PaperCard card) {
|
public boolean test(final PaperCard card) {
|
||||||
return (card.getRarity() == this.operand) == this.shouldBeEqual;
|
return (card.getRarity() == this.operand);
|
||||||
}
|
}
|
||||||
|
|
||||||
private PredicateRarity(final CardRarity type, final boolean wantEqual) {
|
private PredicateRarity(final CardRarity type) {
|
||||||
this.operand = type;
|
this.operand = type;
|
||||||
this.shouldBeEqual = wantEqual;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -132,8 +104,8 @@ public abstract class PaperCardPredicates {
|
|||||||
return this.op(card.getName(), this.operand);
|
return this.op(card.getName(), this.operand);
|
||||||
}
|
}
|
||||||
|
|
||||||
private PredicateName(final StringOp operator, final String operand) {
|
private PredicateName(final String operand) {
|
||||||
super(operator);
|
super(StringOp.EQUALS_IC);
|
||||||
this.operand = operand;
|
this.operand = operand;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -158,42 +130,23 @@ public abstract class PaperCardPredicates {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static final class PredicateCards extends PredicateCard<PaperCard> {
|
|
||||||
private final List<PaperCard> operand;
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean test(final PaperCard card) {
|
|
||||||
for (final PaperCard element : this.operand) {
|
|
||||||
if (this.op(card, element)) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
private PredicateCards(final List<PaperCard> operand) {
|
|
||||||
super(StringOp.EQUALS);
|
|
||||||
this.operand = operand;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static Predicate<PaperCard> fromRules(Predicate<CardRules> cardRulesPredicate) {
|
public static Predicate<PaperCard> fromRules(Predicate<CardRules> cardRulesPredicate) {
|
||||||
return paperCard -> cardRulesPredicate.test(paperCard.getRules());
|
return paperCard -> cardRulesPredicate.test(paperCard.getRules());
|
||||||
}
|
}
|
||||||
|
|
||||||
public static final Predicate<PaperCard> IS_COMMON = PaperCardPredicates.rarity(true, CardRarity.Common);
|
public static final Predicate<PaperCard> IS_COMMON = new PredicateRarity(CardRarity.Common);
|
||||||
public static final Predicate<PaperCard> IS_UNCOMMON = PaperCardPredicates.rarity(true, CardRarity.Uncommon);
|
public static final Predicate<PaperCard> IS_UNCOMMON = new PredicateRarity(CardRarity.Uncommon);
|
||||||
public static final Predicate<PaperCard> IS_RARE = PaperCardPredicates.rarity(true, CardRarity.Rare);
|
public static final Predicate<PaperCard> IS_RARE = new PredicateRarity(CardRarity.Rare);
|
||||||
public static final Predicate<PaperCard> IS_MYTHIC_RARE = PaperCardPredicates.rarity(true, CardRarity.MythicRare);
|
public static final Predicate<PaperCard> IS_MYTHIC_RARE = new PredicateRarity(CardRarity.MythicRare);
|
||||||
public static final Predicate<PaperCard> IS_RARE_OR_MYTHIC = PaperCardPredicates.IS_RARE.or(PaperCardPredicates.IS_MYTHIC_RARE);
|
public static final Predicate<PaperCard> IS_RARE_OR_MYTHIC = PaperCardPredicates.IS_RARE.or(PaperCardPredicates.IS_MYTHIC_RARE);
|
||||||
public static final Predicate<PaperCard> IS_SPECIAL = PaperCardPredicates.rarity(true, CardRarity.Special);
|
public static final Predicate<PaperCard> IS_SPECIAL = new PredicateRarity(CardRarity.Special);
|
||||||
public static final Predicate<PaperCard> IS_BASIC_LAND_RARITY = PaperCardPredicates.rarity(true, CardRarity.BasicLand);
|
public static final Predicate<PaperCard> IS_BASIC_LAND_RARITY = new PredicateRarity(CardRarity.BasicLand);
|
||||||
public static final Predicate<PaperCard> IS_BLACK = PaperCardPredicates.color(true, false, MagicColor.BLACK);
|
public static final Predicate<PaperCard> IS_BLACK = new PredicateColor(MagicColor.BLACK);
|
||||||
public static final Predicate<PaperCard> IS_BLUE = PaperCardPredicates.color(true, false, MagicColor.BLUE);
|
public static final Predicate<PaperCard> IS_BLUE = new PredicateColor(MagicColor.BLUE);
|
||||||
public static final Predicate<PaperCard> IS_GREEN = PaperCardPredicates.color(true, false, MagicColor.GREEN);
|
public static final Predicate<PaperCard> IS_GREEN = new PredicateColor(MagicColor.GREEN);
|
||||||
public static final Predicate<PaperCard> IS_RED = PaperCardPredicates.color(true, false, MagicColor.RED);
|
public static final Predicate<PaperCard> IS_RED = new PredicateColor(MagicColor.RED);
|
||||||
public static final Predicate<PaperCard> IS_WHITE = PaperCardPredicates.color(true, false, MagicColor.WHITE);
|
public static final Predicate<PaperCard> IS_WHITE = new PredicateColor(MagicColor.WHITE);
|
||||||
public static final Predicate<PaperCard> IS_COLORLESS = PaperCardPredicates.color(true, true, MagicColor.COLORLESS);
|
public static final Predicate<PaperCard> IS_COLORLESS = paperCard -> paperCard.getRules().getColor().isColorless();
|
||||||
public static final Predicate<PaperCard> IS_UNREBALANCED = PaperCard::isUnRebalanced;
|
public static final Predicate<PaperCard> IS_UNREBALANCED = PaperCard::isUnRebalanced;
|
||||||
public static final Predicate<PaperCard> IS_REBALANCED = PaperCard::isRebalanced;
|
public static final Predicate<PaperCard> IS_REBALANCED = PaperCard::isRebalanced;
|
||||||
|
|
||||||
|
|||||||
@@ -673,11 +673,7 @@ public class BoosterGenerator {
|
|||||||
|
|
||||||
Predicate<PaperCard> toAdd = null;
|
Predicate<PaperCard> toAdd = null;
|
||||||
if (operator.equalsIgnoreCase(BoosterSlots.DUAL_FACED_CARD)) {
|
if (operator.equalsIgnoreCase(BoosterSlots.DUAL_FACED_CARD)) {
|
||||||
toAdd = PaperCardPredicates.fromRules(
|
toAdd = card -> CardSplitType.DUAL_FACED_CARDS.contains(card.getRules().getSplitType());
|
||||||
CardRulesPredicates.splitType(CardSplitType.Transform)
|
|
||||||
.or(CardRulesPredicates.splitType(CardSplitType.Meld))
|
|
||||||
.or(CardRulesPredicates.splitType(CardSplitType.Modal)
|
|
||||||
));
|
|
||||||
} else if (operator.equalsIgnoreCase(BoosterSlots.LAND)) { toAdd = PaperCardPredicates.IS_LAND;
|
} else if (operator.equalsIgnoreCase(BoosterSlots.LAND)) { toAdd = PaperCardPredicates.IS_LAND;
|
||||||
} else if (operator.equalsIgnoreCase(BoosterSlots.BASIC_LAND)) { toAdd = PaperCardPredicates.IS_BASIC_LAND_RARITY;
|
} else if (operator.equalsIgnoreCase(BoosterSlots.BASIC_LAND)) { toAdd = PaperCardPredicates.IS_BASIC_LAND_RARITY;
|
||||||
} else if (operator.equalsIgnoreCase(BoosterSlots.TIME_SHIFTED)) { toAdd = PaperCardPredicates.IS_SPECIAL;
|
} else if (operator.equalsIgnoreCase(BoosterSlots.TIME_SHIFTED)) { toAdd = PaperCardPredicates.IS_SPECIAL;
|
||||||
@@ -718,8 +714,8 @@ public class BoosterGenerator {
|
|||||||
toAdd = PaperCardPredicates.printedInSets(sets);
|
toAdd = PaperCardPredicates.printedInSets(sets);
|
||||||
} else if (operator.startsWith("fromSheet(") && invert) {
|
} else if (operator.startsWith("fromSheet(") && invert) {
|
||||||
String sheetName = StringUtils.strip(operator.substring(9), "()\" ");
|
String sheetName = StringUtils.strip(operator.substring(9), "()\" ");
|
||||||
Iterable<PaperCard> cards = StaticData.instance().getPrintSheets().get(sheetName).toFlatList();
|
Set<PaperCard> cards = Sets.newHashSet(StaticData.instance().getPrintSheets().get(sheetName).toFlatList());
|
||||||
toAdd = PaperCardPredicates.cards(Lists.newArrayList(cards));
|
toAdd = cards::contains;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (toAdd == null) {
|
if (toAdd == null) {
|
||||||
|
|||||||
@@ -1,83 +0,0 @@
|
|||||||
/*
|
|
||||||
* Forge: Play Magic: the Gathering.
|
|
||||||
* Copyright (C) 2020 Jamin W. Collins
|
|
||||||
*
|
|
||||||
* This program is free software: you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU General Public License as published by
|
|
||||||
* the Free Software Foundation, either version 3 of the License, or
|
|
||||||
* (at your option) any later version.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License
|
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
package forge.util;
|
|
||||||
|
|
||||||
import forge.item.PaperCard;
|
|
||||||
|
|
||||||
import java.util.function.Predicate;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Special predicate class to perform string operations.
|
|
||||||
*
|
|
||||||
* @param <T>
|
|
||||||
* the generic type
|
|
||||||
*/
|
|
||||||
public abstract class PredicateCard<T> implements Predicate<T> {
|
|
||||||
/** Possible operators for string operands. */
|
|
||||||
public enum StringOp {
|
|
||||||
/** The EQUALS. */
|
|
||||||
EQUALS,
|
|
||||||
}
|
|
||||||
|
|
||||||
/** The operator. */
|
|
||||||
private final StringOp operator;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Op.
|
|
||||||
*
|
|
||||||
* @param op1
|
|
||||||
* the op1
|
|
||||||
* @param op2
|
|
||||||
* the op2
|
|
||||||
* @return true, if successful
|
|
||||||
*/
|
|
||||||
protected final boolean op(final PaperCard op1, final PaperCard op2) {
|
|
||||||
switch (this.getOperator()) {
|
|
||||||
case EQUALS:
|
|
||||||
return op1.equals(op2);
|
|
||||||
default:
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Instantiates a new predicate string.
|
|
||||||
*
|
|
||||||
* @param operator
|
|
||||||
* the operator
|
|
||||||
*/
|
|
||||||
public PredicateCard(final StringOp operator) {
|
|
||||||
this.operator = operator;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @return the operator
|
|
||||||
*/
|
|
||||||
public StringOp getOperator() {
|
|
||||||
return operator;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static PredicateCard<PaperCard> equals(final PaperCard what) {
|
|
||||||
return new PredicateCard<PaperCard>(StringOp.EQUALS) {
|
|
||||||
public boolean test(PaperCard subject) {
|
|
||||||
return op(subject, what);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -84,7 +84,7 @@ public class LimitedDeckBuilder extends DeckGeneratorBase {
|
|||||||
|
|
||||||
// keep Conspiracies in a separate list
|
// keep Conspiracies in a separate list
|
||||||
this.draftedConspiracies = aiPlayables.stream()
|
this.draftedConspiracies = aiPlayables.stream()
|
||||||
.filter(PaperCardPredicates.fromRules(CardRulesPredicates.coreType(true, "Conspiracy")))
|
.filter(PaperCardPredicates.fromRules(CardRulesPredicates.IS_CONSPIRACY))
|
||||||
.collect(Collectors.toList());
|
.collect(Collectors.toList());
|
||||||
this.aiPlayables.removeAll(draftedConspiracies);
|
this.aiPlayables.removeAll(draftedConspiracies);
|
||||||
|
|
||||||
|
|||||||
@@ -465,7 +465,7 @@ public final class QuestUtilCards {
|
|||||||
public static Predicate<CardEdition> isLegalInQuestFormat(final GameFormatQuest qFormat) {
|
public static Predicate<CardEdition> isLegalInQuestFormat(final GameFormatQuest qFormat) {
|
||||||
if(qFormat == null)
|
if(qFormat == null)
|
||||||
return x -> true;
|
return x -> true;
|
||||||
return GameFormatQuest.QPredicates.isLegalInFormatQuest(qFormat);
|
return edition -> qFormat.isSetLegal(edition.getCode());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -162,30 +162,4 @@ public final class GameFormatQuest extends GameFormat {
|
|||||||
return unlocksUsed;
|
return unlocksUsed;
|
||||||
}
|
}
|
||||||
|
|
||||||
public abstract static class QPredicates {
|
|
||||||
/**
|
|
||||||
* Checks if is legal in quest format.
|
|
||||||
*
|
|
||||||
* @param qFormat the format
|
|
||||||
* @return the predicate
|
|
||||||
*/
|
|
||||||
public static Predicate<CardEdition> isLegalInFormatQuest(final GameFormatQuest qFormat) {
|
|
||||||
return new LegalInFormatQuest(qFormat);
|
|
||||||
}
|
|
||||||
|
|
||||||
private static final class LegalInFormatQuest implements Predicate<CardEdition> {
|
|
||||||
private final GameFormatQuest qFormat;
|
|
||||||
|
|
||||||
private LegalInFormatQuest(final GameFormatQuest fmt) {
|
|
||||||
this.qFormat = fmt;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean test(final CardEdition subject) {
|
|
||||||
return this.qFormat.isSetLegal(subject.getCode());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user