From e8c87a8edf65282a0f760e146898447c980883cc Mon Sep 17 00:00:00 2001 From: tool4EvEr Date: Fri, 30 Sep 2022 09:09:03 +0200 Subject: [PATCH 1/2] Fix crash when spending mana produced by a gained ability with triggers --- .../java/forge/game/spellability/AbilityManaPart.java | 9 ++++++++- .../main/java/forge/game/spellability/SpellAbility.java | 3 ++- forge-gui/res/cardsfolder/m/myr_superion.txt | 2 +- forge-gui/res/cardsfolder/p/path_of_ancestry.txt | 2 +- .../cardsfolder/p/primal_amulet_primal_wellspring.txt | 2 +- forge-gui/res/cardsfolder/p/pyromancers_goggles.txt | 2 +- 6 files changed, 14 insertions(+), 6 deletions(-) diff --git a/forge-game/src/main/java/forge/game/spellability/AbilityManaPart.java b/forge-game/src/main/java/forge/game/spellability/AbilityManaPart.java index 4986ceff38a..8523ff7d7cd 100644 --- a/forge-game/src/main/java/forge/game/spellability/AbilityManaPart.java +++ b/forge-game/src/main/java/forge/game/spellability/AbilityManaPart.java @@ -29,6 +29,7 @@ import forge.card.MagicColor; import forge.card.mana.ManaAtom; import forge.card.mana.ManaCostShard; import forge.game.GameActionUtil; +import forge.game.IHasSVars; import forge.game.ability.AbilityKey; import forge.game.ability.ApiType; import forge.game.card.Card; @@ -72,6 +73,7 @@ public class AbilityManaPart implements java.io.Serializable { private transient List lastManaProduced = Lists.newArrayList(); private transient Card sourceCard; + private transient IHasSVars sVarHolder; // Spells paid with this mana spell can't be countered. @@ -85,8 +87,13 @@ public class AbilityManaPart implements java.io.Serializable { * @param sourceCard * a {@link forge.game.card.Card} object. */ + public AbilityManaPart(final SpellAbility sourceSA, final Map params) { + this(sourceSA.getHostCard(), params); + sVarHolder = sourceSA; + } public AbilityManaPart(final Card sourceCard, final Map params) { this.sourceCard = sourceCard; + sVarHolder = sourceCard; origProduced = params.getOrDefault("Produced", "1"); this.manaRestrictions = params.getOrDefault("RestrictValid", ""); @@ -260,7 +267,7 @@ public class AbilityManaPart implements java.io.Serializable { return; 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); } diff --git a/forge-game/src/main/java/forge/game/spellability/SpellAbility.java b/forge-game/src/main/java/forge/game/spellability/SpellAbility.java index 68f2aaaf235..756e1da0e81 100644 --- a/forge-game/src/main/java/forge/game/spellability/SpellAbility.java +++ b/forge-game/src/main/java/forge/game/spellability/SpellAbility.java @@ -149,6 +149,7 @@ public abstract class SpellAbility extends CardTraitBase implements ISpellAbilit protected ApiType api = null; private List payingMana = Lists.newArrayList(); + @Deprecated private List paidAbilities = Lists.newArrayList(); private Integer xManaCostPaid = null; @@ -1111,7 +1112,7 @@ public abstract class SpellAbility extends CardTraitBase implements ISpellAbilit clone.setPayCosts(getPayCosts().copy()); if (manaPart != null) { - clone.manaPart = new AbilityManaPart(host, mapParams); + clone.manaPart = new AbilityManaPart(this, mapParams); } // need to copy the damage tables diff --git a/forge-gui/res/cardsfolder/m/myr_superion.txt b/forge-gui/res/cardsfolder/m/myr_superion.txt index 1cde0e51968..8bf51592798 100644 --- a/forge-gui/res/cardsfolder/m/myr_superion.txt +++ b/forge-gui/res/cardsfolder/m/myr_superion.txt @@ -3,6 +3,6 @@ ManaCost:2 Types:Artifact Creature Myr PT:5/6 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 Oracle:Spend only mana produced by creatures to cast this spell. diff --git a/forge-gui/res/cardsfolder/p/path_of_ancestry.txt b/forge-gui/res/cardsfolder/p/path_of_ancestry.txt index 7906a596de5..78b51d43ef1 100644 --- a/forge-gui/res/cardsfolder/p/path_of_ancestry.txt +++ b/forge-gui/res/cardsfolder/p/path_of_ancestry.txt @@ -3,7 +3,7 @@ ManaCost:no cost Types:Land 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.) -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 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.) diff --git a/forge-gui/res/cardsfolder/p/primal_amulet_primal_wellspring.txt b/forge-gui/res/cardsfolder/p/primal_amulet_primal_wellspring.txt index 9af25d1ec31..c18c54ae554 100644 --- a/forge-gui/res/cardsfolder/p/primal_amulet_primal_wellspring.txt +++ b/forge-gui/res/cardsfolder/p/primal_amulet_primal_wellspring.txt @@ -21,6 +21,6 @@ Name:Primal Wellspring ManaCost:no cost 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. -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 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. diff --git a/forge-gui/res/cardsfolder/p/pyromancers_goggles.txt b/forge-gui/res/cardsfolder/p/pyromancers_goggles.txt index ffc243a4add..c1498b83532 100644 --- a/forge-gui/res/cardsfolder/p/pyromancers_goggles.txt +++ b/forge-gui/res/cardsfolder/p/pyromancers_goggles.txt @@ -2,6 +2,6 @@ Name:Pyromancer's Goggles ManaCost:5 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. -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 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. From 8ffe596f319b8962a456485f279201b60a05cbd5 Mon Sep 17 00:00:00 2001 From: tool4EvEr Date: Fri, 30 Sep 2022 10:30:25 +0200 Subject: [PATCH 2/2] Remove Deprecated --- .../src/main/java/forge/game/spellability/SpellAbility.java | 1 - 1 file changed, 1 deletion(-) diff --git a/forge-game/src/main/java/forge/game/spellability/SpellAbility.java b/forge-game/src/main/java/forge/game/spellability/SpellAbility.java index 756e1da0e81..96b0f80b943 100644 --- a/forge-game/src/main/java/forge/game/spellability/SpellAbility.java +++ b/forge-game/src/main/java/forge/game/spellability/SpellAbility.java @@ -149,7 +149,6 @@ public abstract class SpellAbility extends CardTraitBase implements ISpellAbilit protected ApiType api = null; private List payingMana = Lists.newArrayList(); - @Deprecated private List paidAbilities = Lists.newArrayList(); private Integer xManaCostPaid = null;