Fix NPE in tryToAutoChoose when auto-choose is set to "Most"

This commit is contained in:
Alex Vasile 2022-07-09 18:02:32 -04:00
parent a94c837ad0
commit 7ca7e10d80

View file

@ -612,6 +612,10 @@ public abstract class TargetImpl implements Target {
@Override
public UUID tryToAutoChoose(UUID abilityControllerId, Ability source, Game game, Collection<UUID> possibleTargets) {
if (possibleTargets == null || game == null) {
return null;
}
Player player = game.getPlayer(abilityControllerId);
if (player == null) {
return null;
@ -626,7 +630,8 @@ public abstract class TargetImpl implements Target {
boolean canAutoChoose = this.getMinNumberOfTargets() == this.getMaxNumberOfTargets() && // Targets must be picked
possibleTargets.size() == this.getNumberOfTargets() - this.getSize() && // Available targets are equal to the number that must be picked
!strictModeEnabled && // Test AI is not set to strictChooseMode(true)
playerAutoTargetLevel > 0; // Human player has enabled auto-choose in settings
playerAutoTargetLevel > 0 && // Human player has enabled auto-choose in settings
!(playerAutoTargetLevel == 1 && source == null); // Is source is null, then the
if (canAutoChoose) {
boolean autoTargetAll = playerAutoTargetLevel == 2;
@ -664,6 +669,7 @@ public abstract class TargetImpl implements Target {
if (targetingOwnThing) {
String abilityText = source.getRule(true).toLowerCase();
if (abilityText.contains("discard")
|| abilityText.contains("sacrifice")
|| abilityText.contains("destroy")