use of mage.abilities.costs.mana.AlternateManaPaymentAbility in project mage by magefree.
the class PlayerImpl method findActivatedAbilityFromPlayable.
protected ActivatedAbility findActivatedAbilityFromPlayable(MageObject object, ManaOptions availableMana, Ability ability, Game game) {
// special mana to pay spell cost
ManaOptions manaFull = availableMana.copy();
if (ability instanceof SpellAbility) {
for (AlternateManaPaymentAbility altAbility : CardUtil.getAbilities(object, game).stream().filter(a -> a instanceof AlternateManaPaymentAbility).map(a -> (AlternateManaPaymentAbility) a).collect(Collectors.toList())) {
ManaOptions manaSpecial = altAbility.getManaOptions(ability, game, ability.getManaCostsToPay());
manaFull.addMana(manaSpecial);
}
}
// replace alternative abilities by real play abilities (e.g. morph/facedown static ability by play land)
if (ability instanceof ActivatedManaAbilityImpl) {
// mana ability
if (((ActivatedManaAbilityImpl) ability).canActivate(this.getId(), game).canActivate()) {
return (ActivatedManaAbilityImpl) ability;
}
} else if (ability instanceof AlternativeSourceCosts) {
// alternative cost must be replaced by real play ability
return findActivatedAbilityFromAlternativeSourceCost(object, manaFull, ability, game);
} else if (ability instanceof ActivatedAbility) {
// all other activated ability
if (canPlay((ActivatedAbility) ability, manaFull, object, game)) {
return (ActivatedAbility) ability;
}
}
// non playable abilities like static
return null;
}
Aggregations