Merge branch 'ai-hints-npe-fix' into 'master'

Prevent NPEs caused by the AI when testing for the new style AI hints

See merge request core-developers/forge!1044
This commit is contained in:
Hans Mackowiak
2018-10-26 14:34:22 +00:00
6 changed files with 16 additions and 6 deletions

View File

@@ -1844,4 +1844,13 @@ public class ComputerUtilCard {
return AiPlayDecision.WillPlay;
}
// Determine if the AI has an AI:RemoveDeck:All or an AI:RemoveDeck:Random hint specified.
// Includes a NPE guard on getRules() which might otherwise be tripped on some cards (e.g. tokens).
public static boolean isCardRemAIDeck(final Card card) {
return card.getRules() != null && card.getRules().getAiHints().getRemAIDecks();
}
public static boolean isCardRemRandomDeck(final Card card) {
return card.getRules() != null && card.getRules().getAiHints().getRemRandomDecks();
}
}

View File

@@ -1463,7 +1463,7 @@ public class ChangeZoneAi extends SpellAbilityAi {
fetchList = CardLists.filter(fetchList, new Predicate<Card>() {
@Override
public boolean apply(final Card c) {
if (c.getRules().getAiHints().getRemAIDecks() || c.getRules().getAiHints().getRemRandomDecks()) {
if (ComputerUtilCard.isCardRemAIDeck(c) || ComputerUtilCard.isCardRemRandomDeck(c)) {
return false;
}
return true;

View File

@@ -171,7 +171,7 @@ public class ControlGainAi extends SpellAbilityAi {
}
// do not take control on something it doesn't know how to use
return !c.getRules().getAiHints().getRemAIDecks();
return !ComputerUtilCard.isCardRemAIDeck(c);
}
});

View File

@@ -37,7 +37,7 @@ public class PowerExchangeAi extends SpellAbilityAi {
list = CardLists.filter(list, new Predicate<Card>() {
@Override
public boolean apply(final Card c) {
return !c.getRules().getAiHints().getRemAIDecks() && c.canBeTargetedBy(sa);
return !ComputerUtilCard.isCardRemAIDeck(c) && c.canBeTargetedBy(sa);
}
});
CardLists.sortByPowerAsc(list);

View File

@@ -416,8 +416,9 @@ public final class CardPredicates {
public static final Predicate<Card> isRemAIDeck() {
return new Predicate<Card>() {
@Override
public boolean apply(final Card c) {
return c.getRules().getAiHints().getRemAIDecks();
public boolean apply(final Card c)
{
return c.getRules() != null && c.getRules().getAiHints().getRemAIDecks();
}
};
}