From 57ccef60920d947fcc3189adfe00592ebb8154bb Mon Sep 17 00:00:00 2001 From: LevelX2 Date: Sat, 16 Aug 2014 09:33:31 +0200 Subject: [PATCH] * Fixed can't counter ability that did not work correctly. --- .../sets/returntoravnica/LoxodonSmiter.java | 7 +- .../oneshot/counterspell/CantCounterTest.java | 71 +++++++++++++++++++ .../abilities/costs/mana/ManaCostsImpl.java | 2 +- .../common/CantCounterSourceEffect.java | 24 ++++--- 4 files changed, 93 insertions(+), 11 deletions(-) create mode 100644 Mage.Tests/src/test/java/org/mage/test/cards/abilities/oneshot/counterspell/CantCounterTest.java diff --git a/Mage.Sets/src/mage/sets/returntoravnica/LoxodonSmiter.java b/Mage.Sets/src/mage/sets/returntoravnica/LoxodonSmiter.java index 0b242fc5954..23794a4faf4 100644 --- a/Mage.Sets/src/mage/sets/returntoravnica/LoxodonSmiter.java +++ b/Mage.Sets/src/mage/sets/returntoravnica/LoxodonSmiter.java @@ -28,8 +28,6 @@ package mage.sets.returntoravnica; import java.util.UUID; - -import mage.constants.*; import mage.MageInt; import mage.abilities.Ability; import mage.abilities.common.CantCounterAbility; @@ -37,6 +35,11 @@ import mage.abilities.common.SimpleStaticAbility; import mage.abilities.effects.ReplacementEffectImpl; import mage.cards.Card; import mage.cards.CardImpl; +import mage.constants.CardType; +import mage.constants.Duration; +import mage.constants.Outcome; +import mage.constants.Rarity; +import mage.constants.Zone; import mage.game.Game; import mage.game.events.GameEvent; import mage.game.events.ZoneChangeEvent; diff --git a/Mage.Tests/src/test/java/org/mage/test/cards/abilities/oneshot/counterspell/CantCounterTest.java b/Mage.Tests/src/test/java/org/mage/test/cards/abilities/oneshot/counterspell/CantCounterTest.java new file mode 100644 index 00000000000..350a0863905 --- /dev/null +++ b/Mage.Tests/src/test/java/org/mage/test/cards/abilities/oneshot/counterspell/CantCounterTest.java @@ -0,0 +1,71 @@ +/* + * Copyright 2010 BetaSteward_at_googlemail.com. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, are + * permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this list of + * conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, this list + * of conditions and the following disclaimer in the documentation and/or other materials + * provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY BetaSteward_at_googlemail.com ``AS IS'' AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL BetaSteward_at_googlemail.com OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * The views and conclusions contained in the software and documentation are those of the + * authors and should not be interpreted as representing official policies, either expressed + * or implied, of BetaSteward_at_googlemail.com. + */ + +package org.mage.test.cards.abilities.oneshot.counterspell; + +import mage.constants.PhaseStep; +import mage.constants.Zone; +import org.junit.Test; +import org.mage.test.serverside.base.CardTestPlayerBase; + +/** + * + * @author LevelX2 + */ + +public class CantCounterTest extends CardTestPlayerBase { + + /** + * Test that spell with CantCounterAbility can't be countered + * + */ + @Test + public void testCantCounterLoxodon() { + addCard(Zone.BATTLEFIELD, playerA, "Forest", 2); + addCard(Zone.BATTLEFIELD, playerA, "Plains", 2); + addCard(Zone.HAND, playerA, "Loxodon Smiter", 1); + + addCard(Zone.HAND, playerB, "Counterspell"); + addCard(Zone.BATTLEFIELD, playerB, "Island", 2); + + + castSpell(1, PhaseStep.PRECOMBAT_MAIN, playerA, "Loxodon Smiter"); + castSpell(1, PhaseStep.PRECOMBAT_MAIN, playerB, "Counterspell", "Loxodon Smiter", "Loxodon Smiter"); + + setStopAt(1, PhaseStep.BEGIN_COMBAT); + execute(); + + assertLife(playerA, 20); + assertLife(playerB, 20); + + assertPermanentCount(playerA, "Loxodon Smiter", 1); + assertGraveyardCount(playerB, "Counterspell", 1); + + } + +} \ No newline at end of file diff --git a/Mage/src/mage/abilities/costs/mana/ManaCostsImpl.java b/Mage/src/mage/abilities/costs/mana/ManaCostsImpl.java index fc98e09dc4f..f81c63fbc16 100644 --- a/Mage/src/mage/abilities/costs/mana/ManaCostsImpl.java +++ b/Mage/src/mage/abilities/costs/mana/ManaCostsImpl.java @@ -321,7 +321,7 @@ public class ManaCostsImpl extends ArrayList implements M @Override public List getSymbols() { - List symbols = new ArrayList(); + List symbols = new ArrayList<>(); for (ManaCost cost : this) { symbols.add(cost.getText()); } diff --git a/Mage/src/mage/abilities/effects/common/CantCounterSourceEffect.java b/Mage/src/mage/abilities/effects/common/CantCounterSourceEffect.java index 6b9bae6250e..5af1fa349af 100644 --- a/Mage/src/mage/abilities/effects/common/CantCounterSourceEffect.java +++ b/Mage/src/mage/abilities/effects/common/CantCounterSourceEffect.java @@ -28,16 +28,15 @@ package mage.abilities.effects.common; +import mage.MageObject; import mage.abilities.Ability; import mage.abilities.effects.ContinuousRuleModifiyingEffectImpl; -import mage.cards.Card; import mage.constants.Duration; import mage.constants.Outcome; import mage.game.Game; import mage.game.events.GameEvent; import mage.game.events.GameEvent.EventType; - -import java.util.UUID; +import mage.game.stack.StackObject; /** * @@ -46,7 +45,7 @@ import java.util.UUID; public class CantCounterSourceEffect extends ContinuousRuleModifiyingEffectImpl { public CantCounterSourceEffect() { - super(Duration.WhileOnStack, Outcome.Benefit); + super(Duration.WhileOnStack, Outcome.Benefit, false, true); staticText = "{this} can't be countered"; } @@ -64,13 +63,22 @@ public class CantCounterSourceEffect extends ContinuousRuleModifiyingEffectImpl return true; } + @Override + public String getInfoMessage(Ability source, GameEvent event, Game game) { + StackObject stackObject = game.getStack().getStackObject(event.getTargetId()); + MageObject sourceObject = game.getObject(source.getSourceId()); + if (stackObject != null && sourceObject != null) { + return sourceObject.getLogName() + " can't be countered by " + stackObject.getName(); + } + return staticText; + } + @Override public boolean applies(GameEvent event, Ability source, Game game) { if (event.getType() == EventType.COUNTER) { - Card card = game.getCard(source.getSourceId()); - if (card != null) { - UUID spellId = card.getSpellAbility().getSourceId(); - if (event.getTargetId().equals(spellId)) { + StackObject stackObject = game.getStack().getStackObject(event.getTargetId()); + if (stackObject != null) { + if (stackObject.getSourceId().equals(source.getSourceId())) { return true; } }