mirror of
https://github.com/Card-Forge/forge.git
synced 2025-11-18 11:48:02 +00:00
choose color now uses player controller to decide.
removed calls to gui from ability executing classes adjust visibility of CardFace methods
This commit is contained in:
@@ -23,6 +23,7 @@ import forge.card.MagicColor;
|
||||
import forge.deck.CardPool;
|
||||
import forge.deck.Deck;
|
||||
import forge.deck.DeckSection;
|
||||
import forge.game.Game;
|
||||
import forge.game.card.Card;
|
||||
import forge.game.card.CardFactoryUtil;
|
||||
import forge.game.card.CardLists;
|
||||
@@ -31,6 +32,7 @@ import forge.game.card.CardUtil;
|
||||
import forge.game.combat.Combat;
|
||||
import forge.game.player.Player;
|
||||
import forge.game.spellability.SpellAbility;
|
||||
import forge.game.zone.ZoneType;
|
||||
import forge.item.PaperCard;
|
||||
import forge.util.Aggregates;
|
||||
|
||||
@@ -826,5 +828,64 @@ public class ComputerUtilCard {
|
||||
return true;
|
||||
}
|
||||
};
|
||||
public static List<String> chooseColor(SpellAbility sa, int min, int max, List<String> colorChoices) {
|
||||
List<String> chosen = new ArrayList<String>();
|
||||
Player ai = sa.getActivatingPlayer();
|
||||
final Game game = ai.getGame();
|
||||
Player opp = ai.getOpponent();
|
||||
if (sa.hasParam("AILogic")) {
|
||||
final String logic = sa.getParam("AILogic");
|
||||
if (logic.equals("MostProminentInHumanDeck")) {
|
||||
chosen.add(ComputerUtilCard.getMostProminentColor(CardLists.filterControlledBy(game.getCardsInGame(), opp), colorChoices));
|
||||
} else if (logic.equals("MostProminentInComputerDeck")) {
|
||||
chosen.add(ComputerUtilCard.getMostProminentColor(CardLists.filterControlledBy(game.getCardsInGame(), ai), colorChoices));
|
||||
} else if (logic.equals("MostProminentDualInComputerDeck")) {
|
||||
List<String> prominence = ComputerUtilCard.getColorByProminence(CardLists.filterControlledBy(game.getCardsInGame(), ai));
|
||||
chosen.add(prominence.get(0));
|
||||
chosen.add(prominence.get(1));
|
||||
}
|
||||
else if (logic.equals("MostProminentInGame")) {
|
||||
chosen.add(ComputerUtilCard.getMostProminentColor(game.getCardsInGame(), colorChoices));
|
||||
}
|
||||
else if (logic.equals("MostProminentHumanCreatures")) {
|
||||
List<Card> list = opp.getCreaturesInPlay();
|
||||
if (list.isEmpty()) {
|
||||
list = CardLists.filter(CardLists.filterControlledBy(game.getCardsInGame(), opp), CardPredicates.Presets.CREATURES);
|
||||
}
|
||||
chosen.add(ComputerUtilCard.getMostProminentColor(list, colorChoices));
|
||||
}
|
||||
else if (logic.equals("MostProminentComputerControls")) {
|
||||
chosen.add(ComputerUtilCard.getMostProminentColor(ai.getCardsIn(ZoneType.Battlefield), colorChoices));
|
||||
}
|
||||
else if (logic.equals("MostProminentHumanControls")) {
|
||||
chosen.add(ComputerUtilCard.getMostProminentColor(ai.getOpponent().getCardsIn(ZoneType.Battlefield), colorChoices));
|
||||
}
|
||||
else if (logic.equals("MostProminentPermanent")) {
|
||||
final List<Card> list = game.getCardsIn(ZoneType.Battlefield);
|
||||
chosen.add(ComputerUtilCard.getMostProminentColor(list, colorChoices));
|
||||
}
|
||||
else if (logic.equals("MostProminentAttackers") && game.getPhaseHandler().inCombat()) {
|
||||
chosen.add(ComputerUtilCard.getMostProminentColor(game.getCombat().getAttackers(), colorChoices));
|
||||
}
|
||||
else if (logic.equals("MostProminentKeywordInComputerDeck")) {
|
||||
List<Card> list = ai.getAllCards();
|
||||
int m1 = 0;
|
||||
String chosenColor = MagicColor.Constant.WHITE;
|
||||
|
||||
for (final String c : MagicColor.Constant.ONLY_COLORS) {
|
||||
final int cmp = CardLists.filter(list, CardPredicates.containsKeyword(c)).size();
|
||||
if (cmp > m1) {
|
||||
m1 = cmp;
|
||||
chosenColor = c;
|
||||
}
|
||||
}
|
||||
chosen.add(chosenColor);
|
||||
}
|
||||
}
|
||||
if (chosen.size() == 0) {
|
||||
chosen.add(MagicColor.Constant.GREEN);
|
||||
}
|
||||
return chosen;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -8,7 +8,6 @@ import com.google.common.base.Predicates;
|
||||
import com.google.common.collect.Iterables;
|
||||
import com.google.common.collect.Lists;
|
||||
|
||||
import forge.Singletons;
|
||||
import forge.ai.ability.ChangeZoneAi;
|
||||
import forge.card.CardCharacteristicName;
|
||||
import forge.game.Game;
|
||||
@@ -31,7 +30,6 @@ import forge.game.zone.Zone;
|
||||
import forge.game.zone.ZoneType;
|
||||
import forge.gui.GuiChoose;
|
||||
import forge.gui.GuiDialog;
|
||||
import forge.gui.input.InputSelectCardsFromList;
|
||||
import forge.util.Aggregates;
|
||||
import forge.util.Lang;
|
||||
|
||||
@@ -759,19 +757,10 @@ public class ChangeZoneEffect extends SpellAbilityEffect {
|
||||
} else {
|
||||
boolean mustChoose = sa.hasParam("Mandatory");
|
||||
// card has to be on battlefield or in own hand
|
||||
boolean canUseInputToSelectCard = origin.size() == 1 && ( origin.get(0) == ZoneType.Battlefield || origin.get(0) == ZoneType.Hand && player == decider);
|
||||
if (mustChoose && fetchList.size() == 1) {
|
||||
c = fetchList.get(0);
|
||||
} else if( canUseInputToSelectCard ) {
|
||||
InputSelectCardsFromList inp = new InputSelectCardsFromList(1, 1, fetchList);
|
||||
inp.setCancelAllowed(!mustChoose);
|
||||
inp.setMessage(selectPrompt);
|
||||
Singletons.getControl().getInputQueue().setInputAndWait(inp);
|
||||
c = inp.hasCancelled() ? null : inp.getSelected().get(0);
|
||||
}
|
||||
else {
|
||||
List<Card> chosen = GuiChoose.getChoices(selectPrompt, mustChoose ? 1 : 0, 1, fetchList);
|
||||
c = chosen.isEmpty() ? null : chosen.get(0);
|
||||
} else {
|
||||
c = decider.getController().chooseSingleCardForEffect(fetchList, sa, selectPrompt, !mustChoose);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -808,7 +797,7 @@ public class ChangeZoneEffect extends SpellAbilityEffect {
|
||||
if (!list.isEmpty()) {
|
||||
Card attachedTo = null;
|
||||
if (list.size() > 1) {
|
||||
attachedTo = GuiChoose.one(c + " - Select a card to attach to.", list);
|
||||
attachedTo = decider.getController().chooseSingleCardForEffect(list, sa, c + " - Select a card to attach to.");
|
||||
} else {
|
||||
attachedTo = list.get(0);
|
||||
}
|
||||
|
||||
@@ -4,18 +4,13 @@ import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import forge.ai.ComputerUtilCard;
|
||||
import forge.card.MagicColor;
|
||||
import forge.game.Game;
|
||||
import forge.game.ability.SpellAbilityEffect;
|
||||
import forge.game.card.Card;
|
||||
import forge.game.card.CardLists;
|
||||
import forge.game.card.CardPredicates;
|
||||
import forge.game.player.Player;
|
||||
import forge.game.spellability.SpellAbility;
|
||||
import forge.game.spellability.TargetRestrictions;
|
||||
import forge.game.zone.ZoneType;
|
||||
import forge.gui.GuiChoose;
|
||||
import forge.util.Lang;
|
||||
|
||||
public class ChooseColorEffect extends SpellAbilityEffect {
|
||||
|
||||
@@ -51,88 +46,17 @@ public class ChooseColorEffect extends SpellAbilityEffect {
|
||||
|
||||
for (final Player p : tgtPlayers) {
|
||||
if ((tgt == null) || p.canBeTargetedBy(sa)) {
|
||||
if (p.isHuman()) {
|
||||
if (sa.hasParam("OrColors")) {
|
||||
final List<String> o = GuiChoose.getChoices("Choose a color or colors", 1, colorChoices.size(), colorChoices);
|
||||
card.setChosenColor(new ArrayList<String>(o));
|
||||
} else if (sa.hasParam("TwoColors")) {
|
||||
final List<String> o = GuiChoose.getChoices("Choose two colors", 2, 2, colorChoices);
|
||||
card.setChosenColor(new ArrayList<String>(o));
|
||||
} else {
|
||||
final Object o = GuiChoose.one("Choose a color", colorChoices);
|
||||
if (null == o) {
|
||||
return;
|
||||
}
|
||||
final String choice = (String) o;
|
||||
final ArrayList<String> tmpColors = new ArrayList<String>();
|
||||
tmpColors.add(choice);
|
||||
card.setChosenColor(tmpColors);
|
||||
}
|
||||
} else {
|
||||
List<String> chosen = new ArrayList<String>();
|
||||
Player ai = sa.getActivatingPlayer();
|
||||
final Game game = ai.getGame();
|
||||
Player opp = ai.getOpponent();
|
||||
if (sa.hasParam("AILogic")) {
|
||||
final String logic = sa.getParam("AILogic");
|
||||
if (logic.equals("MostProminentInHumanDeck")) {
|
||||
chosen.add(ComputerUtilCard.getMostProminentColor(CardLists.filterControlledBy(game.getCardsInGame(),
|
||||
opp), colorChoices));
|
||||
} else if (logic.equals("MostProminentInComputerDeck")) {
|
||||
chosen.add(ComputerUtilCard.getMostProminentColor(CardLists.filterControlledBy(game.getCardsInGame(),
|
||||
ai), colorChoices));
|
||||
} else if (logic.equals("MostProminentDualInComputerDeck")) {
|
||||
List<String> prominence = ComputerUtilCard.getColorByProminence(CardLists.filterControlledBy(game.getCardsInGame(), ai));
|
||||
chosen.add(prominence.get(0));
|
||||
chosen.add(prominence.get(1));
|
||||
}
|
||||
else if (logic.equals("MostProminentInGame")) {
|
||||
chosen.add(ComputerUtilCard.getMostProminentColor(game.getCardsInGame(), colorChoices));
|
||||
}
|
||||
else if (logic.equals("MostProminentHumanCreatures")) {
|
||||
List<Card> list = opp.getCreaturesInPlay();
|
||||
if (list.isEmpty()) {
|
||||
list = CardLists.filter(CardLists.filterControlledBy(game.getCardsInGame(), opp), CardPredicates.Presets.CREATURES);
|
||||
}
|
||||
chosen.add(ComputerUtilCard.getMostProminentColor(list, colorChoices));
|
||||
}
|
||||
else if (logic.equals("MostProminentComputerControls")) {
|
||||
chosen.add(ComputerUtilCard.getMostProminentColor(ai.getCardsIn(ZoneType.Battlefield), colorChoices));
|
||||
}
|
||||
else if (logic.equals("MostProminentHumanControls")) {
|
||||
chosen.add(ComputerUtilCard.getMostProminentColor(ai.getOpponent().getCardsIn(ZoneType.Battlefield), colorChoices));
|
||||
}
|
||||
else if (logic.equals("MostProminentPermanent")) {
|
||||
final List<Card> list = game.getCardsIn(ZoneType.Battlefield);
|
||||
chosen.add(ComputerUtilCard.getMostProminentColor(list, colorChoices));
|
||||
}
|
||||
else if (logic.equals("MostProminentAttackers") && game.getPhaseHandler().inCombat()) {
|
||||
chosen.add(ComputerUtilCard.getMostProminentColor(game.getCombat().getAttackers(), colorChoices));
|
||||
}
|
||||
else if (logic.equals("MostProminentKeywordInComputerDeck")) {
|
||||
List<Card> list = ai.getAllCards();
|
||||
int max = 0;
|
||||
String chosenColor = MagicColor.Constant.WHITE;
|
||||
|
||||
for (final String c : MagicColor.Constant.ONLY_COLORS) {
|
||||
final int cmp = CardLists.filter(list, CardPredicates.containsKeyword(c)).size();
|
||||
if (cmp > max) {
|
||||
max = cmp;
|
||||
chosenColor = c;
|
||||
}
|
||||
}
|
||||
chosen.add(chosenColor);
|
||||
}
|
||||
}
|
||||
if (chosen.size() == 0) {
|
||||
chosen.add(MagicColor.Constant.GREEN);
|
||||
}
|
||||
GuiChoose.one("Computer picked: ", chosen);
|
||||
final ArrayList<String> colorTemp = new ArrayList<String>();
|
||||
colorTemp.addAll(chosen);
|
||||
card.setChosenColor(colorTemp);
|
||||
}
|
||||
List<String> chosenColors;
|
||||
int cntMin = sa.hasParam("TwoColors") ? 2 : 1;
|
||||
int cntMax = sa.hasParam("TwoColors") ? 2 : sa.hasParam("OrColors") ? colorChoices.size() : 1;
|
||||
String prompt = cntMax == 1 ? "Choose a color" : cntMin == 2 ? "Choose two colors" : "Choose a color or colors";
|
||||
chosenColors = p.getController().chooseColors(prompt, sa, 1, colorChoices.size(), colorChoices);
|
||||
if(chosenColors.isEmpty())
|
||||
return;
|
||||
card.setChosenColor(chosenColors);
|
||||
p.getGame().getAction().nofityOfValue(sa, card, p.getName() + " picked " + Lang.joinHomogenous(chosenColors), p);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -178,4 +178,5 @@ public abstract class PlayerController {
|
||||
public abstract String chooseHybridMana(String s);
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
@@ -510,4 +510,9 @@ public class PlayerControllerAi extends PlayerController {
|
||||
Predicate<PaperCard> cpp, String name) {
|
||||
throw new UnsupportedOperationException("Should not be called for AI"); // or implement it if you know how
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> chooseColors(String message, SpellAbility sa, int min, int max, List<String> options) {
|
||||
return ComputerUtilCard.chooseColor(sa, min, max, options);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -742,7 +742,7 @@ public class PlayerControllerHuman extends PlayerController {
|
||||
String counterChoiceTitle = "Choose a counter type on " + cardWithCounter;
|
||||
final CounterType chosen = GuiChoose.one(counterChoiceTitle, cardWithCounter.getCounters().keySet());
|
||||
|
||||
String putOrRemoveTitle = "Do what with counter " + chosen.getName() + "counter ";
|
||||
String putOrRemoveTitle = "What to do with that '" + chosen.getName() + "' counter ";
|
||||
final String putString = "Put another " + chosen.getName() + " counter on " + cardWithCounter;
|
||||
final String removeString = "Remove a " + chosen.getName() + " counter from " + cardWithCounter;
|
||||
final String addOrRemove = GuiChoose.one(putOrRemoveTitle, new String[]{putString,removeString});
|
||||
@@ -827,6 +827,11 @@ public class PlayerControllerHuman extends PlayerController {
|
||||
return chosen;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> chooseColors(String message, SpellAbility sa, int min, int max, List<String> options) {
|
||||
return GuiChoose.getChoices(message, min, max, options);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String chooseSingleColor(ImmutableList<String> names) {
|
||||
return GuiChoose.one("Choose a color:", names);
|
||||
|
||||
@@ -449,4 +449,9 @@ public class PlayerControllerForTests extends PlayerController {
|
||||
public PaperCard chooseSinglePaperCard( SpellAbility sa, String message, Predicate<PaperCard> cpp, String name ) {
|
||||
throw new IllegalStateException( "Erring on the side of caution here..." );
|
||||
}
|
||||
|
||||
@Override
|
||||
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");
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user