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

@@ -1705,7 +1705,7 @@ public class AiController {
if (!useSimulation) { if (!useSimulation) {
for (Entry<DeckSection, CardPool> ds : myDeck) { for (Entry<DeckSection, CardPool> ds : myDeck) {
for (Entry<PaperCard, Integer> cp : ds.getValue()) { for (Entry<PaperCard, Integer> cp : ds.getValue()) {
if (cp.getKey().getRules().getAiHints().getRemAIDecks()) if (cp.getKey().getRules().getAiHints().getRemAIDecks())
result.add(cp.getKey()); result.add(cp.getKey());
} }
} }

View File

@@ -1844,4 +1844,13 @@ public class ComputerUtilCard {
return AiPlayDecision.WillPlay; 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>() { fetchList = CardLists.filter(fetchList, new Predicate<Card>() {
@Override @Override
public boolean apply(final Card c) { 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 false;
} }
return true; 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 // 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>() { list = CardLists.filter(list, new Predicate<Card>() {
@Override @Override
public boolean apply(final Card c) { public boolean apply(final Card c) {
return !c.getRules().getAiHints().getRemAIDecks() && c.canBeTargetedBy(sa); return !ComputerUtilCard.isCardRemAIDeck(c) && c.canBeTargetedBy(sa);
} }
}); });
CardLists.sortByPowerAsc(list); CardLists.sortByPowerAsc(list);

View File

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