diff --git a/forge-game/src/main/java/forge/game/CardTraitBase.java b/forge-game/src/main/java/forge/game/CardTraitBase.java index a27ddf15232..999effe9c7a 100644 --- a/forge-game/src/main/java/forge/game/CardTraitBase.java +++ b/forge-game/src/main/java/forge/game/CardTraitBase.java @@ -43,6 +43,9 @@ public abstract class CardTraitBase extends GameObject { /** Keys of descriptive (text) parameters. */ private static final ImmutableList descriptiveKeys = ImmutableList.builder() .add("Description", "SpellDescription", "StackDescription", "TriggerDescription").build(); + /** Keys to be followed as SVar names when changing text. */ + private static final ImmutableList mutableKeys = ImmutableList.builder() + .add("AddAbility").build(); /** * Sets the temporary. @@ -357,15 +360,19 @@ public abstract class CardTraitBase extends GameObject { public void changeText() { for (final String key : this.mapParams.keySet()) { final String value = this.originalMapParams.get(key), newValue; - // change descriptions differently if (descriptiveKeys.contains(key)) { + // change descriptions differently newValue = AbilityUtils.applyDescriptionTextChangeEffects(value, this); - } - // don't change literal SVar names! - else if (!this.getHostCard().hasSVar(key)) { - newValue = AbilityUtils.applyAbilityTextChangeEffects(value, this); - } else { + } else if (mutableKeys.contains(key)) { + // follow SVar and change it + final String originalSVarValue = hostCard.getSVar(value); + hostCard.changeSVar(value, AbilityUtils.applyAbilityTextChangeEffects(originalSVarValue, this)); newValue = null; + } else if (this.getHostCard().hasSVar(value)) { + // don't change literal SVar names! + newValue = null; + } else { + newValue = AbilityUtils.applyAbilityTextChangeEffects(value, this); } if (newValue != null) { diff --git a/forge-game/src/main/java/forge/game/card/Card.java b/forge-game/src/main/java/forge/game/card/Card.java index 2f5f8d681c6..3fe8308e8a0 100644 --- a/forge-game/src/main/java/forge/game/card/Card.java +++ b/forge-game/src/main/java/forge/game/card/Card.java @@ -22,6 +22,7 @@ import com.google.common.base.Function; import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableMap; import com.google.common.collect.Lists; +import com.google.common.collect.Maps; import com.google.common.collect.Sets; import forge.GameCommand; @@ -123,6 +124,8 @@ public class Card extends GameEntity implements Comparable { private final CardChangedWords changedTextTypes = new CardChangedWords(); /** List of the keywords that have been added by text changes. */ private final List keywordsGrantedByTextChanges = Lists.newArrayList(); + /** Original values of SVars changed by text changes. */ + private Map originalSVars = Maps.newHashMap(); private final ArrayList rememberedObjects = new ArrayList(); private final MapOfLists rememberMap = new HashMapOfLists(CollectionSuppliers.arrayLists()); @@ -4609,6 +4612,7 @@ public class Card extends GameEntity implements Comparable { * Update the changed text of the intrinsic spell abilities and keywords. */ private final void updateChangedText() { + resetChangedSVars(); final List allAbs = ImmutableList.builder() .addAll(this.getSpellAbilities()) .addAll(this.getStaticAbilities()) @@ -4640,6 +4644,26 @@ public class Card extends GameEntity implements Comparable { this.changedTextTypes.copyFrom(other.changedTextTypes); } + /** + * Change a SVar due to a text change effect. Change is volatile and will be + * reverted upon refreshing text changes (unless it is changed again at that + * time). + * + * @param key the SVar name. + * @param value the new SVar value. + */ + public final void changeSVar(final String key, final String value) { + originalSVars.put(key, getSVar(key)); + this.setSVar(key, value); + } + + private void resetChangedSVars() { + for (final Entry svar : originalSVars.entrySet()) { + this.setSVar(svar.getKey(), svar.getValue()); + } + originalSVars.clear(); + } + /** *

* getIntrinsicAbilities.