diff --git a/forge-ai/src/main/java/forge/ai/ComputerUtil.java b/forge-ai/src/main/java/forge/ai/ComputerUtil.java index dbb0f7a0860..46cf9933423 100644 --- a/forge-ai/src/main/java/forge/ai/ComputerUtil.java +++ b/forge-ai/src/main/java/forge/ai/ComputerUtil.java @@ -307,6 +307,11 @@ public class ComputerUtil { final String[] prefValid = activate.getSVar("AIPreference").split("\\$"); if (prefValid[0].equals(pref)) { final CardCollection prefList = CardLists.getValidCards(typeList, prefValid[1].split(","), activate.getController(), activate, null); + CardCollection overrideList = null; + + if (activate.hasSVar("AIPreferenceOverride")) { + overrideList = CardLists.getValidCards(typeList, activate.getSVar("AIPreferenceOverride"), activate.getController(), activate, null); + } int threshold = getAIPreferenceParameter(activate, "CreatureEvalThreshold"); int minNeeded = getAIPreferenceParameter(activate, "MinCreaturesBelowThreshold"); @@ -332,7 +337,7 @@ public class ComputerUtil { } if (!prefList.isEmpty()) { - return ComputerUtilCard.getWorstAI(prefList); + return ComputerUtilCard.getWorstAI(overrideList == null ? prefList : overrideList); } } } diff --git a/forge-ai/src/main/java/forge/ai/SpecialCardAi.java b/forge-ai/src/main/java/forge/ai/SpecialCardAi.java index 3d135f5e200..1e86b94a7a6 100644 --- a/forge-ai/src/main/java/forge/ai/SpecialCardAi.java +++ b/forge-ai/src/main/java/forge/ai/SpecialCardAi.java @@ -17,11 +17,11 @@ */ package forge.ai; +import com.google.common.base.Predicate; import java.util.Arrays; import java.util.Collections; import java.util.List; -import com.google.common.base.Predicate; import com.google.common.base.Predicates; import com.google.common.collect.Iterables; import com.google.common.collect.Lists; @@ -67,6 +67,44 @@ import forge.util.Aggregates; */ public class SpecialCardAi { + // Birthing Pod + public static class BirthingPod { + public static boolean consider(final Player ai, SpellAbility sa) { + Card source = sa.getHostCard(); + CardCollection listToSac = CardLists.filter(ai.getCardsIn(ZoneType.Battlefield), CardPredicates.Presets.CREATURES); + + listToSac.sort(CardLists.CmcComparatorInv); // try to upgrade best creatures first + + for (Card sacCandidate : listToSac) { + int sacCMC = sacCandidate.getCMC(); + int goalCMC = sacCMC + 1; + + CardCollection listGoal = CardLists.filter(ai.getCardsIn(ZoneType.Library), CardPredicates.Presets.CREATURES); + listGoal = CardLists.getValidCards(listGoal, "Creature.cmcEQ" + goalCMC, source.getController(), source); + listGoal = CardLists.filter(listGoal, new Predicate() { + @Override + public boolean apply(final Card c) { + if (c.getType().isLegendary()) { + if (ai.isCardInPlay(c.getName())) { + return false; + } + } + return true; + } + }); + + if (!listGoal.isEmpty()) { + // make sure we're upgrading sacCMC->goalCMC + source.setSVar("AIPreferenceOverride", "Creature.cmcEQ" + sacCMC); + return true; + } + } + + // no candidates to upgrade + return false; + } + } + // Black Lotus and Lotus Bloom public static class BlackLotus { public static boolean consider(Player ai, SpellAbility sa, ManaCostBeingPaid cost) { diff --git a/forge-ai/src/main/java/forge/ai/ability/ChangeZoneAi.java b/forge-ai/src/main/java/forge/ai/ability/ChangeZoneAi.java index 8fa38ae4298..a294c0204f8 100644 --- a/forge-ai/src/main/java/forge/ai/ability/ChangeZoneAi.java +++ b/forge-ai/src/main/java/forge/ai/ability/ChangeZoneAi.java @@ -48,6 +48,11 @@ public class ChangeZoneAi extends SpellAbilityAi { @Override protected boolean checkAiLogic(final Player ai, final SpellAbility sa, final String aiLogic) { + if (sa.getHostCard() != null && sa.getHostCard().hasSVar("AIPreferenceOverride")) { + // currently used by Birthing Pod logic, might need simplification + sa.getHostCard().removeSVar("AIPreferenceOverride"); + } + if (aiLogic.equals("BeforeCombat")) { if (ai.getGame().getPhaseHandler().getPhase().isAfter(PhaseType.COMBAT_BEGIN)) { return false; @@ -67,8 +72,9 @@ public class ChangeZoneAi extends SpellAbilityAi { if (aiLogic != null) { if (aiLogic.equals("Always")) { return true; - } - if (aiLogic.equals("SameName")) { // Declaration in Stone + } else if (aiLogic.equals("BirthingPod")) { + return SpecialCardAi.BirthingPod.consider(aiPlayer, sa); + } else if (aiLogic.equals("SameName")) { // Declaration in Stone final Game game = aiPlayer.getGame(); final Card source = sa.getHostCard(); final TargetRestrictions tgt = sa.getTargetRestrictions(); diff --git a/forge-gui/res/cardsfolder/b/birthing_pod.txt b/forge-gui/res/cardsfolder/b/birthing_pod.txt index e5edc925f83..85d0923ad3f 100644 --- a/forge-gui/res/cardsfolder/b/birthing_pod.txt +++ b/forge-gui/res/cardsfolder/b/birthing_pod.txt @@ -1,8 +1,8 @@ Name:Birthing Pod ManaCost:3 PG Types:Artifact -A:AB$ ChangeZone | Cost$ 1 PG T Sac<1/Creature> | Origin$ Library | Destination$ Battlefield | ChangeType$ Creature.cmcEQX | References$ X | ChangeNum$ 1 | SorcerySpeed$ True | StackDescription$ Search your library for a creature card with converted mana cost equal to 1 plus the sacrificed creature's converted mana cost, put that card onto the battlefield, then shuffle your library. | SpellDescription$ Search your library for a creature card with converted mana cost equal to 1 plus the sacrificed creature's converted mana cost, put that card onto the battlefield, then shuffle your library. Activate this ability only any time you could cast a sorcery. +A:AB$ ChangeZone | Cost$ 1 PG T Sac<1/Creature> | Origin$ Library | Destination$ Battlefield | ChangeType$ Creature.cmcEQX | References$ X | ChangeNum$ 1 | SorcerySpeed$ True | AILogic$ BirthingPod | StackDescription$ Search your library for a creature card with converted mana cost equal to 1 plus the sacrificed creature's converted mana cost, put that card onto the battlefield, then shuffle your library. | SpellDescription$ Search your library for a creature card with converted mana cost equal to 1 plus the sacrificed creature's converted mana cost, put that card onto the battlefield, then shuffle your library. Activate this ability only any time you could cast a sorcery. SVar:X:Sacrificed$CardManaCost/Plus.1 -SVar:RemAIDeck:True +SVar:AIPreference:SacCost$Creature SVar:Picture:http://www.wizards.com/global/images/magic/general/birthing_pod.jpg Oracle:({P/G} can be paid with either {G} or 2 life.)\n{1}{P/G}, {T}, Sacrifice a creature: Search your library for a creature card with converted mana cost equal to 1 plus the sacrificed creature's converted mana cost, put that card onto the battlefield, then shuffle your library. Activate this ability only any time you could cast a sorcery.