Search in sources :

Example 66 with ChoiceImpl

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

the class VivienMonstersAdvocateTriggeredAbility method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player player = game.getPlayer(source.getControllerId());
    if (player == null) {
        return false;
    }
    token.putOntoBattlefield(1, game, source, source.getControllerId());
    for (UUID tokenId : token.getLastAddedTokenIds()) {
        Permanent permanent = game.getPermanent(tokenId);
        if (permanent == null) {
            continue;
        }
        Choice choice = new ChoiceImpl(true);
        choice.setMessage("Choose vigilance, reach, or trample counter");
        choice.setChoices(choices);
        player.choose(outcome, choice, game);
        String chosen = choice.getChoice();
        if (chosen != null) {
            permanent.addCounters(CounterType.findByName(chosen.toLowerCase(Locale.ENGLISH)).createInstance(), source.getControllerId(), source, game);
        }
    }
    return true;
}
Also used : Player(mage.players.Player) Choice(mage.choices.Choice) Permanent(mage.game.permanent.Permanent) ChoiceImpl(mage.choices.ChoiceImpl) UUID(java.util.UUID)

Example 67 with ChoiceImpl

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

the class ContinuousEffects method asThough.

/**
 * @param objectId        object to check
 * @param type
 * @param affectedAbility null if check full object or ability if check only one ability from that object
 * @param controllerId
 * @param game
 * @return sourceId of the permitting effect if any exists otherwise returns null
 */
public ApprovingObject asThough(UUID objectId, AsThoughEffectType type, Ability affectedAbility, UUID controllerId, Game game) {
    // usage check: effect must apply for specific ability only, not to full object (example: PLAY_FROM_NOT_OWN_HAND_ZONE)
    if (type.needAffectedAbility() && affectedAbility == null) {
        throw new IllegalArgumentException("ERROR, you can't call asThough check to whole object, call it with affected ability instead: " + type);
    }
    // need it then disable that check or add extra param to AsThoughEffectType like needAffectedAbilityOrFullObject
    if (!type.needAffectedAbility() && affectedAbility != null) {
        throw new IllegalArgumentException("ERROR, you can't call AsThough check to affected ability, call it with empty affected ability instead: " + type);
    }
    List<AsThoughEffect> asThoughEffectsList = getApplicableAsThoughEffects(type, game);
    if (!asThoughEffectsList.isEmpty()) {
        MageObject objectToCheck;
        if (affectedAbility != null) {
            objectToCheck = affectedAbility.getSourceObject(game);
        } else {
            objectToCheck = game.getCard(objectId);
        }
        UUID idToCheck;
        if (!type.needPlayCardAbility() && objectToCheck instanceof SplitCardHalf) {
            // each split side uses own characteristics to check for playing, all other cases must use main card
            // rules:
            // 708.4. In every zone except the stack, the characteristics of a split card are those of its two halves combined.
            idToCheck = ((SplitCardHalf) objectToCheck).getMainCard().getId();
        } else if (!type.needPlayCardAbility() && objectToCheck instanceof AdventureCardSpell) {
            // adventure spell uses alternative characteristics for spell/stack, all other cases must use main card
            idToCheck = ((AdventureCardSpell) objectToCheck).getMainCard().getId();
        } else if (!type.needPlayCardAbility() && objectToCheck instanceof ModalDoubleFacesCardHalf) {
            // each mdf side uses own characteristics to check for playing, all other cases must use main card
            // rules:
            // "If an effect allows you to play a land or cast a spell from among a group of cards,
            // you may play or cast a modal double-faced card with any face that fits the criteria
            // of that effect. For example, if Sejiri Shelter / Sejiri Glacier is in your graveyard
            // and an effect allows you to play lands from your graveyard, you could play Sejiri Glacier.
            // That effect doesn't allow you to cast Sejiri Shelter."
            idToCheck = ((ModalDoubleFacesCardHalf) objectToCheck).getMainCard().getId();
        } else {
            idToCheck = objectId;
        }
        Set<ApprovingObject> possibleApprovingObjects = new HashSet<>();
        for (AsThoughEffect effect : asThoughEffectsList) {
            Set<Ability> abilities = asThoughEffectsMap.get(type).getAbility(effect.getId());
            for (Ability ability : abilities) {
                if (affectedAbility == null) {
                    // applies to full object (one effect can be used in multiple abilities)
                    if (effect.applies(idToCheck, ability, controllerId, game)) {
                        if (effect.isConsumable() && !game.inCheckPlayableState()) {
                            possibleApprovingObjects.add(new ApprovingObject(ability, game));
                        } else {
                            return new ApprovingObject(ability, game);
                        }
                    }
                } else {
                    // filter play abilities (no need to check it in every effect's code)
                    if (type.needPlayCardAbility() && !affectedAbility.getAbilityType().isPlayCardAbility()) {
                        continue;
                    }
                    if (effect.applies(idToCheck, affectedAbility, ability, game, controllerId)) {
                        if (effect.isConsumable() && !game.inCheckPlayableState()) {
                            possibleApprovingObjects.add(new ApprovingObject(ability, game));
                        } else {
                            return new ApprovingObject(ability, game);
                        }
                    }
                }
            }
        }
        if (possibleApprovingObjects.size() == 1) {
            return possibleApprovingObjects.iterator().next();
        } else if (possibleApprovingObjects.size() > 1) {
            // Select the ability that you use to permit the action
            Map<String, String> keyChoices = new HashMap<>();
            for (ApprovingObject approvingObject : possibleApprovingObjects) {
                MageObject mageObject = game.getObject(approvingObject.getApprovingAbility().getSourceId());
                String choiceKey = approvingObject.getApprovingAbility().getId().toString();
                String choiceValue;
                if (mageObject == null) {
                    choiceValue = approvingObject.getApprovingAbility().getRule();
                } else {
                    choiceValue = mageObject.getIdName() + ": " + approvingObject.getApprovingAbility().getRule(mageObject.getName());
                }
                keyChoices.put(choiceKey, choiceValue);
            }
            Choice choicePermitting = new ChoiceImpl(true);
            choicePermitting.setMessage("Choose the permitting object");
            choicePermitting.setKeyChoices(keyChoices);
            Player player = game.getPlayer(controllerId);
            player.choose(Outcome.Detriment, choicePermitting, game);
            for (ApprovingObject approvingObject : possibleApprovingObjects) {
                if (approvingObject.getApprovingAbility().getId().toString().equals(choicePermitting.getChoiceKey())) {
                    return approvingObject;
                }
            }
        }
    }
    return null;
}
Also used : StaticAbility(mage.abilities.StaticAbility) Ability(mage.abilities.Ability) Player(mage.players.Player) ApprovingObject(mage.ApprovingObject) Choice(mage.choices.Choice) MageObject(mage.MageObject) ChoiceImpl(mage.choices.ChoiceImpl)

Example 68 with ChoiceImpl

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

the class GiantSlugEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    Permanent sourcePermanent = game.getPermanentOrLKIBattlefield(source.getSourceId());
    if (controller == null || sourcePermanent == null) {
        return false;
    }
    ChoiceImpl choices = new ChoiceBasicLandType();
    if (!controller.choose(outcome, choices, game)) {
        return false;
    }
    game.informPlayers(sourcePermanent.getName() + ":  Chosen basic land type is " + choices.getChoice());
    switch(choices.getChoice()) {
        case "Plains":
            game.addEffect(new GainAbilitySourceEffect(new PlainswalkAbility(), Duration.EndOfTurn, false), source);
            return true;
        case "Island":
            game.addEffect(new GainAbilitySourceEffect(new IslandwalkAbility(), Duration.EndOfTurn, false), source);
            return true;
        case "Swamp":
            game.addEffect(new GainAbilitySourceEffect(new SwampwalkAbility(), Duration.EndOfTurn, false), source);
            return true;
        case "Mountain":
            game.addEffect(new GainAbilitySourceEffect(new MountainwalkAbility(), Duration.EndOfTurn, false), source);
            return true;
        case "Forest":
            game.addEffect(new GainAbilitySourceEffect(new ForestwalkAbility(), Duration.EndOfTurn, false), source);
            return true;
        default:
            return false;
    }
}
Also used : Player(mage.players.Player) Permanent(mage.game.permanent.Permanent) GainAbilitySourceEffect(mage.abilities.effects.common.continuous.GainAbilitySourceEffect) ChoiceImpl(mage.choices.ChoiceImpl) ChoiceBasicLandType(mage.choices.ChoiceBasicLandType)

Example 69 with ChoiceImpl

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

the class GolemArtisanEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Permanent permanent = game.getPermanent(targetPointer.getFirst(game, source));
    Player playerControls = game.getPlayer(source.getControllerId());
    if (permanent != null && playerControls != null) {
        Choice abilityChoice = new ChoiceImpl();
        abilityChoice.setMessage("Choose an ability to add");
        Set<String> abilities = new HashSet<>();
        abilities.add(FlyingAbility.getInstance().getRule());
        abilities.add(TrampleAbility.getInstance().getRule());
        abilities.add(HasteAbility.getInstance().getRule());
        abilityChoice.setChoices(abilities);
        if (!playerControls.choose(Outcome.AddAbility, abilityChoice, game)) {
            return false;
        }
        String chosen = abilityChoice.getChoice();
        Ability ability = null;
        if (FlyingAbility.getInstance().getRule().equals(chosen)) {
            ability = FlyingAbility.getInstance();
        } else if (TrampleAbility.getInstance().getRule().equals(chosen)) {
            ability = TrampleAbility.getInstance();
        } else if (HasteAbility.getInstance().getRule().equals(chosen)) {
            ability = HasteAbility.getInstance();
        }
        if (ability != null) {
            ContinuousEffect effect = new GainAbilityTargetEffect(ability, Duration.EndOfTurn);
            game.addEffect(effect, source);
            return true;
        }
    }
    return false;
}
Also used : HasteAbility(mage.abilities.keyword.HasteAbility) FlyingAbility(mage.abilities.keyword.FlyingAbility) SimpleActivatedAbility(mage.abilities.common.SimpleActivatedAbility) TrampleAbility(mage.abilities.keyword.TrampleAbility) Ability(mage.abilities.Ability) Player(mage.players.Player) Choice(mage.choices.Choice) Permanent(mage.game.permanent.Permanent) TargetCreaturePermanent(mage.target.common.TargetCreaturePermanent) GainAbilityTargetEffect(mage.abilities.effects.common.continuous.GainAbilityTargetEffect) ChoiceImpl(mage.choices.ChoiceImpl) ContinuousEffect(mage.abilities.effects.ContinuousEffect) HashSet(java.util.HashSet)

Example 70 with ChoiceImpl

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

the class KatildaDawnhartPrimeManaEffect method produceMana.

@Override
public Mana produceMana(Game game, Ability source) {
    Mana mana = new Mana();
    if (game != null) {
        Player controller = game.getPlayer(source.getControllerId());
        Permanent permanent = source.getSourcePermanentIfItStillExists(game);
        if (controller != null && permanent != null) {
            Choice choice = new ChoiceImpl();
            choice.setMessage("Pick a mana color");
            ObjectColor color = permanent.getColor(game);
            if (color.isWhite()) {
                choice.getChoices().add("White");
            }
            if (color.isBlue()) {
                choice.getChoices().add("Blue");
            }
            if (color.isBlack()) {
                choice.getChoices().add("Black");
            }
            if (color.isRed()) {
                choice.getChoices().add("Red");
            }
            if (color.isGreen()) {
                choice.getChoices().add("Green");
            }
            if (!choice.getChoices().isEmpty()) {
                if (choice.getChoices().size() == 1) {
                    choice.setChoice(choice.getChoices().iterator().next());
                } else {
                    controller.choose(outcome, choice, game);
                }
                if (choice.getChoice() != null) {
                    switch(choice.getChoice()) {
                        case "White":
                            mana.setWhite(1);
                            break;
                        case "Blue":
                            mana.setBlue(1);
                            break;
                        case "Black":
                            mana.setBlack(1);
                            break;
                        case "Red":
                            mana.setRed(1);
                            break;
                        case "Green":
                            mana.setGreen(1);
                            break;
                    }
                }
            }
        }
    }
    return mana;
}
Also used : Player(mage.players.Player) Mana(mage.Mana) Choice(mage.choices.Choice) FilterPermanent(mage.filter.FilterPermanent) FilterControlledCreaturePermanent(mage.filter.common.FilterControlledCreaturePermanent) Permanent(mage.game.permanent.Permanent) ObjectColor(mage.ObjectColor) 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