Merge pull request #1607 from tool4ever/managainfix

Fix crash when spending mana produced by a gained ability with triggers
This commit is contained in:
Anthony Calosa
2022-09-30 16:39:00 +08:00
committed by GitHub
6 changed files with 13 additions and 6 deletions

View File

@@ -29,6 +29,7 @@ import forge.card.MagicColor;
import forge.card.mana.ManaAtom; import forge.card.mana.ManaAtom;
import forge.card.mana.ManaCostShard; import forge.card.mana.ManaCostShard;
import forge.game.GameActionUtil; import forge.game.GameActionUtil;
import forge.game.IHasSVars;
import forge.game.ability.AbilityKey; import forge.game.ability.AbilityKey;
import forge.game.ability.ApiType; import forge.game.ability.ApiType;
import forge.game.card.Card; import forge.game.card.Card;
@@ -72,6 +73,7 @@ public class AbilityManaPart implements java.io.Serializable {
private transient List<Mana> lastManaProduced = Lists.newArrayList(); private transient List<Mana> lastManaProduced = Lists.newArrayList();
private transient Card sourceCard; private transient Card sourceCard;
private transient IHasSVars sVarHolder;
// Spells paid with this mana spell can't be countered. // Spells paid with this mana spell can't be countered.
@@ -85,8 +87,13 @@ public class AbilityManaPart implements java.io.Serializable {
* @param sourceCard * @param sourceCard
* a {@link forge.game.card.Card} object. * a {@link forge.game.card.Card} object.
*/ */
public AbilityManaPart(final SpellAbility sourceSA, final Map<String, String> params) {
this(sourceSA.getHostCard(), params);
sVarHolder = sourceSA;
}
public AbilityManaPart(final Card sourceCard, final Map<String, String> params) { public AbilityManaPart(final Card sourceCard, final Map<String, String> params) {
this.sourceCard = sourceCard; this.sourceCard = sourceCard;
sVarHolder = sourceCard;
origProduced = params.getOrDefault("Produced", "1"); origProduced = params.getOrDefault("Produced", "1");
this.manaRestrictions = params.getOrDefault("RestrictValid", ""); this.manaRestrictions = params.getOrDefault("RestrictValid", "");
@@ -260,7 +267,7 @@ public class AbilityManaPart implements java.io.Serializable {
return; return;
TriggerHandler handler = card.getGame().getTriggerHandler(); TriggerHandler handler = card.getGame().getTriggerHandler();
Trigger trig = TriggerHandler.parseTrigger(sourceCard.getSVar(this.triggersWhenSpent), sourceCard, false); Trigger trig = TriggerHandler.parseTrigger(sVarHolder.getSVar(this.triggersWhenSpent), sourceCard, false);
handler.registerOneTrigger(trig); handler.registerOneTrigger(trig);
} }

View File

@@ -1111,7 +1111,7 @@ public abstract class SpellAbility extends CardTraitBase implements ISpellAbilit
clone.setPayCosts(getPayCosts().copy()); clone.setPayCosts(getPayCosts().copy());
if (manaPart != null) { if (manaPart != null) {
clone.manaPart = new AbilityManaPart(host, mapParams); clone.manaPart = new AbilityManaPart(this, mapParams);
} }
// need to copy the damage tables // need to copy the damage tables

View File

@@ -3,6 +3,6 @@ ManaCost:2
Types:Artifact Creature Myr Types:Artifact Creature Myr
PT:5/6 PT:5/6
Text:Spend only mana produced by creatures to cast this spell. Text:Spend only mana produced by creatures to cast this spell.
A:SP$ PermanentCreature | Cost$ Mana<2\Creature> A:SP$ PermanentCreature | Cost$ Mana<2\Creature.inZoneBattlefield>
AI:RemoveDeck:Random AI:RemoveDeck:Random
Oracle:Spend only mana produced by creatures to cast this spell. Oracle:Spend only mana produced by creatures to cast this spell.

View File

@@ -3,7 +3,7 @@ ManaCost:no cost
Types:Land Types:Land
K:CARDNAME enters the battlefield tapped. K:CARDNAME enters the battlefield tapped.
A:AB$ Mana | Cost$ T | Produced$ Combo ColorIdentity | TriggersWhenSpent$ TrigScry | SpellDescription$ Add one mana of any color in your commander's color identity. When that mana is spent to cast a creature spell that shares a creature type with your commander, scry 1. (Look at the top card of your library. You may put that card on the bottom of your library.) A:AB$ Mana | Cost$ T | Produced$ Combo ColorIdentity | TriggersWhenSpent$ TrigScry | SpellDescription$ Add one mana of any color in your commander's color identity. When that mana is spent to cast a creature spell that shares a creature type with your commander, scry 1. (Look at the top card of your library. You may put that card on the bottom of your library.)
SVar:TrigScry:Mode$ SpellCast | ValidCard$ Creature.sharesCreatureTypeWith Commander | OneOff$ True | Execute$ DBScry | TriggerDescription$ When mana produced by CARDNAME is spent to cast a creature spell that shares a creature type with your commander, scry 1. SVar:TrigScry:Mode$ SpellCast | ValidCard$ Creature.sharesCreatureTypeWith Commander | Execute$ DBScry | TriggerDescription$ When mana produced by CARDNAME is spent to cast a creature spell that shares a creature type with your commander, scry 1.
SVar:DBScry:DB$ Scry | ScryNum$ 1 SVar:DBScry:DB$ Scry | ScryNum$ 1
AI:RemoveDeck:NonCommander AI:RemoveDeck:NonCommander
Oracle:Path of Ancestry enters the battlefield tapped.\n{T}: Add one mana of any color in your commander's color identity. When that mana is spent to cast a creature spell that shares a creature type with your commander, scry 1. (Look at the top card of your library. You may put that card on the bottom of your library.) Oracle:Path of Ancestry enters the battlefield tapped.\n{T}: Add one mana of any color in your commander's color identity. When that mana is spent to cast a creature spell that shares a creature type with your commander, scry 1. (Look at the top card of your library. You may put that card on the bottom of your library.)

View File

@@ -21,6 +21,6 @@ Name:Primal Wellspring
ManaCost:no cost ManaCost:no cost
Types:Land Types:Land
A:AB$ Mana | Cost$ T | Produced$ Any | TriggersWhenSpent$ TrigCopy | SpellDescription$ Add one mana of any color. When that mana is spent to cast an instant or sorcery spell, copy that spell and you may choose new targets for the copy. A:AB$ Mana | Cost$ T | Produced$ Any | TriggersWhenSpent$ TrigCopy | SpellDescription$ Add one mana of any color. When that mana is spent to cast an instant or sorcery spell, copy that spell and you may choose new targets for the copy.
SVar:TrigCopy:Mode$ SpellCast | ValidCard$ Instant,Sorcery | OneOff$ True | Execute$ TrigCopyMain | TriggerDescription$ When that mana is spent to cast an instant or sorcery spell, copy that spell and you may choose new targets for the copy. SVar:TrigCopy:Mode$ SpellCast | ValidCard$ Instant,Sorcery | Execute$ TrigCopyMain | TriggerDescription$ When that mana is spent to cast an instant or sorcery spell, copy that spell and you may choose new targets for the copy.
SVar:TrigCopyMain:DB$ CopySpellAbility | Defined$ TriggeredSpellAbility | MayChooseTarget$ True SVar:TrigCopyMain:DB$ CopySpellAbility | Defined$ TriggeredSpellAbility | MayChooseTarget$ True
Oracle:(Transforms from Primal Amulet.)\n{T}: Add one mana of any color. When that mana is spent to cast an instant or sorcery spell, copy that spell and you may choose new targets for the copy. Oracle:(Transforms from Primal Amulet.)\n{T}: Add one mana of any color. When that mana is spent to cast an instant or sorcery spell, copy that spell and you may choose new targets for the copy.

View File

@@ -2,6 +2,6 @@ Name:Pyromancer's Goggles
ManaCost:5 ManaCost:5
Types:Legendary Artifact Types:Legendary Artifact
A:AB$ Mana | Cost$ T | Produced$ R | TriggersWhenSpent$ TrigCopy | SpellDescription$ Add {R}. When that mana is spent to cast a red instant or sorcery spell, copy that spell and you may choose new targets for the copy. A:AB$ Mana | Cost$ T | Produced$ R | TriggersWhenSpent$ TrigCopy | SpellDescription$ Add {R}. When that mana is spent to cast a red instant or sorcery spell, copy that spell and you may choose new targets for the copy.
SVar:TrigCopy:Mode$ SpellCast | ValidCard$ Instant.Red,Sorcery.Red | OneOff$ True | Execute$ TrigCopyMain | TriggerDescription$ When that mana is spent to cast a red instant or sorcery spell, copy that spell and you may choose new targets for the copy. SVar:TrigCopy:Mode$ SpellCast | ValidCard$ Instant.Red,Sorcery.Red | Execute$ TrigCopyMain | TriggerDescription$ When that mana is spent to cast a red instant or sorcery spell, copy that spell and you may choose new targets for the copy.
SVar:TrigCopyMain:DB$ CopySpellAbility | Defined$ TriggeredSpellAbility | MayChooseTarget$ True SVar:TrigCopyMain:DB$ CopySpellAbility | Defined$ TriggeredSpellAbility | MayChooseTarget$ True
Oracle:{T}: Add {R}. When that mana is spent to cast a red instant or sorcery spell, copy that spell and you may choose new targets for the copy. Oracle:{T}: Add {R}. When that mana is spent to cast a red instant or sorcery spell, copy that spell and you may choose new targets for the copy.