From af5ff0f4072c93a6ee95f57b2a5f129688f36719 Mon Sep 17 00:00:00 2001 From: LevelX2 Date: Wed, 30 Dec 2015 11:24:55 +0100 Subject: [PATCH] [OGW] Fixed Surge to work with triggered abilities of permanents. --- .../oathofthegatewatch/TyrantOfValakut.java | 9 ++++---- .../cards/abilities/keywords/SurgeTest.java | 22 +++++++++++++++++++ .../cards/triggers/GeistOfSaintTraftTest.java | 8 +++---- .../condition/common/SurgedCondition.java | 14 ++++++++++-- .../mage/abilities/keyword/SurgeAbility.java | 18 +++++++++++++++ 5 files changed, 60 insertions(+), 11 deletions(-) diff --git a/Mage.Sets/src/mage/sets/oathofthegatewatch/TyrantOfValakut.java b/Mage.Sets/src/mage/sets/oathofthegatewatch/TyrantOfValakut.java index a52129b852d..f056207142e 100644 --- a/Mage.Sets/src/mage/sets/oathofthegatewatch/TyrantOfValakut.java +++ b/Mage.Sets/src/mage/sets/oathofthegatewatch/TyrantOfValakut.java @@ -53,18 +53,17 @@ public class TyrantOfValakut extends CardImpl { this.power = new MageInt(5); this.toughness = new MageInt(4); + // Surge {3}{R}{R} (You may cast this spell for its surge cost if you or a teammate has cast another spell this turn) + addAbility(new SurgeAbility(this, "{3}{R}{R}")); + // Flying this.addAbility(FlyingAbility.getInstance()); - + // When Tyrant of Valakut enters the battlefield, if its surge cost was paid, it deals 3 damage to target creature or player. EntersBattlefieldTriggeredAbility ability = new EntersBattlefieldTriggeredAbility(new DamageTargetEffect(3), false); ability.addTarget(new TargetCreatureOrPlayer()); this.addAbility(new ConditionalTriggeredAbility(ability, SurgedCondition.getInstance(), "When {this} enters the battlefield, if its surge cost was paid, it deals 3 damage to target creature or player.")); - - // Has to be placed last here, because added spellAbility objects (e.g. effects) have to be copied from this - // Surge {3}{R}{R} (You may cast this spell for its surge cost if you or a teammate has cast another spell this turn) - addAbility(new SurgeAbility(this, "{3}{R}{R}")); } public TyrantOfValakut(final TyrantOfValakut card) { diff --git a/Mage.Tests/src/test/java/org/mage/test/cards/abilities/keywords/SurgeTest.java b/Mage.Tests/src/test/java/org/mage/test/cards/abilities/keywords/SurgeTest.java index 6c4b97d4886..053f5f8492d 100644 --- a/Mage.Tests/src/test/java/org/mage/test/cards/abilities/keywords/SurgeTest.java +++ b/Mage.Tests/src/test/java/org/mage/test/cards/abilities/keywords/SurgeTest.java @@ -88,4 +88,26 @@ public class SurgeTest extends CardTestPlayerBase { assertLife(playerB, 17); } + @Test + public void testTyrantOfValakut() { + addCard(Zone.BATTLEFIELD, playerA, "Mountain", 6); + // Surge {3}{R}{R} (You may cast this spell for its surge cost if you or a teammate has cast another spell this turn) + // Flying + // When Tyrant of Valakut enters the battlefield, if its surge cost was paid, it deals 3 damage to target creature or player. + addCard(Zone.HAND, playerA, "Tyrant of Valakut"); // {5}{R}{R} + addCard(Zone.HAND, playerA, "Lightning Bolt"); + + castSpell(1, PhaseStep.PRECOMBAT_MAIN, playerA, "Lightning Bolt", playerB); + castSpell(1, PhaseStep.PRECOMBAT_MAIN, playerA, "Tyrant of Valakut"); + addTarget(playerA, playerB); + + setStopAt(1, PhaseStep.BEGIN_COMBAT); + execute(); + + assertGraveyardCount(playerA, "Lightning Bolt", 1); + assertPermanentCount(playerA, "Tyrant of Valakut", 1); + + assertLife(playerB, 14); + } + } diff --git a/Mage.Tests/src/test/java/org/mage/test/cards/triggers/GeistOfSaintTraftTest.java b/Mage.Tests/src/test/java/org/mage/test/cards/triggers/GeistOfSaintTraftTest.java index 2bf22a6a292..afd3f30374b 100644 --- a/Mage.Tests/src/test/java/org/mage/test/cards/triggers/GeistOfSaintTraftTest.java +++ b/Mage.Tests/src/test/java/org/mage/test/cards/triggers/GeistOfSaintTraftTest.java @@ -40,8 +40,9 @@ public class GeistOfSaintTraftTest extends CardTestPlayerBase { /** * Geist of Saint Traft - Legendary Spirit Cleric 2/2, {1}{W}{U} * - * Hexproof - * Whenever Geist of Saint Traft attacks, put a 4/4 white Angel creature token with flying onto the battlefield tapped and attacking. Exile that token at end of combat. + * Hexproof Whenever Geist of Saint Traft attacks, put a 4/4 white Angel + * creature token with flying onto the battlefield tapped and attacking. + * Exile that token at end of combat. * */ @Test @@ -51,7 +52,7 @@ public class GeistOfSaintTraftTest extends CardTestPlayerBase { attack(2, playerB, "Geist of Saint Traft"); - setStopAt(2, PhaseStep.END_COMBAT); + setStopAt(2, PhaseStep.COMBAT_DAMAGE); execute(); assertPermanentCount(playerB, "Geist of Saint Traft", 1); @@ -63,7 +64,6 @@ public class GeistOfSaintTraftTest extends CardTestPlayerBase { assertLife(playerB, 20); } - @Test public void testTokenwillBeExiled() { diff --git a/Mage/src/main/java/mage/abilities/condition/common/SurgedCondition.java b/Mage/src/main/java/mage/abilities/condition/common/SurgedCondition.java index 333832322e9..065a8d9ceb2 100644 --- a/Mage/src/main/java/mage/abilities/condition/common/SurgedCondition.java +++ b/Mage/src/main/java/mage/abilities/condition/common/SurgedCondition.java @@ -27,9 +27,11 @@ */ package mage.abilities.condition.common; +import java.util.ArrayList; import mage.abilities.Ability; import mage.abilities.condition.Condition; import mage.abilities.keyword.SurgeAbility; +import mage.constants.AbilityType; import mage.game.Game; /** @@ -52,7 +54,15 @@ public class SurgedCondition implements Condition { @Override public boolean apply(Game game, Ability source) { - // if surge is used for permanents we have to chnage implementation - return source instanceof SurgeAbility; + if (source.getAbilityType().equals(AbilityType.TRIGGERED)) { + @SuppressWarnings("unchecked") + ArrayList surgeActivations = (ArrayList) game.getState().getValue(SurgeAbility.SURGE_ACTIVATION_VALUE_KEY + source.getSourceId()); + if (surgeActivations != null) { + return surgeActivations.contains(game.getState().getZoneChangeCounter(source.getSourceId()) - 1); + } + return false; + } else { + return source instanceof SurgeAbility; + } } } diff --git a/Mage/src/main/java/mage/abilities/keyword/SurgeAbility.java b/Mage/src/main/java/mage/abilities/keyword/SurgeAbility.java index f7f13273bc9..84c64cd49d5 100644 --- a/Mage/src/main/java/mage/abilities/keyword/SurgeAbility.java +++ b/Mage/src/main/java/mage/abilities/keyword/SurgeAbility.java @@ -27,6 +27,7 @@ */ package mage.abilities.keyword; +import java.util.ArrayList; import java.util.UUID; import mage.abilities.SpellAbility; import mage.abilities.costs.mana.ManaCostsImpl; @@ -43,6 +44,8 @@ import mage.watchers.common.CastSpellLastTurnWatcher; */ public class SurgeAbility extends SpellAbility { + public static final String SURGE_ACTIVATION_VALUE_KEY = "surgeActivation"; + private String rule; public SurgeAbility(Card card, String surgeCosts) { @@ -81,6 +84,21 @@ public class SurgeAbility extends SpellAbility { return false; } + @Override + @SuppressWarnings("unchecked") + public boolean activate(Game game, boolean noMana) { + if (super.activate(game, noMana)) { + ArrayList surgeActivations = (ArrayList) game.getState().getValue(SURGE_ACTIVATION_VALUE_KEY + getSourceId()); + if (surgeActivations == null) { + surgeActivations = new ArrayList<>(); // zoneChangeCounter + game.getState().setValue(SURGE_ACTIVATION_VALUE_KEY + getSourceId(), surgeActivations); + } + surgeActivations.add(game.getState().getZoneChangeCounter(getSourceId())); + return true; + } + return false; + } + @Override public SurgeAbility copy() { return new SurgeAbility(this);