Search in sources :

Example 76 with ChoiceImpl

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

the class ChooseLandTypeEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    MageObject mageObject = game.getPermanentEntering(source.getSourceId());
    if (mageObject == null) {
        mageObject = game.getObject(source.getSourceId());
    }
    if (controller != null && mageObject != null) {
        Choice typeChoice = new ChoiceImpl(true);
        typeChoice.setMessage("Choose land type");
        typeChoice.setChoices(SubType.getLandTypes().stream().map(SubType::toString).collect(Collectors.toSet()));
        if (controller.choose(outcome, typeChoice, game)) {
            if (!game.isSimulation()) {
                game.informPlayers(mageObject.getName() + ": " + controller.getLogName() + " has chosen " + typeChoice.getChoice());
            }
            game.getState().setValue(mageObject.getId() + "_type", SubType.byDescription(typeChoice.getChoice()));
            if (mageObject instanceof Permanent) {
                ((Permanent) mageObject).addInfo("chosen type", CardUtil.addToolTipMarkTags("Chosen type: " + typeChoice.getChoice()), game);
            }
            return true;
        }
    }
    return false;
}
Also used : Player(mage.players.Player) Choice(mage.choices.Choice) SubType(mage.constants.SubType) Permanent(mage.game.permanent.Permanent) MageObject(mage.MageObject) ChoiceImpl(mage.choices.ChoiceImpl)

Example 77 with ChoiceImpl

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

the class KayaTheInexorableEmblemEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player player = game.getPlayer(source.getControllerId());
    if (player != null) {
        Choice zoneChoice = new ChoiceImpl(true);
        zoneChoice.setMessage("Cast a legendary spell from hand, graveyard, or exile");
        zoneChoice.setChoices(choices);
        zoneChoice.clearChoice();
        if (player.choose(Outcome.PlayForFree, zoneChoice, game)) {
            TargetCard target = null;
            switch(zoneChoice.getChoice()) {
                case "Hand":
                    target = new TargetCardInHand(0, 1, filter);
                    target.setTargetName("legendary spell from your hand");
                    break;
                case "Graveyard":
                    target = new TargetCardInYourGraveyard(0, 1, filter, true);
                    target.setTargetName("legendary spell from your graveyard");
                    break;
                case "Exile":
                    target = new TargetCardInExile(0, 1, filter, null, true);
                    target.setNotTarget(true);
                    target.setTargetName("legendary spell you own in exile");
                    break;
            }
            if (target != null && player.chooseTarget(Outcome.PlayForFree, target, source, game)) {
                Card card = game.getCard(target.getFirstTarget());
                if (card != null) {
                    game.getState().setValue("PlayFromNotOwnHandZone" + card.getId(), Boolean.TRUE);
                    boolean cardWasCast = player.cast(player.chooseAbilityForCast(card, game, true), game, true, new ApprovingObject(source, game));
                    game.getState().setValue("PlayFromNotOwnHandZone" + card.getId(), null);
                    return cardWasCast;
                }
            }
        }
    }
    return false;
}
Also used : Player(mage.players.Player) Choice(mage.choices.Choice) ApprovingObject(mage.ApprovingObject) TargetCardInHand(mage.target.common.TargetCardInHand) TargetCardInExile(mage.target.common.TargetCardInExile) ChoiceImpl(mage.choices.ChoiceImpl) TargetCard(mage.target.TargetCard) TargetCardInYourGraveyard(mage.target.common.TargetCardInYourGraveyard) FilterOwnedCard(mage.filter.common.FilterOwnedCard) TargetCard(mage.target.TargetCard) Card(mage.cards.Card)

Example 78 with ChoiceImpl

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

the class ConnectDialog method doFastFlagSearch.

// GEN-LAST:event_btnFindOtherActionPerformed
private void doFastFlagSearch() {
    Choice choice = new ChoiceImpl(false);
    // collect data from country combobox String[name][code]
    Map<String, String> choiceItems = new LinkedHashMap<>();
    DefaultComboBoxModel flagModel = (DefaultComboBoxModel) cbFlag.getModel();
    String[] flagItem;
    for (int i = 0; i < flagModel.getSize(); i++) {
        flagItem = (String[]) flagModel.getElementAt(i);
        choiceItems.put(flagItem[1], flagItem[0]);
    }
    choice.setKeyChoices(choiceItems);
    choice.setMessage("Select your country");
    // current selection value restore
    String needSelectValue = null;
    flagItem = (String[]) flagModel.getSelectedItem();
    if (flagItem != null) {
        needSelectValue = flagItem[1];
    }
    // ask for new value
    PickChoiceDialog dlg = new PickChoiceDialog();
    dlg.setWindowSize(300, 500);
    dlg.showDialog(choice, needSelectValue);
    if (choice.isChosen()) {
        flagItem = new String[2];
        flagItem[0] = choice.getChoiceValue();
        flagItem[1] = choice.getChoiceKey();
        flagModel.setSelectedItem(flagItem);
    }
}
Also used : Choice(mage.choices.Choice) ChoiceImpl(mage.choices.ChoiceImpl)

Example 79 with ChoiceImpl

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

the class ClockspinningAddOrRemoveCounterEffect method selectCounterType.

private Counter selectCounterType(Game game, Ability source, Permanent permanent) {
    Player controller = game.getPlayer(source.getControllerId());
    if (controller != null && !permanent.getCounters(game).isEmpty()) {
        String counterName = null;
        if (permanent.getCounters(game).size() > 1) {
            Choice choice = new ChoiceImpl(true);
            Set<String> choices = new HashSet<>(2);
            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 type to add to " + permanent.getName());
            if (controller.choose(Outcome.Neutral, choice, game)) {
                counterName = choice.getChoice();
            } else {
                return null;
            }
        } else {
            for (Counter counter : permanent.getCounters(game).values()) {
                if (counter.getCount() > 0) {
                    counterName = counter.getName();
                }
            }
        }
        return new Counter(counterName);
    }
    return null;
}
Also used : Player(mage.players.Player) Choice(mage.choices.Choice) Counter(mage.counters.Counter) ChoiceImpl(mage.choices.ChoiceImpl) HashSet(java.util.HashSet)

Example 80 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 CheckBoxList components
 *
 * @param combo         CheckBoxList control with default data model
 * @param chooseMessage caption message for dialog
 */
public static void showFastSearchForStringComboBox(CheckBoxList combo, String chooseMessage) {
    // fast search/choice dialog for string combobox
    mage.choices.Choice choice = new ChoiceImpl(false);
    // collect data from expansion combobox (String)
    DefaultListModel comboModel = (DefaultListModel) 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.size(); 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 = null;
    if (comboModel.size() > 0) {
        needSelectValue = comboModel.firstElement().toString();
    }
    // ask for new value
    PickCheckBoxDialog dlg = new PickCheckBoxDialog(combo);
    dlg.setWindowSize(300, 500);
    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) PickCheckBoxDialog(mage.client.dialog.PickCheckBoxDialog)

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