RelaceDamage: fix DamageTarget check using Replaced values

This commit is contained in:
Hans Mackowiak
2020-12-06 17:51:15 +01:00
parent 8076682d1b
commit c9500859fe

View File

@@ -17,6 +17,7 @@
*/
package forge.game.replacement;
import forge.game.Game;
import forge.game.GameEntity;
import forge.game.ability.AbilityKey;
import forge.game.ability.AbilityUtils;
@@ -48,6 +49,7 @@ public class ReplaceDamage extends ReplacementEffect {
*/
@Override
public boolean canReplace(Map<AbilityKey, Object> runParams) {
final Game game = getHostCard().getGame();
if (!(runParams.containsKey(AbilityKey.Prevention) == (hasParam("PreventionEffect") || hasParam("Prevent")))) {
return false;
@@ -128,12 +130,27 @@ public class ReplaceDamage extends ReplacementEffect {
}
// check for DamageRedirection, the Thing where the damage is redirected to must be a creature or planeswalker or a player
String def = getParam("DamageTarget");
for (Player p : AbilityUtils.getDefinedPlayers(hostCard, def, null)) {
if (!p.getGame().getPlayers().contains(p)) {
if (def.startsWith("Replaced")) {
// this can't work with the Defined below because the replaced objects aren't set to a possible SA yet
if (def.equals("ReplacedSourceController")) {
Card source = (Card) runParams.get(AbilityKey.DamageSource);
if (!game.getPlayers().contains(source.getController())) {
return false;
}
} else if (def.equals("ReplacedTargetController")) {
if (!(affected instanceof Card) || !game.getPlayers().contains(((Card) affected).getController())) {
return false;
}
} else {
return false;
}
} else {
for (Player p : AbilityUtils.getDefinedPlayers(getHostCard(), def, null)) {
if (!game.getPlayers().contains(p)) {
return false;
}
}
for (Card c : AbilityUtils.getDefinedCards(hostCard, def, null)) {
for (Card c : AbilityUtils.getDefinedCards(getHostCard(), def, null)) {
if (!c.isCreature() && !c.isPlaneswalker()) {
return false;
}
@@ -142,6 +159,7 @@ public class ReplaceDamage extends ReplacementEffect {
}
}
}
}
return true;
}