From 701a722904ce191689ccff71cc7c0b35bcc6dc59 Mon Sep 17 00:00:00 2001
From: LevelX2 <ludwig.hirth@online.de>
Date: Tue, 20 Oct 2015 22:58:24 +0200
Subject: [PATCH] * Fixed some redirect effect sthat were implemented as
 prevention effects (fixes #1216).

---
 .../sets/betrayersofkamigawa/WardOfPiety.java | 42 ++++-------
 .../sets/championsofkamigawa/VassalsDuty.java | 40 +++--------
 .../sets/planechase/RaziaBorosArchangel.java  | 66 +++++++----------
 .../src/mage/sets/stronghold/NomadsEnKor.java |  6 +-
 .../src/mage/sets/stronghold/ShamanEnKor.java | 30 +-------
 .../sets/tempestremastered/SpiritEnKor.java   | 53 ++------------
 .../sets/tempestremastered/WarriorEnKor.java  | 51 +------------
 .../replacement/redirect/WardOfPietyTest.java | 71 +++++++++++++++++++
 ...edirectDamageFromSourceToTargetEffect.java | 42 +++++++++++
 9 files changed, 176 insertions(+), 225 deletions(-)
 create mode 100644 Mage.Tests/src/test/java/org/mage/test/cards/replacement/redirect/WardOfPietyTest.java
 create mode 100644 Mage/src/mage/abilities/effects/common/RedirectDamageFromSourceToTargetEffect.java

diff --git a/Mage.Sets/src/mage/sets/betrayersofkamigawa/WardOfPiety.java b/Mage.Sets/src/mage/sets/betrayersofkamigawa/WardOfPiety.java
index 1edee8058e..94b13e99c3 100644
--- a/Mage.Sets/src/mage/sets/betrayersofkamigawa/WardOfPiety.java
+++ b/Mage.Sets/src/mage/sets/betrayersofkamigawa/WardOfPiety.java
@@ -28,11 +28,11 @@
 package mage.sets.betrayersofkamigawa;
 
 import java.util.UUID;
+import mage.MageObjectReference;
 import mage.abilities.Ability;
 import mage.abilities.common.SimpleActivatedAbility;
 import mage.abilities.costs.mana.ManaCostsImpl;
-import mage.abilities.effects.PreventionEffectData;
-import mage.abilities.effects.PreventionEffectImpl;
+import mage.abilities.effects.RedirectionEffect;
 import mage.abilities.effects.common.AttachEffect;
 import mage.abilities.keyword.EnchantAbility;
 import mage.cards.CardImpl;
@@ -44,7 +44,6 @@ import mage.constants.Zone;
 import mage.game.Game;
 import mage.game.events.GameEvent;
 import mage.game.permanent.Permanent;
-import mage.players.Player;
 import mage.target.TargetPermanent;
 import mage.target.common.TargetCreatureOrPlayer;
 import mage.target.common.TargetCreaturePermanent;
@@ -60,7 +59,6 @@ public class WardOfPiety extends CardImpl {
         this.expansionSetCode = "BOK";
         this.subtype.add("Aura");
 
-
         // Enchant creature
         TargetPermanent auraTarget = new TargetCreaturePermanent();
         this.getSpellAbility().addTarget(auraTarget);
@@ -84,10 +82,12 @@ public class WardOfPiety extends CardImpl {
     }
 }
 
-class WardOfPietyPreventDamageTargetEffect extends PreventionEffectImpl {
+class WardOfPietyPreventDamageTargetEffect extends RedirectionEffect {
+
+    protected MageObjectReference redirectToObject;
 
     public WardOfPietyPreventDamageTargetEffect() {
-        super(Duration.EndOfTurn, 1, false, true);
+        super(Duration.EndOfTurn, 1, true);
         staticText = "The next 1 damage that would be dealt to enchanted creature this turn is dealt to target creature or player instead";
     }
 
@@ -106,35 +106,21 @@ class WardOfPietyPreventDamageTargetEffect extends PreventionEffectImpl {
     }
 
     @Override
-    public boolean replaceEvent(GameEvent event, Ability source, Game game) {
-        PreventionEffectData preventionData = preventDamageAction(event, source, game);
-        // deal damage now
-        if (preventionData.getPreventedDamage() > 0) {
-            Permanent permanent = game.getPermanent(getTargetPointer().getFirst(game, source));
-            if (permanent != null) {
-                game.informPlayers("Dealing " + preventionData.getPreventedDamage() + " damage to " + permanent.getLogName() + " instead");
-                // keep the original source id as it is redirecting
-                permanent.damage(preventionData.getPreventedDamage(), event.getSourceId(), game, false, true);
-            }
-            Player player = game.getPlayer(getTargetPointer().getFirst(game, source));
-            if (player != null) {
-                game.informPlayers("Dealing " + preventionData.getPreventedDamage() + " damage to " + player.getLogName() + " instead");
-                // keep the original source id as it is redirecting
-                player.damage(preventionData.getPreventedDamage(), event.getSourceId(), game, false, true);
-            }
-        }
-        return false;
+    public void init(Ability source, Game game) {
+        super.init(source, game);
+        redirectToObject = new MageObjectReference(source.getTargets().get(0).getFirstTarget(), game);
     }
 
     @Override
     public boolean applies(GameEvent event, Ability source, Game game) {
-        if (super.applies(event, source, game)) {
-            Permanent enchantment = game.getPermanent(source.getSourceId());
-            if (enchantment != null && event.getTargetId().equals(enchantment.getAttachedTo())) {
+        Permanent enchantment = game.getPermanent(source.getSourceId());
+        if (enchantment != null && event.getTargetId().equals(enchantment.getAttachedTo())) {
+            if (redirectToObject.equals(new MageObjectReference(source.getTargets().get(0).getFirstTarget(), game))) {
+                redirectTarget = source.getTargets().get(0);
                 return true;
             }
         }
         return false;
     }
 
-}
\ No newline at end of file
+}
diff --git a/Mage.Sets/src/mage/sets/championsofkamigawa/VassalsDuty.java b/Mage.Sets/src/mage/sets/championsofkamigawa/VassalsDuty.java
index 71230bc44e..abd2d87510 100644
--- a/Mage.Sets/src/mage/sets/championsofkamigawa/VassalsDuty.java
+++ b/Mage.Sets/src/mage/sets/championsofkamigawa/VassalsDuty.java
@@ -31,8 +31,7 @@ import java.util.UUID;
 import mage.abilities.Ability;
 import mage.abilities.common.SimpleActivatedAbility;
 import mage.abilities.costs.mana.GenericManaCost;
-import mage.abilities.effects.PreventionEffectData;
-import mage.abilities.effects.PreventionEffectImpl;
+import mage.abilities.effects.RedirectionEffect;
 import mage.cards.CardImpl;
 import mage.constants.CardType;
 import mage.constants.Duration;
@@ -42,8 +41,7 @@ import mage.filter.common.FilterControlledCreaturePermanent;
 import mage.filter.predicate.mageobject.SupertypePredicate;
 import mage.game.Game;
 import mage.game.events.GameEvent;
-import mage.game.permanent.Permanent;
-import mage.players.Player;
+import mage.target.TargetPlayer;
 import mage.target.common.TargetControlledCreaturePermanent;
 
 /**
@@ -53,6 +51,7 @@ import mage.target.common.TargetControlledCreaturePermanent;
 public class VassalsDuty extends CardImpl {
 
     private static final FilterControlledCreaturePermanent filter = new FilterControlledCreaturePermanent("legendary creature you control");
+
     static {
         filter.add(new SupertypePredicate("Legendary"));
     }
@@ -61,10 +60,9 @@ public class VassalsDuty extends CardImpl {
         super(ownerId, 48, "Vassal's Duty", Rarity.RARE, new CardType[]{CardType.ENCHANTMENT}, "{3}{W}");
         this.expansionSetCode = "CHK";
 
-
         // {1}: The next 1 damage that would be dealt to target legendary creature you control this turn is dealt to you instead.
         Ability ability = new SimpleActivatedAbility(Zone.BATTLEFIELD, new VassalsDutyPreventDamageTargetEffect(Duration.EndOfTurn, 1), new GenericManaCost(1));
-        ability.addTarget(new TargetControlledCreaturePermanent(1,1,filter, false));
+        ability.addTarget(new TargetControlledCreaturePermanent(1, 1, filter, false));
         this.addAbility(ability);
     }
 
@@ -78,10 +76,10 @@ public class VassalsDuty extends CardImpl {
     }
 }
 
-class VassalsDutyPreventDamageTargetEffect extends PreventionEffectImpl {
+class VassalsDutyPreventDamageTargetEffect extends RedirectionEffect {
 
     public VassalsDutyPreventDamageTargetEffect(Duration duration, int amount) {
-        super(duration, amount, false);
+        super(duration, amount, true);
         staticText = "The next " + amount + " damage that would be dealt to target legendary creature you control this turn is dealt to you instead";
     }
 
@@ -94,29 +92,13 @@ class VassalsDutyPreventDamageTargetEffect extends PreventionEffectImpl {
         return new VassalsDutyPreventDamageTargetEffect(this);
     }
 
-    @Override
-    public boolean replaceEvent(GameEvent event, Ability source, Game game) {
-        PreventionEffectData preventionResult = preventDamageAction(event, source, game);
-        // deal damage now
-        if (preventionResult.getPreventedDamage() > 0) {
-            UUID redirectTo = source.getControllerId();
-            Player player = game.getPlayer(redirectTo);
-            if (player != null) {
-                game.informPlayers("Dealing " + preventionResult.getPreventedDamage() + " to " + player.getLogName() + " instead");
-                // keep the original source id as it is redirecting
-                player.damage(preventionResult.getPreventedDamage(), event.getSourceId(), game, false, true);
-            }
-        }
-        // damage amount is reduced or set to 0 so complete replacement of damage event is never neccessary
-        return false;
-    }
-
     @Override
     public boolean applies(GameEvent event, Ability source, Game game) {
-        if (!this.used && super.applies(event, source, game)) {
-            if (event.getTargetId().equals(getTargetPointer().getFirst(game, source))) {
-                return game.getPermanent(event.getTargetId()) != null;
-            }
+        if (event.getTargetId().equals(getTargetPointer().getFirst(game, source))) {
+            TargetPlayer target = new TargetPlayer();
+            target.add(source.getControllerId(), game);
+            redirectTarget = target;
+            return true;
         }
         return false;
     }
diff --git a/Mage.Sets/src/mage/sets/planechase/RaziaBorosArchangel.java b/Mage.Sets/src/mage/sets/planechase/RaziaBorosArchangel.java
index 720d19460c..be5502dbe7 100644
--- a/Mage.Sets/src/mage/sets/planechase/RaziaBorosArchangel.java
+++ b/Mage.Sets/src/mage/sets/planechase/RaziaBorosArchangel.java
@@ -29,11 +29,12 @@ package mage.sets.planechase;
 
 import java.util.UUID;
 import mage.MageInt;
+import mage.MageObjectReference;
 import mage.abilities.Ability;
 import mage.abilities.common.SimpleActivatedAbility;
 import mage.abilities.costs.common.TapSourceCost;
 import mage.abilities.effects.Effect;
-import mage.abilities.effects.PreventionEffectImpl;
+import mage.abilities.effects.RedirectionEffect;
 import mage.abilities.keyword.FlyingAbility;
 import mage.abilities.keyword.HasteAbility;
 import mage.abilities.keyword.VigilanceAbility;
@@ -42,9 +43,11 @@ import mage.constants.CardType;
 import mage.constants.Duration;
 import mage.constants.Rarity;
 import mage.constants.Zone;
+import mage.filter.common.FilterCreaturePermanent;
+import mage.filter.predicate.mageobject.AnotherTargetPredicate;
 import mage.game.Game;
 import mage.game.events.GameEvent;
-import mage.game.permanent.Permanent;
+import mage.target.Target;
 import mage.target.common.TargetControlledCreaturePermanent;
 import mage.target.common.TargetCreaturePermanent;
 
@@ -72,11 +75,18 @@ public class RaziaBorosArchangel extends CardImpl {
         // Haste
         this.addAbility(HasteAbility.getInstance());
 
-        // {tap}: The next 3 damage that would be dealt to target creature you control this turn is dealt to another target creature instead.
+        // {T}: The next 3 damage that would be dealt to target creature you control this turn is dealt to another target creature instead.
         Effect effect = new RaziaBorosArchangelEffect(Duration.EndOfTurn, 3);
         Ability ability = new SimpleActivatedAbility(Zone.BATTLEFIELD, effect, new TapSourceCost());
-        ability.addTarget(new TargetControlledCreaturePermanent());
-        ability.addTarget(new TargetCreaturePermanent());
+        Target target = new TargetControlledCreaturePermanent();
+        target.setTargetTag(1);
+        ability.addTarget(target);
+
+        FilterCreaturePermanent filter = new FilterCreaturePermanent("creature (damage is redirected to)");
+        filter.add(new AnotherTargetPredicate(2));
+        target = new TargetCreaturePermanent(filter);
+        target.setTargetTag(2);
+        ability.addTarget(target);
         this.addAbility(ability);
 
     }
@@ -91,19 +101,17 @@ public class RaziaBorosArchangel extends CardImpl {
     }
 }
 
-class RaziaBorosArchangelEffect extends PreventionEffectImpl {
+class RaziaBorosArchangelEffect extends RedirectionEffect {
 
-    private int amount;
+    protected MageObjectReference redirectToObject;
 
     public RaziaBorosArchangelEffect(Duration duration, int amount) {
-        super(duration);
-        this.amount = amount;
+        super(duration, 3, true);
         staticText = "The next " + amount + " damage that would be dealt to target creature you control this turn is dealt to another target creature instead";
     }
 
     public RaziaBorosArchangelEffect(final RaziaBorosArchangelEffect effect) {
         super(effect);
-        this.amount = effect.amount;
     }
 
     @Override
@@ -117,42 +125,16 @@ class RaziaBorosArchangelEffect extends PreventionEffectImpl {
     }
 
     @Override
-    public boolean replaceEvent(GameEvent event, Ability source, Game game) {
-        GameEvent preventEvent = new GameEvent(GameEvent.EventType.PREVENT_DAMAGE, source.getFirstTarget(), source.getSourceId(), source.getControllerId(), event.getAmount(), false);
-        if (!game.replaceEvent(preventEvent)) {
-            int prevented;
-            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.getSourceId(), 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.getSourceId(), source.getControllerId(), damage));
-                prevented = damage;
-            }
-
-            // 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, false, true);
-                }
-            }
-        }
-        return false;
+    public void init(Ability source, Game game) {
+        super.init(source, game);
+        redirectToObject = new MageObjectReference(source.getTargets().get(1).getFirstTarget(), game);
     }
 
     @Override
     public boolean applies(GameEvent event, Ability source, Game game) {
-        if (!this.used && super.applies(event, source, game)) {
-            if (source.getTargets().getFirstTarget().equals(event.getTargetId())) {
+        if (event.getTargetId().equals(getTargetPointer().getFirst(game, source))) {
+            if (redirectToObject.equals(new MageObjectReference(source.getTargets().get(1).getFirstTarget(), game))) {
+                redirectTarget = source.getTargets().get(1);
                 return true;
             }
         }
diff --git a/Mage.Sets/src/mage/sets/stronghold/NomadsEnKor.java b/Mage.Sets/src/mage/sets/stronghold/NomadsEnKor.java
index c1dbfdd8b8..1c3d0aa8da 100644
--- a/Mage.Sets/src/mage/sets/stronghold/NomadsEnKor.java
+++ b/Mage.Sets/src/mage/sets/stronghold/NomadsEnKor.java
@@ -32,8 +32,10 @@ import mage.MageInt;
 import mage.abilities.Ability;
 import mage.abilities.common.SimpleActivatedAbility;
 import mage.abilities.costs.mana.GenericManaCost;
+import mage.abilities.effects.common.RedirectDamageFromSourceToTargetEffect;
 import mage.cards.CardImpl;
 import mage.constants.CardType;
+import mage.constants.Duration;
 import mage.constants.Rarity;
 import mage.constants.Zone;
 import mage.target.common.TargetControlledCreaturePermanent;
@@ -55,7 +57,7 @@ public class NomadsEnKor extends CardImpl {
         this.toughness = new MageInt(1);
 
         // {0}: The next 1 damage that would be dealt to Nomads en-Kor this turn is dealt to target creature you control instead.
-        Ability ability = new SimpleActivatedAbility(Zone.BATTLEFIELD, new ShamanEnKorRedirectFromItselfEffect(), new GenericManaCost(0));
+        Ability ability = new SimpleActivatedAbility(Zone.BATTLEFIELD, new RedirectDamageFromSourceToTargetEffect(Duration.EndOfTurn, 1, true), new GenericManaCost(0));
         ability.addTarget(new TargetControlledCreaturePermanent());
         this.addAbility(ability);
     }
@@ -68,4 +70,4 @@ public class NomadsEnKor extends CardImpl {
     public NomadsEnKor copy() {
         return new NomadsEnKor(this);
     }
-}
\ No newline at end of file
+}
diff --git a/Mage.Sets/src/mage/sets/stronghold/ShamanEnKor.java b/Mage.Sets/src/mage/sets/stronghold/ShamanEnKor.java
index 0bac73f71d..e112c7f782 100644
--- a/Mage.Sets/src/mage/sets/stronghold/ShamanEnKor.java
+++ b/Mage.Sets/src/mage/sets/stronghold/ShamanEnKor.java
@@ -35,6 +35,7 @@ import mage.abilities.common.SimpleActivatedAbility;
 import mage.abilities.costs.mana.GenericManaCost;
 import mage.abilities.costs.mana.ManaCostsImpl;
 import mage.abilities.effects.RedirectionEffect;
+import mage.abilities.effects.common.RedirectDamageFromSourceToTargetEffect;
 import mage.cards.CardImpl;
 import mage.constants.CardType;
 import mage.constants.Duration;
@@ -67,7 +68,8 @@ public class ShamanEnKor extends CardImpl {
         this.toughness = new MageInt(2);
 
         // {0}: The next 1 damage that would be dealt to Shaman en-Kor this turn is dealt to target creature you control instead.
-        Ability ability = new SimpleActivatedAbility(Zone.BATTLEFIELD, new ShamanEnKorRedirectFromItselfEffect(), new GenericManaCost(0));
+        Ability ability = new SimpleActivatedAbility(Zone.BATTLEFIELD,
+                new RedirectDamageFromSourceToTargetEffect(Duration.EndOfTurn, 1, true), new GenericManaCost(0));
         ability.addTarget(new TargetControlledCreaturePermanent());
         this.addAbility(ability);
 
@@ -87,32 +89,6 @@ public class ShamanEnKor extends CardImpl {
     }
 }
 
-class ShamanEnKorRedirectFromItselfEffect extends RedirectionEffect {
-
-    ShamanEnKorRedirectFromItselfEffect() {
-        super(Duration.EndOfTurn, 1, true);
-        staticText = "The next 1 damage that would be dealt to {this} this turn is dealt to target creature you control instead.";
-    }
-
-    ShamanEnKorRedirectFromItselfEffect(final ShamanEnKorRedirectFromItselfEffect effect) {
-        super(effect);
-    }
-
-    @Override
-    public ShamanEnKorRedirectFromItselfEffect copy() {
-        return new ShamanEnKorRedirectFromItselfEffect(this);
-    }
-
-    @Override
-    public boolean applies(GameEvent event, Ability source, Game game) {
-        if (event.getTargetId().equals(source.getSourceId())) {
-            this.redirectTarget = source.getTargets().get(0);
-            return true;
-        }
-        return false;
-    }
-}
-
 class ShamanEnKorRedirectFromTargetEffect extends RedirectionEffect {
 
     protected MageObjectReference sourceObject;
diff --git a/Mage.Sets/src/mage/sets/tempestremastered/SpiritEnKor.java b/Mage.Sets/src/mage/sets/tempestremastered/SpiritEnKor.java
index e07c177ea7..4b4998f494 100644
--- a/Mage.Sets/src/mage/sets/tempestremastered/SpiritEnKor.java
+++ b/Mage.Sets/src/mage/sets/tempestremastered/SpiritEnKor.java
@@ -32,18 +32,13 @@ import mage.MageInt;
 import mage.abilities.Ability;
 import mage.abilities.common.SimpleActivatedAbility;
 import mage.abilities.costs.mana.GenericManaCost;
-import mage.abilities.effects.PreventionEffectData;
-import mage.abilities.effects.PreventionEffectImpl;
+import mage.abilities.effects.common.RedirectDamageFromSourceToTargetEffect;
 import mage.abilities.keyword.FlyingAbility;
 import mage.cards.CardImpl;
 import mage.constants.CardType;
 import mage.constants.Duration;
 import mage.constants.Rarity;
 import mage.constants.Zone;
-import mage.game.Game;
-import mage.game.events.DamageEvent;
-import mage.game.events.GameEvent;
-import mage.game.permanent.Permanent;
 import mage.target.common.TargetControlledCreaturePermanent;
 
 /**
@@ -62,9 +57,10 @@ public class SpiritEnKor extends CardImpl {
 
         // Flying
         this.addAbility(FlyingAbility.getInstance());
-        
+
         // {0}: The next 1 damage that would be dealt to Spirit en-Kor this turn is dealt to target creature you control instead.
-        Ability ability = new SimpleActivatedAbility(Zone.BATTLEFIELD, new SpiritEnKorPreventionEffect(), new GenericManaCost(0));
+        Ability ability = new SimpleActivatedAbility(Zone.BATTLEFIELD,
+                new RedirectDamageFromSourceToTargetEffect(Duration.EndOfTurn, 1, true), new GenericManaCost(0));
         ability.addTarget(new TargetControlledCreaturePermanent());
         this.addAbility(ability);
     }
@@ -78,44 +74,3 @@ public class SpiritEnKor extends CardImpl {
         return new SpiritEnKor(this);
     }
 }
-
-class SpiritEnKorPreventionEffect extends PreventionEffectImpl {
-    
-    SpiritEnKorPreventionEffect() {
-        super(Duration.EndOfTurn, 1, false);
-        staticText = "The next 1 damage that would be dealt to {this} this turn is dealt to target creature you control instead.";
-    }
-    
-    SpiritEnKorPreventionEffect(final SpiritEnKorPreventionEffect effect) {
-        super(effect);
-    }
-    
-    @Override
-    public SpiritEnKorPreventionEffect copy() {
-        return new SpiritEnKorPreventionEffect(this);
-    }
-    
-    @Override
-    public boolean replaceEvent(GameEvent event, Ability source, Game game) {
-        PreventionEffectData preventionResult = preventDamageAction(event, source, game);
-        if (preventionResult.getPreventedDamage() > 0) {
-            Permanent redirectTo = game.getPermanent(getTargetPointer().getFirst(game, source));
-            if (redirectTo != null) {
-                game.informPlayers("Dealing " + preventionResult.getPreventedDamage() + " to " + redirectTo.getName() + " instead.");
-                DamageEvent damageEvent = (DamageEvent) event;
-                redirectTo.damage(preventionResult.getPreventedDamage(), event.getSourceId(), game, damageEvent.isCombatDamage(), damageEvent.isPreventable(), event.getAppliedEffects());
-            }
-        }
-        return false;
-    }
-    
-    @Override
-    public boolean applies(GameEvent event, Ability source, Game game) {
-        if (!this.used && super.applies(event, source, game)) {
-            if (event.getTargetId().equals(source.getSourceId())) {
-                return game.getPermanent(getTargetPointer().getFirst(game, source)) != null;
-            }
-        }
-        return false;
-    }
-}
\ No newline at end of file
diff --git a/Mage.Sets/src/mage/sets/tempestremastered/WarriorEnKor.java b/Mage.Sets/src/mage/sets/tempestremastered/WarriorEnKor.java
index 4d991b1b1f..4587dbd24e 100644
--- a/Mage.Sets/src/mage/sets/tempestremastered/WarriorEnKor.java
+++ b/Mage.Sets/src/mage/sets/tempestremastered/WarriorEnKor.java
@@ -32,17 +32,12 @@ import mage.MageInt;
 import mage.abilities.Ability;
 import mage.abilities.common.SimpleActivatedAbility;
 import mage.abilities.costs.mana.GenericManaCost;
-import mage.abilities.effects.PreventionEffectData;
-import mage.abilities.effects.PreventionEffectImpl;
+import mage.abilities.effects.common.RedirectDamageFromSourceToTargetEffect;
 import mage.cards.CardImpl;
 import mage.constants.CardType;
 import mage.constants.Duration;
 import mage.constants.Rarity;
 import mage.constants.Zone;
-import mage.game.Game;
-import mage.game.events.DamageEvent;
-import mage.game.events.GameEvent;
-import mage.game.permanent.Permanent;
 import mage.target.common.TargetControlledCreaturePermanent;
 
 /**
@@ -61,7 +56,8 @@ public class WarriorEnKor extends CardImpl {
         this.toughness = new MageInt(2);
 
         // {0}: The next 1 damage that would be dealt to Warrior en-Kor this turn is dealt to target creature you control instead.
-        Ability ability = new SimpleActivatedAbility(Zone.BATTLEFIELD, new WarriorEnKorPreventionEffect(), new GenericManaCost(0));
+        Ability ability = new SimpleActivatedAbility(Zone.BATTLEFIELD,
+                new RedirectDamageFromSourceToTargetEffect(Duration.EndOfTurn, 1, true), new GenericManaCost(0));
         ability.addTarget(new TargetControlledCreaturePermanent());
         this.addAbility(ability);
     }
@@ -75,44 +71,3 @@ public class WarriorEnKor extends CardImpl {
         return new WarriorEnKor(this);
     }
 }
-
-class WarriorEnKorPreventionEffect extends PreventionEffectImpl {
-    
-    WarriorEnKorPreventionEffect() {
-        super(Duration.EndOfTurn, 1, false);
-        staticText = "The next 1 damage that would be dealt to {this} this turn is dealt to target creature you control instead.";
-    }
-    
-    WarriorEnKorPreventionEffect(final WarriorEnKorPreventionEffect effect) {
-        super(effect);
-    }
-    
-    @Override
-    public WarriorEnKorPreventionEffect copy() {
-        return new WarriorEnKorPreventionEffect(this);
-    }
-    
-    @Override
-    public boolean replaceEvent(GameEvent event, Ability source, Game game) {
-        PreventionEffectData preventionResult = preventDamageAction(event, source, game);
-        if (preventionResult.getPreventedDamage() > 0) {
-            Permanent redirectTo = game.getPermanent(getTargetPointer().getFirst(game, source));
-            if (redirectTo != null) {
-                game.informPlayers("Dealing " + preventionResult.getPreventedDamage() + " to " + redirectTo.getName() + " instead.");
-                DamageEvent damageEvent = (DamageEvent) event;
-                redirectTo.damage(preventionResult.getPreventedDamage(), event.getSourceId(), game, damageEvent.isCombatDamage(), damageEvent.isPreventable(), event.getAppliedEffects());
-            }
-        }
-        return false;
-    }
-    
-    @Override
-    public boolean applies(GameEvent event, Ability source, Game game) {
-        if (!this.used && super.applies(event, source, game)) {
-            if (event.getTargetId().equals(source.getSourceId())) {
-                return game.getPermanent(getTargetPointer().getFirst(game, source)) != null;
-            }
-        }
-        return false;
-    }
-}
\ No newline at end of file
diff --git a/Mage.Tests/src/test/java/org/mage/test/cards/replacement/redirect/WardOfPietyTest.java b/Mage.Tests/src/test/java/org/mage/test/cards/replacement/redirect/WardOfPietyTest.java
new file mode 100644
index 0000000000..17b12464d7
--- /dev/null
+++ b/Mage.Tests/src/test/java/org/mage/test/cards/replacement/redirect/WardOfPietyTest.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.replacement.redirect;
+
+import mage.constants.PhaseStep;
+import mage.constants.Zone;
+import org.junit.Test;
+import org.mage.test.serverside.base.CardTestPlayerBase;
+
+/**
+ *
+ * @author LevelX2
+ */
+public class WardOfPietyTest extends CardTestPlayerBase {
+
+    @Test
+    public void testNonCombatDamageToPlayer() {
+        addCard(Zone.HAND, playerB, "Lightning Bolt");
+        addCard(Zone.BATTLEFIELD, playerB, "Mountain");
+
+        // Enchant creature
+        // {1}{W}: The next 1 damage that would be dealt to enchanted creature this turn is dealt to target creature or player instead.
+        addCard(Zone.HAND, playerA, "Ward of Piety"); // {1}{W}
+        addCard(Zone.BATTLEFIELD, playerA, "Silvercoat Lion"); // 2/2
+        addCard(Zone.BATTLEFIELD, playerA, "Plains", 6);
+
+        castSpell(1, PhaseStep.PRECOMBAT_MAIN, playerA, "Ward of Piety", "Silvercoat Lion");
+
+        activateAbility(1, PhaseStep.BEGIN_COMBAT, playerA, "{1}{W}: The next 1 damage", playerB);
+        activateAbility(1, PhaseStep.BEGIN_COMBAT, playerA, "{1}{W}: The next 1 damage", playerB);
+
+        castSpell(1, PhaseStep.POSTCOMBAT_MAIN, playerB, "Lightning Bolt", "Silvercoat Lion");
+
+        setStopAt(1, PhaseStep.END_TURN);
+        execute();
+
+        assertGraveyardCount(playerB, "Lightning Bolt", 1);
+        assertPermanentCount(playerA, "Ward of Piety", 1);
+        assertPermanentCount(playerA, "Silvercoat Lion", 1);
+
+        assertLife(playerA, 20);
+        assertLife(playerB, 18);
+
+    }
+
+}
diff --git a/Mage/src/mage/abilities/effects/common/RedirectDamageFromSourceToTargetEffect.java b/Mage/src/mage/abilities/effects/common/RedirectDamageFromSourceToTargetEffect.java
new file mode 100644
index 0000000000..61b35d63ab
--- /dev/null
+++ b/Mage/src/mage/abilities/effects/common/RedirectDamageFromSourceToTargetEffect.java
@@ -0,0 +1,42 @@
+/*
+ * To change this license header, choose License Headers in Project Properties.
+ * To change this template file, choose Tools | Templates
+ * and open the template in the editor.
+ */
+package mage.abilities.effects.common;
+
+import mage.abilities.Ability;
+import mage.abilities.effects.RedirectionEffect;
+import mage.constants.Duration;
+import mage.game.Game;
+import mage.game.events.GameEvent;
+
+/**
+ *
+ * @author LevelX2
+ */
+public class RedirectDamageFromSourceToTargetEffect extends RedirectionEffect {
+
+    public RedirectDamageFromSourceToTargetEffect(Duration duration, int amountToRedirect, boolean oneUsage) {
+        super(duration, amountToRedirect, oneUsage);
+        staticText = "The next " + amountToRedirect + " damage that would be dealt to {this} this turn is dealt to target creature you control instead.";
+    }
+
+    public RedirectDamageFromSourceToTargetEffect(final RedirectDamageFromSourceToTargetEffect effect) {
+        super(effect);
+    }
+
+    @Override
+    public RedirectDamageFromSourceToTargetEffect copy() {
+        return new RedirectDamageFromSourceToTargetEffect(this);
+    }
+
+    @Override
+    public boolean applies(GameEvent event, Ability source, Game game) {
+        if (event.getTargetId().equals(source.getSourceId())) {
+            this.redirectTarget = source.getTargets().get(0);
+            return true;
+        }
+        return false;
+    }
+}