Search in sources :

Example 71 with ChoiceImpl

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

the class StorageMatrixRestrictionEffect method applies.

@Override
public boolean applies(Permanent permanent, Ability source, Game game) {
    if (game.getStep().getType() == PhaseStep.UNTAP) {
        if (game.getTurnNum() != turn) {
            turn = game.getTurnNum();
            applies = false;
            Permanent storageMatrix = game.getPermanent(source.getSourceId());
            if (storageMatrix != null && !storageMatrix.isTapped()) {
                Choice choiceImpl = new ChoiceImpl(true);
                choiceImpl.setMessage("Untap which kind of permanent?");
                choiceImpl.setChoices(choice);
                Player player = game.getPlayer(game.getActivePlayerId());
                if (player != null && player.choose(outcome, choiceImpl, game)) {
                    String choosenType = choiceImpl.getChoice();
                    if (choosenType != null) {
                        game.informPlayers(storageMatrix.getLogName() + ": " + player.getLogName() + " chose to untap " + choosenType);
                        if (choosenType.equals(CardType.ARTIFACT.toString())) {
                            type = CardType.ARTIFACT;
                        } else if (choosenType.equals(CardType.LAND.toString())) {
                            type = CardType.LAND;
                        } else {
                            type = CardType.CREATURE;
                        }
                        applies = true;
                    }
                }
            }
        }
        if (applies) {
            return !permanent.getCardType(game).contains(type);
        }
    }
    return false;
}
Also used : Player(mage.players.Player) Choice(mage.choices.Choice) Permanent(mage.game.permanent.Permanent) ChoiceImpl(mage.choices.ChoiceImpl)

Example 72 with ChoiceImpl

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

the class StingingStudyEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player player = game.getPlayer(source.getControllerId());
    if (player == null) {
        return false;
    }
    Set<Integer> manaValues = new HashSet<>();
    for (Card commander : game.getCommanderCardsFromAnyZones(player, CommanderCardType.ANY, Zone.BATTLEFIELD, Zone.COMMAND)) {
        manaValues.add(commander.getManaValue());
    }
    int chosenValue;
    if (manaValues.size() > 1) {
        Choice choice = new ChoiceImpl(true);
        choice.setChoices(manaValues.stream().map(x -> "" + x).collect(Collectors.toSet()));
        player.choose(outcome, choice, game);
        chosenValue = Integer.parseInt(choice.getChoice());
    } else {
        chosenValue = manaValues.stream().findFirst().orElse(0);
    }
    if (chosenValue == 0) {
        return false;
    }
    player.drawCards(chosenValue, source, game);
    player.loseLife(chosenValue, game, source, false);
    return true;
}
Also used : Player(mage.players.Player) Choice(mage.choices.Choice) ChoiceImpl(mage.choices.ChoiceImpl) HashSet(java.util.HashSet) Card(mage.cards.Card)

Example 73 with ChoiceImpl

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

the class TeferisRealmEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player player = game.getPlayer(getTargetPointer().getFirst(game, source));
    Player controller = game.getPlayer(source.getControllerId());
    if (player != null && controller != null) {
        Choice choiceImpl = new ChoiceImpl(true);
        choiceImpl.setMessage("Phase out which kind of permanents?");
        choiceImpl.setChoices(choices);
        if (!player.choose(outcome, choiceImpl, game)) {
            return false;
        }
        String choosenType = choiceImpl.getChoice();
        FilterPermanent filter = new FilterPermanent();
        filter.add(TokenPredicate.FALSE);
        switch(choosenType) {
            case ARTIFACT:
                filter.add(CardType.ARTIFACT.getPredicate());
                break;
            case CREATURE:
                filter.add(CardType.CREATURE.getPredicate());
                break;
            case LAND:
                filter.add(CardType.LAND.getPredicate());
                break;
            case NON_AURA_ENCHANTMENT:
                filter.add(CardType.ENCHANTMENT.getPredicate());
                filter.add(Predicates.not(SubType.AURA.getPredicate()));
                break;
            default:
                return false;
        }
        game.informPlayers(player.getLogName() + " chooses " + choosenType + "s to phase out");
        List<UUID> permIds = new ArrayList<>();
        for (Permanent permanent : game.getBattlefield().getActivePermanents(filter, controller.getId(), game)) {
            permIds.add(permanent.getId());
        }
        return new PhaseOutAllEffect(permIds).apply(game, source);
    }
    return false;
}
Also used : Player(mage.players.Player) Choice(mage.choices.Choice) FilterPermanent(mage.filter.FilterPermanent) FilterPermanent(mage.filter.FilterPermanent) Permanent(mage.game.permanent.Permanent) PhaseOutAllEffect(mage.abilities.effects.common.PhaseOutAllEffect) ArrayList(java.util.ArrayList) ChoiceImpl(mage.choices.ChoiceImpl) UUID(java.util.UUID)

Example 74 with ChoiceImpl

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

the class WhenFluffyBunniesAttackEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    Permanent permanent = game.getPermanent(source.getFirstTarget());
    ChoiceImpl choice = new ChoiceImpl(true);
    choice.setMessage("Choose letter");
    Set<String> choices = new HashSet<>();
    for (Character letter = 'A'; letter <= 'Z'; letter++) {
        choices.add(letter.toString());
    }
    choice.setChoices(choices);
    if (controller != null && permanent != null && controller.choose(outcome, choice, game)) {
        if (!game.isSimulation()) {
            MageObject mageObject = game.getObject(source.getSourceId());
            if (mageObject != null) {
                game.informPlayers(mageObject.getLogName() + ": " + controller.getLogName() + " has chosen " + choice.getChoice());
            }
        }
        Character chosenLetter = choice.getChoice().charAt(0);
        int unboostValue = 0;
        String permName = permanent.getName();
        for (int i = 0; i < permName.length(); i++) {
            Character letter = permName.charAt(i);
            if (Character.isLetter(letter) && Character.toUpperCase(letter) == chosenLetter) {
                unboostValue--;
            }
        }
        BoostTargetEffect effect = new BoostTargetEffect(unboostValue, unboostValue, Duration.EndOfTurn);
        effect.setTargetPointer(new FixedTarget(permanent, game));
        game.addEffect(effect, source);
        return true;
    }
    return false;
}
Also used : FixedTarget(mage.target.targetpointer.FixedTarget) Player(mage.players.Player) Permanent(mage.game.permanent.Permanent) TargetCreaturePermanent(mage.target.common.TargetCreaturePermanent) BoostTargetEffect(mage.abilities.effects.common.continuous.BoostTargetEffect) MageObject(mage.MageObject) ChoiceImpl(mage.choices.ChoiceImpl) HashSet(java.util.HashSet)

Example 75 with ChoiceImpl

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

the class ChooseExpansionSetEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    MageObject mageObject = game.getPermanentEntering(source.getSourceId());
    if (mageObject == null) {
        mageObject = game.getObject(source.getSourceId());
    }
    if (controller != null) {
        Choice setChoice = new ChoiceImpl(true);
        setChoice.setMessage("Choose expansion set");
        List<String> setCodes = ExpansionRepository.instance.getSetCodes();
        Set<String> sets = new HashSet<String>(setCodes);
        setChoice.setChoices(sets);
        if (controller.choose(outcome, setChoice, game)) {
            if (!game.isSimulation()) {
                game.informPlayers(controller.getLogName() + " has chosen set " + setChoice.getChoice());
            }
            game.getState().setValue(mageObject.getId() + "_set", setChoice.getChoice());
            this.setValue("setchosen", setChoice.getChoice());
            if (mageObject instanceof Permanent) {
                ((Permanent) mageObject).addInfo("chosen set", CardUtil.addToolTipMarkTags("Chosen set: " + setChoice.getChoice()), game);
            }
            return true;
        }
    }
    return false;
}
Also used : Player(mage.players.Player) Choice(mage.choices.Choice) Permanent(mage.game.permanent.Permanent) MageObject(mage.MageObject) ChoiceImpl(mage.choices.ChoiceImpl) HashSet(java.util.HashSet)

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