AI: logic for X in Sac cost

This commit is contained in:
Hans Mackowiak
2021-01-02 05:15:08 +00:00
committed by Michael Kamensky
parent 6841f3c084
commit 7c9ac66e8a
69 changed files with 283 additions and 320 deletions

View File

@@ -29,7 +29,6 @@ import forge.game.ability.AbilityUtils;
import forge.game.card.Card;
import forge.game.card.CardPlayOption;
import forge.game.cost.Cost;
import forge.game.cost.CostPartMana;
import forge.game.cost.CostPayment;
import forge.game.keyword.KeywordInterface;
import forge.game.mana.ManaPool;
@@ -221,9 +220,7 @@ public class HumanPlaySpellAbility {
if (ability.isCopied()) { return true; } //don't re-announce for spell copies
boolean needX = true;
final boolean allowZero = !ability.hasParam("XCantBe0");
final Cost cost = ability.getPayCosts();
final CostPartMana manaCost = cost.getCostMana();
final PlayerController controller = ability.getActivatingPlayer().getController();
final Card card = ability.getHostCard();
@@ -237,7 +234,7 @@ public class HumanPlaySpellAbility {
final boolean isX = "X".equalsIgnoreCase(varName);
if (isX) { needX = false; }
final Integer value = controller.announceRequirements(ability, varName, allowZero && (!isX || manaCost == null || manaCost.canXbe0()));
final Integer value = controller.announceRequirements(ability, varName);
if (value == null) {
return false;
}
@@ -254,17 +251,17 @@ public class HumanPlaySpellAbility {
}
}
if (needX && manaCost != null) {
if (needX) {
if (cost.hasXInAnyCostPart()) {
final String sVar = ability.getSVar("X"); //only prompt for new X value if card doesn't determine it another way
if ("Count$xPaid".equals(sVar) || sVar.isEmpty()) {
final Integer value = controller.announceRequirements(ability, "X", allowZero && manaCost.canXbe0());
final Integer value = controller.announceRequirements(ability, "X");
if (value == null) {
return false;
}
ability.setXManaCostPaid(value);
}
} else if (manaCost.getMana().isZero() && ability.isSpell()) {
} else {
ability.setXManaCostPaid(0);
}
}

View File

@@ -320,12 +320,12 @@ public class PlayerControllerHuman extends PlayerController implements IGameCont
}
@Override
public Integer announceRequirements(final SpellAbility ability, final String announce,
final boolean canChooseZero) {
final int min = canChooseZero ? 0 : 1;
public Integer announceRequirements(final SpellAbility ability, final String announce) {
int max = Integer.MAX_VALUE;
boolean canChooseZero = true;
if ("X".equals(announce)) {
canChooseZero = !ability.hasParam("XCantBe0");
Cost cost = ability.getPayCosts();
if (ability.hasParam("XMaxLimit")) {
max = Math.min(max, AbilityUtils.calculateAmount(ability.getHostCard(), ability.getParam("XMaxLimit"), ability));
@@ -333,10 +333,14 @@ public class PlayerControllerHuman extends PlayerController implements IGameCont
if (cost != null) {
Integer costX = cost.getMaxForNonManaX(ability, player);
if (costX != null) {
max = Math.min(max, min);
max = Math.min(max, costX);
}
if (cost.hasManaCost() && !cost.getCostMana().canXbe0()) {
canChooseZero = false;
}
}
}
final int min = canChooseZero ? 0 : 1;
if (ability.usesTargeting()) {
// if announce is used as min targets, check what the max possible number would be
@@ -344,6 +348,9 @@ public class PlayerControllerHuman extends PlayerController implements IGameCont
max = Math.min(max, CardUtil.getValidCardsToTarget(ability.getTargetRestrictions(), ability).size());
}
}
if (min > max) {
return null;
}
return getGui().getInteger(localizer.getMessage("lblChooseAnnounceForCard", announce,
CardTranslation.getTranslatedName(ability.getHostCard().getName())) , min, max, min + 9);
}