diff --git a/forge-gui/src/main/java/forge/game/ability/effects/CountersMoveEffect.java b/forge-gui/src/main/java/forge/game/ability/effects/CountersMoveEffect.java index a739ed68a6f..242d83b2352 100644 --- a/forge-gui/src/main/java/forge/game/ability/effects/CountersMoveEffect.java +++ b/forge-gui/src/main/java/forge/game/ability/effects/CountersMoveEffect.java @@ -3,13 +3,12 @@ package forge.game.ability.effects; import java.util.ArrayList; import java.util.List; import java.util.Map; - import forge.game.ability.AbilityUtils; import forge.game.ability.SpellAbilityEffect; import forge.game.card.Card; import forge.game.card.CounterType; +import forge.game.player.PlayerController; import forge.game.spellability.SpellAbility; -import forge.gui.GuiChoose; public class CountersMoveEffect extends SpellAbilityEffect { @@ -51,9 +50,9 @@ public class CountersMoveEffect extends SpellAbilityEffect { public void resolve(SpellAbility sa) { final Card host = sa.getSourceCard(); final String counterName = sa.getParam("CounterType"); - int amount = 0; + int cntToMove = 0; if (!sa.getParam("CounterNum").equals("All")) { - amount = AbilityUtils.calculateAmount(host, sa.getParam("CounterNum"), sa); + cntToMove = AbilityUtils.calculateAmount(host, sa.getParam("CounterNum"), sa); } CounterType cType = null; @@ -72,7 +71,7 @@ public class CountersMoveEffect extends SpellAbilityEffect { source = srcCards.get(0); } if (sa.getParam("CounterNum").equals("All")) { - amount = source.getCounters(cType); + cntToMove = source.getCounters(cType); } List tgtCards = getDefinedCardsOrTargeted(sa); @@ -84,70 +83,42 @@ public class CountersMoveEffect extends SpellAbilityEffect { } if (!"Any".matches(counterName)) { if (dest.canReceiveCounters(cType) - && source.getCounters(cType) >= amount) { - dest.addCounter(cType, amount, true); - source.subtractCounter(cType, amount); + && source.getCounters(cType) >= cntToMove) { + dest.addCounter(cType, cntToMove, true); + source.subtractCounter(cType, cntToMove); } } else { if (dest.hasKeyword("CARDNAME can't have counters placed on it.")) { return; } - boolean check = false; + boolean canPlaceM1M1Counters = true; for (final Card c : dest.getController().getCreaturesInPlay()) {//Melira, Sylvok Outcast if (c.hasKeyword("Creatures you control can't have -1/-1 counters placed on them.")) { - check = true; + canPlaceM1M1Counters = false; } } - while (amount > 0 && source.hasCounters()) { + while (cntToMove > 0 && source.hasCounters()) { final Map tgtCounters = source.getCounters(); - CounterType chosenType = null; - int chosenAmount; - if (sa.getActivatingPlayer().isHuman()) { - final ArrayList typeChoices = new ArrayList(); - // get types of counters - for (CounterType key : tgtCounters.keySet()) { - if (tgtCounters.get(key) > 0 && !(key == CounterType.M1M1 && check)) { - typeChoices.add(key); - } - } - if (typeChoices.isEmpty()) { - return; - } - if (typeChoices.size() > 1) { - String prompt = "Select type counters to remove"; - chosenType = GuiChoose.one(prompt, typeChoices); - } else { - chosenType = typeChoices.get(0); - } - chosenAmount = tgtCounters.get(chosenType); - if (chosenAmount > amount) { - chosenAmount = amount; - } - // make list of amount choices - if (chosenAmount > 1) { - final List choices = new ArrayList(); - for (int i = 1; i <= chosenAmount; i++) { - choices.add(Integer.valueOf(i)); - } - String prompt = "Select the number of " + chosenType.getName() + " counters to remove"; - chosenAmount = GuiChoose.one(prompt, choices); - } - } else { - for (Object key : tgtCounters.keySet()) { - if (tgtCounters.get(key) > 0) { - chosenType = (CounterType) key; - break; - } - } - // subtract all of selected type - chosenAmount = tgtCounters.get(chosenType); - if (chosenAmount > amount) { - chosenAmount = amount; + + final ArrayList typeChoices = new ArrayList(); + // get types of counters + for (CounterType ct : tgtCounters.keySet()) { + if (ct != CounterType.M1M1 || canPlaceM1M1Counters) { + typeChoices.add(ct); } } + if (typeChoices.isEmpty()) { + return; + } + + PlayerController pc = sa.getActivatingPlayer().getController(); + CounterType chosenType = pc.chooseCounterType(typeChoices, sa, "Select type counters to remove"); + + String prompt = "Select the number of " + chosenType.getName() + " counters to remove"; + int chosenAmount = pc.chooseNumber(sa, prompt, 1, Math.min(tgtCounters.get(chosenType), cntToMove)); dest.addCounter(chosenType, chosenAmount, true); source.subtractCounter(chosenType, chosenAmount); - amount -= chosenAmount; + cntToMove -= chosenAmount; } } } diff --git a/forge-gui/src/main/java/forge/game/player/PlayerController.java b/forge-gui/src/main/java/forge/game/player/PlayerController.java index 95e6a4a4528..76164f06df0 100644 --- a/forge-gui/src/main/java/forge/game/player/PlayerController.java +++ b/forge-gui/src/main/java/forge/game/player/PlayerController.java @@ -179,4 +179,5 @@ public abstract class PlayerController { public abstract PaperCard chooseSinglePaperCard(SpellAbility sa, String message, Predicate cpp, String name); public abstract List chooseColors(String message, SpellAbility sa, int min, int max, List options); + public abstract CounterType chooseCounterType(Collection options, SpellAbility sa, String prompt); } diff --git a/forge-gui/src/main/java/forge/game/player/PlayerControllerAi.java b/forge-gui/src/main/java/forge/game/player/PlayerControllerAi.java index b84e6de651a..7787225787c 100644 --- a/forge-gui/src/main/java/forge/game/player/PlayerControllerAi.java +++ b/forge-gui/src/main/java/forge/game/player/PlayerControllerAi.java @@ -15,6 +15,7 @@ import org.apache.commons.lang3.tuple.Pair; import com.esotericsoftware.minlog.Log; import com.google.common.base.Predicate; import com.google.common.collect.ImmutableList; +import com.google.common.collect.Iterables; import com.google.common.collect.Lists; import forge.ai.AiBlockController; @@ -515,4 +516,10 @@ public class PlayerControllerAi extends PlayerController { public List chooseColors(String message, SpellAbility sa, int min, int max, List options) { return ComputerUtilCard.chooseColor(sa, min, max, options); } + + @Override + public CounterType chooseCounterType(Collection options, SpellAbility sa, String prompt) { + // may write a smarter AI if you need to (with calls to AI-clas for given API ability) + return Iterables.getFirst(options, null); + } } diff --git a/forge-gui/src/main/java/forge/game/player/PlayerControllerHuman.java b/forge-gui/src/main/java/forge/game/player/PlayerControllerHuman.java index bf4e04f1bcd..c9ac4f93a8c 100644 --- a/forge-gui/src/main/java/forge/game/player/PlayerControllerHuman.java +++ b/forge-gui/src/main/java/forge/game/player/PlayerControllerHuman.java @@ -370,9 +370,9 @@ public class PlayerControllerHuman extends PlayerController { @Override public int chooseNumber(SpellAbility sa, String title, int min, int max) { - final Integer[] choices = new Integer[max + 1]; - for (int i = min; i <= max; i++) { - choices[i] = Integer.valueOf(i); + final Integer[] choices = new Integer[max + 1 - min]; + for (int i = 0; i <= max - min; i++) { + choices[i] = Integer.valueOf(i + min); } return GuiChoose.one(title, choices).intValue(); } @@ -870,4 +870,11 @@ public class PlayerControllerHuman extends PlayerController { Collections.sort(cards); return GuiChoose.one(message, cards); } + + @Override + public CounterType chooseCounterType(Collection options, SpellAbility sa, String prompt) { + if( options.size() <= 1) + return Iterables.getFirst(options, null); + return GuiChoose.one(prompt, options); + } } diff --git a/forge-gui/src/main/java/forge/model/CardBlock.java b/forge-gui/src/main/java/forge/model/CardBlock.java index f19392928e7..1c603968295 100644 --- a/forge-gui/src/main/java/forge/model/CardBlock.java +++ b/forge-gui/src/main/java/forge/model/CardBlock.java @@ -31,7 +31,6 @@ import forge.Singletons; import forge.card.CardEdition; import forge.card.IUnOpenedProduct; import forge.card.UnOpenedProduct; -import forge.card.CardEdition.Collection; import forge.item.PaperCard; import forge.item.IPaperCard; import forge.util.TextUtil; diff --git a/forge-gui/src/test/java/forge/gamesimulationtests/util/PlayerControllerForTests.java b/forge-gui/src/test/java/forge/gamesimulationtests/util/PlayerControllerForTests.java index 2380d725cc5..de9f865696b 100644 --- a/forge-gui/src/test/java/forge/gamesimulationtests/util/PlayerControllerForTests.java +++ b/forge-gui/src/test/java/forge/gamesimulationtests/util/PlayerControllerForTests.java @@ -454,4 +454,9 @@ public class PlayerControllerForTests extends PlayerController { public List chooseColors(String message, SpellAbility sa, int min, int max, List options) { throw new UnsupportedOperationException("No idea how a test player controller would choose colors"); } + + @Override + public CounterType chooseCounterType(Collection options, SpellAbility sa, String prompt) { + return Iterables.getFirst(options, CounterType.P1P1); + } }