Search in sources :

Example 81 with ChoiceImpl

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

the class FastSearchUtil method showFastSearchForStringComboBox.

/**
 * Show fast choice modal dialog with incremental searching for any string combobox components
 *
 * @param combo         combobox control with default data model
 * @param chooseMessage caption message for dialog
 */
public static void showFastSearchForStringComboBox(JComboBox combo, String chooseMessage, int windowWidth, int windowHeight) {
    // fast search/choice dialog for string combobox
    mage.choices.Choice choice = new ChoiceImpl(false);
    // collect data from expansion combobox (String)
    DefaultComboBoxModel comboModel = (DefaultComboBoxModel) combo.getModel();
    Map<String, String> choiceItems = new HashMap<>(comboModel.getSize());
    Map<String, Integer> choiceSorting = new HashMap<>(comboModel.getSize());
    String item;
    for (int i = 0; i < comboModel.getSize(); i++) {
        item = comboModel.getElementAt(i).toString();
        choiceItems.put(item, item);
        // need so sorting
        choiceSorting.put(item, i);
    }
    choice.setKeyChoices(choiceItems);
    choice.setSortData(choiceSorting);
    choice.setMessage(chooseMessage);
    // current selection value restore
    String needSelectValue;
    needSelectValue = comboModel.getSelectedItem().toString();
    // ask for new value
    PickChoiceDialog dlg = new PickChoiceDialog();
    dlg.setWindowSize(windowWidth, windowHeight);
    dlg.showDialog(choice, needSelectValue);
    if (choice.isChosen()) {
        item = choice.getChoiceKey();
        // compatible select for object's models (use setSelectedIndex instead setSelectedObject)
        for (int i = 0; i < comboModel.getSize(); i++) {
            if (comboModel.getElementAt(i).toString().equals(item)) {
                combo.setSelectedIndex(i);
            }
        }
    }
}
Also used : HashMap(java.util.HashMap) ChoiceImpl(mage.choices.ChoiceImpl) PickChoiceDialog(mage.client.dialog.PickChoiceDialog)

Example 82 with ChoiceImpl

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

the class AngelicSkirmisherEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    Permanent sourcePermanent = game.getPermanent(source.getSourceId());
    if (controller != null && sourcePermanent != null) {
        Choice abilityChoice = new ChoiceImpl(true);
        Set<String> abilityChoices = new HashSet<>(3);
        abilityChoice.setMessage("Choose ability for your creatures");
        abilityChoices.add("First strike");
        abilityChoices.add("Vigilance");
        abilityChoices.add("Lifelink");
        abilityChoice.setChoices(abilityChoices);
        if (controller.choose(outcome, abilityChoice, game)) {
            Ability ability = null;
            switch(abilityChoice.getChoice()) {
                case "First strike":
                    ability = FirstStrikeAbility.getInstance();
                    break;
                case "Vigilance":
                    ability = VigilanceAbility.getInstance();
                    break;
                case "Lifelink":
                    ability = LifelinkAbility.getInstance();
                    break;
                default:
                    break;
            }
            if (ability != null) {
                GainAbilityControlledEffect effect = new GainAbilityControlledEffect(ability, Duration.EndOfTurn, new FilterControlledCreaturePermanent());
                game.addEffect(effect, source);
                game.informPlayers(sourcePermanent.getName() + ": " + controller.getLogName() + " has chosen " + abilityChoice.getChoice().toLowerCase(Locale.ENGLISH));
                return true;
            }
        }
    }
    return false;
}
Also used : BeginningOfCombatTriggeredAbility(mage.abilities.common.BeginningOfCombatTriggeredAbility) LifelinkAbility(mage.abilities.keyword.LifelinkAbility) VigilanceAbility(mage.abilities.keyword.VigilanceAbility) FirstStrikeAbility(mage.abilities.keyword.FirstStrikeAbility) FlyingAbility(mage.abilities.keyword.FlyingAbility) Ability(mage.abilities.Ability) Player(mage.players.Player) Choice(mage.choices.Choice) Permanent(mage.game.permanent.Permanent) FilterControlledCreaturePermanent(mage.filter.common.FilterControlledCreaturePermanent) GainAbilityControlledEffect(mage.abilities.effects.common.continuous.GainAbilityControlledEffect) FilterControlledCreaturePermanent(mage.filter.common.FilterControlledCreaturePermanent) ChoiceImpl(mage.choices.ChoiceImpl) HashSet(java.util.HashSet)

Example 83 with ChoiceImpl

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

the class AnimationModuleEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    if (controller != null) {
        Permanent permanent = game.getPermanent(this.getTargetPointer().getFirst(game, source));
        if (permanent != null) {
            if (!permanent.getCounters(game).isEmpty()) {
                if (permanent.getCounters(game).size() == 1) {
                    for (Counter counter : permanent.getCounters(game).values()) {
                        Counter newCounter = new Counter(counter.getName());
                        permanent.addCounters(newCounter, source.getControllerId(), source, game);
                    }
                } else {
                    Choice choice = new ChoiceImpl(true);
                    Set<String> choices = new HashSet<>(permanent.getCounters(game).size());
                    for (Counter counter : permanent.getCounters(game).values()) {
                        choices.add(counter.getName());
                    }
                    choice.setChoices(choices);
                    choice.setMessage("Choose a counter");
                    if (controller.choose(Outcome.Benefit, choice, game)) {
                        for (Counter counter : permanent.getCounters(game).values()) {
                            if (counter.getName().equals(choice.getChoice())) {
                                Counter newCounter = new Counter(counter.getName());
                                permanent.addCounters(newCounter, source.getControllerId(), source, game);
                                break;
                            }
                        }
                    } else {
                        return false;
                    }
                }
            }
        } else {
            Player player = game.getPlayer(this.getTargetPointer().getFirst(game, source));
            if (player != null) {
                if (!player.getCounters().isEmpty()) {
                    if (player.getCounters().size() == 1) {
                        for (Counter counter : player.getCounters().values()) {
                            Counter newCounter = new Counter(counter.getName());
                            player.addCounters(newCounter, source.getControllerId(), source, game);
                        }
                    } else {
                        Choice choice = new ChoiceImpl(true);
                        Set<String> choices = new HashSet<>(player.getCounters().size());
                        for (Counter counter : player.getCounters().values()) {
                            choices.add(counter.getName());
                        }
                        choice.setChoices(choices);
                        choice.setMessage("Choose a counter");
                        if (controller.choose(Outcome.Benefit, choice, game)) {
                            for (Counter counter : player.getCounters().values()) {
                                if (counter.getName().equals(choice.getChoice())) {
                                    Counter newCounter = new Counter(counter.getName());
                                    player.addCounters(newCounter, source.getControllerId(), source, game);
                                    break;
                                }
                            }
                        } else {
                            return false;
                        }
                    }
                }
            }
        }
        return true;
    }
    return false;
}
Also used : Player(mage.players.Player) TargetPermanentOrPlayer(mage.target.common.TargetPermanentOrPlayer) Counter(mage.counters.Counter) Choice(mage.choices.Choice) Permanent(mage.game.permanent.Permanent) ChoiceImpl(mage.choices.ChoiceImpl) HashSet(java.util.HashSet)

Example 84 with ChoiceImpl

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

the class CharmedPendantManaEffect 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) {
        for (Cost cost : source.getCosts()) {
            if (cost instanceof MillCardsCost) {
                Set<Card> cards = ((MillCardsCost) cost).getCardsMovedToGraveyard();
                if (!cards.isEmpty()) {
                    Card card = cards.iterator().next();
                    if (card != null && card.getManaCost() != null) {
                        ManaCosts<ManaCost> newManaCosts = new ManaCostsImpl<>();
                        for (ManaCost manaCost : card.getManaCost()) {
                            if (manaCost instanceof ColorlessManaCost || manaCost instanceof GenericManaCost || manaCost instanceof VariableManaCost) {
                                continue;
                            }
                            if (manaCost instanceof MonoHybridManaCost) {
                                newManaCosts.add(new ColoredManaCost(((MonoHybridManaCost) manaCost).getManaColor()));
                            } else {
                                newManaCosts.add(manaCost.copy());
                            }
                        }
                        ManaOptions manaOptions = newManaCosts.getOptions();
                        if (manaOptions.size() == 1) {
                            mana = newManaCosts.getMana();
                        } else {
                            Choice manaChoice = new ChoiceImpl(true);
                            manaChoice.setMessage("Select which mana you like to produce");
                            for (Mana manaOption : manaOptions) {
                                manaChoice.getChoices().add(manaOption.toString());
                            }
                            if (manaChoice.getChoices().isEmpty()) {
                                // no mana choices available
                                return mana;
                            }
                            if (controller.choose(outcome, manaChoice, game)) {
                                for (Mana manaOption : manaOptions) {
                                    if (manaChoice.getChoice().equals(manaOption.toString())) {
                                        mana = manaOption;
                                        break;
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
    }
    return mana;
}
Also used : ManaOptions(mage.abilities.mana.ManaOptions) Player(mage.players.Player) Mana(mage.Mana) MillCardsCost(mage.abilities.costs.common.MillCardsCost) Choice(mage.choices.Choice) MillCardsCost(mage.abilities.costs.common.MillCardsCost) Cost(mage.abilities.costs.Cost) TapSourceCost(mage.abilities.costs.common.TapSourceCost) Card(mage.cards.Card) 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