mirror of
https://github.com/Card-Forge/forge.git
synced 2025-11-17 03:08:02 +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;
|
package forge.game.replacement;
|
||||||
|
|
||||||
|
import forge.game.Game;
|
||||||
import forge.game.GameEntity;
|
import forge.game.GameEntity;
|
||||||
import forge.game.ability.AbilityKey;
|
import forge.game.ability.AbilityKey;
|
||||||
import forge.game.ability.AbilityUtils;
|
import forge.game.ability.AbilityUtils;
|
||||||
@@ -48,6 +49,7 @@ public class ReplaceDamage extends ReplacementEffect {
|
|||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public boolean canReplace(Map<AbilityKey, Object> runParams) {
|
public boolean canReplace(Map<AbilityKey, Object> runParams) {
|
||||||
|
final Game game = getHostCard().getGame();
|
||||||
|
|
||||||
if (!(runParams.containsKey(AbilityKey.Prevention) == (hasParam("PreventionEffect") || hasParam("Prevent")))) {
|
if (!(runParams.containsKey(AbilityKey.Prevention) == (hasParam("PreventionEffect") || hasParam("Prevent")))) {
|
||||||
return false;
|
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
|
// check for DamageRedirection, the Thing where the damage is redirected to must be a creature or planeswalker or a player
|
||||||
String def = getParam("DamageTarget");
|
String def = getParam("DamageTarget");
|
||||||
for (Player p : AbilityUtils.getDefinedPlayers(hostCard, def, null)) {
|
if (def.startsWith("Replaced")) {
|
||||||
if (!p.getGame().getPlayers().contains(p)) {
|
// 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;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for (Card c : AbilityUtils.getDefinedCards(hostCard, def, null)) {
|
for (Card c : AbilityUtils.getDefinedCards(getHostCard(), def, null)) {
|
||||||
if (!c.isCreature() && !c.isPlaneswalker()) {
|
if (!c.isCreature() && !c.isPlaneswalker()) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@@ -142,6 +159,7 @@ public class ReplaceDamage extends ReplacementEffect {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user