mirror of
https://github.com/Card-Forge/forge.git
synced 2025-11-17 11:18:01 +00:00
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:
@@ -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();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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;
|
||||||
|
|||||||
@@ -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);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -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);
|
||||||
|
|||||||
@@ -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();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user