* Harm's Way - Some minor fixes. Test runs now without error. Stil issues #437 left.

This commit is contained in:
LevelX2 2014-05-26 14:37:15 +02:00
parent b007242761
commit 588da451e5
2 changed files with 38 additions and 54 deletions

View file

@ -27,22 +27,23 @@
*/ */
package mage.sets.magic2010; package mage.sets.magic2010;
import mage.constants.CardType; import java.util.UUID;
import mage.constants.Rarity;
import mage.MageObject; import mage.MageObject;
import mage.abilities.Ability; import mage.abilities.Ability;
import mage.abilities.effects.PreventionEffectData;
import mage.abilities.effects.PreventionEffectImpl; import mage.abilities.effects.PreventionEffectImpl;
import mage.cards.CardImpl; import mage.cards.CardImpl;
import mage.constants.CardType;
import mage.constants.Duration; import mage.constants.Duration;
import mage.constants.Rarity;
import mage.game.Game; import mage.game.Game;
import mage.game.events.GameEvent; import mage.game.events.GameEvent;
import mage.game.permanent.Permanent; import mage.game.permanent.Permanent;
import mage.game.stack.Spell;
import mage.players.Player; import mage.players.Player;
import mage.target.TargetSource; import mage.target.TargetSource;
import mage.target.common.TargetCreatureOrPlayer; import mage.target.common.TargetCreatureOrPlayer;
import java.util.UUID;
/** /**
* @author noxx * @author noxx
*/ */
@ -55,9 +56,9 @@ public class HarmsWay extends CardImpl<HarmsWay> {
this.color.setWhite(true); this.color.setWhite(true);
// The next 2 damage that a source of your choice would deal to you and/or permanents you control this turn is dealt to target creature or player instead. // The next 2 damage that a source of your choice would deal to you and/or permanents you control this turn is dealt to target creature or player instead.
this.getSpellAbility().addEffect(new HarmsWayPreventDamageTargetEffect(Duration.EndOfTurn, 2)); this.getSpellAbility().addEffect(new HarmsWayPreventDamageTargetEffect());
this.getSpellAbility().addTarget(new TargetSource()); this.getSpellAbility().addTarget(new TargetSource());
this.getSpellAbility().addTarget(new TargetCreatureOrPlayer()); this.getSpellAbility().addTarget(new TargetCreatureOrPlayer(true));
} }
public HarmsWay(final HarmsWay card) { public HarmsWay(final HarmsWay card) {
@ -72,17 +73,13 @@ public class HarmsWay extends CardImpl<HarmsWay> {
class HarmsWayPreventDamageTargetEffect extends PreventionEffectImpl<HarmsWayPreventDamageTargetEffect> { class HarmsWayPreventDamageTargetEffect extends PreventionEffectImpl<HarmsWayPreventDamageTargetEffect> {
private int amount; public HarmsWayPreventDamageTargetEffect() {
super(Duration.EndOfTurn, 2, false, true);
public HarmsWayPreventDamageTargetEffect(Duration duration, int amount) { staticText = "The next 2 damage that a source of your choice would deal to you and/or permanents you control this turn is dealt to target creature or player instead";
super(duration);
this.amount = amount;
staticText = "The next " + amount + " damage that a source of your choice would deal to you and/or permanents you control this turn is dealt to target creature or player instead";
} }
public HarmsWayPreventDamageTargetEffect(final HarmsWayPreventDamageTargetEffect effect) { public HarmsWayPreventDamageTargetEffect(final HarmsWayPreventDamageTargetEffect effect) {
super(effect); super(effect);
this.amount = effect.amount;
} }
@Override @Override
@ -97,38 +94,21 @@ class HarmsWayPreventDamageTargetEffect extends PreventionEffectImpl<HarmsWayPre
@Override @Override
public boolean replaceEvent(GameEvent event, Ability source, Game game) { public boolean replaceEvent(GameEvent event, Ability source, Game game) {
GameEvent preventEvent = new GameEvent(GameEvent.EventType.PREVENT_DAMAGE, source.getFirstTarget(), source.getId(), source.getControllerId(), event.getAmount(), false); PreventionEffectData preventionData = preventDamageAction(event, source, game);
if (!game.replaceEvent(preventEvent)) { // deal damage now
int prevented = 0; if (preventionData.getPreventedDamage() > 0) {
if (event.getAmount() >= this.amount) { UUID redirectTo = source.getTargets().get(1).getFirstTarget();
int damage = amount; Permanent permanent = game.getPermanent(redirectTo);
event.setAmount(event.getAmount() - amount); if (permanent != null) {
this.used = true; game.informPlayers("Dealing " + preventionData.getPreventedDamage() + " to " + permanent.getName() + " instead");
game.fireEvent(GameEvent.getEvent(GameEvent.EventType.PREVENTED_DAMAGE, source.getFirstTarget(), source.getId(), source.getControllerId(), damage)); // keep the original source id as it is redirecting
prevented = damage; permanent.damage(preventionData.getPreventedDamage(), event.getSourceId(), game, true, false);
} else {
int damage = event.getAmount();
event.setAmount(0);
amount -= damage;
game.fireEvent(GameEvent.getEvent(GameEvent.EventType.PREVENTED_DAMAGE, source.getFirstTarget(), source.getId(), source.getControllerId(), damage));
prevented = damage;
} }
Player player = game.getPlayer(redirectTo);
// deal damage now if (player != null) {
if (prevented > 0) { game.informPlayers("Dealing " + preventionData.getPreventedDamage() + " to " + player.getName() + " instead");
UUID redirectTo = source.getTargets().get(1).getFirstTarget(); // keep the original source id as it is redirecting
Permanent permanent = game.getPermanent(redirectTo); player.damage(preventionData.getPreventedDamage(), event.getSourceId(), game, false, true);
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, true, false);
}
Player player = game.getPlayer(redirectTo);
if (player != null) {
game.informPlayers("Dealing " + prevented + " to " + player.getName() + " instead");
// keep the original source id as it is redirecting
player.damage(prevented, event.getSourceId(), game, true, false);
}
} }
} }
return false; return false;
@ -145,7 +125,8 @@ class HarmsWayPreventDamageTargetEffect extends PreventionEffectImpl<HarmsWayPre
return false; return false;
} }
if (!object.getId().equals(source.getFirstTarget())) { if (!object.getId().equals(source.getFirstTarget()) &&
(!(object instanceof Spell) || !((Spell) object).getSourceId().equals(source.getFirstTarget()))) {
return false; return false;
} }

View file

@ -2,7 +2,6 @@ package org.mage.test.cards.replacement.prevent;
import mage.constants.PhaseStep; import mage.constants.PhaseStep;
import mage.constants.Zone; import mage.constants.Zone;
import org.junit.Ignore;
import org.junit.Test; import org.junit.Test;
import org.mage.test.serverside.base.CardTestPlayerBase; import org.mage.test.serverside.base.CardTestPlayerBase;
@ -65,26 +64,30 @@ public class HarmsWayRedirectDamageTest extends CardTestPlayerBase {
* Tests redirecting from triggered ability * Tests redirecting from triggered ability
*/ */
@Test @Test
@Ignore
// This test doesn't work in test framework but the test case works fine in real game // This test doesn't work in test framework but the test case works fine in real game
// -- this is because of no possibility to ask AI to play spell when triggered is in the stack // -- this is because of no possibility to ask AI to play spell when triggered is in the stack
public void testRedirectTriggeredAbilityDamage() { public void testRedirectTriggeredAbilityDamage() {
addCard(Zone.HAND, playerA, "Lightning Bolt"); addCard(Zone.HAND, playerA, "Lightning Bolt");
// The next 2 damage that a source of your choice would deal to you and/or permanents
// you control this turn is dealt to target creature or player instead.
addCard(Zone.HAND, playerA, "Harm's Way"); addCard(Zone.HAND, playerA, "Harm's Way");
addCard(Zone.BATTLEFIELD, playerA, "Mountain"); addCard(Zone.BATTLEFIELD, playerA, "Mountain");
addCard(Zone.BATTLEFIELD, playerA, "Plains"); addCard(Zone.BATTLEFIELD, playerA, "Plains");
// Flying
// When Magma Phoenix dies, it deals 3 damage to each creature and each player.
addCard(Zone.BATTLEFIELD, playerB, "Magma Phoenix"); addCard(Zone.BATTLEFIELD, playerB, "Magma Phoenix");
castSpell(1, PhaseStep.PRECOMBAT_MAIN, playerA, "Lightning Bolt", "Magma Phoenix"); castSpell(1, PhaseStep.PRECOMBAT_MAIN, playerA, "Harm's Way", "Magma Phoenix^targetPlayer=PlayerB"/**,
castSpell(1, PhaseStep.PRECOMBAT_MAIN, playerA, "Harm's Way", "Magma Phoenix^targetPlayer=PlayerB"); "When Magma Phoenix dies, Magma Phoenix deals 3 damage to each creature and each player"**/);
castSpell(1, PhaseStep.POSTCOMBAT_MAIN, playerA, "Lightning Bolt", "Magma Phoenix");
setStopAt(1, PhaseStep.BEGIN_COMBAT); setStopAt(1, PhaseStep.POSTCOMBAT_MAIN);
execute(); execute();
assertLife(playerA, 19); assertLife(playerA, 19); // 3 damage from dying Phoenix -> 2 redirected to playerB so playerA gets only 1 damage
assertLife(playerB, 15); assertLife(playerB, 15); // 3 damage from dying Phoenix directly and 2 redirected damage from playerA
} }
} }