* @param unpaid
* @param useableAbilities
* @return
*/
private static LinkedHashMap<UUID, ManaAbility> getManaAbilitiesUsingMana(ManaCost unpaid, LinkedHashMap<UUID, ManaAbility> useableAbilities) {
Mana mana = unpaid.getMana();
int countColorfull = 0;
int countColorless = 0;
ManaAbility chosenManaAbility = null;
for (ManaAbility ability : useableAbilities.values()) {
if (ability instanceof RedManaAbility && mana.contains(Mana.RedMana)) {
chosenManaAbility = ability;
countColorfull++;
}
if (ability instanceof BlackManaAbility && mana.contains(Mana.BlackMana)) {
chosenManaAbility = ability;
countColorfull++;
}
if (ability instanceof BlueManaAbility && mana.contains(Mana.BlueMana)) {
chosenManaAbility = ability;
countColorfull++;
}
if (ability instanceof WhiteManaAbility && mana.contains(Mana.WhiteMana)) {
chosenManaAbility = ability;
countColorfull++;
}
if (ability instanceof GreenManaAbility && mana.contains(Mana.GreenMana)) {
chosenManaAbility = ability;
countColorfull++;
}
}
if (countColorfull == 0) { // seems there is no colorful mana we can use
// try to pay {1}
if (mana.getColorless() > 0) {
// use any (lets choose first)
return replace(useableAbilities, useableAbilities.values().iterator().next());
}
// return map as-is without any modification