From 280e4d10b2199fa7029165ecb785f3640e11ade1 Mon Sep 17 00:00:00 2001 From: Agetian Date: Mon, 23 Jan 2017 10:21:46 +0000 Subject: [PATCH] - Make AILogic BirthingPod obey card restrictions specified in AIPreference SacCost (for the purpose of being flexible for not only Birthing Pod but Natural Order and potentially other cards). Now this AI Logic probably needs a better name. --- .../src/main/java/forge/ai/SpecialCardAi.java | 17 +++++++++++------ forge-gui/res/cardsfolder/n/natural_order.txt | 2 +- 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/forge-ai/src/main/java/forge/ai/SpecialCardAi.java b/forge-ai/src/main/java/forge/ai/SpecialCardAi.java index 39a34fee69f..6b97d92e688 100644 --- a/forge-ai/src/main/java/forge/ai/SpecialCardAi.java +++ b/forge-ai/src/main/java/forge/ai/SpecialCardAi.java @@ -47,6 +47,7 @@ import forge.game.player.PlayerPredicates; import forge.game.spellability.SpellAbility; import forge.game.zone.ZoneType; import forge.util.Aggregates; +import org.apache.commons.lang3.StringUtils; /** * Special logic for individual cards @@ -79,21 +80,25 @@ public class SpecialCardAi { // Should be given a chance to cast other spells as well as to use a previously upgraded creature return false; } - - CardCollection listToSac = CardLists.filter(ai.getCardsIn(ZoneType.Battlefield), CardPredicates.Presets.CREATURES); - listToSac.sort(!sacWorst ? CardLists.CmcComparatorInv : Collections.reverseOrder(CardLists.CmcComparatorInv)); + String definedPref = StringUtils.split(source.getSVar("AIPreference"), "$")[1]; + String overridePrefix = definedPref.contains(".") ? definedPref + "+" : definedPref + "."; + + CardCollection listToSac = CardLists.filter(ai.getCardsIn(ZoneType.Battlefield), CardPredicates.restriction(definedPref.split(","), ai, source, sa)); + listToSac.sort(!sacWorst ? CardLists.CmcComparatorInv : Collections.reverseOrder(CardLists.CmcComparatorInv)); + for (Card sacCandidate : listToSac) { int sacCMC = sacCandidate.getCMC(); int goalCMC = sacCMC + 1; - CardCollection listGoal = CardLists.filter(ai.getCardsIn(ZoneType.Library), CardPredicates.Presets.CREATURES); + CardCollection listGoal = CardLists.filter(ai.getCardsIn(ZoneType.Library), CardPredicates.restriction(definedPref.split(","), ai, source, sa)); + if (!anyCMC) { // e.g. Birthing Pod - ensure we have a valid card to upgrade to - listGoal = CardLists.getValidCards(listGoal, "Creature.cmcEQ" + goalCMC, source.getController(), source); + 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, "Creature.cmcGE" + goalCMC, source.getController(), source); + listGoal = CardLists.getValidCards(listGoal, overridePrefix + "cmcGE" + goalCMC, source.getController(), source); } listGoal = CardLists.filter(listGoal, new Predicate() { @Override diff --git a/forge-gui/res/cardsfolder/n/natural_order.txt b/forge-gui/res/cardsfolder/n/natural_order.txt index e772901756a..60ff249ce1b 100644 --- a/forge-gui/res/cardsfolder/n/natural_order.txt +++ b/forge-gui/res/cardsfolder/n/natural_order.txt @@ -3,6 +3,6 @@ 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$ BirthingPod.SacWorst+AnyCMCGoal | 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 BirthingPod. -SVar:AIPreference:SacCost$Creature +SVar:AIPreference:SacCost$Creature.Green SVar:Picture:http://www.wizards.com/global/images/magic/general/natural_order.jpg Oracle:As an additional cost to cast Natural Order, sacrifice a green creature.\nSearch your library for a green creature card and put it onto the battlefield. Then shuffle your library.