Skip to content

Commit

Permalink
GUI, game: improved priority pass on non-empty mana pool (no more con…
Browse files Browse the repository at this point in the history
…firm dialogs on active "don't lose unspent mana" and other effects, close #11717)
  • Loading branch information
JayDi85 committed Jan 5, 2025
1 parent fbd5cca commit 75d241d
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2928,7 +2928,7 @@ private void setTriggerAutoOrder(PlayerAction playerAction, Game game, Object da

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";
Expand All @@ -2940,7 +2940,7 @@ protected boolean passWithManaPoolCheck(Game game) {
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;
Expand Down
37 changes: 30 additions & 7 deletions Mage/src/main/java/mage/players/ManaPool.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -147,10 +148,10 @@ && isAutoPaymentRestricted()
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
}
}
Expand Down Expand Up @@ -253,6 +254,28 @@ public void init() {
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();
Expand Down

0 comments on commit 75d241d

Please sign in to comment.