From 108fba8ab63124e94ff5fae8925d783be05fe1e4 Mon Sep 17 00:00:00 2001 From: Oleg Agafonov Date: Tue, 16 Apr 2019 10:52:48 +0400 Subject: [PATCH] Firemind Vessel - fixed AI game freeze, improved choose logic (#5023); --- .../src/mage/cards/f/FiremindVessel.java | 30 +++++++++++-------- .../main/java/mage/choices/ChoiceColor.java | 16 +++++----- 2 files changed, 26 insertions(+), 20 deletions(-) diff --git a/Mage.Sets/src/mage/cards/f/FiremindVessel.java b/Mage.Sets/src/mage/cards/f/FiremindVessel.java index 8d93ee5049..ca305fb40c 100644 --- a/Mage.Sets/src/mage/cards/f/FiremindVessel.java +++ b/Mage.Sets/src/mage/cards/f/FiremindVessel.java @@ -62,20 +62,24 @@ class FiremindVesselManaEffect extends ManaEffect { if (player == null) { return null; } - Mana mana = new Mana(); - ChoiceColor color1 = new ChoiceColor(); - ChoiceColor color2 = new ChoiceColor(); - while (true) { - player.choose(outcome, color1, game); - player.choose(outcome, color2, game); - if (color1.getColor().equals(color2.getColor())) { - player.chooseUse(outcome, "Please choose two different colors", source, game); - color1.clearChoice(); - color2.clearChoice(); - } else { - break; - } + + ChoiceColor color1 = new ChoiceColor(true, "Choose color 1"); + if (!player.choose(outcome, color1, game) || color1.getColor() == null) { + return null; } + + ChoiceColor color2 = new ChoiceColor(true, "Choose color 2"); + color2.removeColorFromChoices(color1.getChoice()); + if (!player.choose(outcome, color2, game) || color2.getColor() == null) { + return null; + } + + if (color1.getColor().equals(color2.getColor())) { + game.informPlayers("Player " + player.getName() + " is cheating with mana choices."); + return null; + } + + Mana mana = new Mana(); mana.add(color1.getMana(1)); mana.add(color2.getMana(1)); return mana; diff --git a/Mage/src/main/java/mage/choices/ChoiceColor.java b/Mage/src/main/java/mage/choices/ChoiceColor.java index 9847e9fd51..6673b4e804 100644 --- a/Mage/src/main/java/mage/choices/ChoiceColor.java +++ b/Mage/src/main/java/mage/choices/ChoiceColor.java @@ -1,4 +1,3 @@ - package mage.choices; import mage.MageObject; @@ -8,14 +7,13 @@ import mage.ObjectColor; import java.util.ArrayList; /** - * * @author BetaSteward_at_googlemail.com, JayDi85 */ public class ChoiceColor extends ChoiceImpl { - private static final ArrayList colorChoices = getBaseColors(); + private static final ArrayList colorChoices = getBaseColors(); - public static ArrayList getBaseColors(){ + public static ArrayList getBaseColors() { ArrayList arr = new ArrayList<>(); arr.add("Green"); arr.add("Blue"); @@ -33,15 +31,15 @@ public class ChoiceColor extends ChoiceImpl { this(required, "Choose color"); } - public ChoiceColor(boolean required, String chooseMessage){ + public ChoiceColor(boolean required, String chooseMessage) { this(required, chooseMessage, ""); } - public ChoiceColor(boolean required, String chooseMessage, MageObject source){ + public ChoiceColor(boolean required, String chooseMessage, MageObject source) { this(required, chooseMessage, source.getIdName()); } - public ChoiceColor(boolean required, String chooseMessage, String chooseSubMessage){ + public ChoiceColor(boolean required, String chooseMessage, String chooseSubMessage) { super(required); this.choices.addAll(colorChoices); @@ -59,6 +57,10 @@ public class ChoiceColor extends ChoiceImpl { return new ChoiceColor(this); } + public void removeColorFromChoices(String colorName) { + this.choices.remove(colorName); + } + public ObjectColor getColor() { if (choice == null) { return null;