* Fixed can't counter ability that did not work correctly.

This commit is contained in:
LevelX2 2014-08-16 09:33:31 +02:00
parent 7b16fe8528
commit 57ccef6092
4 changed files with 93 additions and 11 deletions

View file

@ -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;

View file

@ -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);
}
}

View file

@ -321,7 +321,7 @@ public class ManaCostsImpl<T extends ManaCost> extends ArrayList<T> implements M
@Override
public List<String> getSymbols() {
List<String> symbols = new ArrayList<String>();
List<String> symbols = new ArrayList<>();
for (ManaCost cost : this) {
symbols.add(cost.getText());
}

View file

@ -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;
}
}