Added appliedEffects parameter to Player.damage to handle damage redirection effects correct. Fixed Furncae of Rath damage redirectionEffect.

This commit is contained in:
LevelX2 2012-10-09 17:54:21 +02:00
parent 79a9e520c6
commit 06624ed116
3 changed files with 39 additions and 9 deletions

View file

@ -36,7 +36,11 @@ import mage.abilities.common.SimpleStaticAbility;
import mage.abilities.effects.ReplacementEffectImpl;
import mage.cards.CardImpl;
import mage.game.Game;
import mage.game.events.DamageEvent;
import mage.game.events.GameEvent;
import mage.game.events.GameEvent.EventType;
import mage.game.permanent.Permanent;
import mage.players.Player;
/**
*
@ -83,14 +87,14 @@ class FurnaceOfRathEffect extends ReplacementEffectImpl<FurnaceOfRathEffect> {
@Override
public boolean applies(GameEvent event, Ability source, Game game) {
if (!event.getAppliedEffects().contains(this.getId())) {
switch (event.getType()) {
case DAMAGE_PLAYER:
event.setAmount(event.getAmount() * 2);
return true;
case DAMAGE_CREATURE:
event.setAmount(event.getAmount() * 2);
return true;
}
}
return false;
}
@ -101,6 +105,21 @@ class FurnaceOfRathEffect extends ReplacementEffectImpl<FurnaceOfRathEffect> {
@Override
public boolean replaceEvent(GameEvent event, Ability source, Game game) {
return apply(game, source);
DamageEvent damageEvent = (DamageEvent)event;
damageEvent.getAppliedEffects().add(getId());
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());
return true;
}
} else {
Permanent targetPermanent = game.getPermanent(event.getTargetId());
if (targetPermanent != null) {
targetPermanent.damage(damageEvent.getAmount()*2, damageEvent.getSourceId(), game, damageEvent.isPreventable(), damageEvent.isCombatDamage(), event.getAppliedEffects());
return true;
}
}
return false;
}
}

View file

@ -562,6 +562,7 @@ public abstract class PermanentImpl<T extends PermanentImpl<T>> extends CardImpl
return damage(damageAmount, sourceId, game, preventable, combat, false, null);
}
@Override
public int damage(int damageAmount, UUID sourceId, Game game, boolean preventable, boolean combat, ArrayList<UUID> appliedEffects) {
return damage(damageAmount, sourceId, game, preventable, combat, false, appliedEffects);
}

View file

@ -878,11 +878,21 @@ public abstract class PlayerImpl<T extends PlayerImpl<T>> implements Player, Ser
}
return 0;
}
@Override
public int damage(int damage, UUID sourceId, Game game, boolean combatDamage, boolean preventable) {
return doDamage(damage, sourceId, game, combatDamage, preventable, null);
}
@Override
public int damage(int damage, UUID sourceId, Game game, boolean combatDamage, boolean preventable, ArrayList<UUID> appliedEffects) {
return doDamage(damage, sourceId, game, combatDamage, preventable, appliedEffects);
}
private int doDamage(int damage, UUID sourceId, Game game, boolean combatDamage, boolean preventable, ArrayList<UUID> appliedEffects) {
if (damage > 0 && canDamage(game.getObject(sourceId), game)) {
GameEvent event = new DamagePlayerEvent(playerId, sourceId, playerId, damage, preventable, combatDamage);
event.setAppliedEffects(appliedEffects);
if (!game.replaceEvent(event)) {
int actualDamage = event.getAmount();
if (actualDamage > 0) {