forked from External/mage
* Harm's Way - Some minor fixes. Test runs now without error. Stil issues #437 left.
This commit is contained in:
parent
b007242761
commit
588da451e5
2 changed files with 38 additions and 54 deletions
|
|
@ -27,22 +27,23 @@
|
|||
*/
|
||||
package mage.sets.magic2010;
|
||||
|
||||
import mage.constants.CardType;
|
||||
import mage.constants.Rarity;
|
||||
import java.util.UUID;
|
||||
import mage.MageObject;
|
||||
import mage.abilities.Ability;
|
||||
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.Rarity;
|
||||
import mage.game.Game;
|
||||
import mage.game.events.GameEvent;
|
||||
import mage.game.permanent.Permanent;
|
||||
import mage.game.stack.Spell;
|
||||
import mage.players.Player;
|
||||
import mage.target.TargetSource;
|
||||
import mage.target.common.TargetCreatureOrPlayer;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
* @author noxx
|
||||
*/
|
||||
|
|
@ -55,9 +56,9 @@ public class HarmsWay extends CardImpl<HarmsWay> {
|
|||
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.
|
||||
this.getSpellAbility().addEffect(new HarmsWayPreventDamageTargetEffect(Duration.EndOfTurn, 2));
|
||||
this.getSpellAbility().addEffect(new HarmsWayPreventDamageTargetEffect());
|
||||
this.getSpellAbility().addTarget(new TargetSource());
|
||||
this.getSpellAbility().addTarget(new TargetCreatureOrPlayer());
|
||||
this.getSpellAbility().addTarget(new TargetCreatureOrPlayer(true));
|
||||
}
|
||||
|
||||
public HarmsWay(final HarmsWay card) {
|
||||
|
|
@ -72,17 +73,13 @@ public class HarmsWay extends CardImpl<HarmsWay> {
|
|||
|
||||
class HarmsWayPreventDamageTargetEffect extends PreventionEffectImpl<HarmsWayPreventDamageTargetEffect> {
|
||||
|
||||
private int amount;
|
||||
|
||||
public HarmsWayPreventDamageTargetEffect(Duration duration, int amount) {
|
||||
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() {
|
||||
super(Duration.EndOfTurn, 2, false, true);
|
||||
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";
|
||||
}
|
||||
|
||||
public HarmsWayPreventDamageTargetEffect(final HarmsWayPreventDamageTargetEffect effect) {
|
||||
super(effect);
|
||||
this.amount = effect.amount;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
@ -97,40 +94,23 @@ class HarmsWayPreventDamageTargetEffect extends PreventionEffectImpl<HarmsWayPre
|
|||
|
||||
@Override
|
||||
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);
|
||||
if (!game.replaceEvent(preventEvent)) {
|
||||
int prevented = 0;
|
||||
if (event.getAmount() >= this.amount) {
|
||||
int damage = amount;
|
||||
event.setAmount(event.getAmount() - amount);
|
||||
this.used = true;
|
||||
game.fireEvent(GameEvent.getEvent(GameEvent.EventType.PREVENTED_DAMAGE, source.getFirstTarget(), source.getId(), source.getControllerId(), damage));
|
||||
prevented = damage;
|
||||
} 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;
|
||||
PreventionEffectData preventionData = preventDamageAction(event, source, game);
|
||||
// deal damage now
|
||||
if (preventionData.getPreventedDamage() > 0) {
|
||||
UUID redirectTo = source.getTargets().get(1).getFirstTarget();
|
||||
Permanent permanent = game.getPermanent(redirectTo);
|
||||
if (permanent != null) {
|
||||
game.informPlayers("Dealing " + preventionData.getPreventedDamage() + " to " + permanent.getName() + " instead");
|
||||
// keep the original source id as it is redirecting
|
||||
permanent.damage(preventionData.getPreventedDamage(), event.getSourceId(), game, true, false);
|
||||
}
|
||||
|
||||
// deal damage now
|
||||
if (prevented > 0) {
|
||||
UUID redirectTo = source.getTargets().get(1).getFirstTarget();
|
||||
Permanent permanent = game.getPermanent(redirectTo);
|
||||
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);
|
||||
}
|
||||
Player player = game.getPlayer(redirectTo);
|
||||
if (player != null) {
|
||||
game.informPlayers("Dealing " + preventionData.getPreventedDamage() + " to " + player.getName() + " instead");
|
||||
// keep the original source id as it is redirecting
|
||||
player.damage(preventionData.getPreventedDamage(), event.getSourceId(), game, false, true);
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
@ -145,7 +125,8 @@ class HarmsWayPreventDamageTargetEffect extends PreventionEffectImpl<HarmsWayPre
|
|||
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;
|
||||
}
|
||||
|
||||
|
|
@ -170,4 +151,4 @@ class HarmsWayPreventDamageTargetEffect extends PreventionEffectImpl<HarmsWayPre
|
|||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,7 +2,6 @@ package org.mage.test.cards.replacement.prevent;
|
|||
|
||||
import mage.constants.PhaseStep;
|
||||
import mage.constants.Zone;
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
import org.mage.test.serverside.base.CardTestPlayerBase;
|
||||
|
||||
|
|
@ -65,26 +64,30 @@ public class HarmsWayRedirectDamageTest extends CardTestPlayerBase {
|
|||
* Tests redirecting from triggered ability
|
||||
*/
|
||||
@Test
|
||||
@Ignore
|
||||
// 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
|
||||
public void testRedirectTriggeredAbilityDamage() {
|
||||
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.BATTLEFIELD, playerA, "Mountain");
|
||||
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");
|
||||
|
||||
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();
|
||||
|
||||
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
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue