From eedfa950a9546c2094e483632ab173003ecd04fa Mon Sep 17 00:00:00 2001 From: Northmoc Date: Mon, 18 Apr 2022 11:45:24 -0400 Subject: [PATCH] CountersPutEffect : streamline most CounterType choosing into chooseTypeFromList (supporting UniqueType and RandomType) --- .../ability/effects/CountersPutEffect.java | 44 +++++++++++-------- 1 file changed, 25 insertions(+), 19 deletions(-) diff --git a/forge-game/src/main/java/forge/game/ability/effects/CountersPutEffect.java b/forge-game/src/main/java/forge/game/ability/effects/CountersPutEffect.java index 9f4bfc8f8d4..b93dc7c9841 100644 --- a/forge-game/src/main/java/forge/game/ability/effects/CountersPutEffect.java +++ b/forge-game/src/main/java/forge/game/ability/effects/CountersPutEffect.java @@ -348,17 +348,8 @@ public class CountersPutEffect extends SpellAbilityEffect { } continue; } - if (sa.hasParam("CounterTypePerDefined")) { - List choices = Lists.newArrayList(); - for (String s : sa.getParam("CounterType").split(",")) { - choices.add(CounterType.getType(s)); - } - Map params = Maps.newHashMap(); - params.put("Target", obj); - StringBuilder sb = new StringBuilder(); - sb.append(Localizer.getInstance().getMessage("lblSelectCounterTypeAddTo") + " "); - sb.append(obj); - counterType = pc.chooseCounterType(choices, sa, sb.toString(), params); + if (sa.hasParam("CounterTypePerDefined") || sa.hasParam("UniqueType")) { + counterType = chooseTypeFromList(sa, sa.getParam("CounterType"), obj, pc); } if (obj instanceof Card) { @@ -527,14 +518,8 @@ public class CountersPutEffect extends SpellAbilityEffect { && !sa.hasParam("UniqueType") && !sa.hasParam("CounterTypePerDefined") && !sa.hasParam("CounterTypes") && !sa.hasParam("ChooseDifferent")) { try { - List choices = Lists.newArrayList(); - for (String s : sa.getParam("CounterType").split(",")) { - choices.add(CounterType.getType(s)); - } - Map params = Maps.newHashMap(); - StringBuilder sb = new StringBuilder(); - sb.append(Localizer.getInstance().getMessage("lblSelectCounterTypeAddTo")); - counterType = placer.getController().chooseCounterType(choices, sa, sb.toString(), params); + counterType = chooseTypeFromList(sa, sa.getParam("CounterType"), null, + placer.getController()); } catch (Exception e) { System.out.println("Counter type doesn't match, nor does an SVar exist with the type name."); return; @@ -595,6 +580,27 @@ public class CountersPutEffect extends SpellAbilityEffect { } } + protected CounterType chooseTypeFromList(SpellAbility sa, String list, GameEntity obj, PlayerController pc) { + List choices = Lists.newArrayList(); + for (String s : list.split(",")) { + if (!s.equals("") && (!sa.hasParam("UniqueType") || obj.getCounters(CounterType.getType(s)) == 0)) { + choices.add(CounterType.getType(s)); + } + } + if (sa.hasParam("RandomType")) { + return Aggregates.random(choices); + } + Map params = Maps.newHashMap(); + params.put("Target", obj); + StringBuilder sb = new StringBuilder(); + if (obj != null) { + sb.append(Localizer.getInstance().getMessage("lblSelectCounterTypeAddTo")).append(" ").append(obj); + } else { + sb.append(Localizer.getInstance().getMessage("lblSelectCounterType")); + } + return pc.chooseCounterType(choices, sa, sb.toString(), params); + } + protected String logOutput(Map randomMap, Card card) { StringBuilder randomLog = new StringBuilder(); randomLog.append(card.getName()).append(" randomly distributed ");