Search in sources :

Example 21 with ChoiceImpl

use of mage.choices.ChoiceImpl in project mage by magefree.

the class ClockspinningAddOrRemoveCounterEffect method selectCounterType.

private Counter selectCounterType(Game game, Ability source, Card card) {
    Player controller = game.getPlayer(source.getControllerId());
    if (controller != null && !card.getCounters(game).isEmpty()) {
        String counterName = null;
        if (card.getCounters(game).size() > 1) {
            Choice choice = new ChoiceImpl(true);
            Set<String> choices = new HashSet<>();
            for (Counter counter : card.getCounters(game).values()) {
                if (card.getCounters(game).getCount(counter.getName()) > 0) {
                    choices.add(counter.getName());
                }
            }
            choice.setChoices(choices);
            choice.setMessage("Choose a counter type to add to " + card.getName());
            if (controller.choose(Outcome.Neutral, choice, game)) {
                counterName = choice.getChoice();
            } else {
                return null;
            }
        } else {
            for (Counter counter : card.getCounters(game).values()) {
                if (counter.getCount() > 0) {
                    counterName = counter.getName();
                }
            }
        }
        return new Counter(counterName);
    }
    return null;
}
Also used : Player(mage.players.Player) Choice(mage.choices.Choice) Counter(mage.counters.Counter) ChoiceImpl(mage.choices.ChoiceImpl) HashSet(java.util.HashSet)

Example 22 with ChoiceImpl

use of mage.choices.ChoiceImpl in project mage by magefree.

the class GarthOneEyeEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    initMap();
    Player player = game.getPlayer(source.getControllerId());
    if (player == null) {
        return false;
    }
    Set<String> alreadyChosen = getAlreadyChosen(game, source);
    Set<String> choices = new HashSet<>(names);
    choices.removeAll(alreadyChosen);
    String chosen;
    switch(choices.size()) {
        case 0:
            return false;
        case 1:
            chosen = choices.stream().findAny().orElse(null);
            break;
        default:
            Choice choice = new ChoiceImpl(true, ChoiceHintType.CARD);
            choice.setChoices(choices);
            player.choose(outcome, choice, game);
            chosen = choice.getChoice();
    }
    alreadyChosen.add(chosen);
    Card card = cardMap.get(chosen);
    if (card == null || !player.chooseUse(outcome, "Cast " + card.getName() + '?', source, game)) {
        return false;
    }
    Card copiedCard = game.copyCard(card, source, source.getControllerId());
    copiedCard.setZone(Zone.OUTSIDE, game);
    game.getState().setValue("PlayFromNotOwnHandZone" + copiedCard.getId(), Boolean.TRUE);
    player.cast(player.chooseAbilityForCast(copiedCard, game, false), game, false, new ApprovingObject(source, game));
    game.getState().setValue("PlayFromNotOwnHandZone" + copiedCard.getId(), null);
    return true;
}
Also used : Player(mage.players.Player) Choice(mage.choices.Choice) ApprovingObject(mage.ApprovingObject) ChoiceImpl(mage.choices.ChoiceImpl) Card(mage.cards.Card)

Example 23 with ChoiceImpl

use of mage.choices.ChoiceImpl in project mage by magefree.

the class NestingGroundsEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    Permanent fromPermanent = game.getPermanent(source.getFirstTarget());
    Permanent toPermanent = game.getPermanent(source.getTargets().get(1).getFirstTarget());
    if (fromPermanent == null || toPermanent == null || controller == null) {
        return false;
    }
    Set<String> possibleChoices = new HashSet<>(fromPermanent.getCounters(game).keySet());
    if (possibleChoices.size() == 0) {
        return false;
    }
    Choice choice = new ChoiceImpl();
    choice.setChoices(possibleChoices);
    if (controller.choose(outcome, choice, game)) {
        String chosen = choice.getChoice();
        if (fromPermanent.getCounters(game).containsKey(chosen)) {
            CounterType counterType = CounterType.findByName(chosen);
            if (counterType != null) {
                Counter counter = counterType.createInstance();
                fromPermanent.removeCounters(counterType.getName(), 1, source, game);
                toPermanent.addCounters(counter, source.getControllerId(), source, game);
                return true;
            }
        }
    }
    return false;
}
Also used : Player(mage.players.Player) Choice(mage.choices.Choice) CounterType(mage.counters.CounterType) Counter(mage.counters.Counter) FilterPermanent(mage.filter.FilterPermanent) FilterControlledPermanent(mage.filter.common.FilterControlledPermanent) Permanent(mage.game.permanent.Permanent) TargetControlledPermanent(mage.target.common.TargetControlledPermanent) TargetPermanent(mage.target.TargetPermanent) ChoiceImpl(mage.choices.ChoiceImpl) HashSet(java.util.HashSet)

Example 24 with ChoiceImpl

use of mage.choices.ChoiceImpl in project mage by magefree.

the class WalkingSpongeEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    Permanent permanent = game.getPermanent(source.getSourceId());
    if (controller != null && permanent != null) {
        ChoiceImpl chooseAbility = new ChoiceImpl();
        chooseAbility.setMessage("Choose an ability to remove (default is flying)");
        Set<String> choice = new LinkedHashSet<>();
        choice.add("Flying");
        choice.add("First strike");
        choice.add("Trample");
        chooseAbility.setChoices(choice);
        // since the player can't pick "no ability", let's default to the first option
        Ability ability = FlyingAbility.getInstance();
        if (controller.choose(Outcome.UnboostCreature, chooseAbility, game)) {
            String chosenAbility = chooseAbility.getChoice();
            if (chosenAbility.equals("First strike")) {
                ability = FirstStrikeAbility.getInstance();
            } else if (chosenAbility.equals("Trample")) {
                ability = TrampleAbility.getInstance();
            }
        } else {
            return false;
        }
        game.informPlayers(controller.getLogName() + " has chosen " + ability.getRule());
        ContinuousEffect effect = new LoseAbilityTargetEffect(ability, Duration.EndOfTurn);
        game.addEffect(effect, source);
        return true;
    }
    return false;
}
Also used : LinkedHashSet(java.util.LinkedHashSet) FirstStrikeAbility(mage.abilities.keyword.FirstStrikeAbility) FlyingAbility(mage.abilities.keyword.FlyingAbility) SimpleActivatedAbility(mage.abilities.common.SimpleActivatedAbility) TrampleAbility(mage.abilities.keyword.TrampleAbility) Ability(mage.abilities.Ability) LoseAbilityTargetEffect(mage.abilities.effects.common.continuous.LoseAbilityTargetEffect) Player(mage.players.Player) Permanent(mage.game.permanent.Permanent) TargetCreaturePermanent(mage.target.common.TargetCreaturePermanent) ChoiceImpl(mage.choices.ChoiceImpl) ContinuousEffect(mage.abilities.effects.ContinuousEffect)

Example 25 with ChoiceImpl

use of mage.choices.ChoiceImpl in project mage by magefree.

the class FatespinnerSkipEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player player = game.getPlayer(getTargetPointer().getFirst(game, source));
    if (player != null) {
        Choice choice = new ChoiceImpl(true);
        choice.setMessage("Choose phase or step to skip");
        choice.setChoices(choices);
        if (!player.choose(outcome, choice, game)) {
            return false;
        }
        String chosenPhase = choice.getChoice();
        game.informPlayers(player.getLogName() + " has chosen to skip " + chosenPhase.toLowerCase(Locale.ENGLISH) + '.');
        game.addEffect(new FatespinnerSkipEffect(chosenPhase), source);
        return true;
    }
    return false;
}
Also used : Player(mage.players.Player) 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