mirror of
https://github.com/Card-Forge/forge.git
synced 2025-11-17 19:28:01 +00:00
move counters no longer uses gui
This commit is contained in:
@@ -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<Card> 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<CounterType, Integer> tgtCounters = source.getCounters();
|
||||
CounterType chosenType = null;
|
||||
int chosenAmount;
|
||||
if (sa.getActivatingPlayer().isHuman()) {
|
||||
final ArrayList<CounterType> typeChoices = new ArrayList<CounterType>();
|
||||
// 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<Integer> choices = new ArrayList<Integer>();
|
||||
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<CounterType> typeChoices = new ArrayList<CounterType>();
|
||||
// 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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -179,4 +179,5 @@ public abstract class PlayerController {
|
||||
|
||||
public abstract PaperCard chooseSinglePaperCard(SpellAbility sa, String message, Predicate<PaperCard> cpp, String name);
|
||||
public abstract List<String> chooseColors(String message, SpellAbility sa, int min, int max, List<String> options);
|
||||
public abstract CounterType chooseCounterType(Collection<CounterType> options, SpellAbility sa, String prompt);
|
||||
}
|
||||
|
||||
@@ -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<String> chooseColors(String message, SpellAbility sa, int min, int max, List<String> options) {
|
||||
return ComputerUtilCard.chooseColor(sa, min, max, options);
|
||||
}
|
||||
|
||||
@Override
|
||||
public CounterType chooseCounterType(Collection<CounterType> 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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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<CounterType> options, SpellAbility sa, String prompt) {
|
||||
if( options.size() <= 1)
|
||||
return Iterables.getFirst(options, null);
|
||||
return GuiChoose.one(prompt, options);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -454,4 +454,9 @@ public class PlayerControllerForTests extends PlayerController {
|
||||
public List<String> chooseColors(String message, SpellAbility sa, int min, int max, List<String> options) {
|
||||
throw new UnsupportedOperationException("No idea how a test player controller would choose colors");
|
||||
}
|
||||
|
||||
@Override
|
||||
public CounterType chooseCounterType(Collection<CounterType> options, SpellAbility sa, String prompt) {
|
||||
return Iterables.getFirst(options, CounterType.P1P1);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user