- Fixed possible NPE caused by hasEnoughManaSourcesToCast.

This commit is contained in:
Sloth
2013-06-11 08:20:00 +00:00
parent f391259e5c
commit 4c7d8e2c64
2 changed files with 3 additions and 6 deletions

View File

@@ -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.");

View File

@@ -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);
}