Search in sources :

Example 41 with Choice

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

the class BecomesChosenCreatureTypeTargetEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player player = game.getPlayer(source.getControllerId());
    Card card = game.getCard(source.getSourceId());
    String chosenType = "";
    if (player != null && card != null) {
        Choice typeChoice = new ChoiceCreatureType();
        String msg = "Choose a creature type";
        if (nonWall) {
            msg += " other than Wall";
        }
        typeChoice.setMessage(msg);
        if (nonWall) {
            typeChoice.getChoices().remove(SubType.WALL.getDescription());
        }
        while (!player.choose(Outcome.BoostCreature, typeChoice, game)) {
            if (!player.canRespond()) {
                return false;
            }
        }
        game.informPlayers(card.getName() + ": " + player.getLogName() + " has chosen " + typeChoice.getChoice());
        chosenType = typeChoice.getChoice();
        if (chosenType != null && !chosenType.isEmpty()) {
            // ADD TYPE TO TARGET
            ContinuousEffect effect = new BecomesCreatureTypeTargetEffect(duration, SubType.byDescription(chosenType));
            effect.setTargetPointer(new FixedTarget(getTargetPointer().getFirst(game, source), game));
            game.addEffect(effect, source);
            return true;
        }
    }
    return false;
}
Also used : FixedTarget(mage.target.targetpointer.FixedTarget) Player(mage.players.Player) Choice(mage.choices.Choice) ChoiceCreatureType(mage.choices.ChoiceCreatureType) ContinuousEffect(mage.abilities.effects.ContinuousEffect) Card(mage.cards.Card)

Example 42 with Choice

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

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

Example 44 with Choice

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

the class DwarvenArmorerEffect 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 type of counter to add");
        choice.setChoices(choices);
        if (controller.choose(outcome, choice, game)) {
            Counter counter = choice.getChoice().equals("+0/+1") ? CounterType.P0P1.createInstance() : CounterType.P1P0.createInstance();
            Effect effect = new AddCountersTargetEffect(counter);
            effect.setTargetPointer(new FixedTarget(this.getTargetPointer().getFirst(game, source), game));
            return effect.apply(game, source);
        }
    }
    return false;
}
Also used : FixedTarget(mage.target.targetpointer.FixedTarget) Player(mage.players.Player) Choice(mage.choices.Choice) Counter(mage.counters.Counter) ChoiceImpl(mage.choices.ChoiceImpl) AddCountersTargetEffect(mage.abilities.effects.common.counter.AddCountersTargetEffect) OneShotEffect(mage.abilities.effects.OneShotEffect) Effect(mage.abilities.effects.Effect) AddCountersTargetEffect(mage.abilities.effects.common.counter.AddCountersTargetEffect)

Example 45 with Choice

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

the class GraveSifterEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Choice typeChoice = new ChoiceCreatureType(game.getObject(source.getSourceId()));
    typeChoice.setMessage("Choose creature type to return cards from your graveyard");
    Player controller = game.getPlayer(source.getControllerId());
    Set<Card> toHand = new HashSet<>();
    if (controller != null) {
        for (UUID playerId : game.getState().getPlayersInRange(controller.getId(), game)) {
            Player player = game.getPlayer(playerId);
            if (player != null) {
                typeChoice.clearChoice();
                if (player.choose(outcome, typeChoice, game)) {
                    game.informPlayers(player.getLogName() + " has chosen: " + typeChoice.getChoice());
                    FilterCard filter = new FilterCreatureCard("creature cards with creature type " + typeChoice.getChoice() + " from your graveyard");
                    filter.add(SubType.byDescription(typeChoice.getChoice()).getPredicate());
                    Target target = new TargetCardInYourGraveyard(0, Integer.MAX_VALUE, filter);
                    player.chooseTarget(outcome, target, source, game);
                    toHand.addAll(new CardsImpl(target.getTargets()).getCards(game));
                }
            }
        }
        // must happen simultaneously Rule 101.4
        controller.moveCards(toHand, Zone.HAND, source, game, false, false, true, null);
        return true;
    }
    return false;
}
Also used : FilterCard(mage.filter.FilterCard) Player(mage.players.Player) FilterCreatureCard(mage.filter.common.FilterCreatureCard) Target(mage.target.Target) Choice(mage.choices.Choice) ChoiceCreatureType(mage.choices.ChoiceCreatureType) TargetCardInYourGraveyard(mage.target.common.TargetCardInYourGraveyard) UUID(java.util.UUID) CardsImpl(mage.cards.CardsImpl) FilterCard(mage.filter.FilterCard) FilterCreatureCard(mage.filter.common.FilterCreatureCard) Card(mage.cards.Card) HashSet(java.util.HashSet)

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