Search in sources :

Example 41 with ChoiceImpl

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

the class JodahsAvengerEffect method init.

@Override
public void init(Ability source, Game game) {
    super.init(source, game);
    Player controller = game.getPlayer(source.getControllerId());
    if (controller != null) {
        Choice choice = new ChoiceImpl(true);
        choice.setMessage("Choose one");
        choice.setChoices(choices);
        if (controller.choose(outcome, choice, game)) {
            switch(choice.getChoice()) {
                case "Double strike":
                    gainedAbility = DoubleStrikeAbility.getInstance();
                    break;
                case "Vigilance":
                    gainedAbility = VigilanceAbility.getInstance();
                    break;
                case "Shadow":
                    gainedAbility = ShadowAbility.getInstance();
                    break;
                default:
                    gainedAbility = ProtectionAbility.from(ObjectColor.RED);
                    break;
            }
        } else {
            discard();
        }
    }
}
Also used : Player(mage.players.Player) Choice(mage.choices.Choice) ChoiceImpl(mage.choices.ChoiceImpl)

Example 42 with ChoiceImpl

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

the class MaintenanceDroidEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    if (controller != null) {
        Choice choice = new ChoiceImpl(true);
        choice.setMessage("Choose mode");
        choice.setChoices(choices);
        if (!controller.choose(outcome, choice, game)) {
            return false;
        }
        String chosen = choice.getChoice();
        switch(chosen) {
            case "Remove a repair counter":
                new RemoveCounterTargetEffect(CounterType.REPAIR.createInstance()).apply(game, source);
                break;
            default:
                // "Add another repair counter"
                new AddCountersTargetEffect(CounterType.REPAIR.createInstance()).apply(game, source);
                break;
        }
        return true;
    }
    return false;
}
Also used : Player(mage.players.Player) Choice(mage.choices.Choice) RemoveCounterTargetEffect(mage.abilities.effects.common.counter.RemoveCounterTargetEffect) ChoiceImpl(mage.choices.ChoiceImpl) AddCountersTargetEffect(mage.abilities.effects.common.counter.AddCountersTargetEffect)

Example 43 with ChoiceImpl

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

the class TurnaboutEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    if (controller == null || game.getPlayer(source.getFirstTarget()) == null) {
        return true;
    }
    Choice choiceImpl = new ChoiceImpl(true);
    choiceImpl.setMessage("Choose card type to tap or untap");
    choiceImpl.setChoices(choice);
    if (!controller.choose(Outcome.Neutral, choiceImpl, game)) {
        return false;
    }
    FilterPermanent filter;
    switch(choiceImpl.getChoice()) {
        case "Artifact":
            filter = StaticFilters.FILTER_CONTROLLED_PERMANENT_ARTIFACT;
            break;
        case "Land":
            filter = StaticFilters.FILTER_CONTROLLED_PERMANENT_LAND;
            break;
        case "Creature":
            filter = StaticFilters.FILTER_CONTROLLED_CREATURE;
            break;
        default:
            throw new IllegalArgumentException("Choice is required");
    }
    boolean tap = controller.chooseUse(Outcome.Neutral, "Tap or untap?", null, "Tap", "Untap", source, game);
    for (Permanent permanent : game.getBattlefield().getActivePermanents(filter, source.getFirstTarget(), source.getSourceId(), game)) {
        if (tap) {
            permanent.tap(source, game);
        } else {
            permanent.untap(game);
        }
    }
    return true;
}
Also used : TargetPlayer(mage.target.TargetPlayer) Player(mage.players.Player) Choice(mage.choices.Choice) FilterPermanent(mage.filter.FilterPermanent) FilterPermanent(mage.filter.FilterPermanent) Permanent(mage.game.permanent.Permanent) ChoiceImpl(mage.choices.ChoiceImpl)

Example 44 with ChoiceImpl

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

the class TundraKavuEffect method init.

@Override
public void init(Ability source, Game game) {
    landTypes.clear();
    Player controller = game.getPlayer(source.getControllerId());
    if (controller != null) {
        Set<String> choiceSet = new LinkedHashSet<>();
        choiceSet.add("Island");
        choiceSet.add("Plains");
        ChoiceImpl choice = new ChoiceImpl(true, ChoiceHintType.CARD);
        choice.setChoices(choiceSet);
        choice.setMessage("Choose a basic land type");
        if (!controller.choose(outcome, choice, game)) {
            discard();
            return;
        }
        landTypes.add(SubType.byDescription(choice.getChoice()));
    } else {
        this.discard();
    }
    super.init(source, game);
}
Also used : LinkedHashSet(java.util.LinkedHashSet) Player(mage.players.Player) ChoiceImpl(mage.choices.ChoiceImpl)

Example 45 with ChoiceImpl

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

the class RemoveCounterCost 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);
    if (controller != null) {
        if (countersToRemove == 0) {
            // Can happen when used for X costs where X = 0;
            return paid = true;
        }
        target.clearChosen();
        if (target.choose(Outcome.UnboostCreature, controllerId, source.getSourceId(), game)) {
            for (UUID targetId : target.getTargets()) {
                Permanent permanent = game.getPermanent(targetId);
                if (permanent != null) {
                    if (!permanent.getCounters(game).isEmpty() && (counterTypeToRemove == null || permanent.getCounters(game).containsKey(counterTypeToRemove))) {
                        String counterName = null;
                        if (counterTypeToRemove != null) {
                            counterName = counterTypeToRemove.getName();
                        } else if (permanent.getCounters(game).size() > 1 && counterTypeToRemove == null) {
                            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 && !counterName.isEmpty()) {
                            int countersLeft = countersToRemove - countersRemoved;
                            int countersOnPermanent = permanent.getCounters(game).getCount(counterName);
                            int numberOfCountersSelected = 1;
                            if (countersLeft > 1 && countersOnPermanent > 1) {
                                numberOfCountersSelected = controller.getAmount(1, Math.min(countersLeft, countersOnPermanent), new StringBuilder("Remove how many counters from ").append(permanent.getIdName()).toString(), game);
                            }
                            permanent.removeCounters(counterName, numberOfCountersSelected, source, game);
                            countersRemoved += numberOfCountersSelected;
                            if (!game.isSimulation()) {
                                game.informPlayers(new StringBuilder(controller.getLogName()).append(" removes ").append(numberOfCountersSelected == 1 ? "a" : numberOfCountersSelected).append(' ').append(counterName).append(numberOfCountersSelected == 1 ? " counter from " : " counters from ").append(permanent.getName()).toString());
                            }
                            if (countersRemoved == countersToRemove) {
                                this.paid = true;
                                break;
                            }
                        }
                    }
                }
            }
        }
    }
    return paid;
}
Also used : Player(mage.players.Player) Choice(mage.choices.Choice) Set(java.util.Set) HashSet(java.util.HashSet) Counter(mage.counters.Counter) Permanent(mage.game.permanent.Permanent) TargetPermanent(mage.target.TargetPermanent) ChoiceImpl(mage.choices.ChoiceImpl) UUID(java.util.UUID)

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