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

This commit is contained in:
Agetian
2017-01-23 10:21:46 +00:00
parent dffee55c52
commit 280e4d10b2
2 changed files with 12 additions and 7 deletions

View File

@@ -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<Card>() {
@Override

View File

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