Alternative cost - fixed that it doesn't allow to cast cards that was affected by cost modification effects (example: Prowl ability, see #6698);

This commit is contained in:
Oleg Agafonov 2020-07-05 23:11:47 +04:00
parent f9a9a55f7b
commit 1e744a0aae
12 changed files with 218 additions and 114 deletions

View file

@ -3046,6 +3046,7 @@ public abstract class PlayerImpl implements Player, Serializable {
protected boolean canPlayCardByAlternateCost(Card sourceObject, ManaOptions availableMana, Ability ability, Game game) {
if (sourceObject != null && !(sourceObject instanceof Permanent)) {
Ability copyAbility; // for alternative cost and reduce tries
for (Ability alternateSourceCostsAbility : sourceObject.getAbilities()) {
// if cast for noMana no Alternative costs are allowed
if (alternateSourceCostsAbility instanceof AlternativeSourceCosts) {
@ -3064,7 +3065,15 @@ public abstract class PlayerImpl implements Player, Serializable {
if (availableMana == null) {
return true;
}
for (Mana mana : manaCosts.getOptions()) {
// alternative cost reduce
copyAbility = ability.copy();
copyAbility.getManaCostsToPay().clear();
copyAbility.getManaCostsToPay().addAll(manaCosts.copy());
sourceObject.adjustCosts(copyAbility, game);
game.getContinuousEffects().costModification(copyAbility, game);
for (Mana mana : copyAbility.getManaCostsToPay().getOptions()) {
for (Mana avail : availableMana) {
if (mana.enough(avail)) {
return true;
@ -3092,7 +3101,18 @@ public abstract class PlayerImpl implements Player, Serializable {
if (manaCosts.isEmpty()) {
return true;
} else {
for (Mana mana : manaCosts.getOptions()) {
if (availableMana == null) {
return true;
}
// alternative cost reduce
copyAbility = ability.copy();
copyAbility.getManaCostsToPay().clear();
copyAbility.getManaCostsToPay().addAll(manaCosts.copy());
sourceObject.adjustCosts(copyAbility, game);
game.getContinuousEffects().costModification(copyAbility, game);
for (Mana mana : copyAbility.getManaCostsToPay().getOptions()) {
for (Mana avail : availableMana) {
if (mana.enough(avail)) {
return true;