Search in sources :

Example 26 with Choice

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

the class CreepingRenaissanceEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    if (controller == null) {
        return false;
    }
    Choice typeChoice = new ChoiceCardType(true, Arrays.stream(CardType.values()).filter(CardType::isPermanentType).collect(Collectors.toList()));
    typeChoice.setMessage("Choose a permanent type");
    if (!controller.choose(Outcome.ReturnToHand, typeChoice, game)) {
        return false;
    }
    String typeName = typeChoice.getChoice();
    CardType chosenType = CardType.fromString(typeChoice.getChoice());
    if (chosenType == null) {
        return false;
    }
    FilterCard filter = new FilterCard(chosenType.toString().toLowerCase(Locale.ENGLISH) + " card");
    filter.add(chosenType.getPredicate());
    return controller.moveCards(controller.getGraveyard().getCards(filter, source.getSourceId(), controller.getId(), game), Zone.HAND, source, game);
}
Also used : FilterCard(mage.filter.FilterCard) Player(mage.players.Player) Choice(mage.choices.Choice) ChoiceCardType(mage.choices.ChoiceCardType) CardType(mage.constants.CardType) ChoiceCardType(mage.choices.ChoiceCardType)

Example 27 with Choice

use of mage.choices.Choice 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 28 with Choice

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

the class KindredDominanceEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    Choice typeChoice = new ChoiceCreatureType(game.getObject(source.getSourceId()));
    if (controller != null && controller.choose(outcome, typeChoice, game)) {
        game.informPlayers(controller.getLogName() + " has chosen " + typeChoice.getChoice());
        FilterCreaturePermanent filter = new FilterCreaturePermanent("All creatures not of the chosen type");
        filter.add(Predicates.not(SubType.byDescription(typeChoice.getChoice()).getPredicate()));
        return new DestroyAllEffect(filter).apply(game, source);
    }
    return false;
}
Also used : Player(mage.players.Player) Choice(mage.choices.Choice) FilterCreaturePermanent(mage.filter.common.FilterCreaturePermanent) ChoiceCreatureType(mage.choices.ChoiceCreatureType) DestroyAllEffect(mage.abilities.effects.common.DestroyAllEffect)

Example 29 with Choice

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

the class ChangeCreatureTypeTargetEffect method init.

@Override
public void init(Ability source, Game game) {
    Player controller = game.getPlayer(source.getControllerId());
    if (controller == null) {
        return;
    }
    if (fromSubType == null) {
        Choice typeChoice = new ChoiceCreatureType(game.getObject(source.getSourceId()));
        typeChoice.setMessage("Choose creature type to change to Vampire");
        if (!controller.choose(outcome, typeChoice, game)) {
            discard();
            return;
        }
        fromSubType = SubType.byDescription(typeChoice.getChoice());
        if (!game.isSimulation()) {
            game.informPlayers(controller.getLogName() + " has chosen the creature type: " + fromSubType.toString());
        }
    }
    // To change body of generated methods, choose Tools | Templates.
    super.init(source, game);
}
Also used : Player(mage.players.Player) Choice(mage.choices.Choice) ChoiceCreatureType(mage.choices.ChoiceCreatureType)

Example 30 with Choice

use of mage.choices.Choice 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)

Aggregations

Choice (mage.choices.Choice)117 Player (mage.players.Player)114 ChoiceImpl (mage.choices.ChoiceImpl)67 Permanent (mage.game.permanent.Permanent)51 ChoiceCreatureType (mage.choices.ChoiceCreatureType)28 MageObject (mage.MageObject)27 Mana (mage.Mana)22 HashSet (java.util.HashSet)21 Card (mage.cards.Card)17 FilterCreaturePermanent (mage.filter.common.FilterCreaturePermanent)16 UUID (java.util.UUID)15 ContinuousEffect (mage.abilities.effects.ContinuousEffect)13 FilterPermanent (mage.filter.FilterPermanent)12 Ability (mage.abilities.Ability)10 ChoiceColor (mage.choices.ChoiceColor)10 Counter (mage.counters.Counter)10 TargetPermanent (mage.target.TargetPermanent)10 FilterCard (mage.filter.FilterCard)8 FixedTarget (mage.target.targetpointer.FixedTarget)8 CardType (mage.constants.CardType)7