Search in sources :

Example 31 with ChoiceImpl

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

the class DwarvenArmorerEffect 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 type of counter to add");
        choice.setChoices(choices);
        if (controller.choose(outcome, choice, game)) {
            Counter counter = choice.getChoice().equals("+0/+1") ? CounterType.P0P1.createInstance() : CounterType.P1P0.createInstance();
            Effect effect = new AddCountersTargetEffect(counter);
            effect.setTargetPointer(new FixedTarget(this.getTargetPointer().getFirst(game, source), game));
            return effect.apply(game, source);
        }
    }
    return false;
}
Also used : FixedTarget(mage.target.targetpointer.FixedTarget) Player(mage.players.Player) Choice(mage.choices.Choice) Counter(mage.counters.Counter) ChoiceImpl(mage.choices.ChoiceImpl) AddCountersTargetEffect(mage.abilities.effects.common.counter.AddCountersTargetEffect) OneShotEffect(mage.abilities.effects.OneShotEffect) Effect(mage.abilities.effects.Effect) AddCountersTargetEffect(mage.abilities.effects.common.counter.AddCountersTargetEffect)

Example 32 with ChoiceImpl

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

the class GrandWarlordRadhaEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    if (controller != null) {
        CreaturesAttackedWatcher watcher = game.getState().getWatcher(CreaturesAttackedWatcher.class);
        if (watcher != null) {
            int attackingCreatures = 0;
            for (MageObjectReference attacker : watcher.getAttackedThisTurnCreatures()) {
                if (attacker.getPermanentOrLKIBattlefield(game).isControlledBy(controller.getId())) {
                    attackingCreatures++;
                }
            }
            if (attackingCreatures > 0) {
                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 < attackingCreatures; i++) {
                    Mana mana = new Mana();
                    if (!controller.choose(Outcome.Benefit, manaChoice, game)) {
                        return false;
                    }
                    if (manaChoice.getChoice() == null) {
                        // can happen if player leaves game
                        return false;
                    }
                    switch(manaChoice.getChoice()) {
                        case "Green":
                            mana.increaseGreen();
                            break;
                        case "Red":
                            mana.increaseRed();
                            break;
                    }
                    controller.getManaPool().addMana(mana, game, source, true);
                }
                return true;
            }
            return true;
        }
    }
    return false;
}
Also used : LinkedHashSet(java.util.LinkedHashSet) Player(mage.players.Player) Choice(mage.choices.Choice) Mana(mage.Mana) ChoiceImpl(mage.choices.ChoiceImpl) MageObjectReference(mage.MageObjectReference)

Example 33 with ChoiceImpl

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

the class LeechBonderEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    Permanent fromPermanent = game.getPermanent(source.getFirstTarget());
    Permanent toPermanent = game.getPermanent(source.getTargets().get(1).getFirstTarget());
    if (fromPermanent == null || toPermanent == null || controller == null) {
        return false;
    }
    Set<String> possibleChoices = new HashSet<>(fromPermanent.getCounters(game).keySet());
    if (possibleChoices.size() == 0) {
        return false;
    }
    Choice choice = new ChoiceImpl();
    choice.setChoices(possibleChoices);
    if (controller.choose(outcome, choice, game)) {
        String chosen = choice.getChoice();
        if (fromPermanent.getCounters(game).containsKey(chosen)) {
            CounterType counterType = CounterType.findByName(chosen);
            if (counterType != null) {
                Counter counter = counterType.createInstance();
                fromPermanent.removeCounters(counterType.getName(), 1, source, game);
                toPermanent.addCounters(counter, source.getControllerId(), source, game);
                return true;
            }
        }
    }
    return false;
}
Also used : Player(mage.players.Player) Choice(mage.choices.Choice) CounterType(mage.counters.CounterType) Counter(mage.counters.Counter) FilterCreaturePermanent(mage.filter.common.FilterCreaturePermanent) Permanent(mage.game.permanent.Permanent) TargetCreaturePermanent(mage.target.common.TargetCreaturePermanent) ChoiceImpl(mage.choices.ChoiceImpl) HashSet(java.util.HashSet)

Example 34 with ChoiceImpl

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

the class LavabrinkFloodgatesEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player player = game.getPlayer(game.getActivePlayerId());
    Permanent permanent = game.getPermanent(source.getSourceId());
    if (player == null || permanent == null) {
        return false;
    }
    Choice choice = new ChoiceImpl();
    choice.setChoices(new HashSet(Arrays.asList("Add a doom counter", "Remove a doom counter", "Do nothing")));
    player.choose(outcome, choice, game);
    switch(choice.getChoice()) {
        case "Add a doom counter":
            permanent.addCounters(CounterType.DOOM.createInstance(), player.getId(), source, game);
            break;
        case "Remove a doom counter":
            permanent.removeCounters(CounterType.DOOM.createInstance(), source, game);
            break;
        case "Do nothing":
        default:
            break;
    }
    if (permanent.getCounters(game).getCount(CounterType.DOOM) < 3 || !permanent.sacrifice(source, game)) {
        return true;
    }
    game.fireReflexiveTriggeredAbility(new ReflexiveTriggeredAbility(new DamageAllEffect(6, StaticFilters.FILTER_PERMANENT_CREATURE), false, "it deals 6 damage to each creature."), source);
    return true;
}
Also used : Player(mage.players.Player) Choice(mage.choices.Choice) Permanent(mage.game.permanent.Permanent) DamageAllEffect(mage.abilities.effects.common.DamageAllEffect) ReflexiveTriggeredAbility(mage.abilities.common.delayed.ReflexiveTriggeredAbility) ChoiceImpl(mage.choices.ChoiceImpl) HashSet(java.util.HashSet)

Example 35 with ChoiceImpl

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

the class ManaforgeCinderManaEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    if (controller != null) {
        Choice manaChoice = new ChoiceImpl();
        Set<String> choices = new LinkedHashSet<>();
        choices.add("Black");
        choices.add("Red");
        manaChoice.setChoices(choices);
        manaChoice.setMessage("Select black or red mana to add");
        Mana mana = new Mana();
        if (!controller.choose(Outcome.Benefit, manaChoice, game)) {
            return false;
        }
        if (manaChoice.getChoice() == null) {
            return false;
        }
        switch(manaChoice.getChoice()) {
            case "Black":
                mana.increaseBlack();
                break;
            case "Red":
                mana.increaseRed();
                break;
        }
        controller.getManaPool().addMana(mana, game, source);
        return true;
    }
    return false;
}
Also used : LinkedHashSet(java.util.LinkedHashSet) Player(mage.players.Player) Choice(mage.choices.Choice) Mana(mage.Mana) 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