* Use for automatic mana payment of generic mana costs first abilities without additional costs (fixes #6408).

This commit is contained in:
LevelX2 2020-06-14 09:34:29 +02:00
parent aaf1f7da7b
commit 033f80c6ed

View file

@ -1,10 +1,12 @@
package mage.util;
import java.util.*;
import mage.MageObject;
import mage.Mana;
import mage.ManaSymbol;
import mage.abilities.Ability;
import mage.abilities.costs.Cost;
import mage.abilities.costs.common.TapSourceCost;
import mage.abilities.costs.mana.*;
import mage.abilities.dynamicvalue.DynamicValue;
import mage.abilities.dynamicvalue.common.ManacostVariableValue;
@ -17,8 +19,6 @@ import mage.filter.FilterMana;
import mage.game.Game;
import mage.players.Player;
import java.util.*;
/**
* @author noxx
*/
@ -46,7 +46,7 @@ public final class ManaUtil {
* In case we can't auto choose we'll simply return the useableAbilities map
* back to caller without any modification.
*
* @param unpaid Mana we need to pay. Can be null (it is for X costs now).
* @param unpaid Mana we need to pay. Can be null (it is for X costs now).
* @param useableAbilities List of mana abilities permanent may produce
* @return List of mana abilities permanent may produce and are reasonable
* for unpaid mana
@ -373,7 +373,12 @@ public final class ManaUtil {
if (countColorfull == 0) { // seems there is no colorful mana we can use
// try to pay {1}
if (mana.getGeneric() > 0) {
// use any (lets choose first)
// choose first without addional costs if all have addional costs take the first
for (ActivatedManaAbilityImpl manaAbility : useableAbilities.values()) {
if (manaAbility.getCosts().size() == 1 && manaAbility.getCosts().get(0).getClass().equals(TapSourceCost.class)) {
return replace(useableAbilities, manaAbility);
}
}
return replace(useableAbilities, useableAbilities.values().iterator().next());
}
@ -499,7 +504,8 @@ public final class ManaUtil {
}
/**
* all ability/effect code with "= new GenericManaCost" must be replaced by createManaCost call
* all ability/effect code with "= new GenericManaCost" must be replaced by
* createManaCost call
*/
public static ManaCost createManaCost(int genericManaCount, boolean payAsX) {
if (payAsX) {