SpellRestrictions: restrict non special mana abilities when special is used

This commit is contained in:
Hans Mackowiak
2021-02-15 21:13:35 +01:00
parent 000c5cd889
commit 62b10fe79b
3 changed files with 16 additions and 38 deletions

View File

@@ -446,10 +446,9 @@ public abstract class SpellAbility extends CardTraitBase implements ISpellAbilit
public boolean isAbility() { return true; } public boolean isAbility() { return true; }
public boolean isActivatedAbility() { return false; } public boolean isActivatedAbility() { return false; }
public boolean isPayingSpecial() { public boolean isPayingSpecial() {
for (SpellAbility sa : getPayingManaAbilities()) { for (SpellAbility sa : getPayingManaAbilities()) {
if (sa.isImprovise() || sa.isConvoke() || sa.isDelve()) { if (sa.isSpecialPayment()) {
return true; return true;
} }
} }
@@ -461,6 +460,10 @@ public abstract class SpellAbility extends CardTraitBase implements ISpellAbilit
public boolean isImprovise() { return false; } public boolean isImprovise() { return false; }
public boolean isDelve() { return false; } public boolean isDelve() { return false; }
public boolean isSpecialPayment() {
return isConvoke() || isImprovise() || isDelve();
}
public final CardCollectionView getDelved() { public final CardCollectionView getDelved() {
return CardCollection.getView(delvedCards); return CardCollection.getView(delvedCards);
} }

View File

@@ -474,6 +474,15 @@ public class SpellAbilityRestriction extends SpellAbilityVariables {
return false; return false;
} }
} }
if (!sa.isSpecialPayment()) {
IndividualCostPaymentInstance i = game.costPaymentStack.peek();
if (i != null) {
SpellAbility saPay = i.getPayment().getAbility();
if (saPay.isPayingSpecial()) {
return false;
}
}
}
} }
if (this.getsVarToCheck() != null) { if (this.getsVarToCheck() != null) {
@@ -508,7 +517,7 @@ public class SpellAbilityRestriction extends SpellAbilityVariables {
* @return a boolean. * @return a boolean.
*/ */
public final boolean canPlay(final Card c, final SpellAbility sa) { public final boolean canPlay(final Card c, final SpellAbility sa) {
if (c.isPhasedOut() || c.isUsedToPay()) { if (c.isPhasedOut()) {
return false; return false;
} }

View File

@@ -172,40 +172,6 @@ public abstract class InputPayMana extends InputSyncronizedBase {
return false; return false;
} }
@Deprecated
public List<SpellAbility> getUsefulManaAbilities(Card card) {
List<SpellAbility> abilities = new ArrayList<>();
if (card.getController() != player) {
return abilities;
}
byte colorCanUse = 0;
for (final byte color : ManaAtom.MANATYPES) {
if (manaCost.isAnyPartPayableWith(color, player.getManaPool())) {
colorCanUse |= color;
}
}
if (manaCost.isAnyPartPayableWith((byte) ManaAtom.GENERIC, player.getManaPool())) {
colorCanUse |= ManaAtom.GENERIC;
}
if (colorCanUse == 0) { // no mana cost or something
return abilities;
}
final String typeRes = manaCost.getSourceRestriction();
if (StringUtils.isNotBlank(typeRes) && !card.getType().hasStringType(typeRes)) {
return abilities;
}
for (SpellAbility ma : getAllManaAbilities(card)) {
ma.setActivatingPlayer(player);
if (ma.isManaAbilityFor(saPaidFor, colorCanUse))
abilities.add(ma);
}
return abilities;
}
public void useManaFromPool(byte colorCode) { public void useManaFromPool(byte colorCode) {
// find the matching mana in pool. // find the matching mana in pool.
if (player.getManaPool().tryPayCostWithColor(colorCode, saPaidFor, manaCost)) { if (player.getManaPool().tryPayCostWithColor(colorCode, saPaidFor, manaCost)) {
@@ -352,7 +318,7 @@ public abstract class InputPayMana extends InputSyncronizedBase {
@Override @Override
public void run() { public void run() {
if (HumanPlay.playSpellAbility(getController(), chosen.getActivatingPlayer(), chosen)) { if (HumanPlay.playSpellAbility(getController(), chosen.getActivatingPlayer(), chosen)) {
if (chosen.isConvoke() || chosen.isImprovise() || chosen.isDelve()) { if (chosen.isSpecialPayment()) {
saPaidFor.getPayingManaAbilities().add(chosen); saPaidFor.getPayingManaAbilities().add(chosen);
// bypass the mana from Ability part // bypass the mana from Ability part
} else if (chosen.getManaPart().meetsManaRestrictions(saPaidFor)) { } else if (chosen.getManaPart().meetsManaRestrictions(saPaidFor)) {