Search in sources :

Example 66 with Choice

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

the class TsabosDecreeEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player player = game.getPlayer(source.getControllerId());
    Player targetPlayer = game.getPlayer(targetPointer.getFirst(game, source));
    MageObject sourceObject = game.getObject(source.getSourceId());
    if (player == null) {
        return false;
    }
    if (sourceObject == null) {
        return false;
    }
    Choice typeChoice = new ChoiceCreatureType(sourceObject);
    if (!player.choose(outcome, typeChoice, game)) {
        return false;
    }
    game.informPlayers(sourceObject.getLogName() + " chosen type: " + typeChoice.getChoice());
    targetPlayer.revealCards("hand of " + targetPlayer.getName(), targetPlayer.getHand(), game);
    FilterCard filterCard = new FilterCard();
    filterCard.add(SubType.byDescription(typeChoice.getChoice()).getPredicate());
    targetPlayer.discard(new CardsImpl(targetPlayer.getHand().getCards(filterCard, game)), false, source, game);
    FilterCreaturePermanent filterCreaturePermanent = new FilterCreaturePermanent();
    filterCreaturePermanent.add(SubType.byDescription(typeChoice.getChoice()).getPredicate());
    for (Permanent creature : game.getBattlefield().getActivePermanents(filterCreaturePermanent, source.getSourceId(), game)) {
        if (creature.isControlledBy(targetPlayer.getId())) {
            creature.destroy(source, game, true);
        }
    }
    return true;
}
Also used : FilterCard(mage.filter.FilterCard) TargetPlayer(mage.target.TargetPlayer) Player(mage.players.Player) Choice(mage.choices.Choice) FilterCreaturePermanent(mage.filter.common.FilterCreaturePermanent) Permanent(mage.game.permanent.Permanent) FilterCreaturePermanent(mage.filter.common.FilterCreaturePermanent) MageObject(mage.MageObject) ChoiceCreatureType(mage.choices.ChoiceCreatureType) CardsImpl(mage.cards.CardsImpl)

Example 67 with Choice

use of mage.choices.Choice 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)

Example 68 with Choice

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

the class ConvokeEffect method buildChoice.

private Choice buildChoice(ObjectColor creatureColor, Mana mana) {
    Choice choice = new ChoiceColor();
    choice.getChoices().clear();
    if (creatureColor.isBlack() && mana.getBlack() > 0) {
        choice.getChoices().add("Black");
    }
    if (creatureColor.isBlue() && mana.getBlue() > 0) {
        choice.getChoices().add("Blue");
    }
    if (creatureColor.isGreen() && mana.getGreen() > 0) {
        choice.getChoices().add("Green");
    }
    if (creatureColor.isRed() && mana.getRed() > 0) {
        choice.getChoices().add("Red");
    }
    if (creatureColor.isWhite() && mana.getWhite() > 0) {
        choice.getChoices().add("White");
    }
    return choice;
}
Also used : Choice(mage.choices.Choice) ChoiceColor(mage.choices.ChoiceColor)

Example 69 with Choice

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

the class FlowstoneSculptureEffect 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 ability to add");
        choice.setChoices(choices);
        if (!controller.choose(outcome, choice, game)) {
            return false;
        }
        String chosen = choice.getChoice();
        if (chosen.equals("+1/+1 counter")) {
            return new AddCountersSourceEffect(CounterType.P1P1.createInstance()).apply(game, source);
        } else {
            Ability gainedAbility;
            switch(chosen) {
                case "Flying":
                    gainedAbility = FlyingAbility.getInstance();
                    break;
                case "First strike":
                    gainedAbility = FirstStrikeAbility.getInstance();
                    break;
                default:
                    gainedAbility = TrampleAbility.getInstance();
                    break;
            }
            game.addEffect(new GainAbilitySourceEffect(gainedAbility, Duration.WhileOnBattlefield), source);
            return true;
        }
    }
    return false;
}
Also used : AddCountersSourceEffect(mage.abilities.effects.common.counter.AddCountersSourceEffect) FirstStrikeAbility(mage.abilities.keyword.FirstStrikeAbility) FlyingAbility(mage.abilities.keyword.FlyingAbility) SimpleActivatedAbility(mage.abilities.common.SimpleActivatedAbility) TrampleAbility(mage.abilities.keyword.TrampleAbility) Ability(mage.abilities.Ability) Player(mage.players.Player) Choice(mage.choices.Choice) GainAbilitySourceEffect(mage.abilities.effects.common.continuous.GainAbilitySourceEffect) ChoiceImpl(mage.choices.ChoiceImpl)

Example 70 with Choice

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

the class InvokeTheAncientsEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player player = game.getPlayer(source.getControllerId());
    if (player == null) {
        return false;
    }
    token.putOntoBattlefield(2, game, source, source.getControllerId());
    for (UUID tokenId : token.getLastAddedTokenIds()) {
        Permanent permanent = game.getPermanent(tokenId);
        if (permanent == null) {
            continue;
        }
        Choice choice = new ChoiceImpl(true);
        choice.setMessage("Choose vigilance, reach, or trample counter");
        choice.setChoices(choices);
        player.choose(outcome, choice, game);
        String chosen = choice.getChoice();
        if (chosen != null) {
            permanent.addCounters(CounterType.findByName(chosen.toLowerCase(Locale.ENGLISH)).createInstance(), source.getControllerId(), source, game);
        }
    }
    return true;
}
Also used : Player(mage.players.Player) Choice(mage.choices.Choice) Permanent(mage.game.permanent.Permanent) ChoiceImpl(mage.choices.ChoiceImpl) UUID(java.util.UUID)

Aggregations

Choice (mage.choices.Choice)117 Player (mage.players.Player)114 ChoiceImpl (mage.choices.ChoiceImpl)67 Permanent (mage.game.permanent.Permanent)51 ChoiceCreatureType (mage.choices.ChoiceCreatureType)28 MageObject (mage.MageObject)27 Mana (mage.Mana)22 HashSet (java.util.HashSet)21 Card (mage.cards.Card)17 FilterCreaturePermanent (mage.filter.common.FilterCreaturePermanent)16 UUID (java.util.UUID)15 ContinuousEffect (mage.abilities.effects.ContinuousEffect)13 FilterPermanent (mage.filter.FilterPermanent)12 Ability (mage.abilities.Ability)10 ChoiceColor (mage.choices.ChoiceColor)10 Counter (mage.counters.Counter)10 TargetPermanent (mage.target.TargetPermanent)10 FilterCard (mage.filter.FilterCard)8 FixedTarget (mage.target.targetpointer.FixedTarget)8 CardType (mage.constants.CardType)7