Search in sources :

Example 1 with AbilitiesImpl

use of mage.abilities.AbilitiesImpl in project mage by magefree.

the class StackObjectImpl method chooseNewTargets.

/**
 * 114.6. Some effects allow a player to change the target(s) of a spell or
 * ability, and other effects allow a player to choose new targets for a
 * spell or ability.
 * <p>
 * 114.6a If an effect allows a player to "change the target(s)" of a spell
 * or ability, each target can be changed only to another legal target. If a
 * target can't be changed to another legal target, the original target is
 * unchanged, even if the original target is itself illegal by then. If all
 * the targets aren't changed to other legal targets, none of them are
 * changed.
 * <p>
 * 114.6b If an effect allows a player to "change a target" of a spell or
 * ability, the process described in rule 114.6a is followed, except that
 * only one of those targets may be changed (rather than all of them or none
 * of them).
 * <p>
 * 114.6c If an effect allows a player to "change any targets" of a spell or
 * ability, the process described in rule 114.6a is followed, except that
 * any number of those targets may be changed (rather than all of them or
 * none of them).
 * <p>
 * 114.6d If an effect allows a player to "choose new targets" for a spell
 * or ability, the player may leave any number of the targets unchanged,
 * even if those targets would be illegal. If the player chooses to change
 * some or all of the targets, the new targets must be legal and must not
 * cause any unchanged targets to become illegal.
 * <p>
 * 114.6e When changing targets or choosing new targets for a spell or
 * ability, only the final set of targets is evaluated to determine whether
 * the change is legal.
 * <p>
 * Example: Arc Trail is a sorcery that reads "Arc Trail deals 2 damage to
 * any target and 1 damage to another target creature or player." The
 * current targets of Arc Trail are Runeclaw Bear and Llanowar Elves, in
 * that order. You cast Redirect, an instant that reads "You may choose new
 * targets for target spell," targeting Arc Trail. You can change the first
 * target to Llanowar Elves and change the second target to Runeclaw Bear.
 * <p>
 * 114.7. Modal spells and abilities may have different targeting
 * requirements for each mode. An effect that allows a player to change the
 * target(s) of a modal spell or ability, or to choose new targets for a
 * modal spell or ability, doesn't allow that player to change its mode.
 * (See rule 700.2.)
 * <p>
 * 706.10c Some effects copy a spell or ability and state that its
 * controller may choose new targets for the copy. The player may leave any
 * number of the targets unchanged, even if those targets would be illegal.
 * If the player chooses to change some or all of the targets, the new
 * targets must be legal. Once the player has decided what the copy's
 * targets will be, the copy is put onto the stack with those targets.
 *
 * @param game
 * @param targetControllerId       - player that can/has to change the target of
 *                                 the spell
 * @param forceChange              - does only work for targets with maximum of one
 *                                 targetId
 * @param onlyOneTarget            - 114.6b one target must be changed to another
 *                                 target
 * @param newTargetFilterPredicate restriction for the new target (null - can select same targets)
 * @return
 */
@Override
public boolean chooseNewTargets(Game game, UUID targetControllerId, boolean forceChange, boolean onlyOneTarget, Predicate<MageItem> newTargetFilterPredicate) {
    Player targetController = game.getPlayer(targetControllerId);
    if (targetController != null) {
        StringBuilder oldTargetDescription = new StringBuilder();
        StringBuilder newTargetDescription = new StringBuilder();
        // Fused split spells or spells where "Splice on Arcane" was used can have more than one ability
        Abilities<Ability> objectAbilities = new AbilitiesImpl<>();
        if (this instanceof Spell) {
            objectAbilities.addAll(((Spell) this).getSpellAbilities());
        } else {
            objectAbilities.add(getStackAbility());
        }
        for (Ability ability : objectAbilities) {
            // Some spells can have more than one mode
            for (UUID modeId : ability.getModes().getSelectedModes()) {
                Mode mode = ability.getModes().get(modeId);
                ability.getModes().setActiveMode(mode);
                oldTargetDescription.append(ability.getTargetDescription(mode.getTargets(), game));
                for (Target target : mode.getTargets()) {
                    Target newTarget = chooseNewTarget(targetController, ability, mode, target, forceChange, newTargetFilterPredicate, game);
                    // clear the old target and copy all targets from new target
                    target.clearChosen();
                    for (UUID targetId : newTarget.getTargets()) {
                        target.addTarget(targetId, newTarget.getTargetAmount(targetId), ability, game, false);
                    }
                }
                newTargetDescription.append(ability.getTargetDescription(mode.getTargets(), game));
            }
        }
        if (!newTargetDescription.toString().equals(oldTargetDescription.toString()) && !game.isSimulation()) {
            game.informPlayers(this.getLogName() + " is now " + newTargetDescription);
        }
        return true;
    }
    return false;
}
Also used : Ability(mage.abilities.Ability) AbilitiesImpl(mage.abilities.AbilitiesImpl) Player(mage.players.Player) Target(mage.target.Target) Mode(mage.abilities.Mode)

Example 2 with AbilitiesImpl

use of mage.abilities.AbilitiesImpl in project mage by magefree.

the class SplitCard method getAbilities.

@Override
public Abilities<Ability> getAbilities(Game game) {
    Abilities<Ability> allAbilites = new AbilitiesImpl<>();
    for (Ability ability : super.getAbilities(game)) {
        // TODO: why it here, for GUI's cleanup in card texts? Maybe it can be removed, see mdf cards
        if (ability instanceof SpellAbility && (((SpellAbility) ability).getSpellAbilityType() == SpellAbilityType.SPLIT || ((SpellAbility) ability).getSpellAbilityType() == SpellAbilityType.SPLIT_AFTERMATH)) {
            continue;
        }
        allAbilites.add(ability);
    }
    allAbilites.addAll(leftHalfCard.getAbilities(game));
    allAbilites.addAll(rightHalfCard.getAbilities(game));
    return allAbilites;
}
Also used : SpellAbility(mage.abilities.SpellAbility) Ability(mage.abilities.Ability) AbilitiesImpl(mage.abilities.AbilitiesImpl) SpellAbility(mage.abilities.SpellAbility)

Example 3 with AbilitiesImpl

use of mage.abilities.AbilitiesImpl in project mage by magefree.

the class SplitCard method getAbilities.

@Override
public Abilities<Ability> getAbilities() {
    Abilities<Ability> allAbilites = new AbilitiesImpl<>();
    for (Ability ability : super.getAbilities()) {
        // TODO: why it here, for GUI's cleanup in card texts? Maybe it can be removed, see mdf cards
        if (ability instanceof SpellAbility && (((SpellAbility) ability).getSpellAbilityType() == SpellAbilityType.SPLIT || ((SpellAbility) ability).getSpellAbilityType() == SpellAbilityType.SPLIT_AFTERMATH)) {
            continue;
        }
        allAbilites.add(ability);
    }
    allAbilites.addAll(leftHalfCard.getAbilities());
    allAbilites.addAll(rightHalfCard.getAbilities());
    return allAbilites;
}
Also used : SpellAbility(mage.abilities.SpellAbility) Ability(mage.abilities.Ability) AbilitiesImpl(mage.abilities.AbilitiesImpl) SpellAbility(mage.abilities.SpellAbility)

Aggregations

AbilitiesImpl (mage.abilities.AbilitiesImpl)3 Ability (mage.abilities.Ability)3 SpellAbility (mage.abilities.SpellAbility)2 Mode (mage.abilities.Mode)1 Player (mage.players.Player)1 Target (mage.target.Target)1