Search in sources :

Example 11 with Choice

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

the class MeteorCraterEffect method produceMana.

@Override
public Mana produceMana(Game game, Ability source) {
    Mana mana = new Mana();
    if (game == null) {
        return mana;
    }
    Mana types = getManaTypes(game, source);
    Choice choice = new ChoiceColor(true);
    choice.getChoices().clear();
    choice.setMessage("Pick a mana color");
    if (types.getAny() > 0) {
        choice.getChoices().add("Black");
        choice.getChoices().add("Red");
        choice.getChoices().add("Blue");
        choice.getChoices().add("Green");
        choice.getChoices().add("White");
    } else {
        if (types.getBlack() > 0) {
            choice.getChoices().add("Black");
        }
        if (types.getRed() > 0) {
            choice.getChoices().add("Red");
        }
        if (types.getBlue() > 0) {
            choice.getChoices().add("Blue");
        }
        if (types.getGreen() > 0) {
            choice.getChoices().add("Green");
        }
        if (types.getWhite() > 0) {
            choice.getChoices().add("White");
        }
    }
    if (!choice.getChoices().isEmpty()) {
        Player player = game.getPlayer(source.getControllerId());
        if (choice.getChoices().size() == 1) {
            choice.setChoice(choice.getChoices().iterator().next());
        } else {
            player.choose(outcome, choice, game);
        }
        if (choice.getChoice() != null) {
            switch(choice.getChoice()) {
                case "Black":
                    mana.setBlack(1);
                    break;
                case "Blue":
                    mana.setBlue(1);
                    break;
                case "Red":
                    mana.setRed(1);
                    break;
                case "Green":
                    mana.setGreen(1);
                    break;
                case "White":
                    mana.setWhite(1);
                    break;
            }
        }
    }
    return mana;
}
Also used : Player(mage.players.Player) Mana(mage.Mana) Choice(mage.choices.Choice) ChoiceColor(mage.choices.ChoiceColor)

Example 12 with Choice

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

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

the class PatriarchsBiddingEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    MageObject sourceObject = game.getObject(source.getSourceId());
    if (controller != null && sourceObject != null) {
        Set<String> chosenTypes = new HashSet<>();
        for (UUID playerId : game.getState().getPlayersInRange(controller.getId(), game)) {
            Player player = game.getPlayer(playerId);
            Choice typeChoice = new ChoiceCreatureType(sourceObject);
            if (!player.choose(Outcome.PutCreatureInPlay, typeChoice, game)) {
                continue;
            }
            String chosenType = typeChoice.getChoice();
            game.informPlayers(sourceObject.getLogName() + ": " + player.getLogName() + " has chosen " + chosenType);
            chosenTypes.add(chosenType);
        }
        List<SubType.SubTypePredicate> predicates = new ArrayList<>();
        for (String type : chosenTypes) {
            predicates.add(SubType.byDescription(type).getPredicate());
        }
        FilterCard filter = new FilterCreatureCard();
        filter.add(Predicates.or(predicates));
        for (UUID playerId : game.getState().getPlayersInRange(controller.getId(), game)) {
            Player player = game.getPlayer(playerId);
            if (player != null) {
                player.moveCards(player.getGraveyard().getCards(filter, game), Zone.BATTLEFIELD, source, game);
            }
        }
        return true;
    }
    return false;
}
Also used : Player(mage.players.Player) Choice(mage.choices.Choice) MageObject(mage.MageObject) FilterCard(mage.filter.FilterCard) FilterCreatureCard(mage.filter.common.FilterCreatureCard) ChoiceCreatureType(mage.choices.ChoiceCreatureType)

Example 14 with Choice

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

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

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