GUI, game: improved priority pass on non-empty mana pool (no more confirm dialogs on active "don't lose unspent mana" and other effects, close #11717)

This commit is contained in:
Oleg Agafonov 2025-01-06 03:33:06 +04:00
parent fbd5cca14a
commit 75d241d541
2 changed files with 32 additions and 9 deletions

View file

@ -2928,7 +2928,7 @@ public class HumanPlayer extends PlayerImpl {
protected boolean passWithManaPoolCheck(Game game) {
if (userData.confirmEmptyManaPool()
&& game.getStack().isEmpty() && getManaPool().count() > 0) {
&& game.getStack().isEmpty() && getManaPool().count() > 0 && getManaPool().canLostManaOnEmpty()) {
String activePlayerText;
if (game.isActivePlayer(playerId)) {
activePlayerText = "Your turn";
@ -2940,7 +2940,7 @@ public class HumanPlayer extends PlayerImpl {
priorityPlayerText = " / priority " + game.getPlayer(game.getPriorityPlayerId()).getName();
}
// TODO: chooseUse and other dialogs must be under controlling player
if (!chooseUse(Outcome.Detriment, GameLog.getPlayerConfirmColoredText("You still have mana in your mana pool. Pass regardless?")
if (!chooseUse(Outcome.Detriment, GameLog.getPlayerConfirmColoredText("You still have mana in your mana pool and it will be lose. Pass anyway?")
+ GameLog.getSmallSecondLineText(activePlayerText + " / " + game.getTurnStepType().toString() + priorityPlayerText), null, game)) {
sendPlayerAction(PlayerAction.PASS_PRIORITY_CANCEL_ALL_ACTIONS, game, null);
return false;

View file

@ -38,9 +38,10 @@ public class ManaPool implements Serializable {
private boolean forcedToPay; // for Word of Command
private final List<ManaPoolItem> poolBookmark = new ArrayList<>(); // mana pool bookmark for rollback purposes
private final Set<ManaType> doNotEmptyManaTypes = new HashSet<>();
private boolean manaBecomesBlack = false;
private boolean manaBecomesColorless = false;
// empty mana pool effects
private final Set<ManaType> doNotEmptyManaTypes = new HashSet<>(); // keep some colors
private boolean manaBecomesBlack = false; // replace all pool by black
private boolean manaBecomesColorless = false; // replace all pool by colorless
private static final class ConditionalManaInfo {
private final ManaType manaType;
@ -147,10 +148,10 @@ public class ManaPool implements Serializable {
if (ability.getSourceId().equals(mana.getSourceId())
|| !(mana.getSourceObject() instanceof Spell)
|| ((Spell) mana.getSourceObject())
.getAbilities(game)
.stream()
.flatMap(a -> a.getAllEffects().stream())
.anyMatch(ManaEffect.class::isInstance)) {
.getAbilities(game)
.stream()
.flatMap(a -> a.getAllEffects().stream())
.anyMatch(ManaEffect.class::isInstance)) {
continue; // if any of the above cases, not an alt mana payment ability, thus excluded by filter
}
}
@ -253,6 +254,28 @@ public class ManaPool implements Serializable {
manaItems.clear();
}
public boolean canLostManaOnEmpty() {
for (ManaPoolItem item : manaItems) {
for (ManaType manaType : ManaType.values()) {
if (item.get(manaType) == 0) {
continue;
}
if (doNotEmptyManaTypes.contains(manaType)) {
continue;
}
if (manaBecomesBlack) {
continue;
}
if (manaBecomesColorless) {
continue;
}
// found real mana to empty
return true;
}
}
return false;
}
public int emptyPool(Game game) {
int total = 0;
Iterator<ManaPoolItem> it = manaItems.iterator();