Merge branch 'npefix' into 'master'

Fix Charm NPE

See merge request core-developers/forge!6487
This commit is contained in:
Michael Kamensky
2022-04-05 18:00:16 +00:00
2 changed files with 6 additions and 5 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

@@ -167,16 +167,17 @@ public class CharmEffect extends SpellAbilityEffect {
return true; return true;
} }
Card source = sa.getHostCard(); final Card source = sa.getHostCard();
Player activator = sa.getActivatingPlayer(); final 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())))) {