Search in sources :

Example 56 with ChoiceImpl

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

the class SpellsCostReductionControllerEffect method apply.

@Override
public boolean apply(Game game, Ability source, Ability abilityToModify) {
    if (manaCostsToReduce != null) {
        CardUtil.adjustCost((SpellAbility) abilityToModify, manaCostsToReduce, false);
    } else {
        if (upTo) {
            Mana mana = abilityToModify.getManaCostsToPay().getMana();
            int reduceMax = mana.getGeneric();
            if (reduceMax > this.amount) {
                reduceMax = this.amount;
            }
            if (reduceMax > 0) {
                Player controller = game.getPlayer(abilityToModify.getControllerId());
                if (controller == null) {
                    return false;
                }
                int reduce = reduceMax;
                if (!game.inCheckPlayableState()) {
                    ChoiceImpl choice = new ChoiceImpl(false);
                    Set<String> set = new LinkedHashSet<>();
                    for (int i = 0; i <= reduceMax; i++) {
                        set.add(String.valueOf(i));
                    }
                    choice.setChoices(set);
                    MageObject mageObject = game.getObject(abilityToModify.getSourceId());
                    choice.setMessage("Reduce cost of " + (mageObject != null ? mageObject.getIdName() : filter.getMessage()));
                    if (controller.choose(Outcome.Benefit, choice, game)) {
                        reduce = Integer.parseInt(choice.getChoice());
                    } else {
                        // cancel will be set to max possible reduce
                        reduce = reduceMax;
                    }
                }
                if (reduce > 0) {
                    CardUtil.reduceCost(abilityToModify, reduce);
                }
            }
        } else {
            CardUtil.reduceCost(abilityToModify, this.amount);
        }
    }
    return true;
}
Also used : LinkedHashSet(java.util.LinkedHashSet) Player(mage.players.Player) Mana(mage.Mana) MageObject(mage.MageObject) ChoiceImpl(mage.choices.ChoiceImpl)

Example 57 with ChoiceImpl

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

the class SpellsCostReductionAllEffect method apply.

@Override
public boolean apply(Game game, Ability source, Ability abilityToModify) {
    if (upTo) {
        if (game.inCheckPlayableState()) {
            CardUtil.reduceCost(abilityToModify, this.amount);
            return true;
        }
        Mana mana = abilityToModify.getManaCostsToPay().getMana();
        int reduceMax = mana.getGeneric();
        if (reduceMax > this.amount) {
            reduceMax = this.amount;
        }
        if (reduceMax > 0) {
            Player controller = game.getPlayer(abilityToModify.getControllerId());
            if (controller == null) {
                return false;
            }
            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 cost of " + filter);
            if (controller.choose(Outcome.Benefit, choice, game)) {
                int reduce = Integer.parseInt(choice.getChoice());
                CardUtil.reduceCost(abilityToModify, reduce);
            } else {
                return false;
            }
        }
    } else {
        CardUtil.reduceCost(abilityToModify, this.amount);
    }
    return true;
}
Also used : LinkedHashSet(java.util.LinkedHashSet) Player(mage.players.Player) Mana(mage.Mana) ChoiceImpl(mage.choices.ChoiceImpl)

Example 58 with ChoiceImpl

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

the class CommanderIdentityManaEffect method produceMana.

@Override
public Mana produceMana(Game game, Ability source) {
    Mana mana = new Mana();
    if (game == null) {
        return mana;
    }
    Player controller = game.getPlayer(source.getControllerId());
    if (controller != null) {
        Choice choice = new ChoiceImpl();
        choice.setMessage("Pick a mana color");
        for (UUID commanderId : game.getCommandersIds(controller, CommanderCardType.COMMANDER_OR_OATHBREAKER, false)) {
            Card commander = game.getCard(commanderId);
            if (commander != null) {
                FilterMana commanderMana = commander.getColorIdentity();
                if (commanderMana.isWhite()) {
                    choice.getChoices().add("White");
                }
                if (commanderMana.isBlue()) {
                    choice.getChoices().add("Blue");
                }
                if (commanderMana.isBlack()) {
                    choice.getChoices().add("Black");
                }
                if (commanderMana.isRed()) {
                    choice.getChoices().add("Red");
                }
                if (commanderMana.isGreen()) {
                    choice.getChoices().add("Green");
                }
            }
        }
        if (!choice.getChoices().isEmpty()) {
            if (choice.getChoices().size() == 1) {
                choice.setChoice(choice.getChoices().iterator().next());
            } else {
                if (!controller.choose(outcome, choice, game)) {
                    return mana;
                }
            }
            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) FilterMana(mage.filter.FilterMana) Choice(mage.choices.Choice) FilterMana(mage.filter.FilterMana) ChoiceImpl(mage.choices.ChoiceImpl) UUID(java.util.UUID) Card(mage.cards.Card)

Example 59 with ChoiceImpl

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

the class ElementalResonanceEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Permanent thisPerm = game.getPermanentOrLKIBattlefield(source.getSourceId());
    if (thisPerm == null) {
        return false;
    }
    Permanent permanent = game.getPermanentOrLKIBattlefield(thisPerm.getAttachedTo());
    if (permanent == null) {
        return false;
    }
    Player controller = game.getPlayer(source.getControllerId());
    if (controller == null) {
        return false;
    }
    List<String> manaOptions = new ArrayList<>();
    // TODO: Phyrexian mana gives multiple choices when there should only be one (e.g. Slash Panther is {4} or {4}{R}).
    for (Mana mana : permanent.getManaCost().getOptions()) {
        String manaString = mana.toString();
        if (!manaOptions.contains(manaString)) {
            manaOptions.add(manaString);
        }
    }
    String manaToAdd = "";
    if (manaOptions.size() > 1) {
        // TODO: Make the choices look nicer, right now the brace notation is hard to visually parse, especially with Reaper King
        Choice choice = new ChoiceImpl();
        choice.setMessage("Choose a mana combination");
        choice.getChoices().addAll(manaOptions);
        if (!controller.choose(Outcome.PutManaInPool, choice, game)) {
            return false;
        }
        manaToAdd = choice.getChoice();
    } else if (manaOptions.size() == 1) {
        manaToAdd = manaOptions.get(0);
    }
    if (!manaToAdd.equals("")) {
        controller.getManaPool().addMana(getManaFromString(manaToAdd), game, source);
    }
    return true;
}
Also used : Player(mage.players.Player) Mana(mage.Mana) Choice(mage.choices.Choice) Permanent(mage.game.permanent.Permanent) TargetPermanent(mage.target.TargetPermanent) ArrayList(java.util.ArrayList) ChoiceImpl(mage.choices.ChoiceImpl)

Example 60 with ChoiceImpl

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

the class GoblinClearCutterManaEffect method produceMana.

@Override
public Mana produceMana(Game game, Ability source) {
    Mana mana = new Mana();
    if (game == null) {
        return mana;
    }
    Player player = game.getPlayer(source.getControllerId());
    if (player != null) {
        Choice manaChoice = new ChoiceImpl();
        Set<String> choices = new LinkedHashSet<>();
        choices.add("Red");
        choices.add("Green");
        manaChoice.setChoices(choices);
        manaChoice.setMessage("Select color of mana to add");
        for (int i = 0; i < 3; i++) {
            if (!player.choose(Outcome.Benefit, manaChoice, game)) {
                return mana;
            }
            switch(manaChoice.getChoice()) {
                case "Green":
                    mana.increaseGreen();
                    break;
                case "Red":
                    mana.increaseRed();
                    break;
            }
        }
    }
    return mana;
}
Also used : Player(mage.players.Player) Mana(mage.Mana) Choice(mage.choices.Choice) 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