mirror of
https://github.com/Card-Forge/forge.git
synced 2025-11-16 10:48:00 +00:00
Guava migration - Inline Predicates.or
This commit is contained in:
@@ -44,7 +44,6 @@ import forge.game.trigger.Trigger;
|
|||||||
import forge.game.trigger.TriggerType;
|
import forge.game.trigger.TriggerType;
|
||||||
import forge.game.zone.ZoneType;
|
import forge.game.zone.ZoneType;
|
||||||
import forge.util.MyRandom;
|
import forge.util.MyRandom;
|
||||||
import forge.util.Predicates;
|
|
||||||
import forge.util.collect.FCollectionView;
|
import forge.util.collect.FCollectionView;
|
||||||
|
|
||||||
|
|
||||||
@@ -326,7 +325,7 @@ public class AiBlockController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private Predicate<Card> rampagesOrNeedsManyToBlock(final Combat combat) {
|
private Predicate<Card> rampagesOrNeedsManyToBlock(final Combat combat) {
|
||||||
return Predicates.or(CardPredicates.hasKeyword(Keyword.RAMPAGE), input -> {
|
return CardPredicates.hasKeyword(Keyword.RAMPAGE).or(input -> {
|
||||||
// select creature that has a max blocker
|
// select creature that has a max blocker
|
||||||
return StaticAbilityCantAttackBlock.getMinMaxBlocker(input, combat.getDefenderPlayerByAttacker(input)).getRight() < Integer.MAX_VALUE;
|
return StaticAbilityCantAttackBlock.getMinMaxBlocker(input, combat.getDefenderPlayerByAttacker(input)).getRight() < Integer.MAX_VALUE;
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -1578,7 +1578,7 @@ public class AiController {
|
|||||||
if (sa.getHostCard().hasKeyword(Keyword.STORM)
|
if (sa.getHostCard().hasKeyword(Keyword.STORM)
|
||||||
&& sa.getApi() != ApiType.Counter // AI would suck at trying to deliberately proc a Storm counterspell
|
&& sa.getApi() != ApiType.Counter // AI would suck at trying to deliberately proc a Storm counterspell
|
||||||
&& player.getZone(ZoneType.Hand).contains(
|
&& player.getZone(ZoneType.Hand).contains(
|
||||||
Predicates.or(Presets.LANDS, CardPredicates.hasKeyword("Storm")).negate())) {
|
Presets.LANDS.or(CardPredicates.hasKeyword("Storm")).negate())) {
|
||||||
if (game.getView().getStormCount() < this.getIntProperty(AiProps.MIN_COUNT_FOR_STORM_SPELLS)) {
|
if (game.getView().getStormCount() < this.getIntProperty(AiProps.MIN_COUNT_FOR_STORM_SPELLS)) {
|
||||||
// skip evaluating Storm unless we reached the minimum Storm count
|
// skip evaluating Storm unless we reached the minimum Storm count
|
||||||
continue;
|
continue;
|
||||||
|
|||||||
@@ -2801,8 +2801,7 @@ public class ComputerUtil {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// has cards with SacMe or Token
|
// has cards with SacMe or Token
|
||||||
if (CardLists.count(aiCreatures,
|
if (CardLists.count(aiCreatures, CardPredicates.hasSVar("SacMe").or(Presets.TOKEN)) >= numDeath) {
|
||||||
Predicates.or(CardPredicates.hasSVar("SacMe"), CardPredicates.Presets.TOKEN)) >= numDeath) {
|
|
||||||
return "Death";
|
return "Death";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -505,7 +505,7 @@ public class ComputerUtilCard {
|
|||||||
|
|
||||||
if (hasEnchantmants || hasArtifacts) {
|
if (hasEnchantmants || hasArtifacts) {
|
||||||
final List<Card> ae = CardLists.filter(list,
|
final List<Card> ae = CardLists.filter(list,
|
||||||
Predicates.or(CardPredicates.Presets.ARTIFACTS, CardPredicates.Presets.ENCHANTMENTS)
|
(CardPredicates.Presets.ARTIFACTS.or(CardPredicates.Presets.ENCHANTMENTS))
|
||||||
.and(card -> !card.hasSVar("DoNotDiscardIfAble"))
|
.and(card -> !card.hasSVar("DoNotDiscardIfAble"))
|
||||||
);
|
);
|
||||||
return getCheapestPermanentAI(ae, null, false);
|
return getCheapestPermanentAI(ae, null, false);
|
||||||
@@ -522,7 +522,7 @@ public class ComputerUtilCard {
|
|||||||
public static final Card getCheapestSpellAI(final Iterable<Card> list) {
|
public static final Card getCheapestSpellAI(final Iterable<Card> list) {
|
||||||
if (!Iterables.isEmpty(list)) {
|
if (!Iterables.isEmpty(list)) {
|
||||||
CardCollection cc = CardLists.filter(list,
|
CardCollection cc = CardLists.filter(list,
|
||||||
Predicates.or(CardPredicates.isType("Instant"), CardPredicates.isType("Sorcery")));
|
CardPredicates.isType("Instant").or(CardPredicates.isType("Sorcery")));
|
||||||
|
|
||||||
if (cc.isEmpty()) {
|
if (cc.isEmpty()) {
|
||||||
return null;
|
return null;
|
||||||
|
|||||||
@@ -52,7 +52,6 @@ import org.apache.commons.lang3.tuple.Pair;
|
|||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.function.Predicate;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Special logic for individual cards
|
* Special logic for individual cards
|
||||||
@@ -156,8 +155,8 @@ public class SpecialCardAi {
|
|||||||
}
|
}
|
||||||
int libsize = ai.getCardsIn(ZoneType.Library).size();
|
int libsize = ai.getCardsIn(ZoneType.Library).size();
|
||||||
|
|
||||||
final CardCollection hand = CardLists.filter(ai.getCardsIn(ZoneType.Hand), Predicates.or(
|
final CardCollection hand = CardLists.filter(ai.getCardsIn(ZoneType.Hand),
|
||||||
CardPredicates.isType("Instant"), CardPredicates.isType("Sorcery")));
|
CardPredicates.isType("Instant").or(CardPredicates.isType("Sorcery")));
|
||||||
if (!hand.isEmpty()) {
|
if (!hand.isEmpty()) {
|
||||||
// has spell that can be cast in hand with put ability
|
// has spell that can be cast in hand with put ability
|
||||||
if (Iterables.any(hand, CardPredicates.hasCMC(counterNum + 1))) {
|
if (Iterables.any(hand, CardPredicates.hasCMC(counterNum + 1))) {
|
||||||
@@ -169,8 +168,8 @@ public class SpecialCardAi {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
final CardCollection library = CardLists.filter(ai.getCardsIn(ZoneType.Library), Predicates.or(
|
final CardCollection library = CardLists.filter(ai.getCardsIn(ZoneType.Library),
|
||||||
CardPredicates.isType("Instant"), CardPredicates.isType("Sorcery")));
|
CardPredicates.isType("Instant").or(CardPredicates.isType("Sorcery")));
|
||||||
if (!library.isEmpty()) {
|
if (!library.isEmpty()) {
|
||||||
// get max cmc of instant or sorceries in the libary
|
// get max cmc of instant or sorceries in the libary
|
||||||
int maxCMC = 0;
|
int maxCMC = 0;
|
||||||
@@ -360,8 +359,8 @@ public class SpecialCardAi {
|
|||||||
|
|
||||||
public static boolean considerSacrificingCreature(final Player ai, final SpellAbility sa) {
|
public static boolean considerSacrificingCreature(final Player ai, final SpellAbility sa) {
|
||||||
CardCollection flyingCreatures = CardLists.filter(ai.getCardsIn(ZoneType.Battlefield),
|
CardCollection flyingCreatures = CardLists.filter(ai.getCardsIn(ZoneType.Battlefield),
|
||||||
CardPredicates.Presets.UNTAPPED.and(Predicates.or(
|
CardPredicates.Presets.UNTAPPED.and(
|
||||||
CardPredicates.hasKeyword(Keyword.FLYING), CardPredicates.hasKeyword(Keyword.REACH))));
|
CardPredicates.hasKeyword(Keyword.FLYING).or(CardPredicates.hasKeyword(Keyword.REACH))));
|
||||||
boolean hasUsefulBlocker = false;
|
boolean hasUsefulBlocker = false;
|
||||||
|
|
||||||
for (Card c : flyingCreatures) {
|
for (Card c : flyingCreatures) {
|
||||||
@@ -998,7 +997,7 @@ public class SpecialCardAi {
|
|||||||
// Scan the fetch list for a card with at least one activated ability.
|
// Scan the fetch list for a card with at least one activated ability.
|
||||||
// TODO: can be improved to a full consider(sa, ai) logic which would scan the graveyard first and hand last
|
// TODO: can be improved to a full consider(sa, ai) logic which would scan the graveyard first and hand last
|
||||||
public static Card considerCardFromList(final CardCollection fetchList) {
|
public static Card considerCardFromList(final CardCollection fetchList) {
|
||||||
for (Card c : CardLists.filter(fetchList, Predicates.or(CardPredicates.Presets.ARTIFACTS, CardPredicates.Presets.CREATURES))) {
|
for (Card c : CardLists.filter(fetchList, CardPredicates.Presets.ARTIFACTS.or(CardPredicates.Presets.CREATURES))) {
|
||||||
for (SpellAbility ab : c.getSpellAbilities()) {
|
for (SpellAbility ab : c.getSpellAbilities()) {
|
||||||
if (ab.isActivatedAbility()) {
|
if (ab.isActivatedAbility()) {
|
||||||
Player controller = c.getController();
|
Player controller = c.getController();
|
||||||
|
|||||||
@@ -1,10 +1,8 @@
|
|||||||
package forge.ai.ability;
|
package forge.ai.ability;
|
||||||
|
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
import java.util.function.Predicate;
|
|
||||||
|
|
||||||
import forge.game.card.*;
|
import forge.game.card.*;
|
||||||
import forge.util.Predicates;
|
|
||||||
import org.apache.commons.lang3.ObjectUtils;
|
import org.apache.commons.lang3.ObjectUtils;
|
||||||
|
|
||||||
import com.google.common.collect.Lists;
|
import com.google.common.collect.Lists;
|
||||||
@@ -1144,9 +1142,8 @@ public class AttachAi extends SpellAbilityAi {
|
|||||||
|
|
||||||
//some auras/equipments aren't useful in multiples
|
//some auras/equipments aren't useful in multiples
|
||||||
if (attachSource.hasSVar("NonStackingAttachEffect")) {
|
if (attachSource.hasSVar("NonStackingAttachEffect")) {
|
||||||
prefList = CardLists.filter(prefList, Predicates.or(
|
prefList = CardLists.filter(prefList, CardPredicates.isEquippedBy(attachSource.getName())
|
||||||
CardPredicates.isEquippedBy(attachSource.getName()),
|
.or(CardPredicates.isEnchantedBy(attachSource.getName())
|
||||||
CardPredicates.isEnchantedBy(attachSource.getName())
|
|
||||||
).negate());
|
).negate());
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1248,8 +1245,8 @@ public class AttachAi extends SpellAbilityAi {
|
|||||||
|
|
||||||
// Is a SA that moves target attachment
|
// Is a SA that moves target attachment
|
||||||
if ("MoveTgtAura".equals(sa.getParam("AILogic"))) {
|
if ("MoveTgtAura".equals(sa.getParam("AILogic"))) {
|
||||||
CardCollection list = CardLists.filter(CardUtil.getValidCardsToTarget(sa), Predicates.or(CardPredicates.isControlledByAnyOf(aiPlayer.getOpponents()),
|
CardCollection list = CardLists.filter(CardUtil.getValidCardsToTarget(sa), CardPredicates.isControlledByAnyOf(aiPlayer.getOpponents())
|
||||||
card -> ComputerUtilCard.isUselessCreature(aiPlayer, card.getAttachedTo())));
|
.or(card -> ComputerUtilCard.isUselessCreature(aiPlayer, card.getAttachedTo())));
|
||||||
|
|
||||||
return !list.isEmpty() ? ComputerUtilCard.getBestAI(list) : null;
|
return !list.isEmpty() ? ComputerUtilCard.getBestAI(list) : null;
|
||||||
} else if ("Unenchanted".equals(sa.getParam("AILogic"))) {
|
} else if ("Unenchanted".equals(sa.getParam("AILogic"))) {
|
||||||
|
|||||||
@@ -26,7 +26,6 @@ import forge.game.zone.MagicStack;
|
|||||||
import forge.game.zone.ZoneType;
|
import forge.game.zone.ZoneType;
|
||||||
import forge.util.Iterables;
|
import forge.util.Iterables;
|
||||||
import forge.util.MyRandom;
|
import forge.util.MyRandom;
|
||||||
import forge.util.Predicates;
|
|
||||||
import forge.util.TextUtil;
|
import forge.util.TextUtil;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
@@ -57,7 +56,7 @@ public class EffectAi extends SpellAbilityAi {
|
|||||||
for (Player opp : ai.getOpponents()) {
|
for (Player opp : ai.getOpponents()) {
|
||||||
boolean worthHolding = false;
|
boolean worthHolding = false;
|
||||||
CardCollectionView oppCreatsLands = CardLists.filter(opp.getCardsIn(ZoneType.Battlefield),
|
CardCollectionView oppCreatsLands = CardLists.filter(opp.getCardsIn(ZoneType.Battlefield),
|
||||||
Predicates.or(CardPredicates.Presets.LANDS, CardPredicates.Presets.CREATURES));
|
Presets.LANDS.or(Presets.CREATURES));
|
||||||
CardCollectionView oppCreatsLandsTapped = CardLists.filter(oppCreatsLands, CardPredicates.Presets.TAPPED);
|
CardCollectionView oppCreatsLandsTapped = CardLists.filter(oppCreatsLands, CardPredicates.Presets.TAPPED);
|
||||||
|
|
||||||
if (oppCreatsLandsTapped.size() >= 3 || oppCreatsLands.size() == oppCreatsLandsTapped.size()) {
|
if (oppCreatsLandsTapped.size() >= 3 || oppCreatsLands.size() == oppCreatsLandsTapped.size()) {
|
||||||
|
|||||||
@@ -30,7 +30,6 @@ import forge.game.spellability.SpellAbility;
|
|||||||
import forge.game.zone.ZoneType;
|
import forge.game.zone.ZoneType;
|
||||||
import forge.util.Aggregates;
|
import forge.util.Aggregates;
|
||||||
import forge.util.Iterables;
|
import forge.util.Iterables;
|
||||||
import forge.util.Predicates;
|
|
||||||
|
|
||||||
public class ManaAi extends SpellAbilityAi {
|
public class ManaAi extends SpellAbilityAi {
|
||||||
|
|
||||||
@@ -239,7 +238,7 @@ public class ManaAi extends SpellAbilityAi {
|
|||||||
Arrays.asList(
|
Arrays.asList(
|
||||||
CardPredicates.restriction(restrictValid.split(","), ai, host, sa),
|
CardPredicates.restriction(restrictValid.split(","), ai, host, sa),
|
||||||
CardPredicates.lessCMC(searchCMC),
|
CardPredicates.lessCMC(searchCMC),
|
||||||
Predicates.or(CardPredicates.isColorless(), CardPredicates.isColor(producedColor))));
|
CardPredicates.isColorless().or(CardPredicates.isColor(producedColor))));
|
||||||
|
|
||||||
if (logic.startsWith("ManaRitualBattery")) {
|
if (logic.startsWith("ManaRitualBattery")) {
|
||||||
// Don't remove more counters than would be needed to cast the more expensive thing we want to cast,
|
// Don't remove more counters than would be needed to cast the more expensive thing we want to cast,
|
||||||
|
|||||||
@@ -18,7 +18,6 @@ import forge.game.player.Player;
|
|||||||
import forge.game.spellability.SpellAbility;
|
import forge.game.spellability.SpellAbility;
|
||||||
import forge.game.zone.ZoneType;
|
import forge.game.zone.ZoneType;
|
||||||
import forge.util.Iterables;
|
import forge.util.Iterables;
|
||||||
import forge.util.Predicates;
|
|
||||||
import org.apache.commons.lang3.StringUtils;
|
import org.apache.commons.lang3.StringUtils;
|
||||||
|
|
||||||
public class PermanentAi extends SpellAbilityAi {
|
public class PermanentAi extends SpellAbilityAi {
|
||||||
@@ -261,7 +260,7 @@ public class PermanentAi extends SpellAbilityAi {
|
|||||||
int extraMana = CardLists.count(ai.getCardsIn(ZoneType.Hand), CardPredicates.Presets.LANDS) > 0 ? 1 : 0;
|
int extraMana = CardLists.count(ai.getCardsIn(ZoneType.Hand), CardPredicates.Presets.LANDS) > 0 ? 1 : 0;
|
||||||
if (source.getName().equals("Illusions of Grandeur")) {
|
if (source.getName().equals("Illusions of Grandeur")) {
|
||||||
// TODO: this is currently hardcoded for specific Illusions-Donate cost reduction spells, need to make this generic.
|
// TODO: this is currently hardcoded for specific Illusions-Donate cost reduction spells, need to make this generic.
|
||||||
extraMana += Math.min(3, CardLists.filter(ai.getCardsIn(ZoneType.Battlefield), Predicates.or(CardPredicates.nameEquals("Sapphire Medallion"), CardPredicates.nameEquals("Helm of Awakening"))).size()) * 2; // each cost-reduction spell accounts for {1} in both Illusions and Donate
|
extraMana += Math.min(3, CardLists.filter(ai.getCardsIn(ZoneType.Battlefield), CardPredicates.nameEquals("Sapphire Medallion").or(CardPredicates.nameEquals("Helm of Awakening"))).size()) * 2; // each cost-reduction spell accounts for {1} in both Illusions and Donate
|
||||||
}
|
}
|
||||||
if (m.size() + extraMana < Integer.parseInt(value)) {
|
if (m.size() + extraMana < Integer.parseInt(value)) {
|
||||||
dontCast = true;
|
dontCast = true;
|
||||||
|
|||||||
@@ -20,7 +20,6 @@ import forge.game.spellability.SpellAbility;
|
|||||||
import forge.game.spellability.TargetRestrictions;
|
import forge.game.spellability.TargetRestrictions;
|
||||||
import forge.game.zone.ZoneType;
|
import forge.game.zone.ZoneType;
|
||||||
import forge.util.Iterables;
|
import forge.util.Iterables;
|
||||||
import forge.util.Predicates;
|
|
||||||
import org.apache.commons.lang3.StringUtils;
|
import org.apache.commons.lang3.StringUtils;
|
||||||
|
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
@@ -450,7 +449,7 @@ public class PumpAi extends PumpAiBase {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
List<Card> alliedTgts = CardLists.filter(tgts, Predicates.or(CardPredicates.isControlledByAnyOf(ai.getAllies()), CardPredicates.isController(ai)));
|
List<Card> alliedTgts = CardLists.filter(tgts, CardPredicates.isControlledByAnyOf(ai.getAllies()).or(CardPredicates.isController(ai)));
|
||||||
List<Card> oppTgts = CardLists.filter(tgts, CardPredicates.isControlledByAnyOf(ai.getOpponents()));
|
List<Card> oppTgts = CardLists.filter(tgts, CardPredicates.isControlledByAnyOf(ai.getOpponents()));
|
||||||
|
|
||||||
Card destroyTgt = null;
|
Card destroyTgt = null;
|
||||||
@@ -512,7 +511,7 @@ public class PumpAi extends PumpAiBase {
|
|||||||
// Detain target nonland permanent: don't target noncreature permanents that don't have
|
// Detain target nonland permanent: don't target noncreature permanents that don't have
|
||||||
// any activated abilities.
|
// any activated abilities.
|
||||||
if ("DetainNonLand".equals(sa.getParam("AILogic"))) {
|
if ("DetainNonLand".equals(sa.getParam("AILogic"))) {
|
||||||
list = CardLists.filter(list, Predicates.or(CardPredicates.Presets.CREATURES, card -> {
|
list = CardLists.filter(list, Presets.CREATURES.or(card -> {
|
||||||
for (SpellAbility sa1 : card.getSpellAbilities()) {
|
for (SpellAbility sa1 : card.getSpellAbilities()) {
|
||||||
if (sa1.isActivatedAbility()) {
|
if (sa1.isActivatedAbility()) {
|
||||||
return true;
|
return true;
|
||||||
|
|||||||
@@ -27,7 +27,6 @@ import forge.game.player.Player;
|
|||||||
import forge.game.spellability.SpellAbility;
|
import forge.game.spellability.SpellAbility;
|
||||||
import forge.game.zone.ZoneType;
|
import forge.game.zone.ZoneType;
|
||||||
import forge.util.Iterables;
|
import forge.util.Iterables;
|
||||||
import forge.util.Predicates;
|
|
||||||
|
|
||||||
public abstract class PumpAiBase extends SpellAbilityAi {
|
public abstract class PumpAiBase extends SpellAbilityAi {
|
||||||
|
|
||||||
@@ -204,7 +203,7 @@ public abstract class PumpAiBase extends SpellAbilityAi {
|
|||||||
&& ComputerUtilCombat.lifeInDanger(ai, game.getCombat())) {
|
&& ComputerUtilCombat.lifeInDanger(ai, game.getCombat())) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
Predicate<Card> flyingOrReach = Predicates.or(CardPredicates.hasKeyword(Keyword.FLYING), CardPredicates.hasKeyword(Keyword.REACH));
|
Predicate<Card> flyingOrReach = CardPredicates.hasKeyword(Keyword.FLYING).or(CardPredicates.hasKeyword(Keyword.REACH));
|
||||||
if (ph.isPlayerTurn(opp) && combat != null
|
if (ph.isPlayerTurn(opp) && combat != null
|
||||||
&& !attackingFlyer.isEmpty()
|
&& !attackingFlyer.isEmpty()
|
||||||
&& CombatUtil.canBlock(card)) {
|
&& CombatUtil.canBlock(card)) {
|
||||||
|
|||||||
@@ -569,7 +569,7 @@ public final class CardRulesPredicates {
|
|||||||
public static final Predicate<CardRules> IS_ENCHANTMENT = CardRulesPredicates.coreType(true, CardType.CoreType.Enchantment);
|
public static final Predicate<CardRules> IS_ENCHANTMENT = CardRulesPredicates.coreType(true, CardType.CoreType.Enchantment);
|
||||||
public static final Predicate<CardRules> IS_PLANE = CardRulesPredicates.coreType(true, CardType.CoreType.Plane);
|
public static final Predicate<CardRules> IS_PLANE = CardRulesPredicates.coreType(true, 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(true, CardType.CoreType.Phenomenon);
|
||||||
public static final Predicate<CardRules> IS_PLANE_OR_PHENOMENON = Predicates.or(IS_PLANE, 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(true, 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(true, 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(true, CardType.CoreType.Conspiracy);
|
||||||
@@ -577,8 +577,8 @@ public final class CardRulesPredicates {
|
|||||||
public static final Predicate<CardRules> IS_ATTRACTION = Presets.IS_ARTIFACT.and(CardRulesPredicates.subType("Attraction"));
|
public static final Predicate<CardRules> IS_ATTRACTION = Presets.IS_ARTIFACT.and(CardRulesPredicates.subType("Attraction"));
|
||||||
|
|
||||||
public static final Predicate<CardRules> IS_NON_LAND = CardRulesPredicates.coreType(false, CardType.CoreType.Land);
|
public static final Predicate<CardRules> IS_NON_LAND = CardRulesPredicates.coreType(false, CardType.CoreType.Land);
|
||||||
public static final Predicate<CardRules> CAN_BE_BRAWL_COMMANDER = Presets.IS_LEGENDARY.and(Predicates.or(Presets.IS_CREATURE, Presets.IS_PLANESWALKER));
|
public static final Predicate<CardRules> CAN_BE_BRAWL_COMMANDER = Presets.IS_LEGENDARY.and(Presets.IS_CREATURE.or(Presets.IS_PLANESWALKER));
|
||||||
public static final Predicate<CardRules> CAN_BE_TINY_LEADERS_COMMANDER = Presets.IS_LEGENDARY.and(Predicates.or(Presets.IS_CREATURE, Presets.IS_PLANESWALKER));
|
public static final Predicate<CardRules> CAN_BE_TINY_LEADERS_COMMANDER = Presets.IS_LEGENDARY.and(Presets.IS_CREATURE.or(Presets.IS_PLANESWALKER));
|
||||||
|
|
||||||
/** The Constant IS_NON_CREATURE_SPELL. **/
|
/** The Constant IS_NON_CREATURE_SPELL. **/
|
||||||
public static final Predicate<CardRules> IS_NON_CREATURE_SPELL =
|
public static final Predicate<CardRules> IS_NON_CREATURE_SPELL =
|
||||||
|
|||||||
@@ -538,7 +538,7 @@ public enum DeckFormat {
|
|||||||
if (commanders.size() == 1 && commanders.get(0).getRules().canBePartnerCommander()) { //also show available partners a commander can have a partner
|
if (commanders.size() == 1 && commanders.get(0).getRules().canBePartnerCommander()) { //also show available partners a commander can have a partner
|
||||||
//702.124g If a legendary card has more than one partner ability, you may choose which one to use when designating your commander, but you can’t use both.
|
//702.124g If a legendary card has more than one partner ability, you may choose which one to use when designating your commander, but you can’t use both.
|
||||||
//Notably, no partner ability or combination of partner abilities can ever let a player have more than two commanders.
|
//Notably, no partner ability or combination of partner abilities can ever let a player have more than two commanders.
|
||||||
predicate = Predicates.or(predicate, CardRulesPredicates.canBePartnerCommanderWith(commanders.get(0).getRules()));
|
predicate = predicate.or(CardRulesPredicates.canBePartnerCommanderWith(commanders.get(0).getRules()));
|
||||||
}
|
}
|
||||||
return Predicates.compose(predicate, PaperCard::getRules);
|
return Predicates.compose(predicate, PaperCard::getRules);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -289,7 +289,7 @@ public abstract class DeckGeneratorBase {
|
|||||||
};
|
};
|
||||||
|
|
||||||
if (useArtifacts) {
|
if (useArtifacts) {
|
||||||
hasColor = Predicates.or(hasColor, COLORLESS_CARDS);
|
hasColor = hasColor.or(COLORLESS_CARDS);
|
||||||
}
|
}
|
||||||
return Iterables.filter(pool.getAllCards(), Predicates.compose(canPlay.and(hasColor).and(canUseInFormat), PaperCard::getRules));
|
return Iterables.filter(pool.getAllCards(), Predicates.compose(canPlay.and(hasColor).and(canUseInFormat), PaperCard::getRules));
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -209,8 +209,7 @@ public interface IPaperCard extends InventoryItem, Serializable {
|
|||||||
public static final Predicate<PaperCard> IS_MYTHIC_RARE = Predicates.rarity(true, CardRarity.MythicRare);
|
public static final Predicate<PaperCard> IS_MYTHIC_RARE = Predicates.rarity(true, CardRarity.MythicRare);
|
||||||
|
|
||||||
/** The Constant isRareOrMythic. */
|
/** The Constant isRareOrMythic. */
|
||||||
public static final Predicate<PaperCard> IS_RARE_OR_MYTHIC = forge.util.Predicates.or(Presets.IS_RARE,
|
public static final Predicate<PaperCard> IS_RARE_OR_MYTHIC = Presets.IS_RARE.or(Presets.IS_MYTHIC_RARE);
|
||||||
Presets.IS_MYTHIC_RARE);
|
|
||||||
|
|
||||||
/** The Constant isSpecial. */
|
/** The Constant isSpecial. */
|
||||||
public static final Predicate<PaperCard> IS_SPECIAL = Predicates.rarity(true, CardRarity.Special);
|
public static final Predicate<PaperCard> IS_SPECIAL = Predicates.rarity(true, CardRarity.Special);
|
||||||
|
|||||||
@@ -20,12 +20,4 @@ public class Predicates {
|
|||||||
public static <A, B> Predicate<A> compose(Predicate<B> predicate, Function<A, ? extends B> function) {
|
public static <A, B> Predicate<A> compose(Predicate<B> predicate, Function<A, ? extends B> function) {
|
||||||
return x -> predicate.test(function.apply(x));
|
return x -> predicate.test(function.apply(x));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
//TODO: Inline everything below.
|
|
||||||
|
|
||||||
public static <T> Predicate<T> or(Predicate<? super T> first, Predicate<? super T> second) {
|
|
||||||
//TODO: remove casting?
|
|
||||||
return ((Predicate<T>) first).or(second);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -159,7 +159,7 @@ public class GameFormat implements Comparable<GameFormat> {
|
|||||||
p = p.and(Predicates.or(crp));
|
p = p.and(Predicates.or(crp));
|
||||||
}
|
}
|
||||||
if (!this.getAdditionalCards().isEmpty()) {
|
if (!this.getAdditionalCards().isEmpty()) {
|
||||||
p = Predicates.or(p, IPaperCard.Predicates.names(this.getAdditionalCards()));
|
p = p.or(IPaperCard.Predicates.names(this.getAdditionalCards()));
|
||||||
}
|
}
|
||||||
return p;
|
return p;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -88,7 +88,7 @@ public final class CEditorCommander extends CDeckEditor<Deck> {
|
|||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
Predicate<CardRules> commanderFilter = gameType == GameType.Oathbreaker
|
Predicate<CardRules> commanderFilter = gameType == GameType.Oathbreaker
|
||||||
? Predicates.or(CardRulesPredicates.Presets.CAN_BE_OATHBREAKER, CardRulesPredicates.Presets.CAN_BE_SIGNATURE_SPELL)
|
? CardRulesPredicates.Presets.CAN_BE_OATHBREAKER.or(CardRulesPredicates.Presets.CAN_BE_SIGNATURE_SPELL)
|
||||||
: CardRulesPredicates.Presets.CAN_BE_COMMANDER;
|
: CardRulesPredicates.Presets.CAN_BE_COMMANDER;
|
||||||
commanderPool = ItemPool.createFrom(commonCards.getAllCardsNoAlt(Predicates.compose(commanderFilter, PaperCard::getRules)),PaperCard.class);
|
commanderPool = ItemPool.createFrom(commonCards.getAllCardsNoAlt(Predicates.compose(commanderFilter, PaperCard::getRules)),PaperCard.class);
|
||||||
normalPool = ItemPool.createFrom(commonCards.getAllCardsNoAlt(), PaperCard.class);
|
normalPool = ItemPool.createFrom(commonCards.getAllCardsNoAlt(), PaperCard.class);
|
||||||
|
|||||||
@@ -760,9 +760,10 @@ public class DeckgenUtil {
|
|||||||
cardDb = FModel.getMagicDb().getCommonCards();
|
cardDb = FModel.getMagicDb().getCommonCards();
|
||||||
//shuffle first 400 random cards
|
//shuffle first 400 random cards
|
||||||
Iterable<PaperCard> colorList = Iterables.filter(format.getCardPool(cardDb).getAllCards(),
|
Iterable<PaperCard> colorList = Iterables.filter(format.getCardPool(cardDb).getAllCards(),
|
||||||
format.isLegalCardPredicate().and(Predicates.compose(Predicates.or(
|
format.isLegalCardPredicate().and(Predicates.compose(
|
||||||
new CardThemedDeckBuilder.MatchColorIdentity(commander.getRules().getColorIdentity()),
|
new CardThemedDeckBuilder.MatchColorIdentity(commander.getRules().getColorIdentity())
|
||||||
DeckGeneratorBase.COLORLESS_CARDS), PaperCard::getRules)));
|
.or(DeckGeneratorBase.COLORLESS_CARDS),
|
||||||
|
PaperCard::getRules)));
|
||||||
switch (format) {
|
switch (format) {
|
||||||
case Brawl: //for Brawl - add additional filterprinted rule to remove old reprints for a consistent look
|
case Brawl: //for Brawl - add additional filterprinted rule to remove old reprints for a consistent look
|
||||||
colorList = Iterables.filter(colorList,FModel.getFormats().getStandard().getFilterPrinted());
|
colorList = Iterables.filter(colorList,FModel.getFormats().getStandard().getFilterPrinted());
|
||||||
|
|||||||
@@ -183,7 +183,7 @@ public class CardThemedDeckBuilder extends DeckGeneratorBase {
|
|||||||
*/
|
*/
|
||||||
public Deck buildDeck() {
|
public Deck buildDeck() {
|
||||||
// 1. Prepare
|
// 1. Prepare
|
||||||
hasColor = Predicates.or(new MatchColorIdentity(colors), COLORLESS_CARDS);
|
hasColor = new MatchColorIdentity(colors).or(COLORLESS_CARDS);
|
||||||
if (logColorsToConsole) {
|
if (logColorsToConsole) {
|
||||||
System.out.println(keyCard.getName());
|
System.out.println(keyCard.getName());
|
||||||
System.out.println("Colors: " + colors.toEnumSet().toString());
|
System.out.println("Colors: " + colors.toEnumSet().toString());
|
||||||
@@ -192,8 +192,8 @@ public class CardThemedDeckBuilder extends DeckGeneratorBase {
|
|||||||
Predicates.compose(hasColor, PaperCard::getRules));
|
Predicates.compose(hasColor, PaperCard::getRules));
|
||||||
rankedColorList = Lists.newArrayList(colorList);
|
rankedColorList = Lists.newArrayList(colorList);
|
||||||
onColorCreaturesAndSpells = Iterables.filter(rankedColorList,
|
onColorCreaturesAndSpells = Iterables.filter(rankedColorList,
|
||||||
Predicates.compose(Predicates.or(CardRulesPredicates.Presets.IS_CREATURE,
|
Predicates.compose(CardRulesPredicates.Presets.IS_CREATURE
|
||||||
CardRulesPredicates.Presets.IS_NON_CREATURE_SPELL), PaperCard::getRules));
|
.or(CardRulesPredicates.Presets.IS_NON_CREATURE_SPELL), PaperCard::getRules));
|
||||||
|
|
||||||
// Guava iterables do not copy the collection contents, instead they act
|
// Guava iterables do not copy the collection contents, instead they act
|
||||||
// as filters and iterate over _source_ collection each time. So even if
|
// as filters and iterate over _source_ collection each time. So even if
|
||||||
@@ -476,8 +476,8 @@ public class CardThemedDeckBuilder extends DeckGeneratorBase {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
hasColor = CardRulesPredicates.Presets.IS_NON_LAND.and(Predicates.or(new MatchColorIdentity(colors),
|
hasColor = CardRulesPredicates.Presets.IS_NON_LAND.and(new MatchColorIdentity(colors)
|
||||||
DeckGeneratorBase.COLORLESS_CARDS));
|
.or(DeckGeneratorBase.COLORLESS_CARDS));
|
||||||
final Iterable<PaperCard> threeColorList = Iterables.filter(aiPlayables,
|
final Iterable<PaperCard> threeColorList = Iterables.filter(aiPlayables,
|
||||||
Predicates.compose(hasColor, PaperCard::getRules));
|
Predicates.compose(hasColor, PaperCard::getRules));
|
||||||
for (final PaperCard card : threeColorList) {
|
for (final PaperCard card : threeColorList) {
|
||||||
|
|||||||
@@ -134,7 +134,7 @@ public class LimitedDeckBuilder extends DeckGeneratorBase {
|
|||||||
@SuppressWarnings("unused")
|
@SuppressWarnings("unused")
|
||||||
public Deck buildDeck(final String landSetCode) {
|
public Deck buildDeck(final String landSetCode) {
|
||||||
// 1. Prepare
|
// 1. Prepare
|
||||||
hasColor = Predicates.or(new MatchColorIdentity(colors), COLORLESS_CARDS);
|
hasColor = new MatchColorIdentity(colors).or(COLORLESS_CARDS);
|
||||||
Iterable<PaperCard> colorList = Iterables.filter(aiPlayables,
|
Iterable<PaperCard> colorList = Iterables.filter(aiPlayables,
|
||||||
Predicates.compose(hasColor, PaperCard::getRules));
|
Predicates.compose(hasColor, PaperCard::getRules));
|
||||||
rankedColorList = CardRanker.rankCardsInDeck(colorList);
|
rankedColorList = CardRanker.rankCardsInDeck(colorList);
|
||||||
@@ -497,8 +497,7 @@ public class LimitedDeckBuilder extends DeckGeneratorBase {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
hasColor = Predicates.or(new DeckGeneratorBase.MatchColorIdentity(colors),
|
hasColor = new MatchColorIdentity(colors).or(DeckGeneratorBase.COLORLESS_CARDS);
|
||||||
DeckGeneratorBase.COLORLESS_CARDS);
|
|
||||||
final Iterable<PaperCard> threeColorList = Iterables.filter(rankedOthers,
|
final Iterable<PaperCard> threeColorList = Iterables.filter(rankedOthers,
|
||||||
Predicates.compose(hasColor, PaperCard::getRules));
|
Predicates.compose(hasColor, PaperCard::getRules));
|
||||||
for (final PaperCard card : threeColorList) {
|
for (final PaperCard card : threeColorList) {
|
||||||
|
|||||||
@@ -91,13 +91,13 @@ public abstract class QuestRewardCard implements IQuestRewardCard {
|
|||||||
if (rarityCodes.length > 0) {
|
if (rarityCodes.length > 0) {
|
||||||
for (final String rarity : rarityCodes) {
|
for (final String rarity : rarityCodes) {
|
||||||
if (rarity.startsWith("C") || rarity.startsWith("c")) {
|
if (rarity.startsWith("C") || rarity.startsWith("c")) {
|
||||||
filterRarity = (filterRarity == null ? IPaperCard.Predicates.Presets.IS_COMMON : Predicates.or(filterRarity, IPaperCard.Predicates.Presets.IS_COMMON));
|
filterRarity = filterRarity == null ? IPaperCard.Predicates.Presets.IS_COMMON : filterRarity.or(IPaperCard.Predicates.Presets.IS_COMMON);
|
||||||
} else if (rarity.startsWith("U") || rarity.startsWith("u")) {
|
} else if (rarity.startsWith("U") || rarity.startsWith("u")) {
|
||||||
filterRarity = (filterRarity == null ? IPaperCard.Predicates.Presets.IS_UNCOMMON : Predicates.or(filterRarity, IPaperCard.Predicates.Presets.IS_UNCOMMON));
|
filterRarity = filterRarity == null ? IPaperCard.Predicates.Presets.IS_UNCOMMON : filterRarity.or(IPaperCard.Predicates.Presets.IS_UNCOMMON);
|
||||||
} else if (rarity.startsWith("R") || rarity.startsWith("r")) {
|
} else if (rarity.startsWith("R") || rarity.startsWith("r")) {
|
||||||
filterRarity = (filterRarity == null ? IPaperCard.Predicates.Presets.IS_RARE : Predicates.or(filterRarity, IPaperCard.Predicates.Presets.IS_RARE));
|
filterRarity = filterRarity == null ? IPaperCard.Predicates.Presets.IS_RARE : filterRarity.or(IPaperCard.Predicates.Presets.IS_RARE);
|
||||||
} else if (rarity.startsWith("M") || rarity.startsWith("m")) {
|
} else if (rarity.startsWith("M") || rarity.startsWith("m")) {
|
||||||
filterRarity = (filterRarity == null ? IPaperCard.Predicates.Presets.IS_MYTHIC_RARE : Predicates.or(filterRarity, IPaperCard.Predicates.Presets.IS_MYTHIC_RARE));
|
filterRarity = filterRarity == null ? IPaperCard.Predicates.Presets.IS_MYTHIC_RARE : filterRarity.or(IPaperCard.Predicates.Presets.IS_MYTHIC_RARE);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -48,7 +48,6 @@ import forge.item.SealedProduct;
|
|||||||
import forge.model.FModel;
|
import forge.model.FModel;
|
||||||
import forge.util.CardTranslation;
|
import forge.util.CardTranslation;
|
||||||
import forge.util.Localizer;
|
import forge.util.Localizer;
|
||||||
import forge.util.Predicates;
|
|
||||||
|
|
||||||
public class AdvancedSearch {
|
public class AdvancedSearch {
|
||||||
public enum FilterOption {
|
public enum FilterOption {
|
||||||
@@ -1584,7 +1583,7 @@ public class AdvancedSearch {
|
|||||||
pred = pred.and(predPiece);
|
pred = pred.and(predPiece);
|
||||||
}
|
}
|
||||||
else if (operator == Operator.OR) {
|
else if (operator == Operator.OR) {
|
||||||
pred = Predicates.or(pred, predPiece);
|
pred = pred.or(predPiece);
|
||||||
}
|
}
|
||||||
operator = null;
|
operator = null;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -128,7 +128,7 @@ public class BooleanExpression {
|
|||||||
operators.pop();
|
operators.pop();
|
||||||
right = operands.pop();
|
right = operands.pop();
|
||||||
left = operands.pop();
|
left = operands.pop();
|
||||||
operands.push(Predicates.or(left, right));
|
operands.push(left.or(right));
|
||||||
break;
|
break;
|
||||||
case NOT:
|
case NOT:
|
||||||
operators.pop();
|
operators.pop();
|
||||||
|
|||||||
@@ -346,8 +346,8 @@ public final class FModel {
|
|||||||
|
|
||||||
public static ItemPool<PaperCard> getOathbreakerCommander() {
|
public static ItemPool<PaperCard> getOathbreakerCommander() {
|
||||||
if (oathbreakerCommander == null)
|
if (oathbreakerCommander == null)
|
||||||
return ItemPool.createFrom(getMagicDb().getCommonCards().getAllCardsNoAlt(Predicates.compose(Predicates.or(
|
return ItemPool.createFrom(getMagicDb().getCommonCards().getAllCardsNoAlt(Predicates.compose(
|
||||||
CardRulesPredicates.Presets.CAN_BE_OATHBREAKER, CardRulesPredicates.Presets.CAN_BE_SIGNATURE_SPELL), PaperCard::getRules)), PaperCard.class);
|
CardRulesPredicates.Presets.CAN_BE_OATHBREAKER.or(CardRulesPredicates.Presets.CAN_BE_SIGNATURE_SPELL), PaperCard::getRules)), PaperCard.class);
|
||||||
return oathbreakerCommander;
|
return oathbreakerCommander;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user