Search in sources :

Example 16 with ChoiceImpl

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

the class SarkhanUnbrokenAbility1 method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    if (controller != null) {
        controller.drawCards(1, source, game);
        game.fireUpdatePlayersEvent();
        Choice manaChoice = new ChoiceImpl();
        Set<String> choices = new LinkedHashSet<>();
        choices.add("White");
        choices.add("Blue");
        choices.add("Black");
        choices.add("Red");
        choices.add("Green");
        manaChoice.setChoices(choices);
        manaChoice.setMessage("Select color of mana to add");
        Mana mana = new Mana();
        if (!controller.choose(Outcome.Benefit, manaChoice, game)) {
            return false;
        }
        switch(manaChoice.getChoice()) {
            case "White":
                mana.increaseWhite();
                break;
            case "Blue":
                mana.increaseBlue();
                break;
            case "Black":
                mana.increaseBlack();
                break;
            case "Red":
                mana.increaseRed();
                break;
            case "Green":
                mana.increaseGreen();
                break;
        }
        controller.getManaPool().addMana(mana, game, source);
        return true;
    }
    return false;
}
Also used : LinkedHashSet(java.util.LinkedHashSet) Player(mage.players.Player) Choice(mage.choices.Choice) Mana(mage.Mana) ChoiceImpl(mage.choices.ChoiceImpl)

Example 17 with ChoiceImpl

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

the class TayamLuminousEnigmaReplacementEffect method pay.

@Override
public boolean pay(Ability ability, Game game, Ability source, UUID controllerId, boolean noMana, Cost costToPay) {
    paid = false;
    int countersRemoved = 0;
    Player controller = game.getPlayer(controllerId);
    for (int i = 0; i < countersToRemove; i++) {
        if (target.choose(Outcome.UnboostCreature, controllerId, source.getSourceId(), game)) {
            Permanent permanent = game.getPermanent(target.getFirstTarget());
            if (permanent != null) {
                if (!permanent.getCounters(game).isEmpty()) {
                    String counterName = null;
                    if (permanent.getCounters(game).size() > 1) {
                        Choice choice = new ChoiceImpl(true);
                        Set<String> choices = new HashSet<>();
                        for (Counter counter : permanent.getCounters(game).values()) {
                            if (permanent.getCounters(game).getCount(counter.getName()) > 0) {
                                choices.add(counter.getName());
                            }
                        }
                        choice.setChoices(choices);
                        choice.setMessage("Choose a counter to remove from " + permanent.getLogName());
                        if (!controller.choose(Outcome.UnboostCreature, choice, game)) {
                            return false;
                        }
                        counterName = choice.getChoice();
                    } else {
                        for (Counter counter : permanent.getCounters(game).values()) {
                            if (counter.getCount() > 0) {
                                counterName = counter.getName();
                            }
                        }
                    }
                    if (counterName != null) {
                        permanent.removeCounters(counterName, 1, source, game);
                        target.clearChosen();
                        if (!game.isSimulation()) {
                            game.informPlayers(new StringBuilder(controller.getLogName()).append(" removes a ").append(counterName).append(" counter from ").append(permanent.getName()).toString());
                        }
                        countersRemoved++;
                        if (countersRemoved == countersToRemove) {
                            paid = true;
                            break;
                        }
                    }
                }
            }
        } else {
            break;
        }
    }
    return paid;
}
Also used : Player(mage.players.Player) Choice(mage.choices.Choice) Counter(mage.counters.Counter) FilterControlledCreaturePermanent(mage.filter.common.FilterControlledCreaturePermanent) Permanent(mage.game.permanent.Permanent) TargetPermanent(mage.target.TargetPermanent) ChoiceImpl(mage.choices.ChoiceImpl) HashSet(java.util.HashSet)

Example 18 with ChoiceImpl

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

the class UrzaAcademyHeadmasterBrainstormEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player player = game.getPlayer(source.getControllerId());
    if (player != null) {
        int x = game.getBattlefield().count(new FilterControlledCreaturePermanent(), source.getSourceId(), source.getControllerId(), game);
        Choice manaChoice = new ChoiceImpl();
        Set<String> choices = new LinkedHashSet<>();
        choices.add("White");
        choices.add("Blue");
        choices.add("Black");
        choices.add("Red");
        choices.add("Green");
        manaChoice.setChoices(choices);
        manaChoice.setMessage("Select color of mana to add");
        for (int i = 0; i < x; i++) {
            Mana mana = new Mana();
            if (!player.choose(Outcome.Benefit, manaChoice, game)) {
                return false;
            }
            if (manaChoice.getChoice() == null) {
                // can happen if player leaves game
                return false;
            }
            switch(manaChoice.getChoice()) {
                case "White":
                    mana.increaseWhite();
                    break;
                case "Blue":
                    mana.increaseBlue();
                    break;
                case "Black":
                    mana.increaseBlack();
                    break;
                case "Red":
                    mana.increaseRed();
                    break;
                case "Green":
                    mana.increaseGreen();
                    break;
            }
            player.getManaPool().addMana(mana, game, source);
        }
        return true;
    }
    return false;
}
Also used : Player(mage.players.Player) TargetPlayer(mage.target.TargetPlayer) Choice(mage.choices.Choice) Mana(mage.Mana) ChoiceImpl(mage.choices.ChoiceImpl)

Example 19 with ChoiceImpl

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

the class BloodOathEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    MageObject sourceObject = game.getObject(source.getSourceId());
    Player player = game.getPlayer(source.getControllerId());
    Player opponent = game.getPlayer(source.getFirstTarget());
    if (player != null && opponent != null && sourceObject != null) {
        Choice choiceImpl = new ChoiceImpl();
        choiceImpl.setChoices(choice);
        if (player.choose(Outcome.Neutral, choiceImpl, game)) {
            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) {
                Cards hand = opponent.getHand();
                opponent.revealCards(sourceObject.getIdName(), hand, game);
                Set<Card> cards = hand.getCards(game);
                int damageToDeal = 0;
                for (Card card : cards) {
                    if (card != null && card.getCardType(game).contains(type)) {
                        damageToDeal += 3;
                    }
                }
                game.informPlayers(sourceObject.getLogName() + " deals " + (damageToDeal == 0 ? "no" : "" + damageToDeal) + " damage to " + opponent.getLogName());
                opponent.damage(damageToDeal, source.getSourceId(), source, game);
                return true;
            }
        }
    }
    return false;
}
Also used : Player(mage.players.Player) Choice(mage.choices.Choice) CardType(mage.constants.CardType) MageObject(mage.MageObject) ChoiceImpl(mage.choices.ChoiceImpl) Cards(mage.cards.Cards) Card(mage.cards.Card)

Example 20 with ChoiceImpl

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

the class CatalystStoneCostRaiseEffect method apply.

@Override
public boolean apply(Game game, Ability source, Ability abilityToModify) {
    Player controller = game.getPlayer(abilityToModify.getControllerId());
    if (controller != null) {
        Mana mana = abilityToModify.getManaCostsToPay().getMana();
        int reduceMax = mana.getGeneric();
        if (reduceMax > 2) {
            reduceMax = 2;
        }
        if (reduceMax > 0) {
            int reduce;
            if (game.inCheckPlayableState()) {
                reduce = reduceMax;
            } else {
                ChoiceImpl choice = new ChoiceImpl(true);
                Set<String> set = new LinkedHashSet<>();
                for (int i = 0; i <= reduceMax; i++) {
                    set.add(String.valueOf(i));
                }
                choice.setChoices(set);
                choice.setMessage("Reduce flashback cost");
                if (controller.choose(Outcome.Benefit, choice, game)) {
                    reduce = Integer.parseInt(choice.getChoice());
                } else {
                    return false;
                }
            }
            CardUtil.reduceCost(abilityToModify, reduce);
        }
        return true;
    }
    return false;
}
Also used : LinkedHashSet(java.util.LinkedHashSet) Player(mage.players.Player) Mana(mage.Mana) 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