Firemind Vessel - fixed AI game freeze, improved choose logic (#5023);

This commit is contained in:
Oleg Agafonov 2019-04-16 10:52:48 +04:00
parent 5418be51e5
commit 108fba8ab6
2 changed files with 26 additions and 20 deletions

View file

@ -62,20 +62,24 @@ class FiremindVesselManaEffect extends ManaEffect {
if (player == null) { if (player == null) {
return null; return null;
} }
Mana mana = new Mana();
ChoiceColor color1 = new ChoiceColor(); ChoiceColor color1 = new ChoiceColor(true, "Choose color 1");
ChoiceColor color2 = new ChoiceColor(); if (!player.choose(outcome, color1, game) || color1.getColor() == null) {
while (true) { return null;
player.choose(outcome, color1, game); }
player.choose(outcome, color2, game);
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())) { if (color1.getColor().equals(color2.getColor())) {
player.chooseUse(outcome, "Please choose two different colors", source, game); game.informPlayers("Player " + player.getName() + " is cheating with mana choices.");
color1.clearChoice(); return null;
color2.clearChoice();
} else {
break;
}
} }
Mana mana = new Mana();
mana.add(color1.getMana(1)); mana.add(color1.getMana(1));
mana.add(color2.getMana(1)); mana.add(color2.getMana(1));
return mana; return mana;

View file

@ -1,4 +1,3 @@
package mage.choices; package mage.choices;
import mage.MageObject; import mage.MageObject;
@ -8,14 +7,13 @@ import mage.ObjectColor;
import java.util.ArrayList; import java.util.ArrayList;
/** /**
*
* @author BetaSteward_at_googlemail.com, JayDi85 * @author BetaSteward_at_googlemail.com, JayDi85
*/ */
public class ChoiceColor extends ChoiceImpl { public class ChoiceColor extends ChoiceImpl {
private static final ArrayList<String> colorChoices = getBaseColors(); private static final ArrayList<String> colorChoices = getBaseColors();
public static ArrayList<String> getBaseColors(){ public static ArrayList<String> getBaseColors() {
ArrayList<String> arr = new ArrayList<>(); ArrayList<String> arr = new ArrayList<>();
arr.add("Green"); arr.add("Green");
arr.add("Blue"); arr.add("Blue");
@ -33,15 +31,15 @@ public class ChoiceColor extends ChoiceImpl {
this(required, "Choose color"); this(required, "Choose color");
} }
public ChoiceColor(boolean required, String chooseMessage){ public ChoiceColor(boolean required, String chooseMessage) {
this(required, 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()); this(required, chooseMessage, source.getIdName());
} }
public ChoiceColor(boolean required, String chooseMessage, String chooseSubMessage){ public ChoiceColor(boolean required, String chooseMessage, String chooseSubMessage) {
super(required); super(required);
this.choices.addAll(colorChoices); this.choices.addAll(colorChoices);
@ -59,6 +57,10 @@ public class ChoiceColor extends ChoiceImpl {
return new ChoiceColor(this); return new ChoiceColor(this);
} }
public void removeColorFromChoices(String colorName) {
this.choices.remove(colorName);
}
public ObjectColor getColor() { public ObjectColor getColor() {
if (choice == null) { if (choice == null) {
return null; return null;