* Fixed some cards doing preventable non combat damage but handled the damage wrongly as non preventable combat damage.

This commit is contained in:
LevelX2 2015-12-23 16:38:56 +01:00
parent e7b3cb66e0
commit c83f906525
11 changed files with 178 additions and 57 deletions

View file

@ -45,6 +45,7 @@ import mage.filter.predicate.Predicates;
import mage.filter.predicate.mageobject.CardIdPredicate;
import mage.filter.predicate.mageobject.ColorPredicate;
import mage.game.Game;
import mage.game.events.DamageEvent;
import mage.game.events.GameEvent;
import mage.game.permanent.Permanent;
import mage.players.Player;
@ -63,7 +64,6 @@ public class ShiningShoal extends CardImpl {
this.expansionSetCode = "BOK";
this.subtype.add("Arcane");
// You may exile a white card with converted mana cost X from your hand rather than pay Shining Shoal's mana cost
FilterOwnedCard filter = new FilterOwnedCard("a white card with converted mana cost X from your hand");
filter.add(new ColorPredicate(ObjectColor.WHITE));
@ -86,7 +86,6 @@ public class ShiningShoal extends CardImpl {
}
}
class ShiningShoalPreventDamageTargetEffect extends PreventionEffectImpl {
private final DynamicValue dynamicAmount;
@ -145,13 +144,13 @@ class ShiningShoalPreventDamageTargetEffect extends PreventionEffectImpl {
if (permanent != null) {
game.informPlayers("Dealing " + prevented + " to " + permanent.getName() + " instead");
// keep the original source id as it is redirecting
permanent.damage(prevented, event.getSourceId(), game, false, true, event.getAppliedEffects());
permanent.damage(prevented, event.getSourceId(), game, ((DamageEvent) event).isCombatDamage(), ((DamageEvent) event).isPreventable(), event.getAppliedEffects());
}
Player player = game.getPlayer(redirectTo);
if (player != null) {
game.informPlayers("Dealing " + prevented + " to " + player.getLogName() + " instead");
// keep the original source id as it is redirecting
player.damage(prevented, event.getSourceId(), game, true, false, event.getAppliedEffects());
player.damage(prevented, event.getSourceId(), game, ((DamageEvent) event).isCombatDamage(), ((DamageEvent) event).isPreventable(), event.getAppliedEffects());
}
}
}

View file

@ -32,8 +32,8 @@ import mage.MageInt;
import mage.abilities.Ability;
import mage.abilities.common.BlocksCreatureTriggeredAbility;
import mage.abilities.effects.OneShotEffect;
import mage.abilities.keyword.VigilanceAbility;
import mage.abilities.keyword.TrampleAbility;
import mage.abilities.keyword.VigilanceAbility;
import mage.cards.CardImpl;
import mage.constants.CardType;
import mage.constants.Outcome;
@ -97,7 +97,7 @@ class MeglonothEffect extends OneShotEffect {
Permanent meglonoth = game.getPermanent(source.getSourceId());
Permanent blocked = game.getPermanent(targetPointer.getFirst(game, source));
if (blocked != null && meglonoth != null) {
game.getPlayer(blocked.getControllerId()).damage(meglonoth.getPower().getValue(), id, game, true, false);
game.getPlayer(blocked.getControllerId()).damage(meglonoth.getPower().getValue(), id, game, false, true);
return true;
}
return false;

View file

@ -100,7 +100,7 @@ class MorgueBurstEffect extends OneShotEffect {
}
Player targetPlayer = game.getPlayer(source.getTargets().get(1).getTargets().get(0));
if (targetPlayer != null) {
targetPlayer.damage(damage, source.getSourceId(), game, true, false);
targetPlayer.damage(damage, source.getSourceId(), game, false, true);
return true;
}
}

View file

@ -28,9 +28,6 @@
package mage.sets.dragonsmaze;
import java.util.UUID;
import mage.constants.CardType;
import mage.constants.Rarity;
import mage.MageInt;
import mage.abilities.TriggeredAbilityImpl;
import mage.abilities.effects.common.CreateTokenEffect;
@ -39,6 +36,8 @@ import mage.abilities.keyword.FlyingAbility;
import mage.abilities.keyword.ProtectionAbility;
import mage.abilities.keyword.VigilanceAbility;
import mage.cards.CardImpl;
import mage.constants.CardType;
import mage.constants.Rarity;
import mage.constants.Zone;
import mage.filter.common.FilterCreaturePermanent;
import mage.game.Game;
@ -69,7 +68,7 @@ public class TeysaEnvoyOfGhosts extends CardImpl {
// protection from creatures
this.addAbility(new ProtectionAbility(new FilterCreaturePermanent("creatures")));
// Whenever a creature deals combat damage to you, destroy that creature. Put a 1/1 white and black Spirit creature token with flying onto the battlefield.
this.addAbility(new TeysaEnvoyOfGhostsTriggeredAbility());
this.addAbility(new TeysaEnvoyOfGhostsTriggeredAbility());
}
@ -89,7 +88,7 @@ class TeysaEnvoyOfGhostsTriggeredAbility extends TriggeredAbilityImpl {
super(Zone.BATTLEFIELD, new DestroyTargetEffect());
this.addEffect(new CreateTokenEffect(new TeysaEnvoyOfGhostsToken(), 1));
}
}
public TeysaEnvoyOfGhostsTriggeredAbility(final TeysaEnvoyOfGhostsTriggeredAbility ability) {
super(ability);
@ -104,12 +103,15 @@ class TeysaEnvoyOfGhostsTriggeredAbility extends TriggeredAbilityImpl {
public boolean checkEventType(GameEvent event, Game game) {
return event.getType() == GameEvent.EventType.DAMAGED_PLAYER;
}
@Override
public boolean checkTrigger(GameEvent event, Game game) {
DamagedPlayerEvent damageEvent = (DamagedPlayerEvent)event;
DamagedPlayerEvent damageEvent = (DamagedPlayerEvent) event;
Permanent sourcePermanent = game.getPermanent(event.getSourceId());
if (damageEvent.getPlayerId().equals(getControllerId()) && damageEvent.isCombatDamage() && sourcePermanent != null && sourcePermanent.getCardType().contains(CardType.CREATURE)) {
if (damageEvent.getPlayerId().equals(getControllerId())
&& damageEvent.isCombatDamage()
&& sourcePermanent != null
&& sourcePermanent.getCardType().contains(CardType.CREATURE)) {
game.getState().setValue(sourceId.toString(), sourcePermanent.getControllerId());
getEffects().get(0).setTargetPointer(new FixedTarget(event.getSourceId()));
return true;
@ -125,6 +127,7 @@ class TeysaEnvoyOfGhostsTriggeredAbility extends TriggeredAbilityImpl {
}
class TeysaEnvoyOfGhostsToken extends Token {
TeysaEnvoyOfGhostsToken() {
super("Spirit", "1/1 white and black Spirit creature token with flying");
cardType.add(CardType.CREATURE);

View file

@ -44,7 +44,6 @@ import mage.game.Game;
import mage.game.permanent.token.Token;
import mage.players.Player;
import mage.MageInt;
import mage.ObjectColor;
/**
*
@ -76,7 +75,7 @@ class BottleOfSuleimanEffect extends OneShotEffect {
public BottleOfSuleimanEffect() {
super(Outcome.PutCreatureInPlay);
staticText = "Flip a coin. If you lose the flip, Bottle of Suleiman deals 5 damage to you. If you win the flip, put a 5/5 colorless Djinn artifact creature token with flying onto the battlefield.";
staticText = "Flip a coin. If you lose the flip, {this} deals 5 damage to you. If you win the flip, put a 5/5 colorless Djinn artifact creature token with flying onto the battlefield.";
}
public BottleOfSuleimanEffect(final BottleOfSuleimanEffect effect) {
@ -97,7 +96,7 @@ class BottleOfSuleimanEffect extends OneShotEffect {
token.putOntoBattlefield(1, game, source.getSourceId(), source.getControllerId());
return true;
} else {
you.damage(5, source.getSourceId(), game, true, false);
you.damage(5, source.getSourceId(), game, false, true);
return true;
}
@ -117,4 +116,4 @@ class DjinnToken extends Token {
toughness = new MageInt(5);
addAbility(FlyingAbility.getInstance());
}
}
}

View file

@ -57,12 +57,11 @@ public class DictateOfTheTwinGods extends CardImpl {
super(ownerId, 93, "Dictate of the Twin Gods", Rarity.RARE, new CardType[]{CardType.ENCHANTMENT}, "{3}{R}{R}");
this.expansionSetCode = "JOU";
// Flash
this.addAbility(FlashAbility.getInstance());
// If a source would deal damage to a permanent or player, it deals double that damage to that permanent or player instead.
this.addAbility(new SimpleStaticAbility(Zone.BATTLEFIELD, new DictateOfTheTwinGodsEffect()));
}
public DictateOfTheTwinGods(final DictateOfTheTwinGods card) {
@ -91,9 +90,9 @@ class DictateOfTheTwinGodsEffect extends ReplacementEffectImpl {
return new DictateOfTheTwinGodsEffect(this);
}
@Override
@Override
public boolean checksEventType(GameEvent event, Game game) {
switch(event.getType()) {
switch (event.getType()) {
case DAMAGE_CREATURE:
case DAMAGE_PLAYER:
case DAMAGE_PLANESWALKER:
@ -102,7 +101,7 @@ class DictateOfTheTwinGodsEffect extends ReplacementEffectImpl {
return false;
}
}
@Override
public boolean applies(GameEvent event, Ability source, Game game) {
return true;
@ -115,17 +114,17 @@ class DictateOfTheTwinGodsEffect extends ReplacementEffectImpl {
@Override
public boolean replaceEvent(GameEvent event, Ability source, Game game) {
DamageEvent damageEvent = (DamageEvent)event;
DamageEvent damageEvent = (DamageEvent) event;
if (damageEvent.getType() == EventType.DAMAGE_PLAYER) {
Player targetPlayer = game.getPlayer(event.getTargetId());
if (targetPlayer != null) {
targetPlayer.damage(damageEvent.getAmount()*2, damageEvent.getSourceId(), game, damageEvent.isPreventable(), damageEvent.isCombatDamage(), event.getAppliedEffects());
targetPlayer.damage(damageEvent.getAmount() * 2, damageEvent.getSourceId(), game, damageEvent.isCombatDamage(), damageEvent.isPreventable(), event.getAppliedEffects());
return true;
}
} else {
Permanent targetPermanent = game.getPermanent(event.getTargetId());
if (targetPermanent != null) {
targetPermanent.damage(damageEvent.getAmount()*2, damageEvent.getSourceId(), game, damageEvent.isCombatDamage(), damageEvent.isPreventable(), event.getAppliedEffects());
targetPermanent.damage(damageEvent.getAmount() * 2, damageEvent.getSourceId(), game, damageEvent.isCombatDamage(), damageEvent.isPreventable(), event.getAppliedEffects());
return true;
}
}

View file

@ -49,7 +49,6 @@ public class BlazingSalvo extends CardImpl {
super(ownerId, 178, "Blazing Salvo", Rarity.COMMON, new CardType[]{CardType.INSTANT}, "{R}");
this.expansionSetCode = "ODY";
// Blazing Salvo deals 3 damage to target creature unless that creature's controller has Blazing Salvo deal 5 damage to him or her.
this.getSpellAbility().addTarget(new TargetCreaturePermanent());
this.getSpellAbility().addEffect(new BlazingSalvoEffect());
@ -66,16 +65,16 @@ public class BlazingSalvo extends CardImpl {
}
class BlazingSalvoEffect extends OneShotEffect {
public BlazingSalvoEffect() {
super(Outcome.Damage);
this.staticText = "Blazing Salvo deals 3 damage to target creature unless that creature's controller has Blazing Salvo deal 5 damage to him or her";
this.staticText = "{this} deals 3 damage to target creature unless that creature's controller has {this} deal 5 damage to him or her";
}
public BlazingSalvoEffect(final BlazingSalvoEffect effect){
public BlazingSalvoEffect(final BlazingSalvoEffect effect) {
super(effect);
}
@Override
public BlazingSalvoEffect copy() {
return new BlazingSalvoEffect(this);
@ -88,16 +87,15 @@ class BlazingSalvoEffect extends OneShotEffect {
Player player = game.getPlayer(permanent.getControllerId());
if (player != null) {
String message = "Have Blazing Salvo do 5 damage to you?";
if (player.chooseUse(Outcome.Damage, message, source, game)){
player.damage(5, source.getSourceId(), game, true, false);
if (player.chooseUse(Outcome.Damage, message, source, game)) {
player.damage(5, source.getSourceId(), game, false, true);
} else {
permanent.damage(3, source.getSourceId(), game, false, true);
}
return true;
}
}
return true;
}
}
return false;
}
}
}

View file

@ -182,7 +182,7 @@ class SarkhanTheMadDragonDamageEffect extends OneShotEffect {
Player player = game.getPlayer(source.getTargets().getFirstTarget());
if (player != null && dragons != null && !dragons.isEmpty()) {
for (Permanent dragon : dragons) {
player.damage(dragon.getPower().getValue(), dragon.getId(), game, true, false);
player.damage(dragon.getPower().getValue(), dragon.getId(), game, false, true);
}
return true;
}

View file

@ -25,7 +25,6 @@
* authors and should not be interpreted as representing official policies, either expressed
* or implied, of BetaSteward_at_googlemail.com.
*/
package mage.sets.shardsofalara;
import java.util.UUID;
@ -78,6 +77,7 @@ public class FlameblastDragon extends CardImpl {
}
class FlameblastDragonEffect extends OneShotEffect {
FlameblastDragonEffect() {
super(Outcome.Benefit);
staticText = "you may pay {X}{R}. If you do, {this} deals X damage to target creature or player";
@ -103,7 +103,7 @@ class FlameblastDragonEffect extends OneShotEffect {
}
Player targetPlayer = game.getPlayer(source.getFirstTarget());
if (targetPlayer != null) {
targetPlayer.damage(costX, source.getSourceId(), game, true, false);
targetPlayer.damage(costX, source.getSourceId(), game, false, true);
return true;
}
return false;

View file

@ -30,9 +30,6 @@ package mage.sets.worldwake;
import java.util.HashSet;
import java.util.Set;
import java.util.UUID;
import mage.constants.CardType;
import mage.constants.Rarity;
import mage.MageObject;
import mage.abilities.Ability;
import mage.abilities.costs.AlternativeCostImpl;
@ -41,8 +38,10 @@ import mage.abilities.costs.mana.ManaCostsImpl;
import mage.abilities.effects.PreventionEffectData;
import mage.abilities.effects.PreventionEffectImpl;
import mage.cards.CardImpl;
import mage.constants.CardType;
import mage.constants.Duration;
import mage.constants.Outcome;
import mage.constants.Rarity;
import mage.constants.WatcherScope;
import mage.game.Game;
import mage.game.events.GameEvent;
@ -65,7 +64,6 @@ public class RefractionTrap extends CardImpl {
this.expansionSetCode = "WWK";
this.subtype.add("Trap");
// If an opponent cast a red instant or sorcery spell this turn, you may pay {W} rather than pay Refraction Trap's mana cost.
this.getSpellAbility().addAlternativeCost(new RefractionTrapAlternativeCost());
@ -89,7 +87,7 @@ public class RefractionTrap extends CardImpl {
class RefractionTrapWatcher extends Watcher {
Set<UUID> playersMetCondition = new HashSet<>();
public RefractionTrapWatcher() {
super("RefractionTrapWatcher", WatcherScope.GAME);
}
@ -120,19 +118,20 @@ class RefractionTrapWatcher extends Watcher {
public boolean conditionMetForAnOpponent(UUID controllerId, Game game) {
Player controller = game.getPlayer(controllerId);
if (controller != null) {
for(UUID playerId: playersMetCondition) {
for (UUID playerId : playersMetCondition) {
if (controller.hasOpponent(playerId, game)) {
return true;
}
}
}
return false;
}
@Override
public void reset() {
playersMetCondition.clear();
super.reset();
super.reset();
}
}
@ -179,20 +178,20 @@ class RefractionTrapPreventDamageEffect extends PreventionEffectImpl {
public RefractionTrapPreventDamageEffect(final RefractionTrapPreventDamageEffect effect) {
super(effect);
this.amount = effect.amount;
this.target = effect.target.copy();
this.target = effect.target.copy();
}
@Override
public RefractionTrapPreventDamageEffect copy() {
return new RefractionTrapPreventDamageEffect(this);
}
@Override
public void init(Ability source, Game game) {
this.target.choose(Outcome.PreventDamage, source.getControllerId(), source.getSourceId(), game);
super.init(source, game);
}
@Override
public boolean apply(Game game, Ability source) {
return true;
@ -213,7 +212,7 @@ class RefractionTrapPreventDamageEffect extends PreventionEffectImpl {
Player player = game.getPlayer(damageTarget);
if (player != null) {
game.informPlayers("Dealing " + preventionData.getPreventedDamage() + " to " + player.getLogName());
player.damage(preventionData.getPreventedDamage(), source.getSourceId(), game, true, false);
player.damage(preventionData.getPreventedDamage(), source.getSourceId(), game, false, true);
}
}
@ -231,8 +230,8 @@ class RefractionTrapPreventDamageEffect extends PreventionEffectImpl {
}
// check damage source
if (!object.getId().equals(target.getFirstTarget()) &&
!((object instanceof StackObject) && ((StackObject)object).getSourceId().equals(target.getFirstTarget()))) {
if (!object.getId().equals(target.getFirstTarget())
&& !((object instanceof StackObject) && ((StackObject) object).getSourceId().equals(target.getFirstTarget()))) {
return false;
}

View file

@ -0,0 +1,124 @@
/*
* 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.enchantments;
import mage.constants.PhaseStep;
import mage.constants.Zone;
import org.junit.Test;
import org.mage.test.serverside.base.CardTestPlayerBase;
/**
*
* @author LevelX2
*/
public class AnimateDeadTest extends CardTestPlayerBase {
@Test
public void testAnimateOpponentsCreature() {
addCard(Zone.GRAVEYARD, playerB, "Silvercoat Lion", 1);
addCard(Zone.BATTLEFIELD, playerA, "Swamp", 2);
// Enchant creature card in a graveyard
// When Animate Dead enters the battlefield, if it's on the battlefield, it loses "enchant creature card in a graveyard"
// and gains "enchant creature put onto the battlefield with Animate Dead." Return enchanted creature card to the battlefield
// under your control and attach Animate Dead to it. When Animate Dead leaves the battlefield, that creature's controller sacrifices it.
// Enchanted creature gets -1/-0.
addCard(Zone.HAND, playerA, "Animate Dead"); // {1}{B}
castSpell(1, PhaseStep.PRECOMBAT_MAIN, playerA, "Animate Dead", "Silvercoat Lion");
setStopAt(1, PhaseStep.BEGIN_COMBAT);
execute();
assertPowerToughness(playerA, "Silvercoat Lion", 1, 2);
assertPermanentCount(playerA, "Animate Dead", 1);
}
@Test
public void testAnimateEternalWitness() {
// When Eternal Witness enters the battlefield, you may return target card from your graveyard to your hand.
addCard(Zone.GRAVEYARD, playerB, "Eternal Witness", 1);
addCard(Zone.GRAVEYARD, playerA, "Silvercoat Lion", 1);
addCard(Zone.BATTLEFIELD, playerA, "Swamp", 2);
// Enchant creature card in a graveyard
// When Animate Dead enters the battlefield, if it's on the battlefield, it loses "enchant creature card in a graveyard"
// and gains "enchant creature put onto the battlefield with Animate Dead." Return enchanted creature card to the battlefield
// under your control and attach Animate Dead to it. When Animate Dead leaves the battlefield, that creature's controller sacrifices it.
// Enchanted creature gets -1/-0.
addCard(Zone.HAND, playerA, "Animate Dead"); // {1}{B}
castSpell(1, PhaseStep.PRECOMBAT_MAIN, playerA, "Animate Dead", "Eternal Witness");
addTarget(playerA, "Silvercoat Lion");
setStopAt(1, PhaseStep.BEGIN_COMBAT);
execute();
assertPowerToughness(playerA, "Eternal Witness", 1, 1);
assertPermanentCount(playerA, "Animate Dead", 1);
assertHandCount(playerA, "Silvercoat Lion", 1);
}
/**
* Buddy animated an Eternal Witness. I killed the Eternal Witness. Animate
* Dead stayed on the battlefield. Using Meren, Eternal Witness came back to
* the battlefield and immediately got enchanted by Animate Dead.
*
* Very weird. Animate Dead should've hit the graveyard the first time its
* creature died, right?
*
*/
@Test
public void testAnimateAndKillEternalWitness() {
// When Eternal Witness enters the battlefield, you may return target card from your graveyard to your hand.
addCard(Zone.GRAVEYARD, playerB, "Eternal Witness", 1);
addCard(Zone.BATTLEFIELD, playerB, "Mountain", 1);
addCard(Zone.HAND, playerB, "Lightning Bolt", 1);
addCard(Zone.GRAVEYARD, playerA, "Silvercoat Lion", 1);
addCard(Zone.BATTLEFIELD, playerA, "Swamp", 2);
// Enchant creature card in a graveyard
// When Animate Dead enters the battlefield, if it's on the battlefield, it loses "enchant creature card in a graveyard"
// and gains "enchant creature put onto the battlefield with Animate Dead." Return enchanted creature card to the battlefield
// under your control and attach Animate Dead to it. When Animate Dead leaves the battlefield, that creature's controller sacrifices it.
// Enchanted creature gets -1/-0.
addCard(Zone.HAND, playerA, "Animate Dead"); // {1}{B}
castSpell(1, PhaseStep.PRECOMBAT_MAIN, playerA, "Animate Dead", "Eternal Witness");
addTarget(playerA, "Silvercoat Lion");
castSpell(1, PhaseStep.PRECOMBAT_MAIN, playerB, "Lightning Bolt", "Eternal Witness");
setStopAt(1, PhaseStep.BEGIN_COMBAT);
execute();
assertGraveyardCount(playerB, "Lightning Bolt", 1);
assertGraveyardCount(playerB, "Eternal Witness", 1);
assertHandCount(playerA, "Silvercoat Lion", 1);
assertGraveyardCount(playerA, "Animate Dead", 1);
assertPermanentCount(playerA, "Animate Dead", 0);
}
}