refactor: combined announceX methods in one, improved X message and selection for AI (part of #10330)

This commit is contained in:
Oleg Agafonov 2025-05-16 19:34:57 +04:00
parent 6af198836b
commit 66db821437
37 changed files with 90 additions and 158 deletions

View file

@ -787,8 +787,8 @@ public abstract class AbilityImpl implements Ability {
xValue = variableManaCost.getAmount();
} else {
// announce by player
xValue = controller.announceXMana(variableManaCost.getMinX(), variableManaCost.getMaxX(),
"Announce the value for " + variableManaCost.getText(), game, this);
xValue = controller.announceX(variableManaCost.getMinX(), variableManaCost.getMaxX(),
"Announce the value for " + variableManaCost.getText(), game, this, true);
}
int amountMana = xValue * variableManaCost.getXInstancesCount();

View file

@ -158,8 +158,8 @@ public abstract class VariableCostImpl implements Cost, VariableCost {
if (controller != null
&& (source instanceof ManaAbility
|| stackObject != null)) {
xValue = controller.announceXCost(getMinValue(source, game), getMaxValue(source, game),
"Announce the number of " + actionText, game, source, this);
xValue = controller.announceX(getMinValue(source, game), getMaxValue(source, game),
"Announce the value for {X} (" + actionText + ")", game, source, false);
}
return xValue;
}

View file

@ -173,8 +173,8 @@ class AssistEffect extends OneShotEffect {
// AI can't assist other players, maybe for teammates only (but tests must work as normal)
int amountToPay = 0;
if (!targetPlayer.isComputer()) {
amountToPay = targetPlayer.announceXMana(0, unpaid.getMana().getGeneric(),
"How much mana to pay as assist for " + controller.getName() + "?", game, source);
amountToPay = targetPlayer.announceX(0, unpaid.getMana().getGeneric(),
"How much mana to pay as assist for " + controller.getName() + "?", game, source, true);
}
if (amountToPay > 0) {

View file

@ -5,7 +5,6 @@ import mage.abilities.*;
import mage.abilities.costs.AlternativeSourceCosts;
import mage.abilities.costs.Cost;
import mage.abilities.costs.Costs;
import mage.abilities.costs.VariableCost;
import mage.abilities.costs.mana.ManaCost;
import mage.abilities.costs.mana.ManaCosts;
import mage.abilities.mana.ManaOptions;
@ -748,16 +747,12 @@ public interface Player extends MageItem, Copyable<Player> {
boolean shuffleCardsToLibrary(Card card, Game game, Ability source);
/**
* Set the value for X mana spells and abilities
* Set the value for X in spells and abilities
* @param isManaPay helper param for better AI logic
*/
int announceXMana(int min, int max, String message, Game game, Ability ability);
int announceX(int min, int max, String message, Game game, Ability source, boolean isManaPay);
/**
* Set the value for non mana X costs
*/
int announceXCost(int min, int max, String message, Game game, Ability ability, VariableCost variableCost);
// TODO: rework to use pair's list of effect + ability instead string's map
// TODO: rework to use pair's list of effect + ability instead string's map
int chooseReplacementEffect(Map<String, String> effectsMap, Map<String, MageObject> objectsMap, Game game);
TriggeredAbility chooseTriggeredAbility(List<TriggeredAbility> abilities, Game game);

View file

@ -156,13 +156,8 @@ public class StubPlayer extends PlayerImpl {
}
@Override
public int announceXMana(int min, int max, String message, Game game, Ability ability) {
return 0;
}
@Override
public int announceXCost(int min, int max, String message, Game game, Ability ability, VariableCost variableCost) {
return 0;
public int announceX(int min, int max, String message, Game game, Ability source, boolean isManaPay) {
return min;
}
@Override

View file

@ -710,7 +710,7 @@ public final class ManaUtil {
int bookmark = game.bookmarkState();
player.resetStoredBookmark(game);
wantToPay = player.announceXMana(0, maxValue, "Choose how much mana to pay", game, source);
wantToPay = player.announceX(0, maxValue, "Choose how much mana to pay", game, source, true);
if (wantToPay > 0) {
Cost cost = ManaUtil.createManaCost(wantToPay, payAsX);
payed = cost.pay(source, game, source, player.getId(), false, null);