mirror of
https://github.com/Card-Forge/forge.git
synced 2025-11-18 11:48:02 +00:00
- Improved SacAndUpgrade AI, now it works with Eldritch Evolution and requires fewer parameters in scripts.
This commit is contained in:
@@ -1419,8 +1419,8 @@ public class ChangeZoneAi extends SpellAbilityAi {
|
|||||||
private boolean doSacAndUpgradeLogic(final Player ai, SpellAbility sa) {
|
private boolean doSacAndUpgradeLogic(final Player ai, SpellAbility sa) {
|
||||||
Card source = sa.getHostCard();
|
Card source = sa.getHostCard();
|
||||||
PhaseHandler ph = ai.getGame().getPhaseHandler();
|
PhaseHandler ph = ai.getGame().getPhaseHandler();
|
||||||
boolean sacWorst = sa.getParam("AILogic").contains("SacWorst");
|
String logic = sa.getParam("AILogic");
|
||||||
boolean anyCMC = sa.getParam("AILogic").contains("GoalAnyCMC");
|
boolean sacWorst = logic.contains("SacWorst");
|
||||||
|
|
||||||
if (!ph.is(PhaseType.MAIN2)) {
|
if (!ph.is(PhaseType.MAIN2)) {
|
||||||
// Should be given a chance to cast other spells as well as to use a previously upgraded creature
|
// 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 definedSac = StringUtils.split(source.getSVar("AIPreference"), "$")[1];
|
||||||
String definedGoal = sa.hasParam("AISearchGoal") ? sa.getParam("AISearchGoal") : "Creature";
|
String definedGoal = sa.getParam("ChangeType");
|
||||||
|
boolean anyCMC = !definedGoal.contains(".cmc");
|
||||||
String overridePrefix = definedGoal.contains(".") ? definedGoal + "+" : definedGoal + ".";
|
|
||||||
|
|
||||||
CardCollection listToSac = CardLists.filter(ai.getCardsIn(ZoneType.Battlefield), CardPredicates.restriction(definedSac.split(","), ai, source, sa));
|
CardCollection listToSac = CardLists.filter(ai.getCardsIn(ZoneType.Battlefield), CardPredicates.restriction(definedSac.split(","), ai, source, sa));
|
||||||
listToSac.sort(!sacWorst ? CardLists.CmcComparatorInv : Collections.reverseOrder(CardLists.CmcComparatorInv));
|
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) {
|
for (Card sacCandidate : listToSac) {
|
||||||
int sacCMC = sacCandidate.getCMC();
|
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) {
|
if (!anyCMC) {
|
||||||
// e.g. Birthing Pod - ensure we have a valid card to upgrade to
|
// TODO: improve the detection of X in the "cmc**X" part to avoid clashing with other letters in the definition
|
||||||
listGoal = CardLists.getValidCards(listGoal, overridePrefix + "cmcEQ" + goalCMC, source.getController(), source);
|
curGoal = definedGoal.replace("X", String.format("%d", goalCMC));
|
||||||
} else {
|
|
||||||
// e.g. Natural Order - ensure we're upgrading to something better
|
|
||||||
listGoal = CardLists.getValidCards(listGoal, overridePrefix + "cmcGE" + goalCMC, source.getController(), source);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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>() {
|
listGoal = CardLists.filter(listGoal, new Predicate<Card>() {
|
||||||
@Override
|
@Override
|
||||||
public boolean apply(final Card c) {
|
public boolean apply(final Card c) {
|
||||||
|
|||||||
@@ -1,8 +1,9 @@
|
|||||||
Name:Eldritch Evolution
|
Name:Eldritch Evolution
|
||||||
ManaCost:1 G G
|
ManaCost:1 G G
|
||||||
Types:Sorcery
|
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:DBChange:DB$ ChangeZone | Origin$ Stack | Destination$ Exile
|
||||||
SVar:X:Sacrificed$CardManaCost/Plus.2
|
SVar:X:Sacrificed$CardManaCost/Plus.2
|
||||||
|
SVar:AIPreference:SacCost$Creature
|
||||||
SVar:Picture:http://www.wizards.com/global/images/magic/general/eldritch_evolution.jpg
|
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.
|
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.
|
||||||
@@ -1,7 +1,7 @@
|
|||||||
Name:Natural Order
|
Name:Natural Order
|
||||||
ManaCost:2 G G
|
ManaCost:2 G G
|
||||||
Types:Sorcery
|
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.
|
# AI Preference is needed to make the AI consider the ability. Further constraints are defined by AILogic SacAndUpgrade.
|
||||||
SVar:AIPreference:SacCost$Creature.Green
|
SVar:AIPreference:SacCost$Creature.Green
|
||||||
SVar:Picture:http://www.wizards.com/global/images/magic/general/natural_order.jpg
|
SVar:Picture:http://www.wizards.com/global/images/magic/general/natural_order.jpg
|
||||||
|
|||||||
Reference in New Issue
Block a user