Search in sources :

Example 51 with ChoiceImpl

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

the class ShiftingCeratopsEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player player = game.getPlayer(source.getControllerId());
    if (player == null) {
        return false;
    }
    Choice choice = new ChoiceImpl(true);
    choice.setMessage("Choose an ability");
    choice.setChoices(choices);
    if (!player.choose(outcome, choice, game)) {
        return false;
    }
    Ability ability = null;
    switch(choice.getChoice()) {
        case "Reach":
            ability = ReachAbility.getInstance();
            break;
        case "Trample":
            ability = TrampleAbility.getInstance();
            break;
        case "Haste":
            ability = HasteAbility.getInstance();
            break;
    }
    if (ability != null) {
        game.addEffect(new GainAbilitySourceEffect(ability, Duration.EndOfTurn), source);
    }
    return true;
}
Also used : HasteAbility(mage.abilities.keyword.HasteAbility) CantBeCounteredSourceAbility(mage.abilities.common.CantBeCounteredSourceAbility) SimpleActivatedAbility(mage.abilities.common.SimpleActivatedAbility) ReachAbility(mage.abilities.keyword.ReachAbility) TrampleAbility(mage.abilities.keyword.TrampleAbility) ProtectionAbility(mage.abilities.keyword.ProtectionAbility) Ability(mage.abilities.Ability) Player(mage.players.Player) Choice(mage.choices.Choice) GainAbilitySourceEffect(mage.abilities.effects.common.continuous.GainAbilitySourceEffect) ChoiceImpl(mage.choices.ChoiceImpl)

Example 52 with ChoiceImpl

use of mage.choices.ChoiceImpl 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 53 with ChoiceImpl

use of mage.choices.ChoiceImpl 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 54 with ChoiceImpl

use of mage.choices.ChoiceImpl 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 55 with ChoiceImpl

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

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