diff --git a/Mage.Sets/src/mage/cards/b/BoseijuWhoSheltersAll.java b/Mage.Sets/src/mage/cards/b/BoseijuWhoSheltersAll.java index 86f68cfe0b8..95e22f74883 100644 --- a/Mage.Sets/src/mage/cards/b/BoseijuWhoSheltersAll.java +++ b/Mage.Sets/src/mage/cards/b/BoseijuWhoSheltersAll.java @@ -1,10 +1,10 @@ package mage.cards.b; -import java.util.ArrayList; -import java.util.List; -import java.util.UUID; +import java.util.*; + import mage.MageObject; +import mage.MageObjectReference; import mage.Mana; import mage.abilities.Ability; import mage.abilities.common.EntersBattlefieldTappedAbility; @@ -58,7 +58,7 @@ public final class BoseijuWhoSheltersAll extends CardImpl { class BoseijuWhoSheltersAllWatcher extends Watcher { - private List spells = new ArrayList<>(); + private final Set spells = new HashSet<>(); private final UUID originalId; public BoseijuWhoSheltersAllWatcher(UUID originalId) { @@ -69,17 +69,17 @@ class BoseijuWhoSheltersAllWatcher extends Watcher { @Override public void watch(GameEvent event, Game game) { if (event.getType() == GameEvent.EventType.MANA_PAID) { - if (event.getData() != null && event.getData().equals(originalId.toString())) { + if (event.getData() != null && event.getData().equals(originalId.toString()) && event.getTargetId() != null) { Card spell = game.getSpell(event.getTargetId()); if (spell != null && (spell.isInstant() || spell.isSorcery())) { - spells.add(event.getTargetId()); + spells.add(new MageObjectReference(game.getObject(event.getTargetId()), game)); } } } } - public boolean spellCantBeCountered(UUID spellId) { - return spells.contains(spellId); + public boolean spellCantBeCountered(MageObjectReference mor) { + return spells.contains(mor); } @Override @@ -128,6 +128,6 @@ class BoseijuWhoSheltersAllCantCounterEffect extends ContinuousRuleModifyingEffe public boolean applies(GameEvent event, Ability source, Game game) { BoseijuWhoSheltersAllWatcher watcher = game.getState().getWatcher(BoseijuWhoSheltersAllWatcher.class, source.getSourceId()); Spell spell = game.getStack().getSpell(event.getTargetId()); - return spell != null && watcher != null && watcher.spellCantBeCountered(spell.getId()); + return spell != null && watcher != null && watcher.spellCantBeCountered(new MageObjectReference(spell, game)); } } \ No newline at end of file diff --git a/Mage.Sets/src/mage/cards/c/CavernOfSouls.java b/Mage.Sets/src/mage/cards/c/CavernOfSouls.java index 1700ea17be9..bea0f012e58 100644 --- a/Mage.Sets/src/mage/cards/c/CavernOfSouls.java +++ b/Mage.Sets/src/mage/cards/c/CavernOfSouls.java @@ -1,11 +1,11 @@ package mage.cards.c; -import java.util.ArrayList; -import java.util.List; -import java.util.UUID; +import java.util.*; + import mage.ConditionalMana; import mage.MageObject; +import mage.MageObjectReference; import mage.Mana; import mage.abilities.Ability; import mage.abilities.common.AsEntersBattlefieldAbility; @@ -121,7 +121,7 @@ class CavernOfSoulsManaCondition extends CreatureCastManaCondition { class CavernOfSoulsWatcher extends Watcher { - private List spells = new ArrayList<>(); + private final Set spells = new HashSet<>(); private final UUID originalId; public CavernOfSoulsWatcher(UUID originalId) { @@ -132,14 +132,14 @@ class CavernOfSoulsWatcher extends Watcher { @Override public void watch(GameEvent event, Game game) { if (event.getType() == GameEvent.EventType.MANA_PAID) { - if (event.getData() != null && event.getData().equals(originalId.toString())) { - spells.add(event.getTargetId()); + if (event.getData() != null && event.getData().equals(originalId.toString()) && event.getTargetId() != null) { + spells.add(new MageObjectReference(game.getObject(event.getTargetId()), game)); } } } - public boolean spellCantBeCountered(UUID spellId) { - return spells.contains(spellId); + public boolean spellCantBeCountered(MageObjectReference mor) { + return spells.contains(mor); } @Override @@ -188,6 +188,6 @@ class CavernOfSoulsCantCounterEffect extends ContinuousRuleModifyingEffectImpl { public boolean applies(GameEvent event, Ability source, Game game) { CavernOfSoulsWatcher watcher = game.getState().getWatcher(CavernOfSoulsWatcher.class, source.getSourceId()); Spell spell = game.getStack().getSpell(event.getTargetId()); - return spell != null && watcher != null && watcher.spellCantBeCountered(spell.getId()); + return spell != null && watcher != null && watcher.spellCantBeCountered(new MageObjectReference(spell, game)); } } diff --git a/Mage.Tests/src/test/java/org/mage/test/cards/single/avr/CavernOfSoulsTest.java b/Mage.Tests/src/test/java/org/mage/test/cards/single/avr/CavernOfSoulsTest.java index bfbaef65bb8..4bbe5029b3d 100644 --- a/Mage.Tests/src/test/java/org/mage/test/cards/single/avr/CavernOfSoulsTest.java +++ b/Mage.Tests/src/test/java/org/mage/test/cards/single/avr/CavernOfSoulsTest.java @@ -255,4 +255,45 @@ public class CavernOfSoulsTest extends CardTestPlayerBase { } + @Test + public void testBouncedCreatureNotCountered() { + addCard(Zone.BATTLEFIELD, playerA, "Mountain", 2); + addCard(Zone.HAND, playerA, "Forest"); + addCard(Zone.HAND, playerA, "Cavern of Souls"); + addCard(Zone.HAND, playerA, "Runeclaw Bear"); + + addCard(Zone.HAND, playerB, "Counterspell", 2); + addCard(Zone.HAND, playerB, "Unsummon"); + addCard(Zone.BATTLEFIELD, playerB, "Island", 5); + + playLand(1, PhaseStep.PRECOMBAT_MAIN, playerA, "Cavern of Souls"); + setChoice(playerA, "Bear"); + + //wait for next turn, we'll need our next land drop + castSpell(3, PhaseStep.PRECOMBAT_MAIN, playerA, "Runeclaw Bear"); + + //make sure we used our cavern already and try to counter + castSpell(3, PhaseStep.PRECOMBAT_MAIN, playerB, "Counterspell"); + waitStackResolved(3, PhaseStep.PRECOMBAT_MAIN); + + checkPermanentCount("bear not countered", 3, PhaseStep.PRECOMBAT_MAIN, playerA, "Runeclaw Bear", 1); + + //counterspell fizzled, return bear to hand to try countering it again + castSpell(3, PhaseStep.BEGIN_COMBAT, playerB, "Unsummon", "Runeclaw Bear"); + waitStackResolved(3, PhaseStep.BEGIN_COMBAT); + + //recast bear, without cavern of souls conditional mana + playLand(3, PhaseStep.POSTCOMBAT_MAIN, playerA, "Forest"); + castSpell(3, PhaseStep.POSTCOMBAT_MAIN, playerA, "Runeclaw Bear"); + castSpell(3, PhaseStep.POSTCOMBAT_MAIN, playerB, "Counterspell"); + + setStopAt(3, PhaseStep.END_TURN); + execute(); + assertAllCommandsUsed(); + + assertPermanentCount(playerA, "Cavern of Souls", 1); + assertGraveyardCount(playerA, "Runeclaw Bear", 1); + assertGraveyardCount(playerB, "Counterspell", 2); + assertGraveyardCount(playerB, "Unsummon", 1); + } }