Search in sources :

Example 36 with ChoiceImpl

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;
}
Also used : Player(mage.players.Player) Mana(mage.Mana) Choice(mage.choices.Choice) ChoiceImpl(mage.choices.ChoiceImpl)

Example 37 with ChoiceImpl

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;
}
Also used : Player(mage.players.Player) SacrificeTargetCost(mage.abilities.costs.common.SacrificeTargetCost) Choice(mage.choices.Choice) Permanent(mage.game.permanent.Permanent) TargetControlledCreaturePermanent(mage.target.common.TargetControlledCreaturePermanent) ChoiceImpl(mage.choices.ChoiceImpl) GainLifeEffect(mage.abilities.effects.common.GainLifeEffect) Card(mage.cards.Card)

Example 38 with ChoiceImpl

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");
    }
}
Also used : Player(mage.players.Player) Choice(mage.choices.Choice) ChoiceImpl(mage.choices.ChoiceImpl)

Example 39 with ChoiceImpl

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);
}
Also used : Choice(mage.choices.Choice) ChoiceImpl(mage.choices.ChoiceImpl) StackObject(mage.game.stack.StackObject) CommandObject(mage.game.command.CommandObject)

Example 40 with ChoiceImpl

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();
        }
    }
}
Also used : Player(mage.players.Player) RampageAbility(mage.abilities.keyword.RampageAbility) Choice(mage.choices.Choice) ChoiceImpl(mage.choices.ChoiceImpl)

Aggregations

ChoiceImpl (mage.choices.ChoiceImpl)84 Player (mage.players.Player)80 Choice (mage.choices.Choice)67 Permanent (mage.game.permanent.Permanent)39 HashSet (java.util.HashSet)23 MageObject (mage.MageObject)16 Mana (mage.Mana)14 Card (mage.cards.Card)13 Ability (mage.abilities.Ability)11 LinkedHashSet (java.util.LinkedHashSet)10 Counter (mage.counters.Counter)10 UUID (java.util.UUID)8 TargetPermanent (mage.target.TargetPermanent)8 SimpleActivatedAbility (mage.abilities.common.SimpleActivatedAbility)7 CardType (mage.constants.CardType)7 FlyingAbility (mage.abilities.keyword.FlyingAbility)6 TargetCreaturePermanent (mage.target.common.TargetCreaturePermanent)6 ContinuousEffect (mage.abilities.effects.ContinuousEffect)5 GainAbilitySourceEffect (mage.abilities.effects.common.continuous.GainAbilitySourceEffect)5 FilterPermanent (mage.filter.FilterPermanent)5