Search in sources :

Example 6 with ChoiceImpl

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

the class GremlinMineEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player player = game.getPlayer(source.getControllerId());
    Permanent permanent = game.getPermanent(source.getFirstTarget());
    if (player != null && permanent != null) {
        int existingCount = permanent.getCounters(game).getCount(CounterType.CHARGE);
        if (existingCount > 0) {
            Choice choice = new ChoiceImpl();
            choice.setMessage("Select number of charge counters to remove:");
            for (Integer i = 0; i <= existingCount; i++) {
                choice.getChoices().add(i.toString());
            }
            if (player.choose(Outcome.Detriment, choice, game)) {
                permanent.removeCounters(CounterType.CHARGE.getName(), Integer.parseInt(choice.getChoice()), source, game);
                return true;
            }
            return false;
        }
        return true;
    }
    return false;
}
Also used : Player(mage.players.Player) Choice(mage.choices.Choice) TargetArtifactPermanent(mage.target.common.TargetArtifactPermanent) Permanent(mage.game.permanent.Permanent) FilterArtifactPermanent(mage.filter.common.FilterArtifactPermanent) ChoiceImpl(mage.choices.ChoiceImpl)

Example 7 with ChoiceImpl

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

the class MuldrothaTheGravetideWatcher method addPermanentTypes.

private void addPermanentTypes(GameEvent event, Card mageObject, Game game) {
    if (mageObject != null && event.getAdditionalReference() != null && MageIdentifier.MuldrothaTheGravetideWatcher.equals(event.getAdditionalReference().getApprovingAbility().getIdentifier())) {
        UUID playerId = null;
        if (mageObject instanceof Spell) {
            playerId = ((Spell) mageObject).getControllerId();
        } else if (mageObject instanceof Permanent) {
            playerId = ((Permanent) mageObject).getControllerId();
        }
        if (playerId != null) {
            Set<CardType> permanentTypes = sourcePlayedPermanentTypes.get(event.getAdditionalReference().getApprovingMageObjectReference());
            if (permanentTypes == null) {
                permanentTypes = EnumSet.noneOf(CardType.class);
                sourcePlayedPermanentTypes.put(event.getAdditionalReference().getApprovingMageObjectReference(), permanentTypes);
            }
            Set<CardType> typesNotCast = EnumSet.noneOf(CardType.class);
            for (CardType cardType : mageObject.getCardType(game)) {
                if (cardType.isPermanentType()) {
                    if (!permanentTypes.contains(cardType)) {
                        typesNotCast.add(cardType);
                    }
                }
            }
            if (typesNotCast.size() <= 1) {
                permanentTypes.addAll(typesNotCast);
            } else {
                Player player = game.getPlayer(playerId);
                if (player != null) {
                    Choice typeChoice = new ChoiceImpl(true);
                    typeChoice.setMessage("Choose permanent type you consume for casting from graveyard.");
                    for (CardType cardType : typesNotCast) {
                        typeChoice.getChoices().add(cardType.toString());
                    }
                    if (player.choose(Outcome.Detriment, typeChoice, game)) {
                        String typeName = typeChoice.getChoice();
                        CardType chosenType = null;
                        for (CardType cardType : CardType.values()) {
                            if (cardType.toString().equals(typeName)) {
                                chosenType = cardType;
                                break;
                            }
                        }
                        if (chosenType != null) {
                            permanentTypes.add(chosenType);
                        }
                    }
                }
            }
        }
    }
}
Also used : Player(mage.players.Player) Choice(mage.choices.Choice) Permanent(mage.game.permanent.Permanent) CardType(mage.constants.CardType) ChoiceImpl(mage.choices.ChoiceImpl) UUID(java.util.UUID) Spell(mage.game.stack.Spell)

Example 8 with ChoiceImpl

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

the class ReverseTheSandsEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    if (controller != null) {
        Choice lifeChoice = new ChoiceImpl(true);
        Set<String> choices = new HashSet<>();
        for (UUID playerId : game.getState().getPlayersInRange(controller.getId(), game)) {
            Player player = game.getPlayer(playerId);
            if (player != null) {
                choices.add(Integer.toString(player.getLife()) + " life of " + player.getLogName());
            }
        }
        lifeChoice.setChoices(choices);
        for (UUID playersId : game.getState().getPlayersInRange(controller.getId(), game)) {
            Player player = game.getPlayer(playersId);
            if (player != null) {
                String selectedChoice;
                if (choices.size() > 1) {
                    lifeChoice.setMessage("Which players life should get player " + player.getLogName());
                    if (!controller.choose(Outcome.Detriment, lifeChoice, game)) {
                        return false;
                    }
                    selectedChoice = lifeChoice.getChoice();
                } else {
                    selectedChoice = choices.iterator().next();
                }
                int index = selectedChoice.indexOf(' ');
                if (index > 0) {
                    String lifeString = selectedChoice.substring(0, index);
                    int life = Integer.parseInt(lifeString);
                    player.setLife(life, game, source);
                    choices.remove(selectedChoice);
                    game.informPlayers(new StringBuilder("Player ").append(player.getLogName()).append(" life set to ").append(life).toString());
                }
            }
        }
    }
    return false;
}
Also used : Player(mage.players.Player) Choice(mage.choices.Choice) ChoiceImpl(mage.choices.ChoiceImpl) UUID(java.util.UUID) HashSet(java.util.HashSet)

Example 9 with ChoiceImpl

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

the class WorldQuellerEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    List<Card> chosen = new ArrayList<>();
    Player player = game.getPlayer(source.getControllerId());
    Permanent sourceCreature = game.getPermanent(source.getSourceId());
    if (player != null && sourceCreature != null) {
        Choice choiceImpl = new ChoiceImpl();
        choiceImpl.setChoices(choice);
        if (!player.choose(Outcome.Neutral, choiceImpl, game)) {
            return false;
        }
        CardType type = null;
        String choosenType = choiceImpl.getChoice();
        if (choosenType.equals(CardType.ARTIFACT.toString())) {
            type = CardType.ARTIFACT;
        } else if (choosenType.equals(CardType.LAND.toString())) {
            type = CardType.LAND;
        } else if (choosenType.equals(CardType.CREATURE.toString())) {
            type = CardType.CREATURE;
        } else if (choosenType.equals(CardType.ENCHANTMENT.toString())) {
            type = CardType.ENCHANTMENT;
        } else if (choosenType.equals(CardType.INSTANT.toString())) {
            type = CardType.INSTANT;
        } else if (choosenType.equals(CardType.SORCERY.toString())) {
            type = CardType.SORCERY;
        } else if (choosenType.equals(CardType.PLANESWALKER.toString())) {
            type = CardType.PLANESWALKER;
        } else if (choosenType.equals(CardType.TRIBAL.toString())) {
            type = CardType.TRIBAL;
        }
        if (type != null) {
            FilterControlledPermanent filter = new FilterControlledPermanent("permanent you control of type " + type.toString());
            filter.add(type.getPredicate());
            TargetPermanent target = new TargetControlledPermanent(1, 1, filter, false);
            target.setNotTarget(true);
            for (UUID playerId : game.getState().getPlayersInRange(source.getControllerId(), game)) {
                Player player2 = game.getPlayer(playerId);
                if (player2 != null && target.canChoose(source.getSourceId(), playerId, game)) {
                    while (player2.canRespond() && !target.isChosen() && target.canChoose(source.getSourceId(), playerId, game)) {
                        player2.chooseTarget(Outcome.Sacrifice, target, source, game);
                    }
                    Permanent permanent = game.getPermanent(target.getFirstTarget());
                    if (permanent != null) {
                        chosen.add(permanent);
                    }
                    target.clearChosen();
                }
            }
            // all chosen permanents are sacrificed together
            for (Permanent permanent : game.getBattlefield().getAllActivePermanents()) {
                if (chosen.contains(permanent)) {
                    permanent.sacrifice(source, game);
                }
            }
            return true;
        }
    }
    return false;
}
Also used : Player(mage.players.Player) Choice(mage.choices.Choice) FilterControlledPermanent(mage.filter.common.FilterControlledPermanent) Permanent(mage.game.permanent.Permanent) TargetControlledPermanent(mage.target.common.TargetControlledPermanent) TargetPermanent(mage.target.TargetPermanent) FilterControlledPermanent(mage.filter.common.FilterControlledPermanent) Card(mage.cards.Card) TargetControlledPermanent(mage.target.common.TargetControlledPermanent) CardType(mage.constants.CardType) ChoiceImpl(mage.choices.ChoiceImpl) TargetPermanent(mage.target.TargetPermanent)

Example 10 with ChoiceImpl

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

the class ChooseModeEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    Permanent sourcePermanent = game.getPermanent(source.getSourceId());
    if (sourcePermanent == null) {
        sourcePermanent = game.getPermanentEntering(source.getSourceId());
    }
    if (controller != null) {
        Choice choice = new ChoiceImpl(true);
        choice.setMessage(choiceMessage);
        choice.getChoices().addAll(modes);
        if (controller.choose(Outcome.Neutral, choice, game)) {
            if (!game.isSimulation()) {
                game.informPlayers(sourcePermanent.getLogName() + ": " + controller.getLogName() + " has chosen " + choice.getChoice());
            }
            game.getState().setValue(source.getSourceId() + "_modeChoice", choice.getChoice());
            sourcePermanent.addInfo("_modeChoice", "<font color = 'blue'>Chosen mode: " + choice.getChoice() + "</font>", game);
            return true;
        }
    }
    return false;
}
Also used : Player(mage.players.Player) Choice(mage.choices.Choice) Permanent(mage.game.permanent.Permanent) 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