mirror of
https://github.com/Card-Forge/forge.git
synced 2025-11-17 03:08:02 +00:00
Fix NPE
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
package forge.ai.ability;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import com.google.common.base.Predicates;
|
||||
import com.google.common.collect.Iterables;
|
||||
@@ -138,13 +139,17 @@ public class ChangeZoneAllAi extends SpellAbilityAi {
|
||||
return true;
|
||||
} else {
|
||||
// search targetable Opponents
|
||||
final Iterable<Player> oppList = Iterables.filter(ai.getOpponents(), PlayerPredicates.isTargetableBy(sa));
|
||||
final List<Player> oppList = Lists.newArrayList(Iterables.filter(ai.getOpponents(), PlayerPredicates.isTargetableBy(sa)));
|
||||
|
||||
if (oppList.isEmpty()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// get the one with the most handsize
|
||||
Player oppTarget = Collections.max(Lists.newArrayList(oppList), PlayerPredicates.compareByZoneSize(origin));
|
||||
Player oppTarget = Collections.max(oppList, PlayerPredicates.compareByZoneSize(origin));
|
||||
|
||||
// set the target
|
||||
if (oppTarget != null && !oppTarget.getCardsIn(ZoneType.Hand).isEmpty()) {
|
||||
if (!oppTarget.getCardsIn(ZoneType.Hand).isEmpty()) {
|
||||
sa.resetTargets();
|
||||
sa.getTargets().add(oppTarget);
|
||||
} else {
|
||||
@@ -152,24 +157,26 @@ public class ChangeZoneAllAi extends SpellAbilityAi {
|
||||
}
|
||||
}
|
||||
} else if (origin.equals(ZoneType.Battlefield)) {
|
||||
// this statement is assuming the AI is trying to use this spell
|
||||
// offensively
|
||||
// if the AI is using it defensively, then something else needs to
|
||||
// occur
|
||||
// this statement is assuming the AI is trying to use this spell offensively
|
||||
// if the AI is using it defensively, then something else needs to occur
|
||||
// if only creatures are affected evaluate both lists and pass only
|
||||
// if human creatures are more valuable
|
||||
if (sa.usesTargeting()) {
|
||||
// search targetable Opponents
|
||||
final Iterable<Player> oppList = Iterables.filter(ai.getOpponents(),
|
||||
PlayerPredicates.isTargetableBy(sa));
|
||||
final List<Player> oppList = Lists.newArrayList(Iterables.filter(ai.getOpponents(),
|
||||
PlayerPredicates.isTargetableBy(sa)));
|
||||
|
||||
if (oppList.isEmpty()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// get the one with the most in graveyard
|
||||
// zone is visible so evaluate which would be hurt the most
|
||||
Player oppTarget = Collections.max(Lists.newArrayList(oppList),
|
||||
Player oppTarget = Collections.max(oppList,
|
||||
PlayerPredicates.compareByZoneSize(origin));
|
||||
|
||||
// set the target
|
||||
if (oppTarget != null && !oppTarget.getCardsIn(ZoneType.Graveyard).isEmpty()) {
|
||||
if (oppTarget.getCardsIn(ZoneType.Graveyard).isEmpty()) {
|
||||
sa.resetTargets();
|
||||
sa.getTargets().add(oppTarget);
|
||||
} else {
|
||||
@@ -234,7 +241,7 @@ public class ChangeZoneAllAi extends SpellAbilityAi {
|
||||
AiPlayerPredicates.compareByZoneValue(sa.getParam("ChangeType"), origin, sa));
|
||||
|
||||
// set the target
|
||||
if (oppTarget != null && !oppTarget.getCardsIn(ZoneType.Graveyard).isEmpty()) {
|
||||
if (!oppTarget.getCardsIn(ZoneType.Graveyard).isEmpty()) {
|
||||
sa.resetTargets();
|
||||
sa.getTargets().add(oppTarget);
|
||||
} else {
|
||||
@@ -380,15 +387,19 @@ public class ChangeZoneAllAi extends SpellAbilityAi {
|
||||
if (origin.equals(ZoneType.Hand) || origin.equals(ZoneType.Library)) {
|
||||
if (sa.usesTargeting()) {
|
||||
// search targetable Opponents
|
||||
final Iterable<Player> oppList = Iterables.filter(ai.getOpponents(),
|
||||
PlayerPredicates.isTargetableBy(sa));
|
||||
final List<Player> oppList = Lists.newArrayList(Iterables.filter(ai.getOpponents(),
|
||||
PlayerPredicates.isTargetableBy(sa)));
|
||||
|
||||
if (oppList.isEmpty()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// get the one with the most handsize
|
||||
Player oppTarget = Collections.max(Lists.newArrayList(oppList),
|
||||
Player oppTarget = Collections.max(oppList,
|
||||
PlayerPredicates.compareByZoneSize(origin));
|
||||
|
||||
// set the target
|
||||
if (oppTarget != null && !oppTarget.getCardsIn(ZoneType.Hand).isEmpty()) {
|
||||
if (!oppTarget.getCardsIn(ZoneType.Hand).isEmpty()) {
|
||||
sa.resetTargets();
|
||||
sa.getTargets().add(oppTarget);
|
||||
} else {
|
||||
@@ -418,16 +429,20 @@ public class ChangeZoneAllAi extends SpellAbilityAi {
|
||||
} else if (origin.equals(ZoneType.Graveyard)) {
|
||||
if (sa.usesTargeting()) {
|
||||
// search targetable Opponents
|
||||
final Iterable<Player> oppList = Iterables.filter(ai.getOpponents(),
|
||||
PlayerPredicates.isTargetableBy(sa));
|
||||
final List<Player> oppList = Lists.newArrayList(Iterables.filter(ai.getOpponents(),
|
||||
PlayerPredicates.isTargetableBy(sa)));
|
||||
|
||||
if (oppList.isEmpty()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// get the one with the most in graveyard
|
||||
// zone is visible so evaluate which would be hurt the most
|
||||
Player oppTarget = Collections.max(Lists.newArrayList(oppList),
|
||||
Player oppTarget = Collections.max(oppList,
|
||||
AiPlayerPredicates.compareByZoneValue(sa.getParam("ChangeType"), origin, sa));
|
||||
|
||||
// set the target
|
||||
if (oppTarget != null && !oppTarget.getCardsIn(ZoneType.Graveyard).isEmpty()) {
|
||||
if (!oppTarget.getCardsIn(ZoneType.Graveyard).isEmpty()) {
|
||||
sa.resetTargets();
|
||||
sa.getTargets().add(oppTarget);
|
||||
} else {
|
||||
|
||||
@@ -787,7 +787,7 @@ public class CountersPutAi extends CountersAi {
|
||||
List<Player> playerList = Lists.newArrayList(Iterables.filter(
|
||||
sa.getTargetRestrictions().getAllCandidates(sa, true, true), Player.class));
|
||||
|
||||
if (playerList.isEmpty() && mandatory) {
|
||||
if (playerList.isEmpty()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
@@ -117,8 +117,7 @@ public class MillAi extends SpellAbilityAi {
|
||||
|
||||
// if it would mill none, try other one
|
||||
if (numCards <= 0) {
|
||||
if ((sa.getParam("NumCards").equals("X") || sa.getParam("NumCards").equals("Z")))
|
||||
{
|
||||
if ((sa.getParam("NumCards").equals("X") || sa.getParam("NumCards").equals("Z"))) {
|
||||
if (source.getSVar("X").startsWith("Count$xPaid")) {
|
||||
// Spell is PayX based
|
||||
} else if (source.getSVar("X").startsWith("Remembered$ChromaSource")) {
|
||||
@@ -136,7 +135,7 @@ public class MillAi extends SpellAbilityAi {
|
||||
continue;
|
||||
}
|
||||
|
||||
// if that player can be miled, select this one.
|
||||
// if that player can be milled, select this one.
|
||||
if (numCards >= pLibrary.size()) {
|
||||
sa.getTargets().add(o);
|
||||
return true;
|
||||
|
||||
Reference in New Issue
Block a user