- Improved SacAndUpgrade AI, now it works with Eldritch Evolution and requires fewer parameters in scripts.

This commit is contained in:
Agetian
2017-01-24 17:42:03 +00:00
parent e4ddffc0a8
commit 0ba88f3ce5
3 changed files with 20 additions and 16 deletions

View File

@@ -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<Card>() {
@Override
public boolean apply(final Card c) {

View File

@@ -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.

View File

@@ -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