* Repeated Reverberation - fixed rollback error on creatures cast (#7474);

This commit is contained in:
Oleg Agafonov 2021-02-03 10:27:23 +04:00
parent 5077a82585
commit c03279d835
3 changed files with 70 additions and 40 deletions

View file

@ -60,8 +60,8 @@ class RepeatedReverberationTriggeredAbility extends DelayedTriggeredAbility {
@Override @Override
public boolean checkEventType(GameEvent event, Game game) { public boolean checkEventType(GameEvent event, Game game) {
return event.getType() == GameEvent.EventType.SPELL_CAST return event.getType() == GameEvent.EventType.ACTIVATED_ABILITY
|| event.getType() == GameEvent.EventType.ACTIVATED_ABILITY; || event.getType() == GameEvent.EventType.SPELL_CAST;
} }
@Override @Override
@ -69,6 +69,22 @@ class RepeatedReverberationTriggeredAbility extends DelayedTriggeredAbility {
if (!event.getPlayerId().equals(this.getControllerId())) { if (!event.getPlayerId().equals(this.getControllerId())) {
return false; return false;
} }
// activated ability
if (event.getType() == GameEvent.EventType.ACTIVATED_ABILITY) {
StackAbility stackAbility = (StackAbility) game.getStack().getStackObject(event.getSourceId());
if (stackAbility != null && stackAbility.getStackAbility() instanceof LoyaltyAbility) {
this.getEffects().clear();
this.addEffect(
new RepeatedReverberationEffect()
.setTargetPointer(new FixedTarget(event.getTargetId(), game))
);
return true;
}
}
// spell
if (event.getType() == GameEvent.EventType.SPELL_CAST) {
Spell spell = game.getStack().getSpell(event.getTargetId()); Spell spell = game.getStack().getSpell(event.getTargetId());
if (spell != null && spell.isInstantOrSorcery()) { if (spell != null && spell.isInstantOrSorcery()) {
this.getEffects().clear(); this.getEffects().clear();
@ -82,15 +98,8 @@ class RepeatedReverberationTriggeredAbility extends DelayedTriggeredAbility {
); );
return true; return true;
} }
StackAbility stackAbility = (StackAbility) game.getStack().getStackObject(event.getSourceId());
if (stackAbility != null && stackAbility.getStackAbility() instanceof LoyaltyAbility) {
this.getEffects().clear();
this.addEffect(
new RepeatedReverberationEffect()
.setTargetPointer(new FixedTarget(event.getTargetId(), game))
);
return true;
} }
return false; return false;
} }

View file

@ -1,7 +1,5 @@
package mage.cards.r; package mage.cards.r;
import java.util.UUID;
import mage.abilities.Ability; import mage.abilities.Ability;
import mage.abilities.TriggeredAbilityImpl; import mage.abilities.TriggeredAbilityImpl;
import mage.abilities.costs.mana.ManaCostsImpl; import mage.abilities.costs.mana.ManaCostsImpl;
@ -15,13 +13,13 @@ import mage.constants.Outcome;
import mage.constants.Zone; import mage.constants.Zone;
import mage.game.Game; import mage.game.Game;
import mage.game.events.GameEvent; import mage.game.events.GameEvent;
import mage.game.events.GameEvent.EventType;
import mage.game.permanent.Permanent; import mage.game.permanent.Permanent;
import mage.game.stack.StackAbility; import mage.game.stack.StackAbility;
import mage.players.Player; import mage.players.Player;
import java.util.UUID;
/** /**
*
* @author LevelX2 * @author LevelX2
*/ */
public final class RingsOfBrighthearth extends CardImpl { public final class RingsOfBrighthearth extends CardImpl {

View file

@ -1,4 +1,3 @@
package org.mage.test.cards.single.m20; package org.mage.test.cards.single.m20;
import mage.constants.PhaseStep; import mage.constants.PhaseStep;
@ -8,7 +7,6 @@ import org.junit.Test;
import org.mage.test.serverside.base.CardTestPlayerBase; import org.mage.test.serverside.base.CardTestPlayerBase;
/** /**
*
* @author Jgray1206 * @author Jgray1206
*/ */
public class RepeatedReverberationTest extends CardTestPlayerBase { public class RepeatedReverberationTest extends CardTestPlayerBase {
@ -24,7 +22,7 @@ public class RepeatedReverberationTest extends CardTestPlayerBase {
* Repeated Reverberation was not working with loyalty counter abilities. * Repeated Reverberation was not working with loyalty counter abilities.
*/ */
@Test @Test
public void testRepeatedReverberationWorksWithLoyaltyAbilities() { public void test_WorksWithLoyaltyAbilities() {
/* Ajani Goldmane: {2}{W}{W} starts with 4 Loyality counters /* Ajani Goldmane: {2}{W}{W} starts with 4 Loyality counters
* +1: You gain 2 life. * +1: You gain 2 life.
* -1: Put a +1/+1 counter on each creature you control. Those creatures gain vigilance until end of turn. * -1: Put a +1/+1 counter on each creature you control. Those creatures gain vigilance until end of turn.
@ -41,20 +39,20 @@ public class RepeatedReverberationTest extends CardTestPlayerBase {
castSpell(1, PhaseStep.PRECOMBAT_MAIN, playerA, repeatedReverb); castSpell(1, PhaseStep.PRECOMBAT_MAIN, playerA, repeatedReverb);
activateAbility(1, PhaseStep.PRECOMBAT_MAIN, playerA, "+1: You gain 2 life"); activateAbility(1, PhaseStep.PRECOMBAT_MAIN, playerA, "+1: You gain 2 life");
setStopAt(1, PhaseStep.BEGIN_COMBAT);
setStrictChooseMode(true); setStrictChooseMode(true);
setStopAt(1, PhaseStep.BEGIN_COMBAT);
execute(); execute();
assertAllCommandsUsed();
assertPermanentCount(playerA, ajani, 1); assertPermanentCount(playerA, ajani, 1);
assertGraveyardCount(playerA, repeatedReverb, 1); assertGraveyardCount(playerA, repeatedReverb, 1);
assertCounterCount(ajani, CounterType.LOYALTY, 5); // 4 + 1 = 5 assertCounterCount(ajani, CounterType.LOYALTY, 5); // 4 + 1 = 5
assertLife(playerA, 26); assertLife(playerA, 26);
assertAllCommandsUsed();
} }
@Test @Test
public void testRepeatedReverberationWorksWithInstants() { public void test_WorksWithInstants() {
/* Soothing Balm - Instant {1}{W} /* Soothing Balm - Instant {1}{W}
* Target player gains 5 life * Target player gains 5 life
* Just an arbitrary instant to test reverb with. * Just an arbitrary instant to test reverb with.
@ -75,20 +73,20 @@ public class RepeatedReverberationTest extends CardTestPlayerBase {
setChoice(playerA, "Yes"); //Choose new targets? setChoice(playerA, "Yes"); //Choose new targets?
addTarget(playerA, playerA); addTarget(playerA, playerA);
setStopAt(1, PhaseStep.BEGIN_COMBAT);
setStrictChooseMode(true); setStrictChooseMode(true);
setStopAt(1, PhaseStep.BEGIN_COMBAT);
execute(); execute();
assertAllCommandsUsed();
assertGraveyardCount(playerA, soothingBalm, 1); assertGraveyardCount(playerA, soothingBalm, 1);
assertGraveyardCount(playerA, repeatedReverb, 1); assertGraveyardCount(playerA, repeatedReverb, 1);
assertLife(playerA, 30); assertLife(playerA, 30);
assertLife(playerB, 25); assertLife(playerB, 25);
assertAllCommandsUsed();
} }
@Test @Test
public void testRepeatedReverberationWorksWithSorceries() { public void test_WorksWithSorceries() {
/* Soul Feast - Sorcery {3}{B}{B} /* Soul Feast - Sorcery {3}{B}{B}
* Target player loses 4 life. You gain 4 life. * Target player loses 4 life. You gain 4 life.
* Just an arbitrary sorcery to test reverb with. * Just an arbitrary sorcery to test reverb with.
@ -106,15 +104,40 @@ public class RepeatedReverberationTest extends CardTestPlayerBase {
setChoice(playerA, "No"); //Choose new targets? setChoice(playerA, "No"); //Choose new targets?
setChoice(playerA, "No"); //Choose new targets? setChoice(playerA, "No"); //Choose new targets?
setStopAt(1, PhaseStep.BEGIN_COMBAT);
setStrictChooseMode(true); setStrictChooseMode(true);
setStopAt(1, PhaseStep.BEGIN_COMBAT);
execute(); execute();
assertAllCommandsUsed();
assertGraveyardCount(playerA, soulFeast, 1); assertGraveyardCount(playerA, soulFeast, 1);
assertGraveyardCount(playerA, repeatedReverb, 1); assertGraveyardCount(playerA, repeatedReverb, 1);
assertLife(playerA, 32); assertLife(playerA, 32);
assertLife(playerB, 8); assertLife(playerB, 8);
}
@Test
public void test_MustNotWorksWithCreatures() {
addCard(Zone.HAND, playerA, repeatedReverb); // {2}{R}{R}
addCard(Zone.BATTLEFIELD, playerA, "Mountain", 4);
//
addCard(Zone.HAND, playerA, "Balduvian Bears", 1);
addCard(Zone.BATTLEFIELD, playerA, "Forest", 2);
// prepare reverb
activateManaAbility(1, PhaseStep.PRECOMBAT_MAIN, playerA, "{T}: Add {R}", 4);
castSpell(1, PhaseStep.PRECOMBAT_MAIN, playerA, repeatedReverb);
waitStackResolved(1, PhaseStep.PRECOMBAT_MAIN);
// cast creature
activateManaAbility(1, PhaseStep.PRECOMBAT_MAIN, playerA, "{T}: Add {G}", 2);
castSpell(1, PhaseStep.PRECOMBAT_MAIN, playerA, "Balduvian Bears");
setStrictChooseMode(true);
setStopAt(1, PhaseStep.END_TURN);
execute();
assertAllCommandsUsed(); assertAllCommandsUsed();
assertPermanentCount(playerA, "Balduvian Bears", 1);
assertGraveyardCount(playerA, repeatedReverb, 1);
} }
} }