Some changes to RedirectionEffect.

This commit is contained in:
LevelX2 2013-08-24 17:16:42 +02:00
parent 341da30e37
commit 90ec6123b2
3 changed files with 11 additions and 24 deletions

View file

@ -721,6 +721,7 @@ public class ContinuousEffects implements Serializable {
public void addEffect(ContinuousEffect effect, Ability source) {
switch (effect.getEffectType()) {
case REPLACEMENT:
case REDIRECTION:
ReplacementEffect newReplacementEffect = (ReplacementEffect)effect;
replacementEffects.addEffect(newReplacementEffect, source);
break;

View file

@ -28,9 +28,10 @@
package mage.abilities.effects;
import java.util.UUID;
import mage.abilities.Ability;
import mage.constants.Duration;
import mage.constants.Outcome;
import mage.abilities.Ability;
import mage.filter.common.FilterPlaneswalkerPermanent;
import mage.game.Game;
import mage.game.events.DamageEvent;
@ -41,7 +42,6 @@ import mage.game.stack.StackObject;
import mage.players.Player;
import mage.target.TargetPermanent;
import java.util.UUID;
/**
*
@ -92,11 +92,13 @@ public class PlaneswalkerRedirectionEffect extends RedirectionEffect<Planeswalke
private UUID getSourceControllerId(UUID sourceId, Game game) {
StackObject source = game.getStack().getStackObject(sourceId);
if (source != null)
if (source != null) {
return source.getControllerId();
}
Permanent permanent = game.getBattlefield().getPermanent(sourceId);
if (permanent != null)
if (permanent != null) {
return permanent.getControllerId();
}
return null;
}
}

View file

@ -28,18 +28,14 @@
package mage.abilities.effects;
import java.util.UUID;
import mage.abilities.Ability;
import mage.constants.Duration;
import mage.constants.EffectType;
import mage.constants.Outcome;
import mage.abilities.Ability;
import mage.game.Game;
import mage.game.events.DamageEvent;
import mage.game.events.GameEvent;
import mage.game.permanent.Permanent;
import mage.game.stack.Spell;
import mage.game.stack.StackAbility;
import mage.game.stack.StackObject;
import mage.players.Player;
import mage.target.TargetPermanent;
@ -70,28 +66,16 @@ public abstract class RedirectionEffect<T extends RedirectionEffect<T>> extends
public boolean replaceEvent(GameEvent event, Ability source, Game game) {
DamageEvent damageEvent = (DamageEvent)event;
Permanent permanent = game.getPermanent(redirectTarget.getFirstTarget());
Ability damageSource = getSource(damageEvent.getSourceId(), game);
if (permanent != null && damageSource != null) {
permanent.damage(damageEvent.getAmount(), damageSource.getId(), game, damageEvent.isPreventable(), damageEvent.isCombatDamage());
if (permanent != null) {
permanent.damage(damageEvent.getAmount(), event.getSourceId(), game, damageEvent.isPreventable(), damageEvent.isCombatDamage(), event.getAppliedEffects());
return true;
}
Player player = game.getPlayer(redirectTarget.getFirstTarget());
if (player != null) {
player.damage(damageEvent.getAmount(), damageSource.getId(), game, damageEvent.isCombatDamage(), damageEvent.isPreventable());
player.damage(damageEvent.getAmount(), event.getSourceId(), game, damageEvent.isCombatDamage(), damageEvent.isPreventable(), event.getAppliedEffects());
return true;
}
return false;
}
protected Ability getSource(UUID sourceId, Game game) {
StackObject source = game.getStack().getStackObject(sourceId);
if (source != null) {
if (source instanceof StackAbility)
return (StackAbility)source;
if (source instanceof Spell)
return ((Spell)source).getSpellAbility();
}
return null;
}
}