Search in sources :

Example 11 with ChoiceImpl

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

the class ChooseBasicLandTypeEffect 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) {
        ChoiceImpl choices = new ChoiceBasicLandType();
        if (controller.choose(Outcome.Neutral, choices, game)) {
            game.informPlayers(mageObject.getName() + ":  Chosen basic land type is " + choices.getChoice());
            game.getState().setValue(mageObject.getId().toString() + VALUE_KEY, choices.getChoice());
            if (mageObject instanceof Permanent) {
                ((Permanent) mageObject).addInfo("chosen color", CardUtil.addToolTipMarkTags("Chosen basic land type: " + choices.getChoice()), game);
            }
            return true;
        }
    }
    return false;
}
Also used : Player(mage.players.Player) Permanent(mage.game.permanent.Permanent) MageObject(mage.MageObject) ChoiceImpl(mage.choices.ChoiceImpl) ChoiceBasicLandType(mage.choices.ChoiceBasicLandType)

Example 12 with ChoiceImpl

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

the class LoseAbilityOrAnotherAbilityTargetEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Permanent permanent = game.getPermanent(source.getFirstTarget());
    if (permanent != null) {
        ChoiceImpl chooseAbility = new ChoiceImpl();
        chooseAbility.setMessage("Choose an ability to remove");
        Set<String> choice = new HashSet<>();
        if (permanent.getAbilities().contains(ability)) {
            choice.add(ability.getRule());
        }
        if (permanent.getAbilities().contains(ability2)) {
            choice.add(ability2.getRule());
        }
        chooseAbility.setChoices(choice);
        Player player = game.getPlayer(source.getControllerId());
        if (player.choose(outcome, chooseAbility, game)) {
            String chosenAbility = chooseAbility.getChoice();
            if (chosenAbility.equals(ability.getRule())) {
                permanent.removeAbility(ability, source.getSourceId(), game);
            } else if (chosenAbility.equals(ability2.getRule())) {
                permanent.removeAbility(ability2, source.getSourceId(), game);
            }
        } else {
            return false;
        }
    }
    return true;
}
Also used : Player(mage.players.Player) Permanent(mage.game.permanent.Permanent) ChoiceImpl(mage.choices.ChoiceImpl) HashSet(java.util.HashSet)

Example 13 with ChoiceImpl

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

the class RemoveCounterTargetEffect 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<>();
            for (Counter counterOnPermanent : permanent.getCounters(game).values()) {
                if (permanent.getCounters(game).getCount(counterOnPermanent.getName()) > 0) {
                    choices.add(counterOnPermanent.getName());
                }
            }
            choice.setChoices(choices);
            choice.setMessage("Choose a counter type to remove from " + permanent.getName());
            if (controller.choose(Outcome.Detriment, choice, game)) {
                counterName = choice.getChoice();
            } else {
                return null;
            }
        } else {
            for (Counter counterOnPermanent : permanent.getCounters(game).values()) {
                if (counterOnPermanent.getCount() > 0) {
                    counterName = counterOnPermanent.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 14 with ChoiceImpl

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

the class MonkeyMonkeyMonkeyCount 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());
    }
    ChoiceImpl choice = new ChoiceImpl(true);
    choice.setMessage("Choose letter");
    Set<String> choices = new HashSet<>();
    for (char letter = 'A'; letter <= 'Z'; letter++) {
        choices.add(Character.toString(letter));
    }
    choice.setChoices(choices);
    if (controller != null && mageObject != null && controller.choose(outcome, choice, game)) {
        if (!game.isSimulation()) {
            game.informPlayers(mageObject.getLogName() + ": " + controller.getLogName() + " has chosen " + choice.getChoice());
        }
        game.getState().setValue(mageObject.getId() + "_letter", choice.getChoice());
        if (mageObject instanceof Permanent) {
            ((Permanent) mageObject).addInfo("chosen letter", CardUtil.addToolTipMarkTags("Chosen letter: " + choice.getChoice()), game);
        }
        return true;
    }
    return false;
}
Also used : Player(mage.players.Player) FilterNonlandPermanent(mage.filter.common.FilterNonlandPermanent) Permanent(mage.game.permanent.Permanent) MageObject(mage.MageObject) ChoiceImpl(mage.choices.ChoiceImpl) HashSet(java.util.HashSet)

Example 15 with ChoiceImpl

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

the class NaturesBlessingEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    Permanent targetPermanent = game.getPermanent(this.getTargetPointer().getFirst(game, source));
    if (controller != null && targetPermanent != null) {
        Choice choice = new ChoiceImpl(true);
        choice.setMessage("Choose one");
        choice.setChoices(choices);
        if (controller.choose(outcome, choice, game)) {
            switch(choice.getChoice()) {
                case "Banding":
                    gainedAbility = BandingAbility.getInstance();
                    break;
                case "First strike":
                    gainedAbility = FirstStrikeAbility.getInstance();
                    break;
                case "Trample":
                    gainedAbility = TrampleAbility.getInstance();
            }
        }
        if (gainedAbility != null) {
            game.addEffect(new GainAbilityTargetEffect(gainedAbility, Duration.Custom), source);
        } else {
            targetPermanent.addCounters(CounterType.P1P1.createInstance(), source.getControllerId(), source, game);
            game.informPlayers(controller.getLogName() + " puts a +1/+1 counter on " + targetPermanent.getLogName());
        }
        return true;
    }
    return false;
}
Also used : Player(mage.players.Player) Choice(mage.choices.Choice) Permanent(mage.game.permanent.Permanent) TargetCreaturePermanent(mage.target.common.TargetCreaturePermanent) GainAbilityTargetEffect(mage.abilities.effects.common.continuous.GainAbilityTargetEffect) 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