From 39fee40e5f0ac3887eaa427a3104bf9a3034dc0d Mon Sep 17 00:00:00 2001
From: Cameron Merkel <44722506+Cguy7777@users.noreply.github.com>
Date: Wed, 14 Feb 2024 23:22:06 -0600
Subject: [PATCH] [MIR] Implement Torrent of Lava (#11664)
* [MIR] Implement Torrent of Lava
* Show id of the ToL on the stack in the gained ability text
---
Mage.Sets/src/mage/cards/t/TorrentOfLava.java | 134 ++++++++++++++++++
Mage.Sets/src/mage/sets/Mirage.java | 1 +
Mage/src/main/java/mage/util/GameLog.java | 6 +-
3 files changed, 140 insertions(+), 1 deletion(-)
create mode 100644 Mage.Sets/src/mage/cards/t/TorrentOfLava.java
diff --git a/Mage.Sets/src/mage/cards/t/TorrentOfLava.java b/Mage.Sets/src/mage/cards/t/TorrentOfLava.java
new file mode 100644
index 00000000000..4ad328c94c8
--- /dev/null
+++ b/Mage.Sets/src/mage/cards/t/TorrentOfLava.java
@@ -0,0 +1,134 @@
+package mage.cards.t;
+
+import mage.abilities.Ability;
+import mage.abilities.common.SimpleActivatedAbility;
+import mage.abilities.common.SimpleStaticAbility;
+import mage.abilities.costs.common.TapSourceCost;
+import mage.abilities.dynamicvalue.common.ManacostVariableValue;
+import mage.abilities.effects.Effect;
+import mage.abilities.effects.common.DamageAllEffect;
+import mage.abilities.effects.common.PreventDamageToSourceEffect;
+import mage.abilities.effects.common.continuous.GainAbilityAllEffect;
+import mage.abilities.keyword.FlyingAbility;
+import mage.cards.CardImpl;
+import mage.cards.CardSetInfo;
+import mage.constants.CardType;
+import mage.constants.Duration;
+import mage.constants.Zone;
+import mage.filter.StaticFilters;
+import mage.filter.common.FilterCreaturePermanent;
+import mage.filter.predicate.Predicates;
+import mage.filter.predicate.mageobject.AbilityPredicate;
+import mage.game.Game;
+import mage.game.events.GameEvent;
+import mage.game.stack.Spell;
+import mage.util.GameLog;
+
+import java.util.UUID;
+
+/**
+ * @author Cguy7777
+ */
+public final class TorrentOfLava extends CardImpl {
+
+ private static final FilterCreaturePermanent filter = new FilterCreaturePermanent("creature without flying");
+
+ static {
+ filter.add(Predicates.not(new AbilityPredicate(FlyingAbility.class)));
+ }
+
+ public TorrentOfLava(UUID ownerId, CardSetInfo setInfo) {
+ super(ownerId, setInfo, new CardType[]{CardType.SORCERY}, "{X}{R}{R}");
+
+ // Torrent of Lava deals X damage to each creature without flying.
+ this.getSpellAbility().addEffect(new DamageAllEffect(ManacostVariableValue.REGULAR, filter));
+
+ // As long as Torrent of Lava is on the stack, each creature has
+ // "{tap}: Prevent the next 1 damage that would be dealt to this creature by Torrent of Lava this turn."
+ this.addAbility(new SimpleStaticAbility(Zone.STACK, new TorrentOfLavaGainAbilityEffect()));
+ }
+
+ private TorrentOfLava(final TorrentOfLava card) {
+ super(card);
+ }
+
+ @Override
+ public TorrentOfLava copy() {
+ return new TorrentOfLava(this);
+ }
+}
+
+class TorrentOfLavaGainAbilityEffect extends GainAbilityAllEffect {
+
+ TorrentOfLavaGainAbilityEffect() {
+ super(new SimpleActivatedAbility(
+ new TorrentOfLavaPreventionEffect(null, 0), new TapSourceCost()),
+ Duration.Custom,
+ StaticFilters.FILTER_PERMANENT_CREATURES);
+ this.staticText = "As long as {this} is on the stack, " +
+ "each creature has \"{T}: Prevent the next 1 damage that would be dealt to this creature by {this} this turn.\"";
+ }
+
+ private TorrentOfLavaGainAbilityEffect(final TorrentOfLavaGainAbilityEffect effect) {
+ super(effect);
+ }
+
+ @Override
+ public boolean apply(Game game, Ability source) {
+ Spell spell = game.getStack().getSpell(source.getSourceId());
+ if (spell == null) {
+ return false;
+ }
+
+ Effect effect = new TorrentOfLavaPreventionEffect(spell.getId(), spell.getZoneChangeCounter(game));
+ // Display the id of the spell on the stack, not the card id
+ String idName = spell.getName() + " [" + spell.getId().toString().substring(0, 3) + "]";
+ effect.setText("Prevent the next 1 damage that would be dealt to {this} by "
+ + GameLog.getColoredObjectIdNameForTooltip(spell.getColor(game), idName) + " this turn");
+
+ ability = new SimpleActivatedAbility(effect, new TapSourceCost());
+ return super.apply(game, source);
+ }
+
+ @Override
+ public TorrentOfLavaGainAbilityEffect copy() {
+ return new TorrentOfLavaGainAbilityEffect(this);
+ }
+}
+
+class TorrentOfLavaPreventionEffect extends PreventDamageToSourceEffect {
+
+ private final UUID preventDamageFromId;
+ private final int zoneChangeCounter;
+
+ TorrentOfLavaPreventionEffect(UUID preventDamageFromId, int zoneChangeCounter) {
+ super(Duration.EndOfTurn, 1);
+ this.preventDamageFromId = preventDamageFromId;
+ this.zoneChangeCounter = zoneChangeCounter;
+ }
+
+ private TorrentOfLavaPreventionEffect(final TorrentOfLavaPreventionEffect effect) {
+ super(effect);
+ this.preventDamageFromId = effect.preventDamageFromId;
+ this.zoneChangeCounter = effect.zoneChangeCounter;
+ }
+
+ @Override
+ public boolean applies(GameEvent event, Ability source, Game game) {
+ if (!super.applies(event, source, game) || preventDamageFromId == null) {
+ return false;
+ }
+
+ Spell spell = game.getStack().getSpell(event.getSourceId());
+ if (spell == null) {
+ return false;
+ }
+
+ return spell.getId().equals(preventDamageFromId) && spell.getZoneChangeCounter(game) == zoneChangeCounter;
+ }
+
+ @Override
+ public TorrentOfLavaPreventionEffect copy() {
+ return new TorrentOfLavaPreventionEffect(this);
+ }
+}
diff --git a/Mage.Sets/src/mage/sets/Mirage.java b/Mage.Sets/src/mage/sets/Mirage.java
index 9d34e243915..5b3f59aafee 100644
--- a/Mage.Sets/src/mage/sets/Mirage.java
+++ b/Mage.Sets/src/mage/sets/Mirage.java
@@ -329,6 +329,7 @@ public final class Mirage extends ExpansionSet {
cards.add(new SetCardInfo("Thirst", 99, Rarity.COMMON, mage.cards.t.Thirst.class));
cards.add(new SetCardInfo("Tidal Wave", 100, Rarity.UNCOMMON, mage.cards.t.TidalWave.class));
cards.add(new SetCardInfo("Tombstone Stairwell", 149, Rarity.RARE, mage.cards.t.TombstoneStairwell.class));
+ cards.add(new SetCardInfo("Torrent of Lava", 199, Rarity.RARE, mage.cards.t.TorrentOfLava.class));
cards.add(new SetCardInfo("Tranquil Domain", 245, Rarity.COMMON, mage.cards.t.TranquilDomain.class));
cards.add(new SetCardInfo("Tropical Storm", 246, Rarity.UNCOMMON, mage.cards.t.TropicalStorm.class));
cards.add(new SetCardInfo("Uktabi Faerie", 247, Rarity.COMMON, mage.cards.u.UktabiFaerie.class));
diff --git a/Mage/src/main/java/mage/util/GameLog.java b/Mage/src/main/java/mage/util/GameLog.java
index fc9d396cd47..cbc48e670b7 100644
--- a/Mage/src/main/java/mage/util/GameLog.java
+++ b/Mage/src/main/java/mage/util/GameLog.java
@@ -111,7 +111,11 @@ public final class GameLog {
}
public static String getColoredObjectIdNameForTooltip(MageObject mageObject) {
- return "" + mageObject.getIdName() + "";
+ return getColoredObjectIdNameForTooltip(mageObject.getColor(null), mageObject.getIdName());
+ }
+
+ public static String getColoredObjectIdNameForTooltip(ObjectColor color, String idName) {
+ return "" + idName + "";
}
public static String getNeutralColoredText(String text) {