- More careful use of Buyback spells without Buyback.

This commit is contained in:
Agetian
2018-12-04 14:33:46 +03:00
parent 684af6ba0b
commit ae5090a69a

View File

@@ -801,48 +801,62 @@ public class AiController {
if ("True".equals(card.getSVar("NonStackingEffect")) && isNonDisabledCardInPlay(card.getName())) { if ("True".equals(card.getSVar("NonStackingEffect")) && isNonDisabledCardInPlay(card.getName())) {
return AiPlayDecision.NeedsToPlayCriteriaNotMet; return AiPlayDecision.NeedsToPlayCriteriaNotMet;
} }
// Trying to play a card that has Buyback without a Buyback cost // Trying to play a card that has Buyback without a Buyback cost
if (card.hasKeyword(Keyword.BUYBACK) && !sa.isBuyBackAbility() && !canPlaySpellWithoutBuyback(card, sa)) {
if (card.hasStartOfKeyword("Buyback")) { return AiPlayDecision.NeedsToPlayCriteriaNotMet;
//if (card.getBuybackAbility()!=null) {
if (!sa.isBuyBackAbility()) {
boolean wasteBuybackAllowed = false;
// About to lose game : allow
if (ComputerUtil.aiLifeInDanger(player, true, 0)) {
wasteBuybackAllowed = true;
}
int copies = CardLists.filter(player.getCardsIn(ZoneType.Hand), CardPredicates.nameEquals(card.getName())).size();
// Have two copies : allow
if (copies >= 2) {
wasteBuybackAllowed = true;
}
// Won't be able to afford buyback any time soon
// If Buyback cost includes sacrifice, life, discard
int neededMana = 0;
for (SpellAbility sa2 : GameActionUtil.getOptionalCosts(sa)) {
if (sa2.isOptionalCostPaid(OptionalCost.Buyback)) {
Cost sac = sa2.getPayCosts();
CostAdjustment.adjust(sac, sa2); // Does not recognize Memory Crystal anyway???
neededMana = sac.getCostMana().getMana().getCMC();
if (sac.hasSpecificCostType(CostPayLife.class)
|| (sac.hasSpecificCostType(CostDiscard.class)) ||
(sac.hasSpecificCostType(CostSacrifice.class))) {
neededMana = 999;
}
}
}
int hasMana = ComputerUtilMana.getAvailableManaEstimate(player, false);
if (hasMana < neededMana - 1) {
wasteBuybackAllowed = true;
}
if (!wasteBuybackAllowed) return AiPlayDecision.NeedsToPlayCriteriaNotMet;
}
} }
// add any other necessary logic to play a basic spell here // add any other necessary logic to play a basic spell here
return ComputerUtilCard.checkNeedsToPlayReqs(card, sa); return ComputerUtilCard.checkNeedsToPlayReqs(card, sa);
} }
private boolean canPlaySpellWithoutBuyback(Card card, SpellAbility sa) {
boolean wasteBuybackAllowed = false;
// About to lose game : allow
if (ComputerUtil.aiLifeInDanger(player, true, 0)) {
wasteBuybackAllowed = true;
}
int copies = CardLists.filter(player.getCardsIn(ZoneType.Hand), CardPredicates.nameEquals(card.getName())).size();
// Have two copies : allow
if (copies >= 2) {
wasteBuybackAllowed = true;
}
int neededMana = 0;
boolean dangerousRecurringCost = false;
for (SpellAbility sa2 : GameActionUtil.getOptionalCosts(sa)) {
if (sa2.isOptionalCostPaid(OptionalCost.Buyback)) {
Cost sac = sa2.getPayCosts();
CostAdjustment.adjust(sac, sa2); // TODO: Does not recognize Memory Crystal
if (sac.getCostMana() != null) {
neededMana = sac.getCostMana().getMana().getCMC();
}
if (sac.hasSpecificCostType(CostPayLife.class)
|| sac.hasSpecificCostType(CostDiscard.class)
|| sac.hasSpecificCostType(CostSacrifice.class)) {
dangerousRecurringCost = true;
}
}
}
// won't be able to afford buyback any time soon
// if Buyback cost includes sacrifice, life, discard
if (dangerousRecurringCost) {
wasteBuybackAllowed = true;
}
int hasMana = ComputerUtilMana.getAvailableManaEstimate(player, false);
if (hasMana < neededMana - 1) {
wasteBuybackAllowed = true;
}
return wasteBuybackAllowed;
}
// not sure "playing biggest spell" matters? // not sure "playing biggest spell" matters?
private final static Comparator<SpellAbility> saComparator = new Comparator<SpellAbility>() { private final static Comparator<SpellAbility> saComparator = new Comparator<SpellAbility>() {
@Override @Override