Search in sources :

Example 61 with ChoiceImpl

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

the class GrimdancerEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player player = game.getPlayer(source.getControllerId());
    Permanent permanent = game.getPermanentEntering(source.getSourceId());
    if (player == null || permanent == null) {
        return false;
    }
    Choice choice = new ChoiceImpl(true);
    choice.setMessage("Choose two abilities");
    choice.setChoices(choices);
    if (!player.choose(outcome, choice, game)) {
        return false;
    }
    Counter counter1 = null;
    Counter counter2 = null;
    switch(choice.getChoice()) {
        case "Menace and deathtouch":
            counter1 = CounterType.MENACE.createInstance();
            counter2 = CounterType.DEATHTOUCH.createInstance();
            break;
        case "Menace and lifelink":
            counter1 = CounterType.MENACE.createInstance();
            counter2 = CounterType.LIFELINK.createInstance();
            break;
        case "Deathtouch and lifelink":
            counter1 = CounterType.DEATHTOUCH.createInstance();
            counter2 = CounterType.LIFELINK.createInstance();
            break;
    }
    permanent.addCounters(counter1, source.getControllerId(), source, game);
    permanent.addCounters(counter2, source.getControllerId(), source, game);
    return true;
}
Also used : Player(mage.players.Player) Choice(mage.choices.Choice) Counter(mage.counters.Counter) Permanent(mage.game.permanent.Permanent) ChoiceImpl(mage.choices.ChoiceImpl)

Example 62 with ChoiceImpl

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

the class MindblazeEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player player = game.getPlayer(targetPointer.getFirst(game, source));
    Player playerControls = game.getPlayer(source.getControllerId());
    MageObject sourceObject = source.getSourceObject(game);
    if (player == null || playerControls == null || sourceObject == null) {
        return false;
    }
    Choice numberChoice = new ChoiceImpl();
    numberChoice.setMessage("Choose a number greater than 0");
    Set<String> numbers = new HashSet<>();
    for (int i = 1; i <= 4; i++) {
        numbers.add(Integer.toString(i));
    }
    numberChoice.setChoices(numbers);
    String cardName = ChooseACardNameEffect.TypeOfName.NON_LAND_NAME.getChoice(playerControls, game, source, false);
    playerControls.choose(Outcome.Neutral, numberChoice, game);
    game.informPlayers(sourceObject.getIdName() + " - Chosen number: [" + numberChoice.getChoice() + ']');
    Cards cards = new CardsImpl();
    cards.addAll(player.getLibrary().getCards(game));
    playerControls.revealCards("Library", cards, game);
    FilterCard filter = new FilterCard();
    filter.add(new NamePredicate(cardName));
    int count = Integer.parseInt(numberChoice.getChoice());
    if (player.getLibrary().count(filter, game) == count) {
        player.damage(8, source.getSourceId(), source, game);
    }
    player.shuffleLibrary(source, game);
    return true;
}
Also used : FilterCard(mage.filter.FilterCard) TargetPlayer(mage.target.TargetPlayer) Player(mage.players.Player) NamePredicate(mage.filter.predicate.mageobject.NamePredicate) Choice(mage.choices.Choice) MageObject(mage.MageObject) ChoiceImpl(mage.choices.ChoiceImpl) Cards(mage.cards.Cards) CardsImpl(mage.cards.CardsImpl) HashSet(java.util.HashSet)

Example 63 with ChoiceImpl

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

the class StaffOfTheLetterMagusEffect 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<>();
    // Can I choose Y?
    // Yes. We play by popular game show rules here. Y is a consonant.
    // https://magic.wizards.com/en/articles/archive/news/unstable-faqawaslfaqpaftidawabiajtbt-2017-12-06
    Character[] forbiddenChars = { 'A', 'E', 'I', 'N', 'O', 'R', 'S', 'T', 'U' };
    for (Character letter = 'A'; letter <= 'Z'; letter++) {
        if (Arrays.binarySearch(forbiddenChars, letter) < 0) {
            choices.add(letter.toString());
        }
    }
    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) Permanent(mage.game.permanent.Permanent) MageObject(mage.MageObject) ChoiceImpl(mage.choices.ChoiceImpl) HashSet(java.util.HashSet)

Example 64 with ChoiceImpl

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

the class TergridsLaternEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player targetedPlayer = game.getPlayer(source.getTargets().getFirstTarget());
    if (targetedPlayer == null) {
        return false;
    }
    // AI hint to discard/sacrifice before die
    Outcome aiOutcome = (targetedPlayer.getLife() <= 3 * 2) ? Outcome.Benefit : Outcome.Detriment;
    Set<String> choiceSet = new HashSet<>();
    if (game.getBattlefield().count(StaticFilters.FILTER_CONTROLLED_PERMANENT_NON_LAND, source.getSourceId(), targetedPlayer.getId(), game) > 0) {
        choiceSet.add(SACRIFICE_CHOICE);
    }
    if (targetedPlayer.getHand().size() > 0) {
        choiceSet.add(DISCARD_CHOICE);
    }
    choiceSet.add(LIFE_LOSS_CHOICE);
    String chosen;
    if (choiceSet.size() > 1) {
        Choice choice = new ChoiceImpl(true);
        choice.setChoices(choiceSet);
        targetedPlayer.choose(aiOutcome, choice, game);
        chosen = choice.getChoice();
        if (chosen == null) {
            // on disconnect
            chosen = LIFE_LOSS_CHOICE;
        }
    } else {
        chosen = LIFE_LOSS_CHOICE;
    }
    switch(chosen) {
        case SACRIFICE_CHOICE:
            TargetPermanent target = new TargetPermanent(StaticFilters.FILTER_CONTROLLED_PERMANENT_NON_LAND);
            target.setNotTarget(true);
            targetedPlayer.choose(Outcome.Sacrifice, target, source.getSourceId(), game);
            Permanent chosenLand = game.getPermanent(target.getFirstTarget());
            return chosenLand != null && chosenLand.sacrifice(source, game);
        case DISCARD_CHOICE:
            return targetedPlayer.discard(1, false, false, source, game).size() > 0;
        case LIFE_LOSS_CHOICE:
            return targetedPlayer.loseLife(3, game, source, false) > 0;
    }
    return false;
}
Also used : Player(mage.players.Player) TargetPlayer(mage.target.TargetPlayer) Choice(mage.choices.Choice) Permanent(mage.game.permanent.Permanent) TargetPermanent(mage.target.TargetPermanent) ChoiceImpl(mage.choices.ChoiceImpl) TargetPermanent(mage.target.TargetPermanent) HashSet(java.util.HashSet)

Example 65 with ChoiceImpl

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

the class UrzasAvengerEffect 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 "Banding":
                    gainedAbility = BandingAbility.getInstance();
                    break;
                case "Flying":
                    gainedAbility = FlyingAbility.getInstance();
                    break;
                case "First strike":
                    gainedAbility = FirstStrikeAbility.getInstance();
                    break;
                default:
                    gainedAbility = TrampleAbility.getInstance();
                    break;
            }
        }
    }
}
Also used : Player(mage.players.Player) Choice(mage.choices.Choice) 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