Changed to stream, and removed prompt when there is only a single type

This commit is contained in:
Colin Redman 2018-08-04 16:34:30 -06:00
parent d6b8e1240c
commit 53f68197aa

View file

@ -18,7 +18,9 @@ import mage.players.Player;
import mage.target.TargetCard; import mage.target.TargetCard;
import mage.target.targetpointer.FixedTarget; import mage.target.targetpointer.FixedTarget;
import java.util.Arrays;
import java.util.EnumSet; import java.util.EnumSet;
import java.util.Optional;
import java.util.UUID; import java.util.UUID;
/** /**
@ -219,15 +221,21 @@ class ConsumeCardTypeCost extends CostImpl{
if (isPaid()){ if (isPaid()){
return true; return true;
} }
Choice choice = new CardTypeChoice(exileHandler.availableTypes(types)); CardType choiceType;
EnumSet<CardType> availableChoices = exileHandler.availableTypes(types);
if (availableChoices.size()==1){
// if there is only one possibility, don't need to prompt for a choice
choiceType = availableChoices.iterator().next();
}else {
Choice choice = new CardTypeChoice(availableChoices);
if (!game.getPlayer(controllerId).choose(Outcome.Neutral, choice, game)) { if (!game.getPlayer(controllerId).choose(Outcome.Neutral, choice, game)) {
return false; return false;
} }
CardType choiceType = null; Optional<CardType> optionalChoice = Arrays.stream(CardType.values()).filter(type -> type.toString().equals(choice.getChoice())).findAny();
for (CardType type:EnumSet.allOf(CardType.class)){ if (optionalChoice.isPresent()){
if (type.toString().equals(choice.getChoice())){ choiceType = optionalChoice.get();
choiceType = type; }else{
break; return false;
} }
} }
paid = exileHandler.useCardType(choiceType); paid = exileHandler.useCardType(choiceType);