Fix Charm NPE

This commit is contained in:
TRT
2022-04-05 13:41:17 +02:00
parent 311002069a
commit 21043e50d5
2 changed files with 4 additions and 3 deletions

View File

@@ -34,7 +34,7 @@ public class CharmAi extends SpellAbilityAi {
num = min = choices.size(); num = min = choices.size();
} else { } else {
num = AbilityUtils.calculateAmount(source, sa.getParamOrDefault("CharmNum", "1"), sa); num = AbilityUtils.calculateAmount(source, sa.getParamOrDefault("CharmNum", "1"), sa);
min = sa.hasParam("MinCharmNum") ? AbilityUtils.calculateAmount(source, sa.getParamOrDefault("MinCharmNum", "1"), sa) : num; min = sa.hasParam("MinCharmNum") ? AbilityUtils.calculateAmount(source, sa.getParam("MinCharmNum"), sa) : num;
} }
boolean timingRight = sa.isTrigger(); //is there a reason to play the charm now? boolean timingRight = sa.isTrigger(); //is there a reason to play the charm now?

View File

@@ -170,13 +170,14 @@ public class CharmEffect extends SpellAbilityEffect {
Card source = sa.getHostCard(); Card source = sa.getHostCard();
Player activator = sa.getActivatingPlayer(); Player activator = sa.getActivatingPlayer();
final int num = Math.min(AbilityUtils.calculateAmount(source, sa.getParamOrDefault("CharmNum", "1"), sa), choices.size()); int num = AbilityUtils.calculateAmount(source, sa.getParamOrDefault("CharmNum", "1"), sa);
final int min = sa.hasParam("MinCharmNum") ? AbilityUtils.calculateAmount(source, sa.getParamOrDefault("MinCharmNum", "1"), sa) : num; final int min = sa.hasParam("MinCharmNum") ? AbilityUtils.calculateAmount(source, sa.getParam("MinCharmNum"), sa) : num;
// if the amount of choices is smaller than min then they can't be chosen // if the amount of choices is smaller than min then they can't be chosen
if (min > choices.size()) { if (min > choices.size()) {
return false; return false;
} }
num = Math.min(num, choices.size());
boolean isOptional = sa.hasParam("Optional"); boolean isOptional = sa.hasParam("Optional");
if (isOptional && !activator.getController().confirmAction(sa, null, Localizer.getInstance().getMessage("lblWouldYouLikeCharm", CardTranslation.getTranslatedName(source.getName())))) { if (isOptional && !activator.getController().confirmAction(sa, null, Localizer.getInstance().getMessage("lblWouldYouLikeCharm", CardTranslation.getTranslatedName(source.getName())))) {