forked from External/mage
* Implemented chooseTargetAmount and new GUI dialog (distribute damage, distribute mana) * Added tests and AI support; * Test framework: added aliases support in TargetAmount dialogs; Co-authored-by: Oleg Agafonov <jaydi85@gmail.com>
72 lines
1.6 KiB
Java
72 lines
1.6 KiB
Java
|
|
package mage.choices;
|
|
|
|
import mage.abilities.Ability;
|
|
import mage.constants.Outcome;
|
|
import mage.game.Game;
|
|
import mage.players.Player;
|
|
|
|
import java.util.ArrayList;
|
|
import java.util.List;
|
|
import java.util.stream.Collectors;
|
|
|
|
/**
|
|
*
|
|
* @author BetaSteward_at_googlemail.com
|
|
*/
|
|
public class Choices extends ArrayList<Choice> {
|
|
|
|
protected Outcome outcome;
|
|
|
|
public Choices() {
|
|
}
|
|
|
|
public Choices(final Choices choices) {
|
|
this.outcome = choices.outcome;
|
|
for (Choice choice : choices) {
|
|
this.add(choice.copy());
|
|
}
|
|
}
|
|
|
|
public Choices copy() {
|
|
return new Choices(this);
|
|
}
|
|
|
|
public List<Choice> getUnchosen() {
|
|
return stream()
|
|
.filter(choice -> !choice.isChosen())
|
|
.collect(Collectors.toList());
|
|
}
|
|
|
|
public void clearChosen() {
|
|
for (Choice choice : this) {
|
|
choice.clearChoice();
|
|
}
|
|
}
|
|
|
|
public boolean isChosen() {
|
|
for (Choice choice : this) {
|
|
if (!choice.isChosen()) {
|
|
return false;
|
|
}
|
|
}
|
|
return true;
|
|
}
|
|
|
|
public boolean choose(Game game, Ability source) {
|
|
if (this.size() > 0) {
|
|
Player player = game.getPlayer(source.getControllerId());
|
|
if (player == null) {
|
|
return false;
|
|
}
|
|
while (!isChosen()) {
|
|
Choice choice = this.getUnchosen().get(0);
|
|
if (!player.choose(outcome, choice, game)) {
|
|
return false;
|
|
}
|
|
}
|
|
}
|
|
return true;
|
|
}
|
|
|
|
}
|