* Fixed a problem that conditional mana could not be correctly used with AsThoughEffects (fixes #6880).

This commit is contained in:
LevelX2 2020-07-25 22:11:30 +02:00
parent 202e25208e
commit 85d18899b1
4 changed files with 117 additions and 16 deletions

View file

@ -88,15 +88,14 @@ public class ManaPool implements Serializable {
* @return
*/
public boolean pay(ManaType manaType, Ability ability, Filter filter, Game game, Cost costToPay, Mana usedManaToPay) {
if (!isAutoPayment()
&& manaType != unlockedManaType) {
if (!isAutoPayment() && manaType != unlockedManaType) {
// if manual payment and the needed mana type was not unlocked, nothing will be paid
return false;
}
ManaType possibleAsThoughPoolManaType = null;
if (isAutoPayment()
&& isAutoPaymentRestricted()
&& !wasManaAddedBeyondStock()
&& !wasManaAddedBeyondStock() // was not more mana added than at the start of casting something
&& manaType != unlockedManaType) {
// if automatic restricted payment and there is already mana in the pool
// and the needed mana type was not unlocked, nothing will be paid
@ -111,9 +110,10 @@ public class ManaPool implements Serializable {
return false; // if it's not possible return
}
}
if (getConditional(manaType, ability, filter, game, costToPay) > 0) {
removeConditional(manaType, ability, game, costToPay, usedManaToPay);
// first try to pay from conditional mana (the returned manaType can be changed if AsThoughEffects are active)
ManaType conditionalManaType = getConditional(manaType, ability, filter, game, costToPay, possibleAsThoughPoolManaType);
if (conditionalManaType != null) {
removeConditional(conditionalManaType, ability, game, costToPay, usedManaToPay);
lockManaType(); // pay only one mana if mana payment is set to manually
return true;
}
@ -160,21 +160,33 @@ public class ManaPool implements Serializable {
return getMana().get(manaType);
}
private int getConditional(ManaType manaType, Ability ability, Filter filter, Game game, Cost costToPay) {
private ManaType getConditional(ManaType manaType, Ability ability, Filter filter, Game game, Cost costToPay, ManaType possibleAsThoughPoolManaType) {
if (ability == null || getConditionalMana().isEmpty()) {
return 0;
return null;
}
for (ManaPoolItem mana : manaItems) {
if (mana.isConditional()
&& mana.getConditionalMana().get(manaType) > 0
&& mana.getConditionalMana().apply(ability, game, mana.getSourceId(), costToPay)) {
if (filter == null
|| filter.match(mana.getSourceObject(), game)) {
return mana.getConditionalMana().get(manaType);
if (mana.isConditional()) {
ManaType manaTypeToUse = null;
if (mana.getConditionalMana().get(manaType) > 0) {
manaTypeToUse = manaType;
} else {
if (possibleAsThoughPoolManaType == null) {
possibleAsThoughPoolManaType = game.getContinuousEffects().asThoughMana(manaType, mana, ability.getSourceId(), ability, ability.getControllerId(), game);
}
if (possibleAsThoughPoolManaType != null && mana.getConditionalMana().get(possibleAsThoughPoolManaType) > 0) {
manaTypeToUse = possibleAsThoughPoolManaType;
}
}
if (manaTypeToUse != null && mana.getConditionalMana().apply(ability, game, mana.getSourceId(), costToPay)) {
if (filter == null
|| filter.match(mana.getSourceObject(), game)) {
return manaTypeToUse;
}
}
}
}
return 0;
return null;
}
public int getConditionalCount(Ability ability, Game game, FilterMana filter, Cost costToPay) {

View file

@ -1,4 +1,3 @@
package mage.players;
import java.io.Serializable;
@ -205,6 +204,21 @@ public class ManaPoolItem implements Serializable {
} else if (colorless > 0) {
return ManaType.COLORLESS;
}
if (conditionalMana != null) {
if (conditionalMana.getBlack() > 0) {
return ManaType.BLACK;
} else if (conditionalMana.getBlue() > 0) {
return ManaType.BLUE;
} else if (conditionalMana.getGreen() > 0) {
return ManaType.GREEN;
} else if (conditionalMana.getRed() > 0) {
return ManaType.RED;
} else if (conditionalMana.getWhite() > 0) {
return ManaType.WHITE;
} else if (conditionalMana.getColorless() > 0) {
return ManaType.COLORLESS;
}
}
return null;
}