From 4c7d8e2c64a9a7f782bc0a5c0271068155b2d719 Mon Sep 17 00:00:00 2001 From: Sloth Date: Tue, 11 Jun 2013 08:20:00 +0000 Subject: [PATCH] - Fixed possible NPE caused by hasEnoughManaSourcesToCast. --- src/main/java/forge/card/ability/ai/ChangeZoneAi.java | 8 ++------ src/main/java/forge/game/ai/ComputerUtilMana.java | 1 + 2 files changed, 3 insertions(+), 6 deletions(-) diff --git a/src/main/java/forge/card/ability/ai/ChangeZoneAi.java b/src/main/java/forge/card/ability/ai/ChangeZoneAi.java index 41da4e64a45..c45c60cab46 100644 --- a/src/main/java/forge/card/ability/ai/ChangeZoneAi.java +++ b/src/main/java/forge/card/ability/ai/ChangeZoneAi.java @@ -511,9 +511,7 @@ public class ChangeZoneAi extends SpellAbilityAi { // need something AI can cast now CardLists.sortByEvaluateCreature(list); for (Card c : list) { - SpellAbility spell = c.getFirstSpellAbility(); - spell.setActivatingPlayer(ai); - if (ComputerUtilMana.hasEnoughManaSourcesToCast(spell, ai)) + if (ComputerUtilMana.hasEnoughManaSourcesToCast(c.getFirstSpellAbility(), ai)) return c; } return null; @@ -1237,9 +1235,7 @@ public class ChangeZoneAi extends SpellAbilityAi { if (CardLists.filter(hand, Presets.LANDS).isEmpty() && CardLists.filter(ai.getCardsIn(ZoneType.Battlefield), Presets.LANDS).size() < 4) { boolean canCastSomething = false; for (Card cardInHand : hand) { - final SpellAbility spell = cardInHand.getFirstSpellAbility(); - spell.setActivatingPlayer(ai); - canCastSomething |= ComputerUtilMana.hasEnoughManaSourcesToCast(spell, ai); + canCastSomething |= ComputerUtilMana.hasEnoughManaSourcesToCast(cardInHand.getFirstSpellAbility(), ai); } if (!canCastSomething) { System.out.println("Pulling a land as there are none in hand, less than 4 on the board, and nothing in hand is castable."); diff --git a/src/main/java/forge/game/ai/ComputerUtilMana.java b/src/main/java/forge/game/ai/ComputerUtilMana.java index 88008e9afb4..aee38aa572e 100644 --- a/src/main/java/forge/game/ai/ComputerUtilMana.java +++ b/src/main/java/forge/game/ai/ComputerUtilMana.java @@ -54,6 +54,7 @@ public class ComputerUtilMana { // Does not check if mana sources can be used right now, just checks for potential chance. public static boolean hasEnoughManaSourcesToCast(final SpellAbility sa, final Player ai) { + sa.setActivatingPlayer(ai); return payManaCost(sa, ai, true, 0, false); }