}
@Override
public boolean playMana(ManaCost unpaid, Game game) {
// logger.fine("playMana");
ManaCost cost;
List<Permanent> producers;
if (unpaid instanceof ManaCosts) {
cost = ((ManaCosts<ManaCost>)unpaid).get(0);
producers = getSortedProducers((ManaCosts)unpaid, game);
}
else {
cost = unpaid;
producers = this.getAvailableManaProducers(game);
}
for (Permanent perm: producers) {
// pay all colored costs first
for (ManaAbility ability: perm.getAbilities().getManaAbilities(Zone.BATTLEFIELD)) {
if (cost instanceof ColoredManaCost) {
if (cost.testPay(ability.getNetMana(game))) {
if (activateAbility(ability, game))
return true;
}
}
}
// then pay hybrid
for (ManaAbility ability: perm.getAbilities().getManaAbilities(Zone.BATTLEFIELD)) {
if (cost instanceof HybridManaCost) {
if (cost.testPay(ability.getNetMana(game))) {
if (activateAbility(ability, game))
return true;
}
}
}
// then pay mono hybrid
for (ManaAbility ability: perm.getAbilities().getManaAbilities(Zone.BATTLEFIELD)) {
if (cost instanceof MonoHybridManaCost) {
if (cost.testPay(ability.getNetMana(game))) {
if (activateAbility(ability, game))
return true;
}
}
}
// finally pay generic
for (ManaAbility ability: perm.getAbilities().getManaAbilities(Zone.BATTLEFIELD)) {
if (cost instanceof GenericManaCost) {
if (cost.testPay(ability.getNetMana(game))) {
if (activateAbility(ability, game))
return true;
}
}
}