Fix transformed backside cast failing when some AltCost apply (#6070)

This commit is contained in:
tool4ever
2024-09-05 15:34:17 +02:00
committed by GitHub
parent 1f8317dae9
commit 30af288318
2 changed files with 13 additions and 8 deletions

View File

@@ -2821,12 +2821,7 @@ public class CardFactoryUtil {
final String[] k = keyword.split(":");
final Cost disturbCost = new Cost(k[1], true);
SpellAbility newSA;
if (host.getAlternateState().getType().hasSubtype("Aura")) {
newSA = host.getAlternateState().getFirstAbility().copyWithDefinedCost(disturbCost);
} else {
newSA = new SpellPermanent(host, host.getAlternateState(), disturbCost);
}
SpellAbility newSA = host.getAlternateState().getFirstSpellAbilityWithFallback().copyWithDefinedCost(disturbCost);
newSA.setCardState(host.getAlternateState());
StringBuilder sbCost = new StringBuilder("Disturb");
@@ -3137,7 +3132,7 @@ public class CardFactoryUtil {
} else if (keyword.startsWith("Freerunning")) {
final String[] k = keyword.split(":");
final Cost freerunningCost = new Cost(k[1], false);
final SpellAbility newSA = card.getFirstSpellAbility().copyWithDefinedCost(freerunningCost);
final SpellAbility newSA = card.getFirstSpellAbilityWithFallback().copyWithDefinedCost(freerunningCost);
if (host.isInstant() || host.isSorcery()) {
newSA.putParam("Secondary", "True");
@@ -3463,7 +3458,7 @@ public class CardFactoryUtil {
} else if (keyword.startsWith("Prowl")) {
final String[] k = keyword.split(":");
final Cost prowlCost = new Cost(k[1], false);
final SpellAbility newSA = card.getFirstSpellAbility().copyWithDefinedCost(prowlCost);
final SpellAbility newSA = card.getFirstSpellAbilityWithFallback().copyWithDefinedCost(prowlCost);
if (host.isInstant() || host.isSorcery()) {
newSA.putParam("Secondary", "True");

View File

@@ -45,6 +45,7 @@ import forge.game.player.Player;
import forge.game.replacement.ReplacementEffect;
import forge.game.spellability.SpellAbility;
import forge.game.spellability.SpellAbilityPredicates;
import forge.game.spellability.SpellPermanent;
import forge.game.staticability.StaticAbility;
import forge.game.trigger.Trigger;
import forge.util.ITranslatable;
@@ -377,6 +378,15 @@ public class CardState extends GameObject implements IHasSVars, ITranslatable {
return Iterables.getFirst(getNonManaAbilities(), null);
}
public final SpellAbility getFirstSpellAbilityWithFallback() {
SpellAbility sa = getFirstSpellAbility();
if (sa != null || getTypeWithChanges().isLand()) {
return sa;
}
// this happens if it's transformed backside (e.g. Disturbed)
return new SpellPermanent(getCard(), this);
}
public final boolean hasSpellAbility(final SpellAbility sa) {
return getSpellAbilities().contains(sa);
}