Search in sources :

Example 26 with ChoiceImpl

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

the class GideonBlackbladeEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player player = game.getPlayer(source.getControllerId());
    Permanent permanent = game.getPermanent(source.getFirstTarget());
    if (player == null || permanent == null) {
        return false;
    }
    Choice choice = new ChoiceImpl(true);
    choice.setMessage("Choose an ability to give to " + permanent.getLogName());
    choice.setChoices(choices);
    if (!player.choose(outcome, choice, game)) {
        return false;
    }
    Ability ability = null;
    switch(choice.getChoice()) {
        case "Vigilance":
            ability = VigilanceAbility.getInstance();
            break;
        case "Lifelink":
            ability = LifelinkAbility.getInstance();
            break;
        case "Indestructible":
            ability = IndestructibleAbility.getInstance();
            break;
    }
    if (ability != null) {
        game.addEffect(new GainAbilityTargetEffect(ability, Duration.EndOfTurn), source);
    }
    return true;
}
Also used : IndestructibleAbility(mage.abilities.keyword.IndestructibleAbility) SimpleStaticAbility(mage.abilities.common.SimpleStaticAbility) LifelinkAbility(mage.abilities.keyword.LifelinkAbility) VigilanceAbility(mage.abilities.keyword.VigilanceAbility) LoyaltyAbility(mage.abilities.LoyaltyAbility) Ability(mage.abilities.Ability) Player(mage.players.Player) Choice(mage.choices.Choice) FilterPermanent(mage.filter.FilterPermanent) TargetNonlandPermanent(mage.target.common.TargetNonlandPermanent) FilterControlledCreaturePermanent(mage.filter.common.FilterControlledCreaturePermanent) Permanent(mage.game.permanent.Permanent) TargetPermanent(mage.target.TargetPermanent) GainAbilityTargetEffect(mage.abilities.effects.common.continuous.GainAbilityTargetEffect) ChoiceImpl(mage.choices.ChoiceImpl)

Example 27 with ChoiceImpl

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

the class ChooseTwoBasicLandTypesEffect 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());
    }
    if (controller != null && mageObject != null) {
        ChoiceImpl choices = new ChoiceBasicLandType();
        if (controller.choose(Outcome.Neutral, choices, game)) {
            game.informPlayers(mageObject.getName() + ":  First chosen basic land type is " + choices.getChoice());
            game.getState().setValue(mageObject.getId().toString() + "firstChoice", choices.getChoice());
            choiceOne = SubType.byDescription((String) game.getState().getValue(source.getSourceId().toString() + "firstChoice")).getDescription();
        }
        if (controller.choose(Outcome.Neutral, choices, game)) {
            game.informPlayers(mageObject.getName() + ":  Second chosen basic land type is " + choices.getChoice());
            game.getState().setValue(mageObject.getId().toString() + "secondChoice", choices.getChoice());
            choiceTwo = SubType.byDescription((String) game.getState().getValue(source.getSourceId().toString() + "secondChoice")).getDescription();
            if (mageObject instanceof Permanent && choiceOne != null && choiceTwo != null) {
                ((Permanent) mageObject).addInfo("Chosen Types", CardUtil.addToolTipMarkTags("First chosen basic land type: " + choiceOne + "\n Second chosen basic land type: " + choiceTwo), game);
            }
            return true;
        }
    }
    return false;
}
Also used : Player(mage.players.Player) Permanent(mage.game.permanent.Permanent) MageObject(mage.MageObject) ChoiceImpl(mage.choices.ChoiceImpl) ChoiceBasicLandType(mage.choices.ChoiceBasicLandType)

Example 28 with ChoiceImpl

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

the class RiteOfRuinEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    if (controller == null) {
        return false;
    }
    Set<String> choices = new HashSet<>();
    choices.add("Artifacts");
    choices.add("Creatures");
    choices.add("Lands");
    LinkedList<CardType> order = new LinkedList<>();
    ChoiceImpl choice = new ChoiceImpl(true);
    choice.setMessage("Choose a card type");
    choice.setChoices(choices);
    while (choices.size() > 1) {
        if (!controller.choose(Outcome.Sacrifice, choice, game)) {
            return false;
        }
        order.add(getCardType(choice.getChoice()));
        choices.remove(choice.getChoice());
        choice.clearChoice();
    }
    order.add(getCardType(choices.iterator().next()));
    int count = 1;
    for (CardType cardType : order) {
        FilterControlledPermanent filter = new FilterControlledPermanent(cardType + " you control");
        filter.add(cardType.getPredicate());
        new SacrificeAllEffect(count, filter).apply(game, source);
        count++;
    }
    return true;
}
Also used : Player(mage.players.Player) CardType(mage.constants.CardType) SacrificeAllEffect(mage.abilities.effects.common.SacrificeAllEffect) ChoiceImpl(mage.choices.ChoiceImpl) FilterControlledPermanent(mage.filter.common.FilterControlledPermanent)

Example 29 with ChoiceImpl

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

the class AquamorphEntityReplacementEffect method replaceEvent.

@Override
public boolean replaceEvent(GameEvent event, Ability source, Game game) {
    Permanent permanent;
    if (event instanceof EntersTheBattlefieldEvent) {
        permanent = ((EntersTheBattlefieldEvent) event).getTarget();
    } else {
        permanent = game.getPermanent(event.getTargetId());
    }
    if (permanent == null) {
        return false;
    }
    Choice choice = new ChoiceImpl(true);
    choice.setMessage("Choose what the creature becomes to");
    choice.getChoices().add(choice51);
    choice.getChoices().add(choice15);
    Player controller = game.getPlayer(source.getControllerId());
    if (controller != null && !controller.choose(Outcome.Neutral, choice, game)) {
        discard();
        return false;
    }
    int power = 0;
    int toughness = 0;
    switch(choice.getChoice()) {
        case choice51:
            power = 5;
            toughness = 1;
            break;
        case choice15:
            power = 1;
            toughness = 5;
            break;
    }
    game.addEffect(new SetPowerToughnessSourceEffect(power, toughness, Duration.Custom, SubLayer.SetPT_7b), source);
    return true;
}
Also used : SetPowerToughnessSourceEffect(mage.abilities.effects.common.continuous.SetPowerToughnessSourceEffect) Player(mage.players.Player) Choice(mage.choices.Choice) Permanent(mage.game.permanent.Permanent) EntersTheBattlefieldEvent(mage.game.events.EntersTheBattlefieldEvent) ChoiceImpl(mage.choices.ChoiceImpl)

Example 30 with ChoiceImpl

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

the class ButcherOfTheHordeEffect 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(VigilanceAbility.getInstance().getRule());
        abilities.add(LifelinkAbility.getInstance().getRule());
        abilities.add(HasteAbility.getInstance().getRule());
        abilityChoice.setChoices(abilities);
        controller.choose(Outcome.AddAbility, abilityChoice, game);
        if (!abilityChoice.isChosen()) {
            return false;
        }
        String chosen = abilityChoice.getChoice();
        Ability ability = null;
        if (VigilanceAbility.getInstance().getRule().equals(chosen)) {
            ability = VigilanceAbility.getInstance();
        } else if (LifelinkAbility.getInstance().getRule().equals(chosen)) {
            ability = LifelinkAbility.getInstance();
        } else if (HasteAbility.getInstance().getRule().equals(chosen)) {
            ability = HasteAbility.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 : SimpleActivatedAbility(mage.abilities.common.SimpleActivatedAbility) HasteAbility(mage.abilities.keyword.HasteAbility) LifelinkAbility(mage.abilities.keyword.LifelinkAbility) VigilanceAbility(mage.abilities.keyword.VigilanceAbility) FlyingAbility(mage.abilities.keyword.FlyingAbility) 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)

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