Search in sources :

Example 76 with Choice

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

the class SphinxAmbassadorEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    Player targetPlayer = game.getPlayer(targetPointer.getFirst(game, source));
    Permanent sourcePermanent = game.getPermanentOrLKIBattlefield(source.getSourceId());
    if (controller != null && targetPlayer != null && sourcePermanent != null) {
        TargetCardInLibrary target = new TargetCardInLibrary();
        controller.searchLibrary(target, source, game, targetPlayer.getId());
        Card card = game.getCard(target.getFirstTarget());
        if (card != null) {
            TreeSet<String> choices = new TreeSet<>();
            Collection<Card> cards = game.getCards();
            for (Card gameCard : cards) {
                if (gameCard.isOwnedBy(targetPlayer.getId())) {
                    choices.add(gameCard.getName());
                }
            }
            Choice cardChoice = new ChoiceImpl(false, ChoiceHintType.CARD);
            cardChoice.setChoices(choices);
            cardChoice.clearChoice();
            if (!targetPlayer.choose(Outcome.Benefit, cardChoice, game)) {
                return false;
            }
            String cardName = cardChoice.getChoice();
            game.informPlayers(sourcePermanent.getName() + ", named card: [" + cardName + ']');
            if (!card.getName().equals(cardName) && card.isCreature(game)) {
                if (controller.chooseUse(outcome, "Put " + card.getName() + " onto the battlefield?", source, game)) {
                    controller.moveCards(card, Zone.BATTLEFIELD, source, game);
                }
            }
        }
        targetPlayer.shuffleLibrary(source, game);
        return true;
    }
    return false;
}
Also used : Player(mage.players.Player) Choice(mage.choices.Choice) Permanent(mage.game.permanent.Permanent) TreeSet(java.util.TreeSet) ChoiceImpl(mage.choices.ChoiceImpl) TargetCardInLibrary(mage.target.common.TargetCardInLibrary) Card(mage.cards.Card)

Example 77 with Choice

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

the class VeteranWarleaderEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    MageObject sourceObject = game.getObject(source.getSourceId());
    if (sourceObject != null && controller != null) {
        Choice abilityChoice = new ChoiceImpl();
        abilityChoice.setMessage("Choose an ability to add");
        Set<String> abilities = new HashSet<>();
        abilities.add(FirstStrikeAbility.getInstance().getRule());
        abilities.add(VigilanceAbility.getInstance().getRule());
        abilities.add(TrampleAbility.getInstance().getRule());
        abilityChoice.setChoices(abilities);
        if (!controller.choose(Outcome.AddAbility, abilityChoice, game)) {
            return false;
        }
        String chosen = abilityChoice.getChoice();
        Ability ability = null;
        if (FirstStrikeAbility.getInstance().getRule().equals(chosen)) {
            ability = FirstStrikeAbility.getInstance();
        } else if (VigilanceAbility.getInstance().getRule().equals(chosen)) {
            ability = VigilanceAbility.getInstance();
        } else if (TrampleAbility.getInstance().getRule().equals(chosen)) {
            ability = TrampleAbility.getInstance();
        }
        if (ability != null) {
            game.informPlayers(sourceObject.getLogName() + ": " + controller.getLogName() + " has chosen: " + chosen);
            ContinuousEffect effect = new GainAbilitySourceEffect(ability, Duration.EndOfTurn);
            game.addEffect(effect, source);
            return true;
        }
    }
    return false;
}
Also used : SimpleStaticAbility(mage.abilities.common.SimpleStaticAbility) VigilanceAbility(mage.abilities.keyword.VigilanceAbility) FirstStrikeAbility(mage.abilities.keyword.FirstStrikeAbility) 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) MageObject(mage.MageObject) ChoiceImpl(mage.choices.ChoiceImpl) ContinuousEffect(mage.abilities.effects.ContinuousEffect) HashSet(java.util.HashSet)

Example 78 with Choice

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

the class VigeanIntuitionEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    MageObject sourceObject = game.getObject(source.getSourceId());
    Player player = game.getPlayer(source.getControllerId());
    if (sourceObject == null || player == null) {
        return false;
    }
    Library library = player.getLibrary();
    if (library == null) {
        return false;
    }
    Choice choiceImpl = new ChoiceImpl();
    choiceImpl.setChoices(choice);
    if (player.choose(Outcome.Neutral, choiceImpl, game)) {
        String choosenType = choiceImpl.getChoice();
        if (choosenType == null || choosenType.isEmpty()) {
            return false;
        }
        CardType type = null;
        if (choosenType.equals(CardType.ARTIFACT.toString())) {
            type = CardType.ARTIFACT;
        } else if (choosenType.equals(CardType.LAND.toString())) {
            type = CardType.LAND;
        } else if (choosenType.equals(CardType.CREATURE.toString())) {
            type = CardType.CREATURE;
        } else if (choosenType.equals(CardType.ENCHANTMENT.toString())) {
            type = CardType.ENCHANTMENT;
        } else if (choosenType.equals(CardType.INSTANT.toString())) {
            type = CardType.INSTANT;
        } else if (choosenType.equals(CardType.SORCERY.toString())) {
            type = CardType.SORCERY;
        } else if (choosenType.equals(CardType.PLANESWALKER.toString())) {
            type = CardType.PLANESWALKER;
        } else if (choosenType.equals(CardType.TRIBAL.toString())) {
            type = CardType.TRIBAL;
        }
        if (type != null) {
            Set<Card> top = library.getTopCards(game, 4);
            player.revealCards(source, new CardsImpl(top), game);
            Cards putInHand = new CardsImpl();
            Cards putInGraveyard = new CardsImpl();
            for (Card card : top) {
                if (card != null && card.getCardType(game).contains(type)) {
                    putInHand.add(card);
                } else {
                    putInGraveyard.add(card);
                }
            }
            player.moveCards(putInHand, Zone.HAND, source, game);
            player.moveCards(putInGraveyard, Zone.GRAVEYARD, source, game);
            return true;
        }
    }
    return false;
}
Also used : Player(mage.players.Player) Choice(mage.choices.Choice) CardType(mage.constants.CardType) MageObject(mage.MageObject) ChoiceImpl(mage.choices.ChoiceImpl) Library(mage.players.Library)

Example 79 with Choice

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

the class DraftFromSpellbookEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player player = game.getPlayer(source.getControllerId());
    if (player == null) {
        return false;
    }
    Set<String> toSelect = new HashSet<>();
    while (toSelect.size() < 3) {
        toSelect.add(RandomUtil.randomFromCollection(spellbook));
    }
    Choice choice = new ChoiceImpl(true, ChoiceHintType.CARD);
    choice.setMessage("Choose a card to draft");
    choice.setChoices(toSelect);
    player.choose(outcome, choice, game);
    String cardName = choice.getChoice();
    if (cardName == null) {
        return false;
    }
    CardInfo cardInfo = CardRepository.instance.findCards(new CardCriteria().nameExact(cardName)).stream().findFirst().orElse(null);
    if (cardInfo == null) {
        return false;
    }
    Set<Card> cards = new HashSet<>();
    cards.add(cardInfo.getCard());
    game.loadCards(cards, player.getId());
    player.moveCards(cards, Zone.HAND, source, game);
    return true;
}
Also used : Player(mage.players.Player) Choice(mage.choices.Choice) CardCriteria(mage.cards.repository.CardCriteria) ChoiceImpl(mage.choices.ChoiceImpl) CardInfo(mage.cards.repository.CardInfo) HashSet(java.util.HashSet) Card(mage.cards.Card)

Example 80 with Choice

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

the class AnyColorLandsProduceManaEffect method produceMana.

@Override
public Mana produceMana(Game game, Ability source) {
    Mana mana = new Mana();
    if (game == null) {
        return mana;
    }
    Choice choice = ManaType.getChoiceOfManaTypes(getManaTypes(game, source), onlyColors);
    if (!choice.getChoices().isEmpty()) {
        Player player = game.getPlayer(source.getControllerId());
        if (choice.getChoices().size() == 1) {
            choice.setChoice(choice.getChoices().iterator().next());
        } else {
            if (player == null || !player.choose(outcome, choice, game)) {
                return null;
            }
        }
        if (choice.getChoice() != null) {
            switch(choice.getChoice()) {
                case "Black":
                    mana.setBlack(1);
                    break;
                case "Blue":
                    mana.setBlue(1);
                    break;
                case "Red":
                    mana.setRed(1);
                    break;
                case "Green":
                    mana.setGreen(1);
                    break;
                case "White":
                    mana.setWhite(1);
                    break;
                case "Colorless":
                    mana.setColorless(1);
                    break;
            }
        }
    }
    return mana;
}
Also used : Player(mage.players.Player) Mana(mage.Mana) Choice(mage.choices.Choice)

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