use of mage.choices.ChoiceImpl in project mage by magefree.
the class OrcishLumberjackManaEffect method produceMana.
@Override
public Mana produceMana(Game game, Ability source) {
Mana mana = new Mana();
if (game == null) {
return mana;
}
Player player = game.getPlayer(source.getControllerId());
if (player != null) {
Choice manaChoice = new ChoiceImpl();
Set<String> choices = new LinkedHashSet<>();
choices.add("Red");
choices.add("Green");
manaChoice.setChoices(choices);
manaChoice.setMessage("Select color of mana to add");
for (int i = 0; i < 3; i++) {
if (!player.choose(Outcome.Benefit, manaChoice, game)) {
return mana;
}
switch(manaChoice.getChoice()) {
case "Green":
mana.increaseGreen();
break;
case "Red":
mana.increaseRed();
break;
}
}
}
return mana;
}
use of mage.choices.ChoiceImpl in project mage by magefree.
the class SithEvokerEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
if (controller != null) {
Choice choice = new ChoiceImpl(true);
choice.setMessage("Choose mode");
choice.setChoices(choices);
if (!controller.choose(outcome, choice, game)) {
return false;
}
Card sourceCard = game.getCard(source.getSourceId());
if (sourceCard != null) {
for (Object cost : source.getCosts()) {
if (cost instanceof SacrificeTargetCost) {
Permanent p = (Permanent) game.getLastKnownInformation(((SacrificeTargetCost) cost).getPermanents().get(0).getId(), Zone.BATTLEFIELD);
if (p != null) {
String chosen = choice.getChoice();
switch(chosen) {
case "Gain life equal to creature's power":
new GainLifeEffect(p.getPower().getValue()).apply(game, source);
break;
default:
// "Gain life equal to creature's toughness"
new GainLifeEffect(p.getToughness().getValue()).apply(game, source);
break;
}
return true;
}
}
}
}
}
return false;
}
use of mage.choices.ChoiceImpl in project mage by magefree.
the class Dungeon method selectDungeon.
public static Dungeon selectDungeon(UUID playerId, Game game) {
Player player = game.getPlayer(playerId);
Choice choice = new ChoiceImpl(true, ChoiceHintType.CARD_DUNGEON);
choice.setMessage("Choose a dungeon to venture into");
choice.setChoices(dungeonNames);
player.choose(Outcome.Neutral, choice, game);
if (choice.getChoice() != null) {
return createDungeon(choice.getChoice());
} else {
// on disconnect
return createDungeon("Tomb of Annihilation");
}
}
use of mage.choices.ChoiceImpl in project mage by magefree.
the class PlayerImpl method rollDieInner.
/**
* Roll single die. Support both die types: planar and numerical.
*
* @param outcome
* @param game
* @param source
* @param rollDieType
* @param sidesAmount
* @param chaosSidesAmount
* @param planarSidesAmount
* @param rollsAmount
* @return
*/
private Object rollDieInner(Outcome outcome, Game game, Ability source, RollDieType rollDieType, int sidesAmount, int chaosSidesAmount, int planarSidesAmount, int rollsAmount) {
if (rollsAmount == 1) {
return rollDieInnerWithReplacement(game, source, rollDieType, sidesAmount, chaosSidesAmount, planarSidesAmount);
}
Set<Object> choices = new HashSet<>();
for (int j = 0; j < rollsAmount; j++) {
choices.add(rollDieInnerWithReplacement(game, source, rollDieType, sidesAmount, chaosSidesAmount, planarSidesAmount));
}
if (choices.size() == 1) {
return choices.stream().findFirst().orElse(0);
}
// AI hint - use max/min values
if (this.isComputer()) {
if (rollDieType == RollDieType.NUMERICAL) {
// numerical
if (outcome.isGood()) {
return choices.stream().map(Integer.class::cast).max(Comparator.naturalOrder()).orElse(null);
} else {
return choices.stream().map(Integer.class::cast).min(Comparator.naturalOrder()).orElse(null);
}
} else {
// priority: chaos -> planar -> blank
return choices.stream().map(PlanarDieRollResult.class::cast).max(Comparator.comparingInt(PlanarDieRollResult::getAIPriority)).orElse(null);
}
}
Choice choice = new ChoiceImpl(true);
choice.setMessage("Choose which die roll result to keep (the rest will be ignored)");
choice.setChoices(choices.stream().sorted().map(Object::toString).collect(Collectors.toSet()));
this.choose(Outcome.Neutral, choice, game);
Object defaultChoice = choices.iterator().next();
return choices.stream().filter(o -> o.toString().equals(choice.getChoice())).findFirst().orElse(defaultChoice);
}
use of mage.choices.ChoiceImpl in project mage by magefree.
the class GabrielAngelfireGainAbilityEffect method init.
@Override
public void init(Ability source, Game game) {
super.init(source, game);
Player controller = game.getPlayer(source.getControllerId());
if (controller != null) {
Choice choice = new ChoiceImpl(true);
choice.setMessage("Choose one");
choice.setChoices(choices);
if (controller.choose(outcome, choice, game)) {
switch(choice.getChoice()) {
case "First strike":
ability = FirstStrikeAbility.getInstance();
break;
case "Trample":
ability = TrampleAbility.getInstance();
break;
case "Rampage 3":
ability = new RampageAbility(3);
break;
default:
ability = FlyingAbility.getInstance();
break;
}
} else {
discard();
}
}
}
Aggregations