mirror of
https://github.com/Card-Forge/forge.git
synced 2025-11-17 11:18:01 +00:00
Merge branch '1659-npe-at-forge-game-ability-abilityutils-getdefinedplayers-abilityutils-java-1084' into 'master'
Resolve "NPE at forge.game.ability.AbilityUtils.getDefinedPlayers(AbilityUtils.java:1084)" Closes #1659 See merge request core-developers/forge!3491
This commit is contained in:
@@ -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,17 +130,33 @@ 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;
|
||||
}
|
||||
}
|
||||
for (Card c : AbilityUtils.getDefinedCards(hostCard, def, null)) {
|
||||
if (!c.isCreature() && !c.isPlaneswalker()) {
|
||||
return false;
|
||||
} else {
|
||||
for (Player p : AbilityUtils.getDefinedPlayers(getHostCard(), def, null)) {
|
||||
if (!game.getPlayers().contains(p)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
if (!c.isInPlay()) {
|
||||
return false;
|
||||
for (Card c : AbilityUtils.getDefinedCards(getHostCard(), def, null)) {
|
||||
if (!c.isCreature() && !c.isPlaneswalker()) {
|
||||
return false;
|
||||
}
|
||||
if (!c.isInPlay()) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user