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 1aab95f2a05..2c5144ba3f3 100644 --- a/forge-ai/src/main/java/forge/ai/ability/ChangeZoneAi.java +++ b/forge-ai/src/main/java/forge/ai/ability/ChangeZoneAi.java @@ -1419,8 +1419,8 @@ public class ChangeZoneAi extends SpellAbilityAi { private boolean doSacAndUpgradeLogic(final Player ai, SpellAbility sa) { Card source = sa.getHostCard(); PhaseHandler ph = ai.getGame().getPhaseHandler(); - boolean sacWorst = sa.getParam("AILogic").contains("SacWorst"); - boolean anyCMC = sa.getParam("AILogic").contains("GoalAnyCMC"); + String logic = sa.getParam("AILogic"); + boolean sacWorst = logic.contains("SacWorst"); if (!ph.is(PhaseType.MAIN2)) { // Should be given a chance to cast other spells as well as to use a previously upgraded creature @@ -1428,28 +1428,31 @@ public class ChangeZoneAi extends SpellAbilityAi { } String definedSac = StringUtils.split(source.getSVar("AIPreference"), "$")[1]; - String definedGoal = sa.hasParam("AISearchGoal") ? sa.getParam("AISearchGoal") : "Creature"; - - String overridePrefix = definedGoal.contains(".") ? definedGoal + "+" : definedGoal + "."; + String definedGoal = sa.getParam("ChangeType"); + boolean anyCMC = !definedGoal.contains(".cmc"); CardCollection listToSac = CardLists.filter(ai.getCardsIn(ZoneType.Battlefield), CardPredicates.restriction(definedSac.split(","), ai, source, sa)); listToSac.sort(!sacWorst ? CardLists.CmcComparatorInv : Collections.reverseOrder(CardLists.CmcComparatorInv)); - CardCollection listLib = CardLists.filter(ai.getCardsIn(ZoneType.Library), CardPredicates.restriction(definedGoal.split(","), ai, source, sa)); - for (Card sacCandidate : listToSac) { int sacCMC = sacCandidate.getCMC(); - int goalCMC = sacCMC + 1; - CardCollection listGoal = new CardCollection(listLib); + int goalCMC = source.hasSVar("X") ? AbilityUtils.calculateAmount(source, source.getSVar("X").replace("Sacrificed$CardManaCost", "Number$" + sacCMC), sa) : sacCMC + 1; + String curGoal = definedGoal; if (!anyCMC) { - // e.g. Birthing Pod - ensure we have a valid card to upgrade to - listGoal = CardLists.getValidCards(listGoal, overridePrefix + "cmcEQ" + goalCMC, source.getController(), source); - } else { - // e.g. Natural Order - ensure we're upgrading to something better - listGoal = CardLists.getValidCards(listGoal, overridePrefix + "cmcGE" + goalCMC, source.getController(), source); + // TODO: improve the detection of X in the "cmc**X" part to avoid clashing with other letters in the definition + curGoal = definedGoal.replace("X", String.format("%d", goalCMC)); } + + CardCollection listGoal = CardLists.filter(ai.getCardsIn(ZoneType.Library), CardPredicates.restriction(curGoal.split(","), ai, source, sa)); + + if (!anyCMC) { + listGoal = CardLists.getValidCards(listGoal, curGoal, source.getController(), source); + } else { + listGoal = CardLists.getValidCards(listGoal, curGoal + (curGoal.contains(".") ? "+" : ".") + "cmcGE" + goalCMC, source.getController(), source); + } + listGoal = CardLists.filter(listGoal, new Predicate() { @Override public boolean apply(final Card c) { diff --git a/forge-gui/res/cardsfolder/e/eldritch_evolution.txt b/forge-gui/res/cardsfolder/e/eldritch_evolution.txt index 1d7f4f74c1b..e94c2acb4ee 100644 --- a/forge-gui/res/cardsfolder/e/eldritch_evolution.txt +++ b/forge-gui/res/cardsfolder/e/eldritch_evolution.txt @@ -1,8 +1,9 @@ Name:Eldritch Evolution ManaCost:1 G G Types:Sorcery -A:SP$ ChangeZone | Cost$ 1 G G Sac<1/Creature> | Origin$ Library | Destination$ Battlefield | ChangeType$ Creature.cmcLEX | ChangeNum$ 1 | References$ X | SubAbility$ DBChange | StackDescription$ SpellDescription | SpellDescription$ Search your library for a creature card with converted mana cost X or less, where X is 2 plus the sacrificed creature's converted mana cost. Put that card onto the battlefield, then shuffle your library. Exile CARDNAME. +A:SP$ ChangeZone | Cost$ 1 G G Sac<1/Creature> | Origin$ Library | Destination$ Battlefield | ChangeType$ Creature.cmcLEX | ChangeNum$ 1 | References$ X | SubAbility$ DBChange | AILogic$ SacAndUpgrade+SacWorst | StackDescription$ SpellDescription | SpellDescription$ Search your library for a creature card with converted mana cost X or less, where X is 2 plus the sacrificed creature's converted mana cost. Put that card onto the battlefield, then shuffle your library. Exile CARDNAME. SVar:DBChange:DB$ ChangeZone | Origin$ Stack | Destination$ Exile SVar:X:Sacrificed$CardManaCost/Plus.2 +SVar:AIPreference:SacCost$Creature SVar:Picture:http://www.wizards.com/global/images/magic/general/eldritch_evolution.jpg Oracle:As an additional cost to cast Eldritch Evolution, sacrifice a creature.\nSearch your library for a creature card with converted mana cost X or less, where X is 2 plus the sacrificed creature's converted mana cost. Put that card onto the battlefield, then shuffle your library. Exile Eldritch Evolution. \ No newline at end of file diff --git a/forge-gui/res/cardsfolder/n/natural_order.txt b/forge-gui/res/cardsfolder/n/natural_order.txt index 2f461a548e7..37c93dadc9a 100644 --- a/forge-gui/res/cardsfolder/n/natural_order.txt +++ b/forge-gui/res/cardsfolder/n/natural_order.txt @@ -1,7 +1,7 @@ Name:Natural Order ManaCost:2 G G Types:Sorcery -A:SP$ ChangeZone | Cost$ 2 G G Sac<1/Creature.Green/green creature> | Origin$ Library | Destination$ Battlefield | ChangeType$ Creature.Green | ChangeNum$ 1 | AILogic$ SacAndUpgrade.SacWorst+GoalAnyCMC | AISearchGoal$ Creature.Green | SpellDescription$ Search your library for a green creature card and put it onto the battlefield. Then shuffle your library. +A:SP$ ChangeZone | Cost$ 2 G G Sac<1/Creature.Green/green creature> | Origin$ Library | Destination$ Battlefield | ChangeType$ Creature.Green | ChangeNum$ 1 | AILogic$ SacAndUpgrade.SacWorst | AISearchGoal$ Creature.Green | SpellDescription$ Search your library for a green creature card and put it onto the battlefield. Then shuffle your library. # AI Preference is needed to make the AI consider the ability. Further constraints are defined by AILogic SacAndUpgrade. SVar:AIPreference:SacCost$Creature.Green SVar:Picture:http://www.wizards.com/global/images/magic/general/natural_order.jpg