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) {
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);
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())) {
player.chooseUse(outcome, "Please choose two different colors", source, game);
color1.clearChoice();
color2.clearChoice();
} else {
break;
}
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;

View file

@ -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<String> colorChoices = getBaseColors();
public static ArrayList<String> getBaseColors(){
public static ArrayList<String> getBaseColors() {
ArrayList<String> 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;